Разбивка данных на части по дням

This commit is contained in:
2025-12-01 12:12:16 +00:00
parent 1ca544105e
commit cb82dda2c1
3 changed files with 46 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
#include <iostream> #include <iostream>
#include "csv_loader.hpp" #include "csv_loader.hpp"
#include "utils.hpp"
int main() { int main() {
auto records = load_csv("data/data.csv"); auto records = load_csv("data/data.csv");
@@ -14,4 +15,13 @@ int main() {
<< records[i].close << " " << records[i].close << " "
<< records[i].volume << "\n"; << records[i].volume << "\n";
} }
auto days = group_by_day(records);
std::cout << "Total days: " << days.size() << "\n";
auto parts = split_days(days, 4);
for (int i = 0; i < 4; i++) {
std::cout << "Part " << i << " has " << parts[i].size() << " days:\n";
}
} }

View File

@@ -0,0 +1,25 @@
#include "utils.hpp"
std::map<DayIndex, std::vector<Record>> group_by_day(const std::vector<Record>& recs) {
std::map<DayIndex, std::vector<Record>> days;
for (const auto& r : recs) {
DayIndex day = static_cast<DayIndex>(r.timestamp) / 86400;
days[day].push_back(r);
}
return days;
}
std::vector<std::vector<DayIndex>> split_days(const std::map<DayIndex, std::vector<Record>>& days, int parts) {
std::vector<std::vector<DayIndex>> out(parts);
int i = 0;
for (auto& kv : days) {
out[i % parts].push_back(kv.first);
i++;
}
return out;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include "record.hpp"
#include <map>
#include <vector>
using DayIndex = long long;
std::map<DayIndex, std::vector<Record>> group_by_day(const std::vector<Record>& recs);
std::vector<std::vector<DayIndex>> split_days(const std::map<DayIndex, std::vector<Record>>& days, int parts);