Skip to content

Commit

Permalink
[core][fix] History timeseries slotter (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias authored Aug 9, 2024
1 parent 4fffcfa commit 89cf817
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions fixcore/fixcore/db/arango_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from arango.typings import Json
from attrs import evolve
from math import floor

from fixcore.constants import less_greater_then_operations as lgt_ops, arangodb_matches_null_ops
from fixcore.db import EstimatedSearchCost, EstimatedQueryCostRating as Rating
from fixcore.db.arango_query_rewrite import rewrite_query
Expand Down Expand Up @@ -148,14 +146,13 @@ def history_query_timeline(
)
crs = ctx.next_crs()
gran = granularity.total_seconds()
at = after.timestamp()
offset = ctx.add_bind_var((at - int(floor(at / gran) * gran)) * 1000)
slot = ctx.add_bind_var(gran * 1000)
slot_fn = f"DATE_ISO8601((FLOOR(DATE_TIMESTAMP({crs}.changed_at) / @{slot}) * @{slot}) + @{offset})"
atms = after.timestamp() * 1000
slotter = ctx.add_bind_var(gran * 1000)
slot_fn = f"(FLOOR((DATE_TIMESTAMP({crs}.changed_at)-{atms}) / @{slotter}))"
query_str += (
f" FOR {crs} IN {in_cursor} "
f"COLLECT change={crs}.change, at={slot_fn} WITH COUNT INTO v SORT at ASC "
'RETURN {"at": at, "group": {"change": change}, "v": v}'
f"COLLECT change={crs}.change, slot={slot_fn} WITH COUNT INTO v SORT slot ASC "
f'RETURN {{"at": DATE_ISO8601((slot*@{slotter}) + {atms}), "group": {{"change": change}}, "v": v}}'
)
return query_str, ctx.bind_vars

Expand Down

0 comments on commit 89cf817

Please sign in to comment.