On Apr 7, 6:53 am, Marcel Overdijk <marceloverd...@gmail.com> wrote:
> - User1, 1 jan 2009, 1000
> - User1, 1 feb 2009, 1100
> - User1, 1 mar 2009, 1200
> The avarage will be 1100 ***
>
> But maybe the user misses registering the meter reading on 1 feb:
> - User1, 1 jan 2009, 1000
> - User1, 1 mar 2009, 1200
> The average will still be 1100 ***
> I guess the answer will be to store average values when creating (and
> updaing existing) meter reading records.
> But how should this be implemented?

*** Corrected.

Yes, calculate averages when you update the table. If you don't need
to search for particular readings, you might want to store the meter
readings in a db.ListProperty(int), with an associated db.ListProperty
(int) of timestamps.

I need to count various things in my app, so I define a model and
helper functions like this:

class Counter(db.Model):
  count=db.IntegerProperty(required=True,default=0)

# Increment a counter
# NB: These are functions, not class members
def _incrementCounter(counterId,amount):
        counter=Counter.get_by_id(counterId)
        counter.count+=amount
        counter.put()
def incrementCounter(counterId,amount=1):
        db.run_in_transaction(_incrementCounter,counterId,amount)

I'm sure you can do something similar for your averages.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to