def chartdata_erbc(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') print 'retention', retention # Common Data past, today = getTimeRange(retention,projectElement.timezone) #print 'past',past, 'today',today errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') #instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) #AppruncountElemtns = Appruncount.objects.filter(pid=projectElement,date__range=(past,today)) result = {} #chart2 chart2 = [] pre_class = '' #print 'past',past for e in errorElements: instanceCount = Instances.objects.filter(iderror=e,datetime__gte=past).count() if pre_class != e.errorclassname: pre_class = e.errorclassname chart2.append([e.errorclassname, instanceCount]) else: last = len(chart2) chart2[last-1] = [e.errorclassname,chart2[last-1][1] + (instanceCount)] result['chart2'] = chart2 return HttpResponse(json.dumps(result), 'application/json');
def dailyesgraph(request, apikey): #일간 에러 발생비율을 보여준다. default = {"max": {"key": 5, "value": 0}, "tags": []} retention = TimeRange.weekly #7일치 데이터를 보여줌 username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponse(json.dumps(default), 'application/json') #일간 데이터를 얻어오기위한 쿼리 작성 #sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(CONVERT_TZ(datetime,'UTC',%(timezone)s),'%%y-%%m-%%d') as errorday " sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(datetime,'%%y-%%m-%%d') as errorday " sql = sql + "from instances A, errors B " sql = sql + "where A.iderror = B.iderror " sql = sql + "and B.pid = %(pidinput)s " sql = sql + "and B.status in (0,1) " sql = sql + "and A.datetime > %(pasttime)s" sql = sql + "group by errorday" past, today = getTimeRange(retention, projectElement.timezone) params = { 'timezone': projectElement.timezone, 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } places = ErrorsbyApp.objects.raw(sql, params) #얻어온 데이터를 JSON으로 파싱한다. maxvalue = 0 value = {'key': 0, 'value': 0} for i in range(retention - 1, -1, -1): day1 = getTimezoneMidNight( projectElement.timezone) + datetime.timedelta(days=-i) #print >> sys.stderr,'day',day1,day1.month,day1.day,day1.hour,day1.minute #print >> sys.stderr,'utc',toTimezone(day1,'UTC') instanceCount = 0 for idx, pl in enumerate(places): if day1.strftime('%y-%m-%d') == pl.errorday: instanceCount = pl.errorcount break value = {'key': 0, 'value': instanceCount} if maxvalue < instanceCount: #maxvalue! maxvalue = instanceCount value['key'] = day1.strftime('%m / %d') default['tags'].append(value) default['max']['key'] = len(default['tags']) default['max']['value'] = maxvalue return HttpResponse(json.dumps(default), 'application/json')
def typeesgraph(request, apikey): #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') timerange = TimeRange.weekly week, today = getTimeRange(timerange) default = { "tags": [ { "key": "Unhandle", "value": 0 }, { "key": "Native", "value": 0 }, { "key": "Critical", "value": 0 }, { "key": "Major", "value": 0 }, { "key": "Minor", "value": 0 }, ] } for i in range(RANK.Unhandle, RANK.Minor + 1): # unhandled 부터 Native 까지 errorElements = Errors.objects.filter(pid=ProjectElement, lastdate__range=(week, today), rank=i) instanceCount = Instances.objects.filter( iderror__in=errorElements, datetime__range=(week, today)).count() #instanceCount = Instancecount.objects.filter(pid=ProjectElement,date__gte=week,rank=i).aggregate(Sum('count'))['count__sum'] #print 'instanceCount',instanceCount if instanceCount: default['tags'][i]['value'] = instanceCount popcount = RANK.Unhandle for i in range(RANK.Unhandle, RANK.Minor + 1): if default['tags'][i - popcount]['value'] == 0: default['tags'].pop(i - popcount) popcount += 1 result = json.dumps(default) return HttpResponse(result, 'application/json')
def chartdata_erbd(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') print 'retention', retention # Common Data past, today = getTimeRange(retention,projectElement.timezone) #print 'past',past, 'today',today errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) #AppruncountElemtns = Appruncount.objects.filter(pid=projectElement,date__range=(past,today)) result = {} #chart3 - Device error temp_data = {} activities = [] instances = instanceElements.order_by('device') for i in instances: if i.device: device = i.device else: device = "Unknown" if not device in activities: activities.append(device) temp_data[device] = 1 else: temp_data[device] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) categories = [] temp_data = [] i = 0 others_count = 0 for l,v in sorted_dic: i += 1 if i>25: others_count += v else: categories.append(l) temp_data.append(v) if others_count != 0: categories.append('Others') temp_data.append(others_count) dev_data = [{'name':'Device','data':temp_data}] chart3 = {'categories':categories,'data':dev_data} result['chart3'] = chart3 return HttpResponse(json.dumps(result), 'application/json');
def dailyesgraph(request, apikey): #일간 에러 발생비율을 보여준다. default = { "max":{"key":5, "value":0}, "tags":[ ] } retention = TimeRange.weekly #7일치 데이터를 보여줌 username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponse(json.dumps(default),'application/json') #일간 데이터를 얻어오기위한 쿼리 작성 #sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(CONVERT_TZ(datetime,'UTC',%(timezone)s),'%%y-%%m-%%d') as errorday " sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(datetime,'%%y-%%m-%%d') as errorday " sql = sql + "from instances A, errors B " sql = sql + "where A.iderror = B.iderror " sql = sql + "and B.pid = %(pidinput)s " sql = sql + "and B.status in (0,1) " sql = sql + "and A.datetime > %(pasttime)s" sql = sql + "group by errorday" past, today = getTimeRange(retention,projectElement.timezone) params = {'timezone':projectElement.timezone,'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} places = ErrorsbyApp.objects.raw(sql, params) #얻어온 데이터를 JSON으로 파싱한다. maxvalue = 0 value = {'key' : 0 , 'value' : 0} for i in range(retention-1,-1,-1): day1 = getTimezoneMidNight(projectElement.timezone) + datetime.timedelta(days = -i) #print >> sys.stderr,'day',day1,day1.month,day1.day,day1.hour,day1.minute #print >> sys.stderr,'utc',toTimezone(day1,'UTC') instanceCount = 0 for idx, pl in enumerate(places): if day1.strftime('%y-%m-%d') == pl.errorday: instanceCount = pl.errorcount break; value = {'key' : 0 , 'value' : instanceCount} if maxvalue < instanceCount: #maxvalue! maxvalue = instanceCount value['key'] = day1.strftime('%m / %d') default['tags'].append(value) default['max']['key'] = len(default['tags']) default['max']['value'] = maxvalue return HttpResponse(json.dumps(default),'application/json')
def dailyesgraph(request, apikey): #기본 데이터 default = { "max":{"key":5, "value":0}, "tags":[ ] } #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey= apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json'); #오늘 날짜 및 일주일 전을 계산 timerange = TimeRange.weekly week , today = getTimeRange(timerange,ProjectElement.timezone) #defalut값에 날짜를 대입함 maxvalue = 0 errorElements = Errors.objects.filter(pid=ProjectElement,lastdate__range=(week , today)) for i in range(0,timerange): value = {'key' : 0 , 'value' : 0} begin_date = today + datetime.timedelta(days = i-(timerange) ) end_date = today + datetime.timedelta(days = i-(timerange-1) ) instanceCount = Instances.objects.filter(iderror__in=errorElements,datetime__range=(begin_date,end_date)).count() #instanceCount = Instancecount.objects.filter(pid = ProjectElement,date=tmpdate).aggregate(Sum('count'))['count__sum'] if instanceCount: value['value'] = instanceCount if maxvalue < instanceCount: #maxvalue! maxvalue = instanceCount else: value['value'] = 0 #timezone 적용 adtimezone = toTimezone(end_date,ProjectElement.timezone) value['key'] = adtimezone.__format__('%m / %d') default['tags'].append(value) default['max']['key'] = len(default['tags']) default['max']['value'] = maxvalue #print 'default',default return HttpResponse(json.dumps(default),'application/json')
def typeesgraph(request, apikey): #Error Type(Unhandle, Critical, Major, Minor, Native)에 따라 에러비율을 그래프로 나타내는 루틴 #print >> sys.stderr,'typeesgraph' #프로젝트 ID에 맞는 에러들을 가져오기 위함 default = { "tags":[ {"key":"Unhandle", "value":0}, {"key":"Native", "value":0}, {"key":"Critical", "value":0}, {"key":"Major", "value":0}, {"key":"Minor", "value":0}, ] } try: projectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: #print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') retention = TimeRange.weekly past, today = getTimeRange(retention,projectElement.timezone) sql = 'select B.iderror as iderrorbyrank, count(*) as errorcount, rank as errorrank ' sql = sql + ' from instances A, errors B ' sql = sql + ' where A.iderror = B.iderror ' sql = sql + ' and B.status in (0,1) ' sql = sql + ' and B.pid = %(pidinput)s and datetime > %(pasttime)s' sql = sql + ' group by errorrank' params = {'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} places = ErrorsbyApp.objects.raw(sql, params) #DB로 얻어온 데이터를 JSON으로 변환함. for i in range(RANK.Unhandle,RANK.Minor+1): for idx, pl in enumerate(places): if pl.errorrank == i: default['tags'][i]['value'] = pl.errorcount break #print >> sys.stderr,pl.iderrorbyrank,pl.errorcount,pl.errorrank popcount = RANK.Unhandle for i in range(RANK.Unhandle,RANK.Minor+1): if default['tags'][i-popcount]['value'] == 0: default['tags'].pop(i-popcount) popcount += 1 result = json.dumps(default) return HttpResponse(result,'application/json')
def typeescolor(request, apikey): timerange = TimeRange.weekly #print >> sys.stderr,'typeescolor' default = { "tags": [{ "key": "Unhandle", "value": 0 }, { "key": "Critical", "value": 0 }, { "key": "Major", "value": 0 }, { "key": "Minor", "value": 0 }, { "key": "Native", "value": 0 }] } #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: #print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') week, today = getTimeRange(timerange, ProjectElement.timezone) for i in range(RANK.Unhandle, RANK.Minor + 1): # unhandled 부터 Minor 까지 errorweight = Errors.objects.filter( pid=ProjectElement, status__in=[Status.New, Status.Open], lastdate__range=(week, today), rank=i).aggregate(Sum('errorweight')) #일주일치 얻어옴 if errorweight is not None: default['tags'][i]['value'] = errorweight ColorTable = [] for i in range(RANK.Unhandle, RANK.Minor + 1): if default['tags'][i]['value'] != 0: ColorTable.append(RANK.rankcolorbit[i]) result = json.dumps(ColorTable) print >> sys.stderr, 'ColorTable', ColorTable return HttpResponse(result, 'application/json')
def chartdata_sbav(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') print 'retention', retention # Common Data past, today = getTimeRange(retention,projectElement.timezone) #print 'past',past, 'today',today errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') #instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) AppruncountElemtns = Appruncount.objects.filter(pid=projectElement,date__range=(past,today)) result = {} # Chart 0 session by appversion appversions = AppruncountElemtns.values('appversion').distinct().order_by('appversion') categories = [] appcount_data = {} for appversion in appversions: appcount_data[appversion['appversion']] = [] for i in range(retention-1,-1,-1): day1 = getTimezoneMidNight('UTC') + datetime.timedelta(days = -i) categories.append(day1.strftime('%b-%d')) for appversion in appversions: #appcount_data[appversion['appversion']].append(Appruncount.objects.filter(pid=projectElement,appversion=appversion['appversion'],date__range=(day1,day2))) runcounts = Appruncount.objects.filter(pid=projectElement,appversion=appversion['appversion'],date=day1.strftime('20%y-%m-%d')) result_runcount = 0 for runcount in runcounts: result_runcount = result_runcount + runcount.runcount appcount_data[appversion['appversion']].append(result_runcount); appver_data = [] for appversion in appversions: appver_data.append( { 'name': appversion['appversion'], 'data': appcount_data[appversion['appversion']] } ) chart_sbav = {'categories':categories,'data':appver_data} result['chart_sbav'] = chart_sbav return HttpResponse(json.dumps(result), 'application/json');
def dailyesgraph(request, apikey): #기본 데이터 default = {"max": {"key": 5, "value": 0}, "tags": []} #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') #오늘 날짜 및 일주일 전을 계산 timerange = TimeRange.weekly week, today = getTimeRange(timerange) #defalut값에 날짜를 대입함 maxvalue = 0 errorElements = Errors.objects.filter(pid=ProjectElement, lastdate__range=(week, today)) for i in range(0, timerange): value = {'key': 0, 'value': 0} begin_date = today + datetime.timedelta(days=i - (timerange)) end_date = today + datetime.timedelta(days=i - (timerange - 1)) instanceCount = Instances.objects.filter( iderror__in=errorElements, datetime__range=(begin_date, end_date)).count() #instanceCount = Instancecount.objects.filter(pid = ProjectElement,date=tmpdate).aggregate(Sum('count'))['count__sum'] if instanceCount: value['value'] = instanceCount if maxvalue < instanceCount: #maxvalue! maxvalue = instanceCount else: value['value'] = 0 #timezone 적용 adtimezone = toTimezone(end_date, ProjectElement.timezone) value['key'] = adtimezone.__format__('%m / %d') default['tags'].append(value) default['max']['key'] = len(default['tags']) default['max']['value'] = maxvalue #print 'default',default return HttpResponse(json.dumps(default), 'application/json')
def typeescolor(request, apikey): timerange = TimeRange.weekly week, today = getTimeRange(timerange) default = { "tags": [{ "key": "Unhandle", "value": 0 }, { "key": "Critical", "value": 0 }, { "key": "Major", "value": 0 }, { "key": "Minor", "value": 0 }, { "key": "Native", "value": 0 }] } #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') for i in range(RANK.Unhandle, RANK.Minor + 1): # unhandled 부터 Minor 까지 ErrorsElements = Errors.objects.filter( pid=ProjectElement, status__in=[Status.New, Status.Open], lastdate__range=(week, today), rank=i) #일주일치 얻어옴 if len(ErrorsElements) > 0: for error in ErrorsElements: default['tags'][i]['value'] += error.errorweight #print str(i) + ':' + str(default['tags'][i]['value']) ColorTable = [] for i in range(RANK.Unhandle, RANK.Minor + 1): if default['tags'][i]['value'] != 0: ColorTable.append(RANK.rankcolorbit[i]) result = json.dumps(ColorTable) return HttpResponse(result, 'application/json')
def errorscorelist(apikey): try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse('') #print today week, today = getTimeRange(TimeRange.weekly, ProjectElement.timezone) # 최초 50개 만 가져온다. ErrorElements = Errors.objects.filter( pid=ProjectElement, status__in=[Status.New, Status.Open], lastdate__range=(week, today)).order_by('rank', '-numofinstances', '-lastdate')[:50] jsondata = [] for error in ErrorElements: #if error.rank == RANK.Suspense: #continue TagElements = Tags.objects.filter(iderror=error) rankcolor = '' if error.rank == -1: rankcolor = 'none' else: rankcolor = RANK.rankcolor[error.rank] dicerrordata = { 'ErrorName': error.errorname, #'ErrorClassName' : error.errorclassname + '(' + error.linenum + ')' , 'ErrorClassName': error.errorclassname + ':' + error.linenum, 'tags': TagElements, 'ErrorCount': error.numofinstances, 'Errorid': error.iderror, 'Errorrankcolor': rankcolor, 'ErrorDateFactor': error.gain1, 'ErrorQuantityFactor': error.gain2 } jsondata.append(dicerrordata) #print dicerrordata Viewer.objects.create return jsondata
def chartdata_erbv(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') print 'retention', retention # Common Data past, today = getTimeRange(retention,projectElement.timezone) #print 'past',past, 'today',today errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) #AppruncountElemtns = Appruncount.objects.filter(pid=projectElement,date__range=(past,today)) result = {} #Chart5 categories = [] ver_data = [] temp_data = {} instances = instanceElements.order_by('-appversion','-osversion') appv_idx = -1 for i in instances: if not i.appversion in categories: appv_idx += 1 categories.append(i.appversion) if not i.osversion in temp_data: temp_data[i.osversion] = [] while len(temp_data[i.osversion]) <= appv_idx: temp_data[i.osversion].append(0) #score = float(i.iderror.errorweight) / i.iderror.numofinstances temp_data[i.osversion][appv_idx] += 1#score for t in temp_data: idx = 0 for e in temp_data[t]: temp_data[t][idx] = e#round(e,2) idx += 1 ver_data.append({'name':t,'data':temp_data[t]}) chart5 = {'categories':categories,'data':ver_data} result['chart5'] = chart5 return HttpResponse(json.dumps(result), 'application/json');
def errorscorelist(apikey): try: ProjectElement = Projects.objects.get(apikey = apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse('') #print today week, today = getTimeRange(TimeRange.weekly,ProjectElement.timezone) ErrorElements = Errors.objects.filter(pid = ProjectElement , status__in=[Status.New,Status.Open],lastdate__range = (week, today) ).order_by('rank','-numofinstances','-lastdate') jsondata = [] for error in ErrorElements: #if error.rank == RANK.Suspense: #continue TagElements = Tags.objects.filter(iderror = error) rankcolor = '' if error.rank == -1: rankcolor = 'none' else: rankcolor = RANK.rankcolor[error.rank] dicerrordata = { 'ErrorName' : error.errorname , #'ErrorClassName' : error.errorclassname + '(' + error.linenum + ')' , 'ErrorClassName' : error.errorclassname + ':' + error.linenum, 'tags': TagElements, 'ErrorCount' : error.numofinstances, 'Errorid' : error.iderror , 'Errorrankcolor' : rankcolor, 'ErrorDateFactor' : error.gain1, 'ErrorQuantityFactor' : error.gain2 } jsondata.append(dicerrordata); #print dicerrordata Viewer.objects.create return jsondata
def errorscorelist(apikey): try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print "invalid pid" return HttpResponse("") # print today week, today = getTimeRange(TimeRange.weekly, ProjectElement.timezone) ErrorElements = Errors.objects.filter( pid=ProjectElement, status__in=[Status.New, Status.Open], lastdate__range=(week, today) ).order_by("rank", "-numofinstances", "-lastdate") jsondata = [] for error in ErrorElements: # if error.rank == RANK.Suspense: # continue TagElements = Tags.objects.filter(iderror=error) rankcolor = "" if error.rank == -1: rankcolor = "none" else: rankcolor = RANK.rankcolor[error.rank] dicerrordata = { "ErrorName": error.errorname, #'ErrorClassName' : error.errorclassname + '(' + error.linenum + ')' , "ErrorClassName": error.errorclassname + ":" + error.linenum, "tags": TagElements, "ErrorCount": error.numofinstances, "Errorid": error.iderror, "Errorrankcolor": rankcolor, "ErrorDateFactor": error.gain1, "ErrorQuantityFactor": error.gain2, } jsondata.append(dicerrordata) # print dicerrordata Viewer.objects.create return jsondata
def typeesgraph(request, apikey): #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') timerange = TimeRange.weekly week , today = getTimeRange(timerange,ProjectElement.timezone) default = { "tags":[ {"key":"Unhandle", "value":0}, {"key":"Native", "value":0}, {"key":"Critical", "value":0}, {"key":"Major", "value":0}, {"key":"Minor", "value":0}, ] } for i in range(RANK.Unhandle,RANK.Minor+1): # unhandled 부터 Native 까지 errorElements = Errors.objects.filter(pid=ProjectElement,lastdate__range=(week,today),rank=i) instanceCount = Instances.objects.filter(iderror__in=errorElements,datetime__range=(week,today)).count() #instanceCount = Instancecount.objects.filter(pid=ProjectElement,date__gte=week,rank=i).aggregate(Sum('count'))['count__sum'] #print 'instanceCount',instanceCount if instanceCount: default['tags'][i]['value'] = instanceCount popcount = RANK.Unhandle for i in range(RANK.Unhandle,RANK.Minor+1): if default['tags'][i - popcount]['value'] == 0: default['tags'].pop(i - popcount) popcount+=1 result = json.dumps(default) return HttpResponse(result,'application/json')
def typeescolor(request ,apikey): timerange = TimeRange.weekly default = { "tags":[ {"key":"Unhandle", "value":0}, {"key":"Critical", "value":0}, {"key":"Major", "value":0}, {"key":"Minor", "value":0}, {"key":"Native", "value":0} ] } #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey= apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') week , today = getTimeRange(timerange,ProjectElement.timezone) for i in range(RANK.Unhandle,RANK.Minor+1): # unhandled 부터 Minor 까지 ErrorsElements = Errors.objects.filter(pid = ProjectElement ,status__in=[Status.New,Status.Open] ,lastdate__range = (week,today), rank = i) #일주일치 얻어옴 if len(ErrorsElements) > 0: for error in ErrorsElements: default['tags'][i]['value'] += error.errorweight #print str(i) + ':' + str(default['tags'][i]['value']) ColorTable = [] for i in range(RANK.Unhandle,RANK.Minor+1): if default['tags'][i]['value'] != 0: ColorTable.append(RANK.rankcolorbit[i]) result = json.dumps(ColorTable) return HttpResponse(result,'application/json')
def typeescolor(request ,apikey): timerange = TimeRange.weekly #print >> sys.stderr,'typeescolor' default = { "tags":[ {"key":"Unhandle", "value":0}, {"key":"Critical", "value":0}, {"key":"Major", "value":0}, {"key":"Minor", "value":0}, {"key":"Native", "value":0} ] } #프로젝트 ID에 맞는 에러들을 가져오기 위함 try: ProjectElement = Projects.objects.get(apikey= apikey) except ObjectDoesNotExist: #print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') week , today = getTimeRange(timerange,ProjectElement.timezone) for i in range(RANK.Unhandle,RANK.Minor+1): # unhandled 부터 Minor 까지 errorweight = Errors.objects.filter(pid = ProjectElement ,status__in=[Status.New,Status.Open] ,lastdate__range = (week,today), rank = i).aggregate(Sum('errorweight')) #일주일치 얻어옴 if errorweight is not None: default['tags'][i]['value'] = errorweight ColorTable = [] for i in range(RANK.Unhandle,RANK.Minor+1): if default['tags'][i]['value'] != 0: ColorTable.append(RANK.rankcolorbit[i]) result = json.dumps(ColorTable) print >>sys.stderr,'ColorTable',ColorTable return HttpResponse(result,'application/json')
def chartdata(request, apikey): jsonData = json.loads(request.POST['json'], encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention) errorElements = Errors.objects.filter( pid=projectElement, status__in=[Status.New, Status.Open], lastdate__range=(past, today)).order_by('errorclassname', 'errorweight') instanceElements = Instances.objects.select_related().filter( iderror__in=errorElements, datetime__range=(past, today)) #Chart1 chart1 = [] pre_class = '' print 'past', past for e in errorElements: instanceCount = Instances.objects.filter(iderror=e, datetime__gte=past).count() if pre_class != e.errorclassname: pre_class = e.errorclassname chart1.append([e.errorclassname, instanceCount]) else: last = len(chart1) chart1[last - 1] = [ e.errorclassname, chart1[last - 1][1] + (instanceCount) ] result = {} result['chart1'] = chart1 #Chart2 chart2 = [] temp_data = {} activities = [] instances = instanceElements.order_by('device') for i in instances: if i.device: device = i.device else: device = "Unknown" if not device in activities: activities.append(device) temp_data[device] = 1 else: temp_data[device] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l, v in sorted_dic: chart2.append({ 'label': l, 'value': v, }) result['chart2'] = chart2 """chart2 = [] temp_data = {} for e in errorElements: devices = Devicestatistics.objects.filter(iderror=e).order_by('devicename') if devices.count() == 0: continue total = 0 for d in devices: total += d.count for d in devices: if not d.devicename in temp_data: temp_data[d.devicename] = e.errorweight * d.count / total else: temp_data[d.devicename] += e.errorweight * d.count / total sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart2.append({ 'label': l, 'value': v, }) result['chart2'] = chart2""" #Chart3 chart3 = [] temp_data = {} activities = [] instances = instanceElements.order_by('lastactivity') for i in instances: if i.lastactivity: lastactivity = i.lastactivity else: lastactivity = "Unknown" if not lastactivity in activities: activities.append(lastactivity) temp_data[lastactivity] = 1 else: temp_data[lastactivity] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l, v in sorted_dic: chart3.append({ 'label': l, 'value': v, }) result['chart3'] = chart3 """temp_data = {} for e in errorElements: activity = Activitystatistics.objects.filter(iderror=e).order_by('activityname') if devices.count() == 0: continue total = 0 for d in activity: print d.activityname total += d.count #print d.devicename #print total,e.errorweight for d in activity: if not d.activityname in temp_data: temp_data[d.activityname] = e.errorweight * d.count / total else: temp_data[d.activityname] += e.errorweight * d.count / total sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart3.append({ 'label': l, 'value': v, }) """ #Chart4 categories = [] ver_data = [] temp_data = {} instances = instanceElements.order_by('-appversion', '-osversion') appv_idx = -1 for i in instances: if not i.appversion in categories: appv_idx += 1 categories.append(i.appversion) if not i.osversion in temp_data: temp_data[i.osversion] = [] while len(temp_data[i.osversion]) <= appv_idx: temp_data[i.osversion].append(0) #score = float(i.iderror.errorweight) / i.iderror.numofinstances temp_data[i.osversion][appv_idx] += 1 #score for t in temp_data: idx = 0 for e in temp_data[t]: temp_data[t][idx] = e #round(e,2) idx += 1 ver_data.append({'name': t, 'data': temp_data[t]}) #print categories #print ver_data #ver_data[appv_idx][] #print categories chart4 = {'categories': categories, 'data': ver_data} result['chart4'] = chart4 return HttpResponse(json.dumps(result), 'application/json')
def appv_ratio(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) depth = int(jsonData['depth']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention,projectElement.timezone) errorElements = Errors.objects.filter(pid=projectElement,lastdate__range=(past,today)) data = {'appv':{},'osv':{}} instances = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)).order_by('-appversion') for i in instances: key = i.appversion if not key in data['appv']: data['appv'][key] = 1 else: data['appv'][key] += 1 #print "data['appv']",data['appv'] osv_list = {} instances.order_by('-osversion') for i in instances: k = i.osversion.split('.') if len(k) < 2: k.append(' ') key = k[0]+'.'+k[1]; if not key in data['osv']: #print key data['osv'][key] = 1 osv_list[key] = [] else: data['osv'][key] += 1 if not i.osversion in osv_list[key]: osv_list[key].append(i.osversion) #print "data['osv']",data['osv'] max_count = 5 appv_data = sorted(data['appv'].iteritems(), key=operator.itemgetter(1), reverse=True) appv_others = [] if len(appv_data) > max_count: appv_others.append(appv_data[max_count-1][0]) while len(appv_data) > max_count: appv_data[max_count-1] = ('Others',appv_data[max_count-1][1] + appv_data[max_count][1]) appv_others.append(appv_data[max_count][0]) appv_data.pop(max_count) osv_data = sorted(data['osv'].iteritems(), key=operator.itemgetter(1), reverse=True) osv_others = [] if len(appv_data) > max_count: osv_others.append(appv_data[max_count-1][0]) while len(osv_data) > max_count: osv_data[max_count-1] = ('Others',osv_data[max_count-1][1] + osv_data[max_count][1]) osv_others.append(osv_data[max_count][0]) osv_data.pop(max_count) #print osv_data return HttpResponse(json.dumps({'total':instances.count(),'appv':appv_data,'osv':osv_data,'osv_list':osv_list,'appv_others':appv_others,'osv_others':osv_others}), 'application/json'); """
def appv_ratio(request, apikey): jsonData = json.loads(request.POST['json'], encoding='utf-8') retention = int(jsonData['retention']) depth = int(jsonData['depth']) username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention) errorElements = Errors.objects.filter(pid=projectElement, lastdate__range=(past, today)) data = {'appv': {}, 'osv': {}} instances = Instances.objects.select_related().filter( iderror__in=errorElements, datetime__range=(past, today)).order_by('-appversion') for i in instances: key = i.appversion if not key in data['appv']: data['appv'][key] = 1 else: data['appv'][key] += 1 #print "data['appv']",data['appv'] osv_list = {} instances.order_by('-osversion') for i in instances: k = i.osversion.split('.') key = k[0] + '.' + k[1] if not key in data['osv']: #print key data['osv'][key] = 1 osv_list[key] = [] else: data['osv'][key] += 1 if not i.osversion in osv_list[key]: osv_list[key].append(i.osversion) #print "data['osv']",data['osv'] max_count = 5 appv_data = sorted(data['appv'].iteritems(), key=operator.itemgetter(1), reverse=True) appv_others = [] if len(appv_data) > max_count: appv_others.append(appv_data[max_count - 1][0]) while len(appv_data) > max_count: appv_data[max_count - 1] = ('Others', appv_data[max_count - 1][1] + appv_data[max_count][1]) appv_others.append(appv_data[max_count][0]) appv_data.pop(max_count) osv_data = sorted(data['osv'].iteritems(), key=operator.itemgetter(1), reverse=True) osv_others = [] if len(appv_data) > max_count: osv_others.append(appv_data[max_count - 1][0]) while len(osv_data) > max_count: osv_data[max_count - 1] = ('Others', osv_data[max_count - 1][1] + osv_data[max_count][1]) osv_others.append(osv_data[max_count][0]) osv_data.pop(max_count) #print osv_data return HttpResponse( json.dumps({ 'total': instances.count(), 'appv': appv_data, 'osv': osv_data, 'osv_list': osv_list, 'appv_others': appv_others, 'osv_others': osv_others }), 'application/json') """
def filter_view(request,apikey): username = request.user valid , message , userelement, projectelement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') user = AuthUser.objects.get(username = request.user) week, today = getTimeRange(TimeRange.weekly,projectelement.timezone) try: projectElement = Projects.objects.get(apikey = apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse('') errorElements = Errors.objects.filter(pid = projectElement , lastdate__range = (week, today) ).order_by('-errorweight','rank', '-lastdate') valid_tag = Tags.objects.filter(pid=projectElement).values('tag').distinct().order_by('tag') valid_class = errorElements.values('errorclassname').distinct().order_by('errorclassname') valid_app = Appstatistics.objects.filter(iderror__in=errorElements).values('appversion').distinct().order_by('-appversion') valid_os = Osstatistics.objects.filter(iderror__in=errorElements).values('osversion').distinct().order_by('-osversion') osv_list = [] os_idx = -1 prev_v = ['-1','-1','-1'] for e in valid_os: v = e['osversion'].split('.') if len(v) < 2: v.append(' ') if v[0] != prev_v[0] or v[1] != prev_v[1]: prev_v = v os_idx += 1 osv_list.append({}) osv_list[os_idx]['key'] = '%s.%s' % (v[0],v[1]) osv_list[os_idx]['value'] = [] osv_list[os_idx]['value'].append(e['osversion']) appv_list = [] app_idx = -1 prev_v = ['-1','-1','-1'] for e in valid_app: v = e['appversion'].split('.') if v[0] != prev_v[0] or v[1] != prev_v[1]: prev_v = v app_idx += 1 appv_list.append({}) appv_list[app_idx]['key'] = '%s.%s' % (v[0],v[1]) appv_list[app_idx]['value'] = [] appv_list[app_idx]['value'].append(e['appversion']) tag_list = [] for e in valid_tag: tag_list.append(e['tag']) class_list = [] for e in valid_class: class_list.append(e['errorclassname']) osv_margin = '' for i in range(0,5 - len(osv_list)): osv_margin += ' ' appv_margin = '' for i in range(0,5 - len(appv_list)): appv_margin += ' ' #tpl = loader.get_template('filter.html') filterdict = { #'ServerURL' : 'http://'+request.get_host() + '/urqa/project/', 'tag_list' : tag_list, 'class_list' : class_list, 'osv_list' : osv_list, 'margin' : {'osv':osv_margin,'appv':appv_margin}, 'appv_list' : appv_list, } userdict = getUserProfileDict(user) apikeydict = getApikeyDict(apikey) settingdict = getSettingDict(projectelement,user) print userdict ctxdict = dict(userdict.items() + apikeydict.items() + settingdict.items() + filterdict.items() ) ctx = Context(ctxdict); #return HttpResponse(tpl.render(ctx)) return render(request, 'filter.html', ctx)
def error_list(request,apikey): username = request.user valid , message , userelement, projectelement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') try: projectElement = Projects.objects.get(apikey = apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps({"response":"fail"}), 'application/json'); jsonData = json.loads(request.POST['json'],encoding='utf-8') date = int(jsonData['date']) _status = [[0,1,2,3],[0],[1],[2],[3]] status = _status[int(jsonData['status'])] rank = jsonData['rank'] tags = jsonData['tags'] classes = jsonData['classes'] appversion = jsonData['appv'] if appversion and appversion[0] == 'All': appversion = [] osversion = jsonData['osv'] if osversion and osversion[0] == 'All': osversion = [] week, today = getTimeRange(date,projectElement.timezone) errorElements = Errors.objects.filter(pid=projectElement,rank__in=rank,status__in=status,lastdate__range=(week,today)).order_by('-errorweight','rank', '-lastdate') #print '1',errorElements #print classes if classes: errorElements = errorElements.filter(errorclassname__in=classes) #print tags if tags: tagElements = Tags.objects.select_related().filter(iderror__in=errorElements,tag__in=tags).values('iderror').distinct().order_by('iderror') print tagElements iderror_list = [] for e in tagElements: iderror_list.append(int(e['iderror'])) errorElements = errorElements.filter(iderror__in=iderror_list) #print appversion if appversion: print 'appversion',appversion appvElements = Appstatistics.objects.select_related().filter(iderror__in=errorElements,appversion__in=appversion).values('iderror').distinct().order_by('iderror') print 'appvElements',appvElements iderror_list = [] for e in appvElements: iderror_list.append(int(e['iderror'])) #if iderror_list: errorElements = errorElements.filter(iderror__in=iderror_list) #print osversion if osversion: osvElements = Osstatistics.objects.select_related().filter(iderror__in=errorElements,osversion__in=osversion).values('iderror').distinct().order_by('iderror') iderror_list = [] for e in osvElements: iderror_list.append(int(e['iderror'])) #if iderror_list: errorElements = errorElements.filter(iderror__in=iderror_list) #print errorElements result = [] for e in errorElements: adtimezone = toTimezone(e.lastdate,projectelement.timezone) #print adtimezone new_e = {} new_e['iderror'] = e.iderror new_e['color'] = RANK.rankcolor[e.rank] new_e['rank'] = e.rank new_e['status'] = e.status#Status.toString[e.status] new_e['errorname'] = e.errorname new_e['errorclassname'] = e.errorclassname new_e['linenum'] = e.linenum new_e['count'] = e.numofinstances new_e['year'] = adtimezone.year new_e['month'] = '%02d' % adtimezone.month new_e['day'] = '%02d' % adtimezone.day new_e['es'] = e.errorweight new_e['auto'] = e.autodetermine new_e['tags'] = [] tags = Tags.objects.filter(iderror=e) for t in tags: new_e['tags'].append(t.tag) result.append(new_e) #print new_e return HttpResponse(json.dumps(result), 'application/json')
def chartdata_sbav(request,apikey): #App version별 Client의 Session을 보여주는 차트 jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') #print 'retention', retention if retention == 1: retention = 24 #retention을 24로 변경 24시를 의미 past, today = getTimeRangeExactHour(retention,projectElement.timezone) strformat = '%y-%m-%d %H' dateformat = '%%y-%%m-%%d %%H' else: past, today = getTimeRange(retention,projectElement.timezone) strformat = '%y-%m-%d' dateformat = '%%y-%%m-%%d' ######################################### #90% 에 해당하는 appversion 리스트 얻어오는 로직 # 1. 전체 session 수 구하기 # 2. 전체 세션수 대비 90% 에 해당하는 app version 리스트만 가져옴 ######################################### sql2 = 'SELECT appversion ,sum(appruncount) as total FROM appruncount2 where pid = %(pidinput)s and datetime >= %(pasttime)s group by appversion order by total desc' params2 = {'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} totalSession = TotalSession.objects.raw(sql2, params2) sum = 0 for idx, pl in enumerate(totalSession): sum = sum + pl.total ratio = float(sum) / 1.1 ratioappversion = () ratioappversion = list(ratioappversion) sum = 0 recentVersion = '0.0' othersNumber = 0 for idx, pl in enumerate(totalSession): if len(ratioappversion) == 0: ratioappversion.append(str(pl.appversion)) if LooseVersion(recentVersion) < LooseVersion(pl.appversion): if not pl.appversion == "unknown": recentVersion = pl.appversion if sum <= ratio: ratioappversion.append(str(pl.appversion)) else: othersNumber = othersNumber + pl.total sum = sum + pl.total #check recent version is exist in array if not recentVersion in ratioappversion: ratioappversion.append(str(recentVersion)) ratioappversion = tuple(ratioappversion) if len(ratioappversion) == 1: ratioappversion = str(ratioappversion)[:len(str(ratioappversion)) - 2] + str(ratioappversion)[-1] #날짜별 Session수를 얻어오기 위한 Query생성 sql = 'SELECT idappruncount2 as idsessionbyapp, sum(appruncount) as runcount, appversion, DATE_FORMAT(CONVERT_TZ(datetime,"UTC",%(timezone)s),"' + dateformat +'") as sessionday' sql = sql + ' from urqa.appruncount2' if len(ratioappversion) == 0: sql = sql + ' where pid = %(pidinput)s and datetime >= %(pasttime)s and appversion' else: sql = sql + ' where pid = %(pidinput)s and datetime >= %(pasttime)s and appversion in ' + str(ratioappversion) sql = sql + ' Group by appversion, sessionday' params = {'timezone':projectElement.timezone,'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} places = SessionbyApp.objects.raw(sql, params) appversions = [] dates = [] for idx, pl in enumerate(places): if not pl.appversion in appversions: appversions.append(pl.appversion) if not pl.sessionday in dates: dates.append(pl.sessionday) result = {} categories = [] appcount_data = {} for appversion in appversions: appcount_data[appversion] = [] new_places = [] for idx, pl in enumerate(places): new_places.append({'appversion':pl.appversion,'sessionday':pl.sessionday,'runcount':pl.runcount}) #시간,날짜별로 Session Data를 나눔 for i in range(retention-1,-1,-1): if retention == 24: # Statistics 하루치 day1 = getTimezoneHour(projectElement.timezone) + datetime.timedelta(hours = -i) if day1.hour == 0: categories.append(day1.strftime('%b-%d')) else: categories.append(day1.strftime('%H')) else: day1 = getTimezoneMidNight(projectElement.timezone) + datetime.timedelta(days = -i) categories.append(day1.strftime('%b-%d')) for appversion in appversions: result_runcount = 0 for idx in range(0,len(new_places)): if new_places[idx]['appversion'] == appversion and new_places[idx]['sessionday'] == day1.strftime(strformat): result_runcount = new_places[idx]['runcount'] new_places.pop(idx) break appcount_data[appversion].append(int(result_runcount)) appver_data = [] for appversion in appversions: appver_data.append( { 'name': appversion, 'data': appcount_data[appversion] } ) chart_sbav = {'categories':categories,'data':appver_data} result['chart_sbav'] = chart_sbav return HttpResponse(json.dumps(result), 'application/json');
def appv_ratio(request,apikey): #Filter페이지에 보여줄 App, OS Version의 비율을 계산하는 루틴 #에러가 많이 발생한 App, OS Version일 수록 비율이 크게 계산된다. jsonData = json.loads(request.POST['json'],encoding='utf-8') num = request.POST.get('num', 10) page = request.POST.get('page', 0) retention = int(jsonData['retention']) depth = int(jsonData['depth']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention,projectElement.timezone) #errorElements = Errors.objects.filter(pid=projectElement,lastdate__range=(past,today)) data = {'appv':{},'osv':{}} instances = Instances.objects.select_related('pid').filter( pid=projectElement, datetime__range=(past, today)) #Instances.objects.select_related('pid').values('appversion').filter(pid=projectElement,datetime__range=(past,today)).annotate(count=Count('appversion')).order_by('-count') print 1 appv_instances = instances.values('appversion').annotate(count=Count('appversion')).order_by('-count') for i in appv_instances.iterator(): key = i['appversion'] print key #if not key in data['appv']: data['appv'][key] = i['count'] #else: # data['appv'][key] += 1 #print "data['appv']",data['appv'] print 2 osv_list = {} os_instances = instances.values('osversion').annotate(count=Count('osversion')).order_by('-count') for i in os_instances.iterator(): k = i['osversion'].split('.') if len(k) < 2: k.append(' ') key = k[0]+'.'+k[1] if not key in data['osv']: data['osv'][key] = i['count'] osv_list[key] = [] else: data['osv'][key] += i['count'] print 3 max_count = 5 appv_data = sorted(data['appv'].iteritems(), key=operator.itemgetter(1), reverse=True) appv_others = [] if len(appv_data) > max_count: appv_others.append(appv_data[max_count-1][0]) while len(appv_data) > max_count: appv_data[max_count-1] = ('Others',appv_data[max_count-1][1] + appv_data[max_count][1]) appv_others.append(appv_data[max_count][0]) appv_data.pop(max_count) print 4 osv_data = sorted(data['osv'].iteritems(), key=operator.itemgetter(1), reverse=True) osv_others = [] if len(appv_data) > max_count: osv_others.append(appv_data[max_count-1][0]) print 5 while len(osv_data) > max_count: osv_data[max_count-1] = ('Others', osv_data[max_count-1][1] + osv_data[max_count][1]) osv_others.append(osv_data[max_count][0]) osv_data.pop(max_count) print 6 return HttpResponse(json.dumps({'total':instances.count(),'appv':appv_data,'osv':osv_data,'osv_list':osv_list,'appv_others':appv_others,'osv_others':osv_others}), 'application/json');
def filter_view(request, apikey): #Filter page를 Randering하는 루틴 username = request.user valid, message, userelement, projectelement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') week, today = getTimeRange(TimeRange.weekly, projectelement.timezone) try: projectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse('') # Post 로 원하는 Date의 range를 얻어와서 errorElements = Errors.objects.filter( pid=projectElement, lastdate__range=(week, today)).order_by('-errorweight', 'rank', '-lastdate') valid_tag = Tags.objects.filter( pid=projectElement).values('tag').distinct().order_by('tag') valid_class = errorElements.values('errorclassname').distinct().order_by( 'errorclassname') #valid_app = Appstatistics.objects.filter(iderror__in=errorElements).values('appversion').distinct().order_by('-appversion') #valid_os = Osstatistics.objects.filter(iderror__in=errorElements).values('osversion').distinct().order_by('-osversion') valid_app = Appstatistics.objects.filter(pid=projectElement).values( 'appversion').distinct().order_by('-appversion') valid_os = Osstatistics.objects.filter(pid=projectElement).values( 'osversion').distinct().order_by('-osversion') # Web Rendering용 데이터 만들기 osv_list = [] os_idx = -1 prev_v = ['-1', '-1', '-1'] for e in valid_os: v = e['osversion'].split('.') if len(v) < 2: v.append(' ') if len(v) < 3: v.append(' ') if v[0] != prev_v[0] or v[1] != prev_v[1]: prev_v = v os_idx += 1 osv_list.append({}) osv_list[os_idx]['key'] = '%s.%s' % (v[0], v[1]) osv_list[os_idx]['value'] = [] osv_list[os_idx]['value'].append(e['osversion']) appv_list = [] app_idx = -1 prev_v = ['-1', '-1', '-1'] for e in valid_app: v = e['appversion'].split('.') if len(v) < 2: v.append(' ') if len(v) < 3: v.append(' ') if v[0] != prev_v[0] or v[1] != prev_v[1]: prev_v = v app_idx += 1 appv_list.append({}) appv_list[app_idx]['key'] = '%s.%s' % (v[0], v[1]) appv_list[app_idx]['value'] = [] appv_list[app_idx]['value'].append(e['appversion']) tag_list = [] for e in valid_tag: tag_list.append(e['tag']) class_list = [] for e in valid_class: class_list.append(e['errorclassname']) osv_margin = '' for i in range(0, 5 - len(osv_list)): osv_margin += ' ' appv_margin = '' for i in range(0, 5 - len(appv_list)): appv_margin += ' ' user = AuthUser.objects.get(username=request.user) tpl = loader.get_template('filter.html') filterdict = { #'ServerURL' : 'http://'+request.get_host() + '/urqa/project/', 'tag_list': tag_list, 'class_list': class_list, 'osv_list': osv_list, 'margin': { 'osv': osv_margin, 'appv': appv_margin }, 'appv_list': appv_list, 'max_error': errorElements.count() } userdict = getUserProfileDict(user) apikeydict = getApikeyDict(apikey) settingdict = getSettingDict(projectelement, user) ctxdict = dict(userdict.items() + apikeydict.items() + settingdict.items() + filterdict.items()) ctx = Context(ctxdict) return HttpResponse(tpl.render(ctx))
def projects(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/urqa/') #주인인 project들 UserElement = AuthUser.objects.get(username=request.user) OwnerProjectElements = Projects.objects.filter(owner_uid=UserElement.id) ViewerElements = Viewer.objects.filter(uid=UserElement.id).values('pid') ViewerProjectElements = Projects.objects.filter(pid__in=ViewerElements) MergeProjectElements = OwnerProjectElements | ViewerProjectElements #print MergeProjectElements project_list = [] stagedata = json.loads(get_config('app_stages')) #stagecolordata = json.loads(get_config('app_stages_color')) #avgcolordata = json.loads(get_config('avg_error_score_color')) countcolordata = json.loads(get_config('error_rate_color')) platformdata = json.loads(get_config('app_platforms')) week, today = getTimeRange(TimeRange.weekly) #최근 7일이내것만 표시 for idx, project in enumerate(MergeProjectElements): projectdata = {} projectdata['apikey'] = project.apikey #stage color 구하기 stagetxt = get_dict_value_matchin_key(stagedata, project.stage) #projectdata['color'] = stagecolordata.get(stagetxt) errorElements = Errors.objects.filter( pid=project.pid, status__in=[Status.New, Status.Open]) instanceCount = Instances.objects.filter( iderror__in=errorElements, datetime__range=(week, today)).count() apprunCount = Appruncount.objects.filter( pid=project.pid, date__range=(week, today)).aggregate( apprunCount=Sum('runcount'))['apprunCount'] #print instanceCount #print '(week, today)',project.pid,(week, today) #print Appruncount.objects.filter(pid=project.pid,date__gte = week) #print apprunCount projectdata['count'] = instanceCount if not apprunCount: errorRate = 0 else: errorRate = int(instanceCount * 100.0 / apprunCount) print project.name, 'errorRate %d%%' % errorRate, instanceCount, apprunCount #Avg ErrorScore에 대한 컬러 projectdata['color'] = ErrorRate_for_color(countcolordata, errorRate) #print projectdata['color'] projectdata['name'] = project.name projectdata['platform'] = get_dict_value_matchin_key( platformdata, project.platform).lower() projectdata['stage'] = stagetxt project_list.append(projectdata) categorydata = json.loads(get_config('app_categories')) platformdata = json.loads(get_config('app_platforms')) stagedata = json.loads(get_config('app_stages')) ctx = { 'project_list': project_list, 'app_platformlist': platformdata.items(), 'app_categorylist': categorydata.items(), 'app_stagelist': stagedata.items() } return render(request, 'project-select.html', ctx)
def projects(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/urqa/') if request.user.is_superuser: #Super User일 경우 모든 프로젝트 보이기 MergeProjectElements = Projects.objects.all() else: #주인인 project들 UserElement = AuthUser.objects.get(username = request.user) OwnerProjectElements = Projects.objects.filter(owner_uid = UserElement.id) ViewerElements = Viewer.objects.filter(uid = UserElement.id).values('pid') ViewerProjectElements = Projects.objects.filter(pid__in = ViewerElements) MergeProjectElements = OwnerProjectElements | ViewerProjectElements #print MergeProjectElements project_list = [] stagedata = json.loads(get_config('app_stages')) #stagecolordata = json.loads(get_config('app_stages_color')) #avgcolordata = json.loads(get_config('avg_error_score_color')) countcolordata = json.loads(get_config('error_rate_color')) platformdata = json.loads(get_config('app_platforms')) for idx, project in enumerate(MergeProjectElements): projectdata = {} projectdata['apikey'] = project.apikey #stage color 구하기 stagetxt = get_dict_value_matchin_key(stagedata,project.stage) #projectdata['color'] = stagecolordata.get(stagetxt) week, today = getTimeRange(TimeRange.weekly,project.timezone)#최근 7일이내것만 표시 errorElements = Errors.objects.filter(pid = project.pid, status__in = [Status.New,Status.Open]) instanceCount = Instances.objects.filter(iderror__in=errorElements,datetime__range = (week, today)).count() apprunCount = Appruncount.objects.filter(pid=project.pid,date__range = (week, today)).aggregate(apprunCount=Sum('runcount'))['apprunCount'] #print instanceCount #print '(week, today)',project.pid,(week, today) #print Appruncount.objects.filter(pid=project.pid,date__gte = week) #print apprunCount projectdata['count'] = instanceCount if not apprunCount: errorRate = 0 else: errorRate = int(instanceCount * 100.0 / apprunCount) print project.name, 'errorRate %d%%' % errorRate, instanceCount, apprunCount #Avg ErrorScore에 대한 컬러 projectdata['color'] = ErrorRate_for_color( countcolordata , errorRate ) #print projectdata['color'] projectdata['name'] = project.name projectdata['platform'] = get_dict_value_matchin_key(platformdata,project.platform).lower() projectdata['stage'] = stagetxt project_list.append(projectdata) categorydata = json.loads(get_config('app_categories')) platformdata = json.loads(get_config('app_platforms')) stagedata = json.loads(get_config('app_stages')) ctx = { 'project_list' : project_list , 'app_platformlist' : platformdata.items(), 'app_categorylist' : categorydata.items(), 'app_stagelist' : stagedata.items() } return render(request, 'project-select.html', ctx)
def chartdata(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention) errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) #Chart1 chart1 = [] pre_class = '' print 'past',past for e in errorElements: instanceCount = Instances.objects.filter(iderror=e,datetime__gte=past).count() if pre_class != e.errorclassname: pre_class = e.errorclassname chart1.append([e.errorclassname, instanceCount]) else: last = len(chart1) chart1[last-1] = [e.errorclassname,chart1[last-1][1] + (instanceCount)] result = {} result['chart1'] = chart1 #Chart2 chart2 = [] temp_data = {} activities = [] instances = instanceElements.order_by('device') for i in instances: if i.device: device = i.device else: device = "Unknown" if not device in activities: activities.append(device) temp_data[device] = 1 else: temp_data[device] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart2.append({ 'label': l, 'value': v, }) result['chart2'] = chart2 """chart2 = [] temp_data = {} for e in errorElements: devices = Devicestatistics.objects.filter(iderror=e).order_by('devicename') if devices.count() == 0: continue total = 0 for d in devices: total += d.count for d in devices: if not d.devicename in temp_data: temp_data[d.devicename] = e.errorweight * d.count / total else: temp_data[d.devicename] += e.errorweight * d.count / total sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart2.append({ 'label': l, 'value': v, }) result['chart2'] = chart2""" #Chart3 chart3 = [] temp_data = {} activities = [] instances = instanceElements.order_by('lastactivity') for i in instances: if i.lastactivity: lastactivity = i.lastactivity else: lastactivity = "Unknown" if not lastactivity in activities: activities.append(lastactivity) temp_data[lastactivity] = 1 else: temp_data[lastactivity] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart3.append({ 'label': l, 'value': v, }) result['chart3'] = chart3 """temp_data = {} for e in errorElements: activity = Activitystatistics.objects.filter(iderror=e).order_by('activityname') if devices.count() == 0: continue total = 0 for d in activity: print d.activityname total += d.count #print d.devicename #print total,e.errorweight for d in activity: if not d.activityname in temp_data: temp_data[d.activityname] = e.errorweight * d.count / total else: temp_data[d.activityname] += e.errorweight * d.count / total sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) for l,v in sorted_dic: chart3.append({ 'label': l, 'value': v, }) """ #Chart4 categories = [] ver_data = [] temp_data = {} instances = instanceElements.order_by('-appversion','-osversion') appv_idx = -1 for i in instances: if not i.appversion in categories: appv_idx += 1 categories.append(i.appversion) if not i.osversion in temp_data: temp_data[i.osversion] = [] while len(temp_data[i.osversion]) <= appv_idx: temp_data[i.osversion].append(0) #score = float(i.iderror.errorweight) / i.iderror.numofinstances temp_data[i.osversion][appv_idx] += 1#score for t in temp_data: idx = 0 for e in temp_data[t]: temp_data[t][idx] = e#round(e,2) idx += 1 ver_data.append({'name':t,'data':temp_data[t]}) #print categories #print ver_data #ver_data[appv_idx][] #print categories chart4 = {'categories':categories,'data':ver_data} result['chart4'] = chart4 return HttpResponse(json.dumps(result), 'application/json');
def chartdata_ebav(request,apikey): #App version별 Client의 Error 수를 보여주는 차트 jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') # Common Data result = {} #appcount_data = {} categories = [] #appver_data = [] if retention == 1: retention = 24 #retention을 24로 변경 24시를 의미 past, today = getTimeRangeExactHour(retention,projectElement.timezone) strformat = '%y-%m-%d %H' dateformat = '%%y-%%m-%%d %%H' else: past, today = getTimeRange(retention,projectElement.timezone) strformat = '%y-%m-%d' dateformat = '%%y-%%m-%%d' ######################################### #90% 에 해당하는 appversion 리스트 얻어오는 로직 # 1. 전체 session 수 구하기 # 2. 전체 세션수 대비 90% 에 해당하는 app version 리스트만 가져옴 ######################################### #sql2 = 'SELECT appversion ,count(*) as total FROM instances A, errors B where A.iderror = B.iderror and pid = %(pidinput)s and B.status in (0,1) and datetime >= %(pasttime)s group by appversion order by total desc' sql2 = "SELECT appversion ,count(*) as total " sql2 = sql2 + "FROM instances " sql2 = sql2 + "where pid = %(pidinput)s and datetime >= %(pasttime)s " sql2 = sql2 + "group by appversion " sql2 = sql2 + "order by total desc" params2 = {'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} totalSession = TotalSession.objects.raw(sql2, params2) #======= 장고로 변환 테스트가 안되어 있음;; # pasttime= '%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second) # # totalSession = sorted(Instances.objects.values('appversion').annotate(total=Count('*')).filter( # pid=projectElement, datetime__gte=pasttime # ).group_by('appversion'), key=lambda instance: instance['total'], reverse=True) sum = 0 for idx, pl in enumerate(totalSession): sum = sum + pl.total ratio = float(sum) / 1.1 ratioappversion = () ratioappversion = list(ratioappversion) sum = 0 recentVersion = '0.0' othersNumber = 0 for idx, pl in enumerate(totalSession): if len(ratioappversion) == 0: ratioappversion.append(str(pl.appversion)) if LooseVersion(recentVersion) < LooseVersion(pl.appversion): if not pl.appversion == "unknown": recentVersion = pl.appversion if sum <= ratio: ratioappversion.append(str(pl.appversion)) else: othersNumber = othersNumber + pl.total sum = sum + pl.total #check recent version is exist in array if not recentVersion in ratioappversion: ratioappversion.append(str(recentVersion)) ratioappversion = tuple(ratioappversion) if len(ratioappversion) == 1: ratioappversion = str(ratioappversion)[:len(str(ratioappversion)) - 2] + str(ratioappversion)[-1] #Error Count를 얻어올 Query를 생성한다. sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(CONVERT_TZ(datetime,'UTC',%(timezone)s),'" + dateformat + "') as errorday " sql = sql + "from instances " sql = sql + "where pid = %(pidinput)s " if len(ratioappversion) == 0: sql = sql + ' and datetime >= %(pasttime)s and appversion ' else: sql = sql + ' and datetime >= %(pasttime)s and appversion in ' + str(ratioappversion) sql = sql + "group by errorday,appversion" past, today = getTimeRange(retention,projectElement.timezone) params = {'timezone':projectElement.timezone,'pidinput':projectElement.pid,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} places = ErrorsbyApp.objects.raw(sql, params) #listing app version appversions = [] dates = [] for idx, pl in enumerate(places): if not pl.appversion in appversions: appversions.append(pl.appversion) if not pl.errorday in dates: dates.append(pl.errorday) result = {} categories = [] appcount_data = {} for appversion in appversions: appcount_data[appversion] = [] new_places = [] for idx, pl in enumerate(places): new_places.append({'appversion':pl.appversion,'errorday':pl.errorday,'errorcount':pl.errorcount}) #시간,날짜별로 Error Count를 나눔 for i in range(retention-1,-1,-1): if retention == 24: day1 = getTimezoneHour(projectElement.timezone) + datetime.timedelta(hours = -i) if day1.hour == 0: categories.append(day1.strftime('%b-%d')) else: categories.append(day1.strftime('%H')) else: day1 = getTimezoneMidNight(projectElement.timezone) + datetime.timedelta(days = -i) categories.append(day1.strftime('%b-%d')) for appversion in appversions: result_runcount = 0 for idx in range(0,len(new_places)): if new_places[idx]['appversion'] == appversion and new_places[idx]['errorday'] == day1.strftime(strformat): result_runcount = new_places[idx]['errorcount'] new_places.pop(idx) break appcount_data[appversion].append(int(result_runcount)) appver_data = [] for appversion in appversions: appver_data.append( { 'name': appversion, 'data': appcount_data[appversion] } ) chart_ebav = {'categories':categories,'data':appver_data} result['chart_sbav'] = chart_ebav chart1 = {'categories':categories,'data':appver_data} result['chart1'] = chart1 #print >>sys.stderr, chart1 return HttpResponse(json.dumps(result), 'application/json');
def chartdata(request,apikey): jsonData = json.loads(request.POST['json'],encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid , message , userElement, projectElement = validUserPjt(username,apikey) if not valid: return HttpResponseRedirect('/urqa') print 'retention', retention past, today = getTimeRange(retention,projectElement.timezone) #print 'past',past, 'today',today errorElements = Errors.objects.filter(pid=projectElement,status__in=[Status.New,Status.Open],lastdate__range=(past,today)).order_by('errorclassname','errorweight') instanceElements = Instances.objects.select_related().filter(iderror__in=errorElements,datetime__range=(past,today)) result = {} categories = [] appversions = instanceElements.values('appversion').distinct().order_by('appversion') appcount_data = {} for appversion in appversions: appcount_data[appversion['appversion']] = [] for i in range(retention-1,-1,-1): category_time = getTimezoneMidNight(projectElement.timezone) + datetime.timedelta(days = -i) categories.append(category_time.strftime('%b-%d')) p1, dummy = getTimeRange(i+1, projectElement.timezone) p2, dummy = getTimeRange(i, projectElement.timezone) instances = instanceElements.filter(datetime__range=(p1,p2)) for appversion in appversions: appcount_data[appversion['appversion']].append(instances.filter(appversion=appversion['appversion']).count()) #print appversion['appversion'], ' hello', instances.filter(appversion=appversion['appversion']).count() #print categories #print appcount_data appver_data = [] for appversion in appversions: appver_data.append( { 'name': appversion['appversion'], 'data': appcount_data[appversion['appversion']] } ) chart1 = {'categories':categories,'data':appver_data} result['chart1'] = chart1 #chart2 chart2 = [] pre_class = '' #print 'past',past for e in errorElements: instanceCount = Instances.objects.filter(iderror=e,datetime__gte=past).count() if pre_class != e.errorclassname: pre_class = e.errorclassname chart2.append([e.errorclassname, instanceCount]) else: last = len(chart2) chart2[last-1] = [e.errorclassname,chart2[last-1][1] + (instanceCount)] result['chart2'] = chart2 #chart3 - Device error temp_data = {} activities = [] instances = instanceElements.order_by('device') for i in instances: if i.device: device = i.device else: device = "Unknown" if not device in activities: activities.append(device) temp_data[device] = 1 else: temp_data[device] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) categories = [] temp_data = [] i = 0 others_count = 0 for l,v in sorted_dic: i += 1 if i>25: others_count += v else: categories.append(l) temp_data.append(v) if others_count != 0: categories.append('Others') temp_data.append(others_count) dev_data = [{'name':'Device','data':temp_data}] chart3 = {'categories':categories,'data':dev_data} result['chart3'] = chart3 #print 'chart3',chart3 #chart4 temp_data = {} activities = [] instances = instanceElements.order_by('lastactivity') for i in instances: if i.lastactivity: lastactivity = i.lastactivity else: lastactivity = "Unknown" if not lastactivity in activities: activities.append(lastactivity) temp_data[lastactivity] = 1 else: temp_data[lastactivity] += 1 sorted_dic = sorted(temp_data.iteritems(), key=operator.itemgetter(1), reverse=True) categories = [] temp_data = [] i = 0 others_count = 0 for l,v in sorted_dic: i += 1 if i>25: others_count += v else: categories.append(l) temp_data.append(v) if others_count != 0: categories.append('Others') temp_data.append(others_count) act_data = [{'name':'Activity','data':temp_data}] chart4 = {'categories':categories,'data':act_data} result['chart4'] = chart4 #Chart4 categories = [] ver_data = [] temp_data = {} instances = instanceElements.order_by('-appversion','-osversion') appv_idx = -1 for i in instances: if not i.appversion in categories: appv_idx += 1 categories.append(i.appversion) if not i.osversion in temp_data: temp_data[i.osversion] = [] while len(temp_data[i.osversion]) <= appv_idx: temp_data[i.osversion].append(0) #score = float(i.iderror.errorweight) / i.iderror.numofinstances temp_data[i.osversion][appv_idx] += 1#score for t in temp_data: idx = 0 for e in temp_data[t]: temp_data[t][idx] = e#round(e,2) idx += 1 ver_data.append({'name':t,'data':temp_data[t]}) #print categories #print ver_data #ver_data[appv_idx][] #print categories chart5 = {'categories':categories,'data':ver_data} result['chart5'] = chart5 #print 'chart4',chart4 return HttpResponse(json.dumps(result), 'application/json');
def typeesgraph(request, apikey): #Error Type(Unhandle, Critical, Major, Minor, Native)에 따라 에러비율을 그래프로 나타내는 루틴 #print >> sys.stderr,'typeesgraph' #프로젝트 ID에 맞는 에러들을 가져오기 위함 default = { "tags": [ { "key": "Unhandle", "value": 0 }, { "key": "Native", "value": 0 }, { "key": "Critical", "value": 0 }, { "key": "Major", "value": 0 }, { "key": "Minor", "value": 0 }, ] } try: projectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: #print 'invalid pid' return HttpResponse(json.dumps(default), 'application/json') retention = TimeRange.weekly past, today = getTimeRange(retention, projectElement.timezone) sql = 'select B.iderror as iderrorbyrank, count(*) as errorcount, rank as errorrank ' sql = sql + ' from instances A, errors B ' sql = sql + ' where A.iderror = B.iderror ' sql = sql + ' and B.status in (0,1) ' sql = sql + ' and B.pid = %(pidinput)s and datetime > %(pasttime)s' sql = sql + ' group by errorrank' params = { 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } places = ErrorsbyApp.objects.raw(sql, params) #DB로 얻어온 데이터를 JSON으로 변환함. for i in range(RANK.Unhandle, RANK.Minor + 1): for idx, pl in enumerate(places): if pl.errorrank == i: default['tags'][i]['value'] = pl.errorcount break #print >> sys.stderr,pl.iderrorbyrank,pl.errorcount,pl.errorrank popcount = RANK.Unhandle for i in range(RANK.Unhandle, RANK.Minor + 1): if default['tags'][i - popcount]['value'] == 0: default['tags'].pop(i - popcount) popcount += 1 result = json.dumps(default) return HttpResponse(result, 'application/json')
def appv_ratio(request, apikey): #Filter페이지에 보여줄 App, OS Version의 비율을 계산하는 루틴 #에러가 많이 발생한 App, OS Version일 수록 비율이 크게 계산된다. jsonData = json.loads(request.POST['json'], encoding='utf-8') num = request.POST.get('num', 10) page = request.POST.get('page', 0) retention = int(jsonData['retention']) depth = int(jsonData['depth']) username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') past, today = getTimeRange(retention, projectElement.timezone) #errorElements = Errors.objects.filter(pid=projectElement,lastdate__range=(past,today)) data = {'appv': {}, 'osv': {}} instances = Instances.objects.select_related('pid').filter( pid=projectElement, datetime__range=(past, today)) #Instances.objects.select_related('pid').values('appversion').filter(pid=projectElement,datetime__range=(past,today)).annotate(count=Count('appversion')).order_by('-count') print 1 appv_instances = instances.values('appversion').annotate( count=Count('appversion')).order_by('-count') for i in appv_instances.iterator(): key = i['appversion'] print key #if not key in data['appv']: data['appv'][key] = i['count'] #else: # data['appv'][key] += 1 #print "data['appv']",data['appv'] print 2 osv_list = {} os_instances = instances.values('osversion').annotate( count=Count('osversion')).order_by('-count') for i in os_instances.iterator(): k = i['osversion'].split('.') if len(k) < 2: k.append(' ') key = k[0] + '.' + k[1] if not key in data['osv']: data['osv'][key] = i['count'] osv_list[key] = [] else: data['osv'][key] += i['count'] print 3 max_count = 5 appv_data = sorted(data['appv'].iteritems(), key=operator.itemgetter(1), reverse=True) appv_others = [] if len(appv_data) > max_count: appv_others.append(appv_data[max_count - 1][0]) while len(appv_data) > max_count: appv_data[max_count - 1] = ('Others', appv_data[max_count - 1][1] + appv_data[max_count][1]) appv_others.append(appv_data[max_count][0]) appv_data.pop(max_count) print 4 osv_data = sorted(data['osv'].iteritems(), key=operator.itemgetter(1), reverse=True) osv_others = [] if len(appv_data) > max_count: osv_others.append(appv_data[max_count - 1][0]) print 5 while len(osv_data) > max_count: osv_data[max_count - 1] = ('Others', osv_data[max_count - 1][1] + osv_data[max_count][1]) osv_others.append(osv_data[max_count][0]) osv_data.pop(max_count) print 6 return HttpResponse( json.dumps({ 'total': instances.count(), 'appv': appv_data, 'osv': osv_data, 'osv_list': osv_list, 'appv_others': appv_others, 'osv_others': osv_others }), 'application/json')
def chartdata_ebav(request, apikey): #App version별 Client의 Error 수를 보여주는 차트 jsonData = json.loads(request.POST['json'], encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') # Common Data result = {} #appcount_data = {} categories = [] #appver_data = [] if retention == 1: retention = 24 #retention을 24로 변경 24시를 의미 past, today = getTimeRangeExactHour(retention, projectElement.timezone) strformat = '%y-%m-%d %H' dateformat = '%%y-%%m-%%d %%H' else: past, today = getTimeRange(retention, projectElement.timezone) strformat = '%y-%m-%d' dateformat = '%%y-%%m-%%d' ######################################### #90% 에 해당하는 appversion 리스트 얻어오는 로직 # 1. 전체 session 수 구하기 # 2. 전체 세션수 대비 90% 에 해당하는 app version 리스트만 가져옴 ######################################### #sql2 = 'SELECT appversion ,count(*) as total FROM instances A, errors B where A.iderror = B.iderror and pid = %(pidinput)s and B.status in (0,1) and datetime >= %(pasttime)s group by appversion order by total desc' sql2 = "SELECT appversion ,count(*) as total " sql2 = sql2 + "FROM instances " sql2 = sql2 + "where pid = %(pidinput)s and datetime >= %(pasttime)s " sql2 = sql2 + "group by appversion " sql2 = sql2 + "order by total desc" params2 = { 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } totalSession = TotalSession.objects.raw(sql2, params2) #======= 장고로 변환 테스트가 안되어 있음;; # pasttime= '%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second) # # totalSession = sorted(Instances.objects.values('appversion').annotate(total=Count('*')).filter( # pid=projectElement, datetime__gte=pasttime # ).group_by('appversion'), key=lambda instance: instance['total'], reverse=True) sum = 0 for idx, pl in enumerate(totalSession): sum = sum + pl.total ratio = float(sum) / 1.1 ratioappversion = () ratioappversion = list(ratioappversion) sum = 0 recentVersion = '0.0' othersNumber = 0 for idx, pl in enumerate(totalSession): if len(ratioappversion) == 0: ratioappversion.append(str(pl.appversion)) if LooseVersion(recentVersion) < LooseVersion(pl.appversion): if not pl.appversion == "unknown": recentVersion = pl.appversion if sum <= ratio: ratioappversion.append(str(pl.appversion)) else: othersNumber = othersNumber + pl.total sum = sum + pl.total #check recent version is exist in array if not recentVersion in ratioappversion: ratioappversion.append(str(recentVersion)) ratioappversion = tuple(ratioappversion) if len(ratioappversion) == 1: ratioappversion = str(ratioappversion)[:len(str(ratioappversion)) - 2] + str(ratioappversion)[-1] #Error Count를 얻어올 Query를 생성한다. sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(CONVERT_TZ(datetime,'UTC',%(timezone)s),'" + dateformat + "') as errorday " sql = sql + "from instances " sql = sql + "where pid = %(pidinput)s " if len(ratioappversion) == 0: sql = sql + ' and datetime >= %(pasttime)s and appversion ' else: sql = sql + ' and datetime >= %(pasttime)s and appversion in ' + str( ratioappversion) sql = sql + "group by errorday,appversion" past, today = getTimeRange(retention, projectElement.timezone) params = { 'timezone': projectElement.timezone, 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } places = ErrorsbyApp.objects.raw(sql, params) #listing app version appversions = [] dates = [] for idx, pl in enumerate(places): if not pl.appversion in appversions: appversions.append(pl.appversion) if not pl.errorday in dates: dates.append(pl.errorday) result = {} categories = [] appcount_data = {} for appversion in appversions: appcount_data[appversion] = [] new_places = [] for idx, pl in enumerate(places): new_places.append({ 'appversion': pl.appversion, 'errorday': pl.errorday, 'errorcount': pl.errorcount }) #시간,날짜별로 Error Count를 나눔 for i in range(retention - 1, -1, -1): if retention == 24: day1 = getTimezoneHour( projectElement.timezone) + datetime.timedelta(hours=-i) if day1.hour == 0: categories.append(day1.strftime('%b-%d')) else: categories.append(day1.strftime('%H')) else: day1 = getTimezoneMidNight( projectElement.timezone) + datetime.timedelta(days=-i) categories.append(day1.strftime('%b-%d')) for appversion in appversions: result_runcount = 0 for idx in range(0, len(new_places)): if new_places[idx]['appversion'] == appversion and new_places[ idx]['errorday'] == day1.strftime(strformat): result_runcount = new_places[idx]['errorcount'] new_places.pop(idx) break appcount_data[appversion].append(int(result_runcount)) appver_data = [] for appversion in appversions: appver_data.append({ 'name': appversion, 'data': appcount_data[appversion] }) chart_ebav = {'categories': categories, 'data': appver_data} result['chart_sbav'] = chart_ebav chart1 = {'categories': categories, 'data': appver_data} result['chart1'] = chart1 #print >>sys.stderr, chart1 return HttpResponse(json.dumps(result), 'application/json')
def projects(request): #Project리스트를 출력하는 루틴 if not request.user.is_authenticated(): return HttpResponseRedirect('/urqa/') project_list = [] stagedata = json.loads(get_config('app_stages')) #stagecolordata = json.loads(get_config('app_stages_color')) #avgcolordata = json.loads(get_config('avg_error_score_color')) countcolordata = json.loads(get_config('error_rate_color')) platformdata = json.loads(get_config('app_platforms')) if request.user.is_superuser: MergeProjectElements = Projects.objects.filter() else: #User가 소유한 Project를 얻어온다. UserElement = AuthUser.objects.get(username=request.user) OwnerProjectElements = Projects.objects.filter( owner_uid=UserElement.id) ViewerElements = Viewer.objects.filter( uid=UserElement.id).values('pid') ViewerProjectElements = Projects.objects.filter(pid__in=ViewerElements) MergeProjectElements = OwnerProjectElements | ViewerProjectElements #print MergeProjectElements idxProjectList = [] placesDict = {} apprunDit = {} for idx, project in enumerate(MergeProjectElements): idxProjectList.append(project.pid) past, today = getTimeRange(TimeRange.weekly, project.timezone) #최근 7일이내것만 표시 #idxProjectList = Projects.objects.values_list('pid') if idxProjectList: pasttime = '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) #pidList = ", ".join(str(v) for v in idxProjectList) pasttime = '%d-%d-%d %d:%d:%d' % (2014, 12, 3, 12, 0, 0) #pid_list = [str(project) for project in Projects.objects.values_list('pid')] #places = Instances.objects.values('iderror').annotate(count=Count('iderror')).prefech_selected('iderror').filter( # iderror__pid__in=pidList, # datetime__gt=pasttime #).group_by('iderror__pid') pidList = ", ".join(str(v) for v in idxProjectList) sql = "SELECT B.pid AS pid, count(*) AS count FROM errors B JOIN instances A ON A.iderror = B.iderror " sql = sql + "where B.pid IN ( " + pidList + ") " sql = sql + "and B.status IN (0,1) " sql = sql + "and A.datetime > %(pasttime)s " sql = sql + "GROUP BY B.pid " params = { 'pidinput': "(" + ",".join(str(v) for v in idxProjectList) + ")", 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } places = LoginErrorCountModel.objects.raw(sql, params) for idx, pl in enumerate(places): placesDict[pl.pid] = pl.count sql = "SELECT app.pid AS pid ,SUM(app.appruncount) AS count FROM appruncount2 app " sql = sql + "WHERE app.pid in (" + pidList + ") AND " sql = sql + "app.datetime > %(pasttime)s " sql = sql + "GROUP BY app.pid" apprunCount = LoginApprunCount.objects.raw(sql, params) for idx, app in enumerate(apprunCount): apprunDit[app.pid] = app.count for idx, project in enumerate(MergeProjectElements): projectdata = {} projectdata['apikey'] = project.apikey #stage color 구하기 stagetxt = get_dict_value_matchin_key(stagedata, project.stage) instanceCount = 0 if placesDict.has_key(project.pid): instanceCount = instanceCount + placesDict[project.pid] if request.user.is_superuser and instanceCount == 0: continue #Project에서 사용자의 수를 얻어온다 apprunCount = float('1') if apprunDit.has_key(project.pid): apprunCount = float(apprunDit.get(project.pid)) #프로젝트 DAU대비 Error수를 측정한다. projectdata['count'] = instanceCount convertData = float(instanceCount) if not apprunCount: errorRate = 0 else: errorRate = int(convertData * 100.0 / apprunCount) #Error발생 비율에 따라 Project의 컬러를 설정한다. projectdata['color'] = ErrorRate_for_color(countcolordata, errorRate) #print projectdata['color'] projectdata['name'] = project.name projectdata['platform'] = get_dict_value_matchin_key( platformdata, project.platform).lower() projectdata['stage'] = stagetxt project_list.append(projectdata) #로딩한 데이터를 Template에 Randering한다. categorydata = json.loads(get_config('app_categories')) platformdata = json.loads(get_config('app_platforms')) sorted_platform = [] for key in sorted(platformdata, key=lambda key: platformdata[key]): sorted_platform.append((key, platformdata[key])) stagedata = json.loads(get_config('app_stages')) ctx = { # 'project_list' : project_list , 'project_list': project_list, 'app_platformlist': sorted_platform, 'app_categorylist': categorydata.items(), 'app_stagelist': stagedata.items(), 'user': request.user } response_type = request.GET.get('response_type', None) if response_type == 'json': return HttpResponse(json.dumps(project_list)) return render(request, 'project-select.html', ctx)
def error_list(request, apikey): #Error Filtering페이지에서 보여줄 리스트를 랜더링함 username = request.user valid, message, userelement, projectelement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') try: projectElement = Projects.objects.get(apikey=apikey) except ObjectDoesNotExist: print 'invalid pid' return HttpResponse(json.dumps({"response": "fail"}), 'application/json') jsonData = json.loads(request.POST['json'], encoding='utf-8') #Appstatistics.objects.values('ierror').annotate(iderror_count=Count('iderror')).filter(pid=projectElement).group_by('iderror') date = int(jsonData['date']) _status = [[0, 1, 2, 3], [0], [1], [2], [3]] status = _status[int(jsonData['status'])] rank = jsonData['rank'] tags = jsonData['tags'] classes = jsonData['classes'] appversion = jsonData['appv'] if appversion and appversion[0] == 'All': appversion = [] osversion = jsonData['osv'] if osversion and osversion[0] == 'All': osversion = [] page = jsonData['page'] num = jsonData['num'] #Filtering Query를 적용하여 해당하는 Error를 보여줌 week, today = getTimeRange(date, projectElement.timezone) ##일단 로직을 추가 하고 page, num 처리하여씀 여기서 속도가 느릴 경우 errorElements 쪽을 수정 errorElements = Errors.objects.filter( pid=projectElement, rank__in=rank, status__in=status, lastdate__range=(week, today)).order_by('-errorweight', 'rank', '-lastdate') #print '1',errorElements #print classes if classes: errorElements = errorElements.filter(errorclassname__in=classes) #print tags if tags: #tagElements = Tags.objects.filter(iderror__in=errorElements,tag__in=tags).values('iderror').distinct().order_by('iderror') tagElements = Tags.objects.select_related('iderror').filter( iderror__in=errorElements, tag__in=tags).values('iderror').distinct().order_by( 'iderror')[page * num:(page + 1) * num] print tagElements iderror_list = [] for e in tagElements: iderror_list.append(int(e['iderror'])) errorElements = errorElements.filter(iderror__in=iderror_list) #print appversion if appversion: print 'appversion', appversion appvElements = Appstatistics.objects.select_related().filter( iderror__in=errorElements, appversion__in=appversion).values( 'iderror').distinct().order_by('iderror') print 'appvElements', appvElements iderror_list = [] for e in appvElements: iderror_list.append(int(e['iderror'])) #if iderror_list: errorElements = errorElements.filter(iderror__in=iderror_list) #print osversion if osversion: iderror_list = [] for v in osversion: if v == "M. ": v = "M" osvElements = Osstatistics.objects.select_related().filter( iderror__in=errorElements, osversion__startswith=v).values( 'iderror').distinct().order_by('iderror') for e in osvElements: iderror_list.append(int(e['iderror'])) #if iderror_list: errorElements = errorElements.filter(iderror__in=iderror_list) #print errorElements errorElements = errorElements[page * num:(page + 1) * num] result = [] for e in errorElements.iterator(): adtimezone = toTimezone(e.lastdate, projectelement.timezone) #print adtimezone new_e = {} new_e['iderror'] = e.iderror new_e['color'] = RANK.rankcolor[e.rank] new_e['rank'] = e.rank new_e['status'] = e.status #Status.toString[e.status] new_e['errorname'] = e.errorname new_e['errorclassname'] = e.errorclassname new_e['linenum'] = e.linenum new_e['count'] = e.numofinstances new_e['year'] = adtimezone.year new_e['month'] = '%02d' % adtimezone.month new_e['day'] = '%02d' % adtimezone.day new_e['es'] = e.errorweight new_e['auto'] = e.autodetermine new_e['tags'] = [] tags = Tags.objects.filter(iderror=e) for t in tags: new_e['tags'].append(t.tag) result.append(new_e) #print new_e return HttpResponse(json.dumps(result), 'application/json')
def chartdata_sbav(request, apikey): #App version별 Client의 Session을 보여주는 차트 jsonData = json.loads(request.POST['json'], encoding='utf-8') retention = int(jsonData['retention']) username = request.user valid, message, userElement, projectElement = validUserPjt( username, apikey) if not valid: return HttpResponseRedirect('/urqa') #print 'retention', retention if retention == 1: retention = 24 #retention을 24로 변경 24시를 의미 past, today = getTimeRangeExactHour(retention, projectElement.timezone) strformat = '%y-%m-%d %H' dateformat = '%%y-%%m-%%d %%H' else: past, today = getTimeRange(retention, projectElement.timezone) strformat = '%y-%m-%d' dateformat = '%%y-%%m-%%d' ######################################### #90% 에 해당하는 appversion 리스트 얻어오는 로직 # 1. 전체 session 수 구하기 # 2. 전체 세션수 대비 90% 에 해당하는 app version 리스트만 가져옴 ######################################### sql2 = 'SELECT appversion ,sum(appruncount) as total FROM appruncount2 where pid = %(pidinput)s and datetime >= %(pasttime)s group by appversion order by total desc' params2 = { 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } totalSession = TotalSession.objects.raw(sql2, params2) sum = 0 for idx, pl in enumerate(totalSession): sum = sum + pl.total ratio = float(sum) / 1.1 ratioappversion = () ratioappversion = list(ratioappversion) sum = 0 recentVersion = '0.0' othersNumber = 0 for idx, pl in enumerate(totalSession): if len(ratioappversion) == 0: ratioappversion.append(str(pl.appversion)) if LooseVersion(recentVersion) < LooseVersion(pl.appversion): if not pl.appversion == "unknown": recentVersion = pl.appversion if sum <= ratio: ratioappversion.append(str(pl.appversion)) else: othersNumber = othersNumber + pl.total sum = sum + pl.total #check recent version is exist in array if not recentVersion in ratioappversion: ratioappversion.append(str(recentVersion)) ratioappversion = tuple(ratioappversion) if len(ratioappversion) == 1: ratioappversion = str(ratioappversion)[:len(str(ratioappversion)) - 2] + str(ratioappversion)[-1] #날짜별 Session수를 얻어오기 위한 Query생성 sql = 'SELECT idappruncount2 as idsessionbyapp, sum(appruncount) as runcount, appversion, DATE_FORMAT(CONVERT_TZ(datetime,"UTC",%(timezone)s),"' + dateformat + '") as sessionday' sql = sql + ' from urqa.appruncount2' if len(ratioappversion) == 0: sql = sql + ' where pid = %(pidinput)s and datetime >= %(pasttime)s and appversion' else: sql = sql + ' where pid = %(pidinput)s and datetime >= %(pasttime)s and appversion in ' + str( ratioappversion) sql = sql + ' Group by appversion, sessionday' params = { 'timezone': projectElement.timezone, 'pidinput': projectElement.pid, 'pasttime': '%d-%d-%d %d:%d:%d' % (past.year, past.month, past.day, past.hour, past.minute, past.second) } places = SessionbyApp.objects.raw(sql, params) appversions = [] dates = [] for idx, pl in enumerate(places): if not pl.appversion in appversions: appversions.append(pl.appversion) if not pl.sessionday in dates: dates.append(pl.sessionday) result = {} categories = [] appcount_data = {} for appversion in appversions: appcount_data[appversion] = [] new_places = [] for idx, pl in enumerate(places): new_places.append({ 'appversion': pl.appversion, 'sessionday': pl.sessionday, 'runcount': pl.runcount }) #시간,날짜별로 Session Data를 나눔 for i in range(retention - 1, -1, -1): if retention == 24: # Statistics 하루치 day1 = getTimezoneHour( projectElement.timezone) + datetime.timedelta(hours=-i) if day1.hour == 0: categories.append(day1.strftime('%b-%d')) else: categories.append(day1.strftime('%H')) else: day1 = getTimezoneMidNight( projectElement.timezone) + datetime.timedelta(days=-i) categories.append(day1.strftime('%b-%d')) for appversion in appversions: result_runcount = 0 for idx in range(0, len(new_places)): if new_places[idx]['appversion'] == appversion and new_places[ idx]['sessionday'] == day1.strftime(strformat): result_runcount = new_places[idx]['runcount'] new_places.pop(idx) break appcount_data[appversion].append(int(result_runcount)) appver_data = [] for appversion in appversions: appver_data.append({ 'name': appversion, 'data': appcount_data[appversion] }) chart_sbav = {'categories': categories, 'data': appver_data} result['chart_sbav'] = chart_sbav return HttpResponse(json.dumps(result), 'application/json')
def projects(request): #Project리스트를 출력하는 루틴 if not request.user.is_authenticated(): return HttpResponseRedirect('/urqa/') project_list = [] stagedata = json.loads(get_config('app_stages')) #stagecolordata = json.loads(get_config('app_stages_color')) #avgcolordata = json.loads(get_config('avg_error_score_color')) countcolordata = json.loads(get_config('error_rate_color')) platformdata = json.loads(get_config('app_platforms')) if request.user.is_superuser: MergeProjectElements = Projects.objects.filter() else : #User가 소유한 Project를 얻어온다. UserElement = AuthUser.objects.get(username = request.user) OwnerProjectElements = Projects.objects.filter(owner_uid = UserElement.id) ViewerElements = Viewer.objects.filter(uid = UserElement.id).values('pid') ViewerProjectElements = Projects.objects.filter(pid__in = ViewerElements) MergeProjectElements = OwnerProjectElements | ViewerProjectElements #print MergeProjectElements idxProjectList = []; placesDict = {}; apprunDit = {}; for idx, project in enumerate(MergeProjectElements): idxProjectList.append(project.pid); past, today = getTimeRange(TimeRange.weekly,project.timezone)#최근 7일이내것만 표시 #idxProjectList = Projects.objects.values_list('pid') if idxProjectList: pasttime = '%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second) #pidList = ", ".join(str(v) for v in idxProjectList) pasttime = '%d-%d-%d %d:%d:%d' % (2014,12,3,12,0,0) #pid_list = [str(project) for project in Projects.objects.values_list('pid')] #places = Instances.objects.values('iderror').annotate(count=Count('iderror')).prefech_selected('iderror').filter( # iderror__pid__in=pidList, # datetime__gt=pasttime #).group_by('iderror__pid') pidList = ", ".join(str(v) for v in idxProjectList) sql = "SELECT B.pid AS pid, count(*) AS count FROM errors B JOIN instances A ON A.iderror = B.iderror " sql = sql + "where B.pid IN ( " + pidList +") " sql = sql + "and B.status IN (0,1) " sql = sql + "and A.datetime > %(pasttime)s " sql = sql + "GROUP BY B.pid " params = {'pidinput': "(" + ",".join(str(v) for v in idxProjectList)+")" ,'pasttime':'%d-%d-%d %d:%d:%d' % (past.year,past.month,past.day,past.hour,past.minute,past.second)} places = LoginErrorCountModel.objects.raw(sql, params) for idx,pl in enumerate(places): placesDict[pl.pid]=pl.count sql = "SELECT app.pid AS pid ,SUM(app.appruncount) AS count FROM appruncount2 app " sql = sql + "WHERE app.pid in (" + pidList + ") AND " sql = sql + "app.datetime > %(pasttime)s " sql = sql + "GROUP BY app.pid" apprunCount = LoginApprunCount.objects.raw(sql, params); for idx, app in enumerate(apprunCount): apprunDit[app.pid] = app.count for idx, project in enumerate(MergeProjectElements): projectdata = {} projectdata['apikey'] = project.apikey #stage color 구하기 stagetxt = get_dict_value_matchin_key(stagedata,project.stage) instanceCount = 0; if placesDict.has_key(project.pid): instanceCount = instanceCount + placesDict[project.pid] if request.user.is_superuser and instanceCount == 0: continue #Project에서 사용자의 수를 얻어온다 apprunCount = float('1') if apprunDit.has_key(project.pid): apprunCount = float(apprunDit.get(project.pid)) #프로젝트 DAU대비 Error수를 측정한다. projectdata['count'] = instanceCount convertData = float(instanceCount) if not apprunCount: errorRate = 0 else: errorRate = int(convertData * 100.0 / apprunCount) #Error발생 비율에 따라 Project의 컬러를 설정한다. projectdata['color'] = ErrorRate_for_color( countcolordata , errorRate ) #print projectdata['color'] projectdata['name'] = project.name projectdata['platform'] = get_dict_value_matchin_key(platformdata,project.platform).lower() projectdata['stage'] = stagetxt project_list.append(projectdata) #로딩한 데이터를 Template에 Randering한다. categorydata = json.loads(get_config('app_categories')) platformdata = json.loads(get_config('app_platforms')) sorted_platform = []; for key in sorted(platformdata, key=lambda key: platformdata[key]): sorted_platform.append((key,platformdata[key])) stagedata = json.loads(get_config('app_stages')) ctx = { # 'project_list' : project_list , 'project_list' : project_list, 'app_platformlist' : sorted_platform, 'app_categorylist' : categorydata.items(), 'app_stagelist' : stagedata.items(), 'user' : request.user } return render(request, 'project-select.html', ctx)