That's what Massimo's code does. You'll just have to add the
auth.user_id and session.adate filters to the query (i.e., in the
parentheses before the .select).

Anthony

On Dec 6, 1:05 am, Rick <[email protected]> wrote:
> Perhaps I should explain my problem once again. I'd like to summarize
> the values for each day in the record list. With other words, so that
> this:
> ********
> record.thedate[0] = 2011-12-01
> record.value[0] = 10
> record.thedate[1] = 2011-12-01
> record.value[1] = 20
> record.thedate[3] = 2011-12-02
> record.value[3] = 10
> ********
> ...becomes this:
> ********
> sumlist.thedate[0] = 2011-12-01
> sumlist.value[0] = 30
> sumlist.thedate[1] = 2011-12-02
> sumlist.value[1] = 10
> ********
>
> Here is the code:
>
> ********
> from the model file:
>
> db.define_table('day',
>     Field('thedate','date', default=request.now),
>     Field('value', 'integer'),
>     Field('theauth', db.auth_user, default=auth.user_id),
>     Field('uuid', length=64, default=uuid.uuid4()))
>
> ********
> from the controller file:
>
> prerecords = db().select(db.day.ALL, orderby=db.day.thedate)
> for prerecord in prerecords:
>     if prerecord.theauth==auth.user_id:
>         if session.adate==prerecord.thedate:
>             records.append(prerecord)
> ********
>
> On Dec 5, 3:49 pm, Anthony <[email protected]> wrote:
>
>
>
> > It doesn't look like you applied Massimo's solution. You're calling
> > select() all by itself (not as a method of a Set object) -- doesn't that
> > raise an error (there's no function called 'select' in web2py)? The sum
> > should be applied in the initial query, not on the returned rows after the
> > query.
>
> > Anthony
>
> > On Sunday, December 4, 2011 9:33:42 PM UTC-5, Rick wrote:
>
> > > I tried to apply the solution to my code, but it still doesn't work.
> > > Here is the code:
>
> > > prerecords = db().select(db.day.ALL, orderby=db.day.thedate) for
> > > prerecord in prerecords: if prerecord.theauth==auth.user_id: if
> > > session.adate==prerecord.thedate: records.append(prerecord) rows =
> > > select(records.thedate,records.value.sum(),orderby=records.thedate)
> > > for row in rows: print row.records.thedate, row(records.value.sum())
> > > On Dec 5, 3:04 am, Massimo Di Pierro <[email protected]>
> > > wrote:
> > > > rows =
> > > > db(...).select(db.table.date,db.table.value.sum(),groupby=db.table.date)
> > > > for row in rows: print row.table.date, row(db.table.value.sum())
>
> > > > mind that 'date' and 'value' are not good field names. Will work with
> > > > sqlite but will break with other engines.
>
> > > > On Dec 4, 8:00 pm, Rick <[email protected]> wrote:
>
> > > > > Hi,
> > > > > I've a stack of records where records with the same date has different
> > > > > values, eg:
> > > > > record.date[0] = 2011-12-01
> > > > > record.value[0] = 10
> > > > > record.date[1] = 2011-12-01
> > > > > record.value[1] = 20
> > > > > record.date[3] = 2011-12-02
> > > > > record.value[3] = 10
> > > > > And now I want to summarize the values that are recorded for
> > > > > respective date:
> > > > > sumlist.date[0] = 2011-12-01
> > > > > sumlist.value[0] = 30
> > > > > sumlist.date[1] = 2011-12-02
> > > > > sumlist.value[1] = 10
>
> > > > > I suppose I should use "filter" and  "sum", but I don't know how. Any
> > > > > ideas?
>
> > > > > Thanks in advance for help!- Hide quoted text -
>
> - Show quoted text -

Reply via email to