Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing competitor kpis #89

Merged
merged 9 commits into from
Dec 13, 2024
Merged

Optimizing competitor kpis #89

merged 9 commits into from
Dec 13, 2024

Conversation

PoloX2021
Copy link
Contributor

Updated the queries to fit the new table prices.minute to use them more efficiently.
For total TVL, switched to the table prices.day: less expensive and gets an average over the time frame for the study

@PoloX2021 PoloX2021 requested a review from fleupold December 9, 2024 20:02
Copy link
Contributor

@fleupold fleupold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approach looks good. However, I'd like to see if we can make the date filter a bit less ugly given that we need to add it all over the place.

on
date_trunc('minute', block_time) = p0.timestamp
p0.timestamp = date_trunc('day', case when ('{{end_time}}' = '2100-01-01' or date('{{end_time}}') = date_trunc('day', now())) then now() - interval '1' day else date('{{end_time}}') end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this logic seems unnecessarily complex. Isn't this the same as

least(date('{{end_time}}'), now() - interval '1' day)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please document the new parameter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed :)

Comment on lines 38 to 39
and p0.timestamp >= date_add('day', -1, (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end))
and p0.timestamp <= (case when '{{competitor_end_time}}' = '2100-01-01' then now() else timestamp '{{competitor_end_time}}' end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe using

p0.timestamp between date_add('day', -1, least('{{competitor_end_time}}', now())) and least('{{competitor_end_time}}', now())

is slightly easier to read? Also I'm not sure if reducing the range to now() is actually making the query more effective (since there are no datapoints beyond now the full table scan should complete in the same time)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

About the now(), the query is built to only search for 24 hours, so the upper bound is meant to backfill the data base

@PoloX2021
Copy link
Contributor Author

I changed the parameter from end_time to start_time, as it makes more sense when rounding to a date

@PoloX2021 PoloX2021 merged commit ec565b9 into main Dec 13, 2024
2 checks passed
@PoloX2021 PoloX2021 deleted the optimizing-competitor-kpis branch December 13, 2024 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants