What would be the best data model to use in a metering application for example and app that captures daily water meter data.
What I can think of is that I could have a water_reading
table that captures data for all users.
Example:
2014-05-20 09:40 AM - user_1 - 0
2014-05-20 09:41 AM - user_1 - 4
2014-05-20 09:42 AM - user_1 - 9
2014-05-20 09:40 AM - user_2 - 0
2014-05-20 09:41 AM - user_2 - 2
2014-05-20 09:42 AM - user_2 - 7
Is that the best way to capture the data?
My main use for this data is to give the user the ability to view charts etc. in order to get usage patterns.
For example, a monthly water usage line chart.
Challenges
The only issue I can foresee with this model is that the readings need to be regular. If the user starts the data entry at a non-zero point, will it still be valid? Or if the user misses a few entries, how do I fill in the gaps etc.
For example: If a user entered the data the following data:
day_1 12pm - 20
day_2 12pm - 50
day_5 12pm - 120
How would I create a chart that shows daily water usage. Because as per the data:
day_1 : 20 - ? (I don't know if the meter was started the same day or the 5 days ago)
day_2 : 50 - 20
day_3 : ? - 50
day_4 : ? - ?
day_5 : 120 - ?
Any help would be much appreciated.
PS: I am using Ruby on Rails and database is postgresql.