[web2py] Re: Groupby year on date field

2015-02-17 Thread Moiz Nagpurwala
Thanks Niphlod. I worked for me. Here is the complete code. In my controller: sum_of_entries = db.mydiary.id.count() year_part = db.mydiary.Entry_Date.year() distinct_years = db(db.mydiary.id 0).select(sum_of_entries, year_part, groupby=db.mydiary.Entry_Date.year(), orderby=~sum_of_entries)

[web2py] Re: Groupby year on date field

2015-02-16 Thread Niphlod
it's the same method as extrapolating the count() part year_part = db.mydiary.Entry_Date.year() distinct_years = . for row in distinct_years: only_year = row[year_part] On Monday, February 16, 2015 at 10:19:17 AM UTC+1, Moiz Nagpurwala wrote: In my controller I have this

[web2py] Re: Groupby year on date field

2015-02-16 Thread Moiz Nagpurwala
In my controller I have this code: sum_of_entries = db.mydiary.id.count() distinct_years = db(db.mydiary.id 0).select(sum_of_entries, db.mydiary. Entry_Date.year(), groupby=db.mydiary.Entry_Date.year(), orderby=~ sum_of_entries) In my view I'm trying to display the results in a loop like so:

[web2py] Re: Groupby year on date field

2015-02-05 Thread Moiz Nagpurwala
Yes sir, I'm sure. The sample database I had sent previously and my production database both have records in them. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report

[web2py] Re: Groupby year on date field

2015-02-04 Thread Niphlod
are you sure that there are effectively records on the table ? On Monday, February 2, 2015 at 10:27:09 PM UTC+1, Moiz Nagpurwala wrote: Hello, Sorry to bug you all, but I am still stuck with this year groupby issue. I am fairly new to Python and web2py. Any suggestions or alternative

[web2py] Re: Groupby year on date field

2015-02-04 Thread Dave S
On Wednesday, February 4, 2015 at 1:12:27 AM UTC-8, Niphlod wrote: are you sure that there are effectively records on the table ? It might be helpful to use appadmin to examine a few records. Appadmin can also be used to enter a few sample records. If Moiz still has problems, perhaps

[web2py] Re: Groupby year on date field

2015-02-03 Thread Moiz Nagpurwala
Hello, Sorry to bug you all, but I am still stuck with this year groupby issue. I am fairly new to Python and web2py. Any suggestions or alternative method to achieve the result is highly appreciated. Thank you all. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation)

[web2py] Re: Groupby year on date field

2015-02-02 Thread Moiz Nagpurwala
trangely, this is what I get with the same app, same data, same code, both on pythonanywhere and my local machine. https://lh3.googleusercontent.com/-mJM6wRc-lpc/VMxUS7cXeQI/A90/xFO6KgNk-DI/s1600/Capture.JPG On Saturday, January 31, 2015 at 3:14:22 AM UTC+5:30, Niphlod wrote:

[web2py] Re: Groupby year on date field

2015-01-30 Thread Niphlod
https://lh6.googleusercontent.com/-pWsAPTKJbZ8/VMv7E7GHWnI/ARs/OMWXe-Ku54c/s1600/counts.png are you sure that the issue is not fetching but rather visualizing the results you already fetched ??? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) -

[web2py] Re: Groupby year on date field

2015-01-30 Thread Niphlod
it works perfectly fine! On Friday, January 30, 2015 at 5:10:46 AM UTC+1, Moiz Nagpurwala wrote: Thanks Niphlod for the replies. The code you provided does not seem to work for me. I tried the attached app on my local machine with SQLITE as well as MySQL on PythonAnywhere

[web2py] Re: Groupby year on date field

2015-01-29 Thread Moiz Nagpurwala
This is the controller: def year(): sum_of_entries = db.mydiary.id.count() years = db(db.mydiary.id 0).select(sum_of_entries, db.mydiary.Date. year(), groupby=db.mydiary.Date.year()) # years = db(db.mydiary.id 0).select(db.mydiary.Date.year(), distinct=True) return locals()

[web2py] Re: Groupby year on date field

2015-01-29 Thread Moiz Nagpurwala
Both of the approaches you suggested are not yielding any results. given that db.entries.date is a datetime field, the former is fetched with db(db.entries.id 0).select(db.entries.date.year(), distinct=True) while the latter, e.g. the entry count per year, with sum_of_entries =

[web2py] Re: Groupby year on date field

2015-01-29 Thread Niphlod
I assure you you will get results, as long as there are values in the table try using: 1) this model in a fresh app db.define_table('entries', Field('this_is_datetime', 'datetime')) 2) fill some data in 3) create this controller function def test(): distinct_ = db(db.entries.id

[web2py] Re: Groupby year on date field

2015-01-27 Thread Niphlod
the doc is rather incomplete. Either you want a set of distinct things, or you want to aggregate something over a group of distinct things. given that db.entries.date is a datetime field, the former is fetched with db(db.entries.id 0).select(db.entries.date.year(), distinct=True) while the