Разбивка данных на части по дням
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include "csv_loader.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
int main() {
|
||||
auto records = load_csv("data/data.csv");
|
||||
@@ -14,4 +15,13 @@ int main() {
|
||||
<< records[i].close << " "
|
||||
<< 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";
|
||||
}
|
||||
}
|
||||
|
||||
25
bitcoin-project/src/utils.cpp
Normal file
25
bitcoin-project/src/utils.cpp
Normal 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;
|
||||
}
|
||||
|
||||
11
bitcoin-project/src/utils.hpp
Normal file
11
bitcoin-project/src/utils.hpp
Normal 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);
|
||||
|
||||
Reference in New Issue
Block a user