15#include <unordered_set>
24int defaultAnalysisYear() {
25 const std::time_t now = std::time(
nullptr);
26 const std::tm *local = std::localtime(&now);
30 return local->tm_year + 1900 - 1;
33std::vector<std::string> splitList(
const std::string &raw) {
34 std::vector<std::string> out;
35 std::unordered_set<std::string> seen;
37 std::istringstream ss(raw);
39 const std::string trimmed =
trim(token);
40 if (trimmed.empty() || seen.contains(trimmed)) {
44 out.push_back(trimmed);
54 out.
year = std::to_string(defaultAnalysisYear());
55 const std::string normalized =
57 if (normalized.empty()) {
61 std::istringstream ss(normalized);
65 clause =
trim(clause);
81 out.
dateTo = clause.substr(6);
89 out.
dateField = value ==
"valuta" ?
"valuta" :
"bookingDate";
96 const std::vector<std::string> values = splitList(clause.substr(11));
98 std::find(values.begin(), values.end(),
102 for (
const auto &value : values) {
113 const std::vector<std::string> values = splitList(clause.substr(14));
115 std::find(values.begin(), values.end(),
119 for (
auto value : values) {
132 if (mode ==
"allocatable" || mode ==
"non-allocatable") {
142 out.
dateFrom.ends_with(
"-01-01") && out.
dateTo.ends_with(
"-12-31") &&
154 std::vector<std::string> clauses;
156 if (normalizedDateField ==
"valuta") {
157 clauses.emplace_back(
"dateField=valuta");
161 const std::string year =
trim(selection.
year);
162 if (normalizedDateMode ==
"range") {
164 const std::string to =
trim(selection.
dateTo);
165 bool hasDateClause =
false;
167 clauses.push_back(
"date>=" + from);
168 hasDateClause =
true;
171 clauses.push_back(
"date<=" + to);
172 hasDateClause =
true;
174 if (!hasDateClause) {
175 const std::string fallbackYear = std::to_string(defaultAnalysisYear());
176 clauses.push_back(
"date>=" + fallbackYear +
"-01-01");
177 clauses.push_back(
"date<=" + fallbackYear +
"-12-31");
180 const std::string resolvedYear =
181 year.empty() ? std::to_string(defaultAnalysisYear()) : year;
182 clauses.push_back(
"date>=" + resolvedYear +
"-01-01");
183 clauses.push_back(
"date<=" + resolvedYear +
"-12-31");
186 std::unordered_set<std::string> propertySeen;
187 std::vector<std::string> propertyValues;
189 const std::string value =
trim(raw);
190 if (value.empty() || propertySeen.contains(value)) {
193 propertySeen.insert(value);
194 propertyValues.push_back(value);
197 !propertySeen.contains(
199 propertyValues.push_back(
202 if (!propertyValues.empty()) {
203 std::ostringstream propertyClause;
204 propertyClause <<
"propertyId=";
205 for (std::size_t i = 0; i < propertyValues.size(); ++i) {
207 propertyClause <<
',';
209 propertyClause << propertyValues[i];
211 clauses.push_back(propertyClause.str());
214 std::unordered_set<std::string> contractSeen;
215 std::vector<std::string> contractValues;
218 if (raw.empty() || contractSeen.contains(raw)) {
221 contractSeen.insert(raw);
222 contractValues.push_back(raw);
225 !contractSeen.contains(
227 contractValues.push_back(
230 if (!contractValues.empty()) {
231 std::ostringstream contractClause;
232 contractClause <<
"contract.type=";
233 for (std::size_t i = 0; i < contractValues.size(); ++i) {
235 contractClause <<
',';
237 contractClause << contractValues[i];
239 clauses.push_back(contractClause.str());
243 if (allocatable ==
"allocatable" || allocatable ==
"non-allocatable") {
244 clauses.push_back(
"allocatable=" + allocatable);
247 std::ostringstream out;
248 for (std::size_t i = 0; i < clauses.size(); ++i) {
Defines stable analysis type, configuration, filter, and result keys.
Declares analysis use-case request DTOs and filter-spec helpers.
Value object for analysis filter specifications.
Declares private string helpers shared across core implementation files.
static std::string normalize(std::string value)
Trims leading and trailing whitespace from a filter specification.
constexpr std::string_view kGreaterEqual
constexpr std::string_view kEqual
constexpr std::string_view kLessEqual
constexpr std::string_view kDateField
constexpr std::string_view kContractType
constexpr std::string_view kDate
constexpr std::string_view kPropertyId
constexpr std::string_view kAllocatable
constexpr std::string_view kUnassigned
AnalysisFilterSelection parseAnalysisFilterSelection(const std::string &filterSpec)
Parses a serialized analysis filter specification.
std::string buildAnalysisFilterSpec(const AnalysisFilterSelection &selection)
Serializes an analysis filter selection.
std::string lowerAscii(std::string s)
Converts ASCII letters in a string to lowercase.
std::string trim(std::string s)
Removes leading and trailing ASCII whitespace from a string.
std::string lowerAscii(std::string s)
Converts ASCII letters in a string to lowercase.
std::string trim(std::string s)
Removes leading and trailing ASCII whitespace from a string.
std::vector< std::string > contractTypes
bool propertyIdsUnassigned
std::vector< std::string > propertyIds
std::string allocatableMode
bool contractTypesUnassigned