def get_net_compare_data_list(request): print 'in get_net_compare_data_list' datas =[] columnIndexNameMap = {0: 'datetime'} appprotc = request.GET["appprotc"] print appprotc earliest_time = NetBehaviour.objects.order_by("datetime")[0].datetime latest_time = NetBehaviour.objects.order_by("-datetime")[0].datetime end_days = (latest_time-earliest_time).days #check the days between make sure it is 30 days if end_days < 30: earliest_time = earliest_time print earliest_time,'get_net_compare_data_list 30 ' end_days = 30 else: earliest_time = latest_time + datetime.timedelta(hours=-30*24) print earliest_time,'get_net_compare_data_list 60' #fill the time with 0 and add num to the one that exist filterdict = dict() filterdict["appprotc"] = appprotc if User.objects.get(username = request.user).is_superuser == False: userinfo = Userinfo.objects.get(user=request.user) filterdict["user_id"] =ObjectId(userinfo.id) db_datetime = get_highcharts_records(NetBehaviour,columnIndexNameMap,filterdict,"datetime") appprotcdict = {} for i in range((latest_time - earliest_time).seconds/3600 + 1 + end_days*24): currtime = earliest_time + datetime.timedelta(hours=i) totime = earliest_time + datetime.timedelta(hours=i+1) secstimestr = datestrtsecs(currtime.strftime("%Y-%m-%d %H:00:00"))*1000 #print secstimestr totimestr = datestrtsecs(totime.strftime("%Y-%m-%d %H:00:00"))*1000 appprotcdict[secstimestr] = 0 for cmp_time in db_datetime: icmp_time = int(cmp_time[0]) #print icmp_time,'icmp_time' if icmp_time >= secstimestr and icmp_time <= totimestr: appprotcdict[secstimestr] += 1 # change tha data to style what we want strlist = list() for i in sorted(appprotcdict): tmpstr = "[%s,%d]"%(i,appprotcdict[i]) strlist.append(tmpstr) appprotcdata = ",".join(strlist) #print driverdata datas.append(appprotcdata) response = HttpResponse(simplejson.dumps(datas), mimetype='application/json') #阻止缓存 add_never_cache_headers(response) #print response return response
except Exception,e: traceback.print_exc() if end: try: timedict["$lt"] = end except Exception,e: traceback.print_exc() if timedict: filterdict["insert_time"] = timedict columnIndexNameMap = { 0: 'insert_time', } columnNameIndexMap = dict([[v,k] for k,v in columnIndexNameMap.items()])#将columnIndexNameMap的key,value对调 aaData = get_highcharts_detail_records(AlarmList,columnIndexNameMap,filterdict,'insert_time') tempbegin = datestrtsecs(begin.strftime("%Y-%m-%d %H")+':00:00')*1000 redata = [] alarmdict = dict() for i in range(24*7): alarmdict[str(tempbegin)]=0 tempbegin = tempbegin+60*60*1000 for i in aaData: hours = i[0] alarmdict[str(hours)] += 1 tempbegin = datestrtsecs(begin.strftime("%Y-%m-%d %H")+':00:00')*1000 for i in range(24*7): tempdata = [0,0] tempdata[0]=tempbegin tempdata[1]=alarmdict[str(tempbegin)] redata.append(tempdata)