python 位置参数溢出,溢出错误mktime参数超出范围

@login_required(login_url='/accounts/login/')

def loggedin(request):

data = []

data2 = []

data3 = []

dicdata2 = {}

dicdata3 = {}

datainterior = []

today = timezone.localtime(timezone.now()+timedelta(hours=1)).date()

tomorrow = today + timedelta(1)

semana= today - timedelta(7)

today = today - timedelta(1)

semana_start = datetime.combine(today, time())

semana_start = timezone.make_aware(semana_start, timezone.utc)

today_start = datetime.combine(today, time())

today_start = timezone.make_aware(today_start, timezone.utc)

today_end = datetime.combine(tomorrow, time())

today_end = timezone.make_aware(today_end, timezone.utc)

for modulo in Repository.objects.values("des_especialidade").distinct():

dic = {}

mod = str(modulo['des_especialidade'])

dic["label"] = str(mod)

dic["value"] = Repository.objects.filter(des_especialidade__iexact=mod).count()

data.append(dic)

for modulo in Repository.objects.values("modulo").distinct():

dic = {}

mod = str(modulo['modulo'])

dic["label"] = str(mod)

dic["value"] = Repository.objects.filter(modulo__iexact=mod, dt_diag__gte=semana_start).count()

datainterior.append(dic)

# print mod, Repository.objects.filter(modulo__iexact=mod).count()

# data[mod] = Repository.objects.filter(modulo__iexact=mod).count()

dicdata2['values'] = datainterior

dicdata2['key'] = "Cumulative Return"

dicdata3['values'] = data

dicdata3['color'] = "#d67777"

dicdata3['key'] = "Diagnosticos Identificados"

data3.append(dicdata3)

data2.append(dicdata2)

#-------sunburst

databurst = []

dictburst = {}

dictburst['name'] = "CHP"

childrenmodulo = []

for modulo in Repository.objects.values("modulo").distinct():

childrenmodulodic = {}

mod = str(modulo['modulo'])

childrenmodulodic['name'] = mod

childrenesp = []

for especialidade in Repository.objects.filter(modulo__iexact=mod).values("des_especialidade").distinct():

childrenespdic = {}

esp = str(especialidade['des_especialidade'])

childrenespdic['name'] = esp

childrencode = []

for code in Repository.objects.filter(modulo__iexact=mod,des_especialidade__iexact=esp).values("cod_diagnosis").distinct():

childrencodedic = {}

codee= str(code['cod_diagnosis'])

childrencodedic['name'] = 'ICD9 - '+codee

childrencodedic['size'] = Repository.objects.filter(modulo__iexact=mod,des_especialidade__iexact=esp,cod_diagnosis__iexact=codee).count()

childrencode.append(childrencodedic)

childrenespdic['children'] = childrencode

#childrenespdic['size'] = Repository.objects.filter(des_especialidade__iexact=esp).count()

childrenesp.append(childrenespdic)

childrenmodulodic['children'] = childrenesp

childrenmodulo.append(childrenmodulodic)

dictburst['children'] = childrenmodulo

databurst.append(dictburst)

# print databurst

# --------stacked area chart

datastack = []

for modulo in Repository.objects.values("modulo").distinct():

datastackdic = {}

mod = str(modulo['modulo'])

datastackdic['key'] = mod

monthsarray = []

year = timezone.localtime(timezone.now()+timedelta(hours=1)).year

month = timezone.localtime(timezone.now()+timedelta(hours=1)).month

last = timezone.localtime(timezone.now()+timedelta(hours=1)) - relativedelta(years=1)

lastyear = int(last.year)

lastmonth = int(last.month)

#i = 1

while lastmonth <= int(month) or lastyear

date = str(lastmonth) + '/' + str(lastyear)

if (lastmonth < 12):

datef = str(lastmonth + 1) + '/' + str(lastyear)

else:

lastmonth = 01

lastyear = int(lastyear)+1

datef = str(lastmonth)+'/'+ str(lastyear)

lastmonth = 0

datainicial = datetime.strptime(date, '%m/%Y')

datainicial = timezone.make_aware(datainicial, timezone.utc)

datafinal = datetime.strptime(datef, '%m/%Y')

datafinal = timezone.make_aware(datafinal, timezone.utc)

#print "lastmonth",lastmonth,"lastyear", lastyear

#print "datainicial:",datainicial,"datafinal: ",datafinal

filtro = Repository.objects.filter(modulo__iexact=mod)

count = filtro.filter(dt_diag__gte=datainicial, dt_diag__lt=datafinal).count()

conv = datetime.strptime(date, '%m/%Y')

ms = datetime_to_ms_str(conv)

monthsarray.append([ms, count])

#i += 1

lastmonth += 1

datastackdic['values'] = monthsarray

datastack.append(datastackdic)

#print datastack

if request.user.last_login is not None:

#print(request.user.last_login)

contador_novas = Repository.objects.filter(dt_diag__lte=today_end, dt_diag__gte=today_start).count()

return render_to_response('loggedin.html',

{'user': request.user.username, 'contador': contador_novas, 'data': data, 'data2': data2,

'data3': data3,

'databurst': databurst, 'datastack':datastack})

def datetime_to_ms_str(dt):

return str(1000 * mktime(dt.timetuple()))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值