16#include <fmt/format.h>
17#include <nlohmann/json.hpp>
28nlohmann::json
get(
const nlohmann::json &j,
const std::string &key);
36template <
class T>
bool get_to(
const nlohmann::json &j,
const std::string &key, T &out)
noexcept {
38 out = j.at(key).get<T>();
40 }
catch (
const nlohmann::json::out_of_range &) {
41 fmt::print(fg(fmt::color::red),
"Missing key \"{}\"\n", key);
43 }
catch (
const nlohmann::json::type_error &) {
44 fmt::print(fg(fmt::color::red),
"Key \"{}\" is of wrong type\n", key);
57bool get_to(
const nlohmann::json &j,
const std::string &key, T &out,
bool &success)
noexcept {
58 const bool ret =
get_to(j, key, out);
69void rebase_valid_path(std::filesystem::path &path,
const std::filesystem::path &base_dir);
78 std::filesystem::path &out,
79 const std::filesystem::path &base_dir)
noexcept;
88 std::filesystem::path &out,
const std::filesystem::path &base_dir,
89 bool &success)
noexcept;
96FileInfo
get_file_info(
const nlohmann::json &node,
const std::filesystem::path &base_dir);
109BaselineInfo
get_baseline_info(
const nlohmann::json &j,
const std::filesystem::path &base_dir);
119 if (!opt.contains(
"project_requirements")) {
122 if (opt.contains(
"trend_type") || opt.contains(
"income_categories")) {
124 "Deprecated root-level trend_type and/or income_categories are not allowed when "
125 "project_requirements is present. Use project_requirements.trend and "
126 "project_requirements.income.categories instead."};
131 if (trend_type !=
"null" && trend_type !=
"trend" && trend_type !=
"upf_trend" &&
132 trend_type !=
"UPFTrend" && trend_type !=
"income_trend") {
133 throw ConfigurationError{fmt::format(
"Invalid trend_type: {}. Must be one of: null, trend, "
134 "upf_trend, UPFTrend, income_trend",
141 if (opt.contains(
"trend_type")) {
142 const auto trend_type = opt[
"trend_type"].get<std::string>();
147 if (opt.contains(
"income_categories")) {
148 const auto categories = opt[
"income_categories"].get<std::string>();
156 const auto &d = pr[
"demographics"];
162 if (d.contains(
"education") && !d[
"education"].is_null()) {
165 if (d.contains(
"employment") && !d[
"employment"].is_null()) {
168 if (d.contains(
"max_age_for_linear_models") && !d[
"max_age_for_linear_models"].is_null()) {
171 if (d.contains(
"gender2") && !d[
"gender2"].is_null()) {
176 const auto &inc = pr[
"income"];
179 if (!inc.contains(
"type") || !inc.contains(
"categories")) {
181 "project_requirements.income.enabled is true but type and/or categories missing"};
183 req.
income.
type = inc[
"type"].get<std::string>();
186 if (inc.contains(
"type") && !inc[
"type"].is_null()) {
187 req.
income.
type = inc[
"type"].get<std::string>();
189 if (inc.contains(
"categories") && !inc[
"categories"].is_null()) {
194 if (inc.contains(
"adjust_to_factors_mean") && !inc[
"adjust_to_factors_mean"].is_null()) {
197 if (inc.contains(
"trended") && !inc[
"trended"].is_null()) {
200 if (inc.contains(
"income_based_csv_output") && !inc[
"income_based_csv_output"].is_null()) {
204 const auto &pa = pr[
"physical_activity"];
207 if (!pa.contains(
"type")) {
209 "project_requirements.physical_activity.enabled is true but type is missing"};
212 }
else if (pa.contains(
"type") && !pa[
"type"].is_null()) {
215 if (pa.contains(
"adjust_to_factors_mean") && !pa[
"adjust_to_factors_mean"].is_null()) {
218 if (pa.contains(
"trended") && !pa[
"trended"].is_null()) {
222 const auto &rf = pr[
"risk_factors"];
226 const auto &tr = pr[
"trend"];
229 if (!tr.contains(
"type")) {
231 "project_requirements.trend.enabled is true but type is missing"};
233 req.
trend.
type = tr[
"type"].get<std::string>();
234 }
else if (tr.contains(
"type") && !tr[
"type"].is_null()) {
235 req.
trend.
type = tr[
"type"].get<std::string>();
240 const auto &ts = pr[
"two_stage"];
242 if (ts.contains(
"logistic_file") && !ts[
"logistic_file"].is_null()) {
Main header file for functionality related to loading config files.
IncomeCategoryLayout income_category_layout_from_config(std::string_view categories)
Parse project_requirements.income.categories ("3", "4", or "5").
Definition income_category_layout.cpp:20