質問

I'm design an analytics page for a product, and I want to show the average time spent on the product. I want to show the average time for the past hour, past day, past week, past year, and all time. Is there a better way to get the result than going through all user records and calculating the average on the fly?

There are many similar problems in implementing analytics, since by giving user the power to specify an arbitrary time range, the app can no longer just store pre-computed values in database (e.g. store day average for each day in the past) and use them directly. I can certainly just have A "Loading... please wait" page while retrieving the data and calculating, just wondering is there a faster way to calculate these?

Thanks!

役に立ちましたか?

解決

There's only 8760 hours in a year, just save the average for every hour, or if you want more fine grained every half hour or every 10 minutes (52560 records / year).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top