-
Notifications
You must be signed in to change notification settings - Fork 894
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
interpolated_delta calculation #7536
Comments
@VishalSolankiTatvaSoft I ran the query you provided on the original data, and got a different result than the one you got:
This is definitely odd. Can you share the details of the |
meter_data schema and data.txt I have attached meter_data schema and data script. Also, In my system, I have set UTC date & time. |
@VishalSolankiTatvaSoft I used these details and got the same output as before. When I change my timezone to something else (e.g. MST), the output changes, but the result is what you'd expect due to interpolation at the end points:
|
@kpan2034 But, y1?+((t−t1)/(t2-t1)??)×(y2?−y1?) formula is used for calculate Interpolated delta value. When we calculate the Interpolated delta using the interpolated_delta function, that value does not match the formula. Or any other formula used for calculate Interpolated delta? |
@VishalSolankiTatvaSoft We can try to verify this by including
|
@kpan2034 Thank you!! Do you have any formula for calculating interpolated_delta? I want to calculate manually using a formula. I have tried to calculate using y1?+((t−t1)/(t2-t1)??)×(y2?−y1?) formula But the delta value didn't match with the function value. |
@VishalSolankiTatvaSoft Yes, that formula should be correct. Just to note, this doesn't calculate |
What type of bug is this?
Incorrect result
What subsystems and features are affected?
Other
What happened?
Here we have original data for 30 minute of interval and some of the case we will have random data within a day. When we are trying to aggregate data for day using the interpolated delta function. We have attached the sheet of original data and aggregated data.
As per documentation value should be calculated using the formula:
Interpolated value=y1?+((t−t1)/(t2-t1)??)×(y2?−y1?)
But the value is not matching with this formula.
Our use case scenario is, We have energy meters that has cumulative type of channel and send random data and in dashboard we want to show the usage for that day.
Interpolated Data.csv
Original Data.csv
We have used below queries to calculate the interpolated value.
WITH daily_meter AS (
SELECT
meter_id,
time_bucket ('1 day', md."offset_timestamp") AS bucket,
counter_agg (md."offset_timestamp", md.value)
FROM
meter_data md
WHERE
md.meter_channel_id = 289106571
AND lower(md.meter_id) = lower('Avalon_502-SP')
AND md."offset_timestamp" >= (to_timestamp('2024-04-01 00:00', 'YYYY-MM-DD hh24:mi:ss')::timestamp + INTERVAL'-1 millisecond')
AND md."offset_timestamp" <= (to_timestamp('2024-04-05 00:00', 'YYYY-MM-DD hh24:mi:ss')::timestamp + INTERVAL'-1 millisecond')
GROUP BY
1,
2
)
SELECT
bucket,
meter_id,
first_val (counter_agg),
last_val (counter_agg),
interpolated_delta (counter_agg, bucket, '1 day'::interval, lag(counter_agg) OVER ordered_meter, lead(counter_agg) OVER ordered_meter)
FROM
daily_meter
WINDOW ordered_meter AS (PARTITION BY meter_id ORDER BY bucket)
ORDER BY
meter_id,
bucket;
TimescaleDB version affected
2.17
PostgreSQL version used
15.10
What operating system did you use?
Windows 11
What installation method did you use?
Other
What platform did you run on?
Managed Service for TimescaleDB (MST/Aiven)
Relevant log output and stack trace
No response
How can we reproduce the bug?
The text was updated successfully, but these errors were encountered: