116 cfg[
"active_topics"].as_array()->for_each(
117 [&](
auto &e) { _topics.push_back(e.value_or(
"undefined")); });
118 for (
auto &t : _topics) {
119 if (!cfg[
"topics"][t].is_table()) {
120 cerr << fg::red <<
"Topic " << t <<
" is not defined" << fg::reset
124 auto tab = cfg[
"topics"][t];
125 auto type = tab[
"type"].value_or(
"undefined");
126 _topic_freqs[t] = tab[
"frequency"].value_or(1);
127 if (type ==
"arima"s) {
128 _topic_type[t] =
"arima";
129 map<string, ARIMA> m{};
130 tab[
"content"].as_table()->for_each([&](
auto &k,
auto &v) {
131 m[
static_cast<string>(k)] =
ARIMA();
132 m[
static_cast<string>(k)].p.clear();
133 m[
static_cast<string>(k)].q.clear();
134 v.as_table()->at(
"p").as_array()->for_each([&](
auto &e) {
135 m[
static_cast<string>(k)].p.push_back(
136 e.as_floating_point()->value_or(0));
138 m[
static_cast<string>(k)].d = v.as_table()->at(
"d").value_or(0);
139 v.as_table()->at(
"q").as_array()->for_each([&](
auto &e) {
140 m[
static_cast<string>(k)].q.push_back(
141 e.as_floating_point()->value_or(0));
143 m[
static_cast<string>(k)].sigma =
144 v.as_table()->at(
"s").as_floating_point()->value_or(0.5);
145 if (v.as_table()->contains(
"start")) {
147 v.as_table()->at(
"start").as_floating_point()->value_or(0);
148 m[
static_cast<string>(k)].reset(x0);
150 m[
static_cast<string>(k)].reset();
154 }
else if (type ==
"bits"s) {
155 _topic_type[t] =
"bits";
156 map<string, double> m{};
157 tab[
"content"].as_table()->for_each([&](
auto &k,
auto &v) {
158 m[
static_cast<string>(k)] = v.as_floating_point()->value_or(0.5);
161 }
else if (type ==
"gpio"s) {
162 _topic_type[t] =
"gpio";
163 map<string, list<int>> m{{
"lines", {}}};
164 tab[
"content"][
"lines"].as_array()->for_each(
165 [&](
auto &e) { m[
"lines"].push_back(e.value_or(0)); });
167 }
else if (type ==
"image"s) {
168 _topic_type[t] =
"image";
169 map<string, unsigned int> m{};
170 m[
"width"] = tab[
"content"][
"size"].as_array()->at(0).value_or(0);
171 m[
"height"] = tab[
"content"][
"size"].as_array()->at(1).value_or(1);
172 m[
"levels"] = tab[
"content"][
"levels"].value_or(256);
174 }
else if (type ==
"matrix"s) {
175 _topic_type[t] =
"matrix";
176 map<string, double> m{};
177 m[
"width"] = tab[
"content"][
"size"].as_array()->at(0).value_or(0);
178 m[
"height"] = tab[
"content"][
"size"].as_array()->at(1).value_or(1);
179 m[
"mean"] = tab[
"content"][
"mean"].as_floating_point()->value_or(0);
180 m[
"std"] = tab[
"content"][
"std"].as_floating_point()->value_or(0);
183 cerr << fg::red <<
"Undefined topic type (topic " << t <<
")"
184 << fg::reset << endl;
191 for (
auto &t : _topics) {
192 if (_topic_type[t] ==
"arima") {
193 auto m = any_cast<map<string, ARIMA>>(_topic_data[t]);
195 data[t][e.first] = e.second.next();
197 }
else if (_topic_type[t] ==
"gpio") {
198 auto m = any_cast<map<string, list<int>>>(_topic_data[t]);
199 for (
auto &l : m[
"lines"]) {
200 data[t][to_string(l)] =
201 static_cast<int>(round(arma::randu(arma::distr_param(0, 1))));
203 }
else if (_topic_type[t] ==
"image") {
204 auto m = any_cast<map<string, unsigned int>>(_topic_data[t]);
205 data[t][
"width"] = m[
"width"];
206 data[t][
"height"] = m[
"height"];
207 data[t][
"levels"] = m[
"levels"];
208 data[t][
"data"] = arma::randi<arma::Mat<unsigned int>>(
209 m[
"height"], m[
"width"], arma::distr_param(0, m[
"levels"]));
210 }
else if (_topic_type[t] ==
"matrix") {
211 auto m = any_cast<map<string, double>>(_topic_data[t]);
212 data[t][
"width"] = m[
"width"];
213 data[t][
"height"] = m[
"height"];
214 data[t][
"mean"] = m[
"mean"];
215 data[t][
"std"] = m[
"std"];
216 data[t][
"data"] = arma::randn<arma::Mat<double>>(
217 m[
"height"], m[
"width"], arma::distr_param(m[
"mean"], m[
"std"]));
218 }
else if (_topic_type[t] ==
"bits") {
219 auto m = any_cast<map<string, double>>(_topic_data[t]);
220 for (
auto &[k, v] : m) {
221 data[t][k] = (arma::randu(arma::distr_param(0, 1)) > v ? 1 : 0);