diff --git a/grammar/grammar.py b/grammar/grammar.py index 59460271..8a7b4c5a 100644 --- a/grammar/grammar.py +++ b/grammar/grammar.py @@ -126,6 +126,7 @@ class SiriGrammar(Grammar): k_ninf = Sequence('-', k_inf) k_now = Keyword('now') k_number = Keyword('number') + k_offset = Keyword('offset') k_online = Keyword('online') k_open_files = Keyword('open_files') k_or = Keyword('or') @@ -527,6 +528,9 @@ class SiriGrammar(Grammar): f_last = Sequence( k_last, '(', Optional(time_expr), ')') + f_offset = Sequence( + k_offset, + '(', time_expr, ')') f_timeval = Sequence( k_timeval, '(', ')') @@ -572,6 +576,7 @@ class SiriGrammar(Grammar): aggregate_functions = List(Choice( f_all, + f_offset, f_limit, f_mean, f_sum, diff --git a/include/siri/grammar/grammar.h b/include/siri/grammar/grammar.h index 3d48891f..50229652 100644 --- a/include/siri/grammar/grammar.h +++ b/include/siri/grammar/grammar.h @@ -5,7 +5,7 @@ * should be used with the libcleri module. * * Source class: SiriGrammar - * Created at: 2022-05-05 15:08:05 + * Created at: 2023-10-24 15:46:26 */ #ifndef CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_ #define CLERI_EXPORT_SIRI_GRAMMAR_GRAMMAR_H_ @@ -70,6 +70,7 @@ enum cleri_grammar_ids { CLERI_GID_F_MEDIAN_HIGH, CLERI_GID_F_MEDIAN_LOW, CLERI_GID_F_MIN, + CLERI_GID_F_OFFSET, CLERI_GID_F_POINTS, CLERI_GID_F_PVARIANCE, CLERI_GID_F_STDDEV, @@ -201,6 +202,7 @@ enum cleri_grammar_ids { CLERI_GID_K_NINF, CLERI_GID_K_NOW, CLERI_GID_K_NUMBER, + CLERI_GID_K_OFFSET, CLERI_GID_K_ONLINE, CLERI_GID_K_OPEN_FILES, CLERI_GID_K_OR, diff --git a/include/siri/version.h b/include/siri/version.h index 52b8907c..a04e30d6 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -6,7 +6,7 @@ #define SIRIDB_VERSION_MAJOR 2 #define SIRIDB_VERSION_MINOR 0 -#define SIRIDB_VERSION_PATCH 50 +#define SIRIDB_VERSION_PATCH 51 /* * Use SIRIDB_VERSION_PRE_RELEASE for alpha release versions. @@ -15,7 +15,7 @@ * Note that debian alpha packages should use versions like this: * 2.0.34-0alpha0 */ -#define SIRIDB_VERSION_PRE_RELEASE "" +#define SIRIDB_VERSION_PRE_RELEASE "-alpha-2" #ifndef NDEBUG #define SIRIDB_VERSION_BUILD_RELEASE "+debug" diff --git a/src/siri/db/aggregate.c b/src/siri/db/aggregate.c index 2dad9014..d56fa4d2 100644 --- a/src/siri/db/aggregate.c +++ b/src/siri/db/aggregate.c @@ -206,7 +206,7 @@ void siridb_init_aggregates(void) vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg) { uint32_t gid; - siridb_aggr_t * aggr; + siridb_aggr_t * aggr = NULL; vec_t * vec = vec_new(VEC_DEFAULT_SIZE); if (vec == NULL) { @@ -221,6 +221,19 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg) switch (gid) { + case CLERI_GID_F_OFFSET: + if (aggr == NULL || aggr->group_by == 0) + { + sprintf(err_msg, + "Offset must be used after an aggregation method."); + siridb_aggregate_list_free(vec); + return NULL; + } + /* group_by is always > 0 */ + aggr->offset = CLERI_NODE_DATA( + cleri_gn(cleri_gn(cleri_gn(children) + ->children)->children->next->next)) % aggr->group_by; + break; case CLERI_GID_F_LIMIT: AGGR_NEW { @@ -319,11 +332,6 @@ vec_t * siridb_aggregate_list(cleri_children_t * children, char * err_msg) case CLERI_GID_F_TIMEVAL: case CLERI_GID_F_INTERVAL: AGGR_NEW - { - aggr->timespan = 1; - aggr->group_by = 0; - } - VEC_APPEND break; diff --git a/src/siri/grammar/grammar.c b/src/siri/grammar/grammar.c index ba49e8a9..46736df0 100644 --- a/src/siri/grammar/grammar.c +++ b/src/siri/grammar/grammar.c @@ -5,7 +5,7 @@ * should be used with the libcleri module. * * Source class: SiriGrammar - * Created at: 2022-05-05 15:08:05 + * Created at: 2023-10-24 15:46:26 */ #include "siri/grammar/grammar.h" @@ -124,6 +124,7 @@ cleri_grammar_t * compile_siri_grammar_grammar(void) ); cleri_t * k_now = cleri_keyword(CLERI_GID_K_NOW, "now", CLERI_CASE_SENSITIVE); cleri_t * k_number = cleri_keyword(CLERI_GID_K_NUMBER, "number", CLERI_CASE_SENSITIVE); + cleri_t * k_offset = cleri_keyword(CLERI_GID_K_OFFSET, "offset", CLERI_CASE_SENSITIVE); cleri_t * k_online = cleri_keyword(CLERI_GID_K_ONLINE, "online", CLERI_CASE_SENSITIVE); cleri_t * k_open_files = cleri_keyword(CLERI_GID_K_OPEN_FILES, "open_files", CLERI_CASE_SENSITIVE); cleri_t * k_or = cleri_keyword(CLERI_GID_K_OR, "or", CLERI_CASE_SENSITIVE); @@ -1050,6 +1051,14 @@ cleri_grammar_t * compile_siri_grammar_grammar(void) cleri_optional(CLERI_NONE, time_expr), cleri_token(CLERI_NONE, ")") ); + cleri_t * f_offset = cleri_sequence( + CLERI_GID_F_OFFSET, + 4, + k_offset, + cleri_token(CLERI_NONE, "("), + time_expr, + cleri_token(CLERI_NONE, ")") + ); cleri_t * f_timeval = cleri_sequence( CLERI_GID_F_TIMEVAL, 3, @@ -1114,8 +1123,9 @@ cleri_grammar_t * compile_siri_grammar_grammar(void) cleri_t * aggregate_functions = cleri_list(CLERI_GID_AGGREGATE_FUNCTIONS, cleri_choice( CLERI_NONE, CLERI_FIRST_MATCH, - 21, + 22, f_all, + f_offset, f_limit, f_mean, f_sum,