Agh..  and I guess it worked in my Dev machine because I had more than one
record in the set for 10/1.  Sorry to clog this group with thus type of
logic error.
On Oct 1, 2012 1:22 PM, "Massimo Di Pierro" <massimo.dipie...@gmail.com>
wrote:

> Not all of your results.items()[i][1] have a 'created'. Some only
> have {'yymm_count': 1}. Try
>
>     results = {}
>     for row in set:
>         label = str(row.created_on.strftime('%**b-%y'))   #works but
> screw up ordering
>         try:
>             results[label] = {'yymm_count': results[label]['yymm_count'] +
> 1, 'created': row.created_on}
>         except KeyError, e:
>             results[label] = {'yymm_count': 1, 'created':row.created_on} #
> <<< changed!
>
>     # jump thru hopops to sort the dict
>    * sortedresults = collections.OrderedDict(sorted(results.items(),
> key=lambda x: x[1]['created']))*
>
>
> On Monday, 1 October 2012 08:08:25 UTC-5, david.waldrop wrote:
>>
>> I have a very weird issue I cannot resolve regarding sorting a dictionary
>> based on a DAL query.  The code below runs as expected on my dev box, but
>> emits an error when i push to production (both environments are running the
>> same version of web2py 2.0.0 and python v2.7.3.
>>
>> ...
>>     results = {}
>>     for row in set:
>>         label = str(row.created_on.strftime('%**b-%y'))   #works but
>> screw up ordering
>>         try:
>>             results[label] = {'yymm_count': results[label]['yymm_count']
>> + 1, 'created': row.created_on}
>>         except KeyError, e:
>>             results[label] = {'yymm_count': 1}
>>
>>     # jump thru hopops to sort the dict
>>    * sortedresults = collections.OrderedDict(sorted(results.items(),
>> key=lambda x: x[1]['created']))*
>>
>>     return results
>>
>>
>> The error is in the sortedresults line.  I am trying to sort the results
>> dict by the actual time and preserve a user friendly label as the key (i.e
>> "Jan-12").  The ordering is needed because this is being displayed in a bar
>> chart.  Note the results dict is being built correctly AND contains the
>> created filed.  To repeat this works on the dev box using sqllitre, the
>> prod env uses postgress - could this affect pure python?
>>
>> On production I get a key error as follows:
>>
>> 1.
>> 2.
>> 3.
>> 4.
>> 5.
>> 6.
>> 7.
>> 8.
>> 9.
>> 10.
>> 11.
>> 12.
>> 13.
>> 14.
>>
>> Traceback (most recent call last):
>>   File "/home/dlwatey/webapps/web2py/**web2py/gluon/restricted.py", line 
>> 205, in restricted
>>     exec ccode in environment
>>   File 
>> "/home/dlwatey/webapps/web2py/**web2py/applications/COPSIS/**controllers/metrics.py"
>>  
>> <https://www.meetingmonkey.net/admin/default/edit/COPSIS/controllers/metrics.py>,
>>  line 130, in <module>
>>   File "/home/dlwatey/webapps/web2py/**web2py/gluon/globals.py", line 175, 
>> in <lambda>
>>     self._caller = lambda f: f()
>>   File 
>> "/home/dlwatey/webapps/web2py/**web2py/applications/COPSIS/**controllers/metrics.py"
>>  
>> <https://www.meetingmonkey.net/admin/default/edit/COPSIS/controllers/metrics.py>,
>>  line 68, in data
>>     response_components["activity"**] = data_logsbymonth()
>>   File 
>> "/home/dlwatey/webapps/web2py/**web2py/applications/COPSIS/**controllers/metrics.py"
>>  
>> <https://www.meetingmonkey.net/admin/default/edit/COPSIS/controllers/metrics.py>,
>>  line 126, in data_logsbymonth
>>     sortedresults = collections.OrderedDict(sorted**(results.items(), 
>> key=lambda x: x[1]['created']))
>>   File 
>> "/home/dlwatey/webapps/web2py/**web2py/applications/COPSIS/**controllers/metrics.py"
>>  
>> <https://www.meetingmonkey.net/admin/default/edit/COPSIS/controllers/metrics.py>,
>>  line 126, in <lambda>
>>     sortedresults = collections.OrderedDict(sorted**(results.items(), 
>> key=lambda x: x[1]['created']))
>> KeyError: 'created'
>>
>>
>> Any one have any ideas?
>>
>>
>>  --
>
>
>
>

-- 



Reply via email to