#include "fx/constants.h"
#include <string>
#include <string_view>
#include <vector>
Go to the source code of this file.
|
| std::string | epoch_to_utc (const size_t) |
| | Routine to convert epoch seconds to a UTC time string.
|
| std::string | file_read (const std::string_view) |
| | Open a file a return a string of the contents.
|
| std::vector< std::vector< double > > | to_series (const std::string) |
| | Open a CSV file and return a vector of floating points for each row.
|
| std::vector< std::vector< double > > | to_series3 (const std::string &) |
| | Open a CSV file and return a vector of floating points for each row.
|
| std::vector< std::vector< double > > | to_series4 (const std::string &) |
| | Open a CSV file and return a vector of floating points for each row.
|
◆ epoch_to_utc()
| std::string epoch_to_utc |
( |
const size_t | epoch | ) |
|
Routine to convert epoch seconds to a UTC time string.
Definition at line 7 of file time.cxx.
7 {
9 std::tm tm = *std::gmtime(&t);
10 std::ostringstream oss;
11 oss << std::put_time(&tm, "%Y-%m-%d %H:%M:%S");
12 return oss.str();
13}
◆ file_read()
| std::string file_read |
( |
const std::string_view | file_name | ) |
|
Open a file a return a string of the contents.
Open file and return the contents as a string
Definition at line 12 of file file.cxx.
12 {
13
14
15 std::ifstream in{std::string{file_name}};
16
17 if (not in.good())
18 return {};
19
20
21 in.seekg(0, std::ios::end);
22
23
24 std::string out(in.tellg(), '\0');
25
26
27 in.seekg(0, std::ios::beg);
28
29
30 in.read(out.data(), out.size());
31
32 return out;
33}
◆ to_series()
| std::vector< std::vector< double > > to_series |
( |
const std::string | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 78 of file file.cxx.
78 {
79
80
81 std::istringstream in{csv};
82 std::ranges::istream_view<std::string> rows(in);
83
84
85 return rows | std::views::drop(1) | std::views::transform(
split_on_comma)
86 | std::ranges::to<std::vector<std::vector<double>>>();
87};
const auto split_on_comma
Take a row of data, split on delimiter and return a row of floating points.
◆ to_series3()
| std::vector< std::vector< double > > to_series3 |
( |
const std::string & | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 90 of file file.cxx.
90 {
91
92
93 std::istringstream in{csv};
94 std::ranges::istream_view<std::string> rows(in);
95
96
97 auto &&px =
99
100
102
103
104 auto &&series = std::vector<std::vector<double>>{};
105
106 for (auto v : px) {
107
108
109 std::ranges::copy(v, std::begin(xs));
110
111
112 series.emplace_back(xs);
113 }
114
115 return std::move(series);
116};
const auto split_on_comma2
Take a row of data, split on delimiter and return a row of floating points.
const std::vector< std::vector< double > > xs
An example of a full set of price data.
constexpr auto cells
Number of cells in a row of price data.
◆ to_series4()
| std::vector< std::vector< double > > to_series4 |
( |
const std::string & | csv | ) |
|
Open a CSV file and return a vector of floating points for each row.
Definition at line 119 of file file.cxx.
119 {
120
121
122 std::istringstream in{csv};
123 std::ranges::istream_view<std::string> rows(in);
124
125
126 auto &&px =
128
129
130 auto &&series = std::vector<std::vector<double>>{};
131 series.reserve(std::ranges::distance(px));
132
133 std::ranges::transform(px, std::back_inserter(series), [&](auto &&v) {
134
136 std::ranges::copy(v, std::begin(xs));
138 });
139
140 return series;
141};