getlago / lago-doc

1 stars 10 forks source link

Issue on docs: Weighted Sum #155

Open markandpathak opened 1 week ago

markandpathak commented 1 week ago

Path: /guide/billable-metrics/aggregation-types/weighted-sum

The weighted sum calculation is very confusing or may be I have understood it all wrong: There's an image, an equation and a calculated example. All three doesn't match image

The image simply divides property by the time elapsed between two consecutive reading and sums up all values. There's no mention of billing period in that info-graphic.

The equation mentioned is SUM(events.properties.property_name) / (DATEDIFF(SECOND, timestamp.event_1, timestamp.event_2) + 1) * (DATEDIFF(SECOND, 'period_start', 'period_end') + 1) In which property is divided by time difference between events and then multiplied by the billing period.

However, the example calculations shows opposite: image

In examples the property is divided by the billing period(Compare with the equation provided) which is 2678400 for a month and then multiplied by the time duration between two events.

Can you please clarify, out of three which logic is the true logic? The documentation also doesn't provide any useful information on how a particular pricing model can be implemented using this Agg type. Can I implement metering for storage (GB-month like in s3) using this? How?

sarkissianraffi commented 5 days ago

I don't see differences in the calculation. It's always a value weighted per seconds used during a period (like a month). For instance, this one is correct: (20 / 2678400) x 86400 = 0.64516129032 GB/s 👉 20GB used for 86400 seconds during a month (30 / 2678400) x 1296000 = 14.5161290323 GB/s 👉 30GB used for 1296000 seconds during a month

The one from the image explains exactly the same: A- 1GB used for 3600 seconds. In that case, there is no division by a month, because this value is not necessarily a month. It can be a week, a quarter or a year, depending on the plan cadence