示例#1
0
def index(request):
    starttime = request.GET.get('starttime',None)
    endtime = request.GET.get('endtime',None)

    timeout = settings.LOGGIT_TIMEOUT

    if starttime and endtime:
        if starttime >= endtime:
            day = datetime.datetime.strptime(endtime,'%Y-%m-%d').strftime('%Y%m%d')
            if cache.get(day+'alarm'+'success') is None:
                domains = list(quality_mint.objects(date__startswith=day).order_by('date'))
                success_data,failure_data,total_data = chart_total_data(domains)
                cache.set(day+'alarm'+'success', success_data, timeout)
                cache.set(day+'alarm'+'failure', failure_data, timeout)
                cache.set(day+'alarm'+'total', total_data, timeout)
            else:
                success_data = cache.get(day+'alarm'+'success')
                failure_data = cache.get(day+'alarm'+'failure')
                total_data = cache.get(day+'alarm'+'total')
        else:
            start = datetime.datetime.strptime(starttime,'%Y-%m-%d').strftime('%Y%m%d0000')
            end = datetime.datetime.strptime(endtime,'%Y-%m-%d').strftime('%Y%m%d0000')

            if cache.get(start+end+'alarm'+'success') is None:
                domains = list(quality_mint.objects(date__gte=start, date__lte=end).order_by('date'))
                success_data,failure_data,total_data = chart_total_data(domains)
                cache.set(start+end+'alarm'+'success', success_data, timeout)
                cache.set(start+end+'alarm'+'failure', failure_data, timeout)
                cache.set(start+end+'alarm'+'total', total_data, timeout)
            else:
                success_data = cache.get(start+end+'alarm'+'success')
                failure_data = cache.get(start+end+'alarm'+'failure')
                total_data = cache.get(start+end+'alarm'+'total')

    return {'success_data':success_data,'failure_data':failure_data,'total_data':total_data}
示例#2
0
def map_percent(data):
    domain = data[0]
    count = data[1]
    isp = data[2]
    province = data[3]
    namelist = data[4]
    date = data[5]
    qm = quality_mint.objects(isp=isp,province=province,date=date).values_list('total',)
    if len(qm) != 0:
        strpre = "%0.2f" % (float(count)/float(qm[0])*100) + '%' 
    else:
        strpre ='0.0%'
    tuple_data = (domain,count,isp,province,namelist,date,strpre)
    return tuple_data