django - creating list of lists alimented with data from database gives empty list -


i'm trying plot graph shows average call duration every day each minute 7 days in same plot, i'm defining function give me data asked according conditions plotted i'm getting list of empty lists.can 1 me tof ind bug? (acc example of data global database) function:

import time import calendar datetime import datetime itertools import repeat acc=[{u'switch_id': 3, u'hangup_cause_id': 7, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 1), u'duration': 32}, {u'switch_id': 3, u'hangup_cause_id': 10, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 8), u'duration': 20}, {u'switch_id': 3, u'hangup_cause_id': 10, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 10), u'duration': 17}] t = datetime.now() y = t.year m = t.month d = t.day donnees=[] k in range(7):     try:         m = t.month         data=[]         liste=[]         liste_time=[]         in acc:             if (i["start_uepoch"].year == y , i["start_uepoch"].month == m , i["start_uepoch"].day == d-k):             liste.append([i["start_uepoch"],i["duration"]])         q in range(24):             mnt in range(60):                 liste2=[]                 acd=0                 somme_duration=0                 n=0                 p in liste:                     if (p[0].hour==q , p[0].minute == mnt):                         liste2.append(p[1])                         temps=p[0]                 if len(liste2)!=0:                     j in liste2:                         somme_duration+=j                         n+=1                     acd=round((float(somme_duration)/n)*100)/100                     liste_time.append(calendar.timegm(temps.timetuple()))                     data.append(acd)                                                else:                     liste_time.append(calendar.timegm(temps.timetuple()))                     data.append(0)     except:         pass     donnees.append(data) print donnees 

this due try / except condition, if remove settings temps = none after loop solves issue :

import time import calendar datetime import datetime itertools import repeat acc=[{u'switch_id': 3, u'hangup_cause_id': 7, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 1), u'duration': 32}, {u'switch_id': 3, u'hangup_cause_id': 10, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 8), u'duration': 20}, {u'switch_id': 3, u'hangup_cause_id': 10, u'start_uepoch': datetime(2015, 5, 8, 13, 32, 10), u'duration': 17}] t = datetime.now() y = t.year m = t.month d = t.day donnees=[] k in range(7):     m = t.month     data=[]     liste=[]     liste_time=[]     in acc:         if (i["start_uepoch"].year == y , i["start_uepoch"].month == m , i["start_uepoch"].day == d-k):             liste.append([i["start_uepoch"],i["duration"]])     q in range(24):         mnt in range(60):             temps = none             liste2=[]             acd=0             somme_duration=0             n=0             p in liste:                 if (p[0].hour==q , p[0].minute == mnt):                     liste2.append(p[1])                     temps=p[0]             if temps:                 if len(liste2)!=0:                     j in liste2:                         somme_duration+=j                         n+=1                     acd=round((float(somme_duration)/n)*100)/100                     liste_time.append(calendar.timegm(temps.timetuple()))                     data.append(acd)                                                else:                     liste_time.append(calendar.timegm(temps.timetuple()))                     data.append(0)     donnees.append(data) print donnees 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -