Example #1
0
def statistics(request,apikey):
    #통계페이지를 Randering하는 루틴
    username = request.user

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return HttpResponseRedirect('/urqa')

    user = AuthUser.objects.get(username = request.user)

    tpl = loader.get_template('statistics.html')

    #userdict = getUserProfileDict(userelement)
    userdict = getUserProfileDict(user)
    apikeydict = getApikeyDict(apikey)
    settingdict = getSettingDict(projectelement,userelement)

    
    statisticsdict = {
        'ServerURL' : 'http://'+request.get_host() + '/urqa/project/',
    }

    ctxdict = dict(userdict.items() + apikeydict.items() + settingdict.items() + statisticsdict.items() )
    ctx = Context(ctxdict)

    #return render(request, 'statistics.html', ctx)
    return HttpResponse(tpl.render(ctx))
Example #2
0
def modify_req(request, apikey):

    username = request.user

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return HttpResponse(json.dupms({'success' : False , 'message' : 'wrong access'}),'application/json')

    #오너가 아니라면 안됨!!
    if(projectelement.owner_uid.id != userelement.id):
        return HttpResponse(json.dupms({'success' : False , 'message' : 'Only the owner'}),'application/json')


    stagedata = json.loads(get_config('app_stages'))
    categorydata = json.loads(get_config('app_categories'))
    platformdata = json.loads(get_config('app_platforms'))

    projectelement.category = categorydata[request.POST['category']]
    projectelement.stage = stagedata[request.POST['stage']]
    projectelement.platform = platformdata[request.POST['platform']]
    projectelement.name = request.POST['projectname']
    projectelement.timezone = request.POST['timezone']

    #project modify
    projectelement.save();
    return HttpResponse(json.dumps({'success' : True , 'message' : 'success modify project'}),'application/json')
Example #3
0
def projectdashboard(request, apikey):
    #Project의 데시보드를 랜더링 하는 루틴
    username = request.user

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return HttpResponseRedirect('/urqa')

    #print request.META.get('REMOTE_ADDR'),username, projectelement.name

    userdict = getUserProfileDict(userelement)
    apikeydict = getApikeyDict(apikey)
    settingdict = getSettingDict(projectelement, userelement)

    listdict = errorscorelist(apikey)
    #listdict = []

    dashboarddict = {
        'error_list': listdict,
        'total_error_counter': len(listdict)
    }

    ctx = dict(userdict.items() + apikeydict.items() + settingdict.items() +
               dashboarddict.items())

    return render(request, 'projectdashboard.html', ctx)
Example #4
0
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');
Example #5
0
def projectdashboard(request, apikey):

    username = request.user

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return HttpResponseRedirect('/urqa')

    print request.META.get('REMOTE_ADDR'),username, projectelement.name

    userdict = getUserProfileDict(userelement)
    apikeydict = getApikeyDict(apikey)
    settingdict = getSettingDict(projectelement,userelement)

    listdict = errorscorelist(apikey)

    dashboarddict = {
        'error_list' : listdict,
        'total_error_counter' :  len(listdict)
    }

    ctx = dict(userdict.items() + apikeydict.items() + settingdict.items() + dashboarddict.items() )

    return render(request, 'projectdashboard.html', ctx)
Example #6
0
def viewer_registration(request, apikey):

    username = request.user

    valid, message, userelement, projectelement = validUserPjt(username, apikey)

    if not valid:
        return HttpResponse(
            json.dumps({"success": False, "username": "", "message": "Wrong Access"}), "application/json"
        )

    registusername = request.POST["username"]

    # 존재하지 않으면 fail
    user = AuthUser.objects.filter(username__exact=registusername)
    if not user.exists():
        return HttpResponse(
            json.dumps({"success": False, "username": "", "message": "not exists user name"}), "application/json"
        )

    viewerElement = Viewer(uid=user[0], pid=projectelement)
    viewerElement.save()

    return HttpResponse(
        json.dumps({"success": True, "username": registusername, "message": "success registration"}), "application/json"
    )
Example #7
0
def chartdata_erbc(request, apikey):
    #발생한 에러를 Class별로 나누어 나타낸다.
    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
    #past, today = getTimeRange(retention,projectElement.timezone)

    sql = "select errorclassname, ( select count(*) from instances where iderror = A.iderror ) as cnt "
    sql = sql + "from errors A "
    sql = sql + "where lastdate > (curdate() - interval %(intervalinput)s day) and A.pid = %(pidinput)s "

    params = {'pidinput': projectElement.pid, 'intervalinput': retention}

    tmp = Erbc.objects.raw(sql, params)[:100]
    chart2 = []

    for idx, pl in enumerate(tmp):
        chart2.append([str(pl.errorclassname), int(pl.cnt)])
        #print str(pl.errorclassname)

    result = {}
    result['chart2'] = chart2
    return HttpResponse(json.dumps(result), 'application/json')
Example #8
0
def modify_req(request, apikey):

    username = request.user

    valid, message, userelement, projectelement = validUserPjt(username, apikey)

    if not valid:
        return HttpResponse(json.dupms({"success": False, "message": "wrong access"}), "application/json")

    # 오너가 아니라면 안됨!!
    if projectelement.owner_uid.id != userelement.id:
        return HttpResponse(json.dupms({"success": False, "message": "Only the owner"}), "application/json")

    stagedata = json.loads(get_config("app_stages"))
    categorydata = json.loads(get_config("app_categories"))
    platformdata = json.loads(get_config("app_platforms"))

    projectelement.category = categorydata[request.POST["category"]]
    projectelement.stage = stagedata[request.POST["stage"]]
    projectelement.platform = platformdata[request.POST["platform"]]
    projectelement.name = request.POST["projectname"]
    projectelement.timezone = request.POST["timezone"]

    # project modify
    projectelement.save()
    return HttpResponse(json.dumps({"success": True, "message": "success modify project"}), "application/json")
Example #9
0
def statistics(request, apikey):
    #통계페이지를 Randering하는 루틴
    username = request.user

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return HttpResponseRedirect('/urqa')

    user = AuthUser.objects.get(username=request.user)

    tpl = loader.get_template('statistics.html')

    #userdict = getUserProfileDict(userelement)
    userdict = getUserProfileDict(user)
    apikeydict = getApikeyDict(apikey)
    settingdict = getSettingDict(projectelement, userelement)

    statisticsdict = {
        'ServerURL': 'http://' + request.get_host() + '/urqa/project/',
    }

    ctxdict = dict(userdict.items() + apikeydict.items() +
                   settingdict.items() + statisticsdict.items())
    ctx = Context(ctxdict)

    #return render(request, 'statistics.html', ctx)
    return HttpResponse(tpl.render(ctx))
Example #10
0
def chartdata_erbc(request,apikey):
    #발생한 에러를 Class별로 나누어 나타낸다.
    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
    #past, today = getTimeRange(retention,projectElement.timezone)

    sql = "select errorclassname, ( select count(*) from instances where iderror = A.iderror ) as cnt "
    sql = sql + "from errors A "
    sql = sql + "where lastdate > (curdate() - interval %(intervalinput)s day) and A.pid = %(pidinput)s "

    params = {'pidinput':projectElement.pid,'intervalinput':retention }

    tmp = Erbc.objects.raw(sql, params)[:100]
    chart2 = []

    for idx, pl in enumerate(tmp):
        chart2.append( [str(pl.errorclassname), int(pl.cnt) ] )
        #print str(pl.errorclassname)

    result = {}
    result['chart2'] = chart2
    return HttpResponse(json.dumps(result), 'application/json');
Example #11
0
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')
Example #12
0
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');
Example #13
0
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')
Example #14
0
def author_check_error_page(username,apikey,iderror):

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return valid , message , '',''

    try:
        ErrorsElement = Errors.objects.get(iderror = iderror)
    except ObjectDoesNotExist:
        return False, 'DoesNotExist ErrorsElement' , '',''

    return True, 'success' , userelement ,ErrorsElement, projectelement
Example #15
0
def author_check_error_page(username, apikey, iderror):

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return valid, message, '', ''

    try:
        ErrorsElement = Errors.objects.get(iderror=iderror)
    except ObjectDoesNotExist:
        return False, 'DoesNotExist ErrorsElement', '', ''

    return True, 'success', userelement, ErrorsElement, projectelement
Example #16
0
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');
Example #17
0
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');
Example #18
0
def proguardmap_delete(request, apikey):
    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    appversion = request.POST["appversion"]
    filename = request.POST["filename"]

    try:
        mapElement = Proguardmap.objects.get(pid=projectElement, appversion=appversion, filename=filename)
        temp_path = os.path.join(PROJECT_DIR, get_config("proguard_map_path"))
        temp_path = os.path.join(temp_path, apikey)
        temp_path = os.path.join(temp_path, appversion)
        os.remove(os.path.join(temp_path, filename))
        mapElement.delete()
        retdat = {"result": 0, "msg": "Success"}
    except ObjectDoesNotExist:
        retdat = {"result": -1, "msg": "Invalid delete request"}
    return HttpResponse(json.dumps(retdat), "application/json")
Example #19
0
def proguardmap_delete(request,apikey):
    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    appversion = request.POST['appversion']
    filename = request.POST['filename']

    try:
        mapElement = Proguardmap.objects.get(pid=projectElement,appversion=appversion,filename=filename)
        temp_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
        temp_path = os.path.join(temp_path,apikey)
        temp_path = os.path.join(temp_path,appversion)
        os.remove(os.path.join(temp_path,filename))
        mapElement.delete();
        retdat = {'result':0,'msg':'Success'}
    except ObjectDoesNotExist:
        retdat = {'result':-1,'msg':'Invalid delete request'}
    return HttpResponse(json.dumps(retdat), 'application/json');
Example #20
0
def proguardmap_delete(request, apikey):
    #Proguard map data를 삭제한다.
    result, msg, userElement, projectElement = validUserPjt(
        request.user, apikey)

    appversion = request.POST['appversion']
    filename = request.POST['filename']

    try:
        mapElement = Proguardmap.objects.get(pid=projectElement,
                                             appversion=appversion,
                                             filename=filename)
        temp_path = os.path.join(PROJECT_DIR, get_config('proguard_map_path'))
        temp_path = os.path.join(temp_path, apikey)
        temp_path = os.path.join(temp_path, appversion)
        os.remove(os.path.join(temp_path, filename))
        mapElement.delete()
        retdat = {'result': 0, 'msg': 'Success'}
    except ObjectDoesNotExist:
        retdat = {'result': -1, 'msg': 'Invalid delete request'}
    return HttpResponse(json.dumps(retdat), 'application/json')
Example #21
0
def modify_req(request, apikey):
    #Project의 설정을 바꿀수 있다.
    #Porject의 Status, Timezone, Viewer를 변경 할 수있다.
    username = request.user

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return HttpResponse(
            json.dupms({
                'success': False,
                'message': 'wrong access'
            }), 'application/json')

    #오너가 아니라면 안됨!!
    if (projectelement.owner_uid.id != userelement.id):
        return HttpResponse(
            json.dupms({
                'success': False,
                'message': 'Only the owner'
            }), 'application/json')

    stagedata = json.loads(get_config('app_stages'))
    categorydata = json.loads(get_config('app_categories'))
    platformdata = json.loads(get_config('app_platforms'))

    projectelement.category = categorydata[request.POST['category']]
    projectelement.stage = stagedata[request.POST['stage']]
    projectelement.platform = platformdata[request.POST['platform']]
    projectelement.name = request.POST['projectname']
    projectelement.timezone = request.POST['timezone']

    #project modify
    projectelement.save()
    return HttpResponse(
        json.dumps({
            'success': True,
            'message': 'success modify project'
        }), 'application/json')
Example #22
0
def viewer_registration(request,apikey):

    username = request.user

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return HttpResponse(json.dumps({'success' : False, 'username' : '' ,'message' : 'Wrong Access' } ),'application/json')

    registusername = request.POST['username']


    #존재하지 않으면 fail
    user = AuthUser.objects.filter(username__exact=registusername)
    if not user.exists():
        return HttpResponse(json.dumps({'success' : False, 'username' : '' , 'message' : 'not exists user name' } ),'application/json')


    viewerElement = Viewer(uid = user[0], pid = projectelement)
    viewerElement.save()

    return HttpResponse(json.dumps({'success': True, 'username' : registusername , 'message' : 'success registration'}),'application/json')
Example #23
0
def chartdata_ebcs(request,apikey):
    #발생한 에러를 Country(나라)별로 나누어 나타낸다.
    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 = {}

    #chart4
    temp_data = {}
    activities = []

    sql = "select count(*) count, country from instances "
    sql = sql + " where pid = %(pname)s "
    sql = sql + " and datetime > (curdate() - interval %(intervalinput)s day) "
    sql = sql + " group by country"
    sql = sql + " order by count desc"
    sql = sql + " limit 10"

    params = {'pname':projectElement.pid, 'intervalinput':retention }
    counts = CountrysbyApp.objects.raw(sql, params)

    categories = []
    temp_data = []

    for idx, pl in enumerate(counts):
        categories.append(pl.country)
        temp_data.append(pl.count)


    act_data = [{'name':'Country','data':temp_data}]
    chart6 = {'categories':categories,'data':act_data}
    result['chart6'] = chart6
    return HttpResponse(json.dumps(result), 'application/json');
Example #24
0
def chartdata_ebcs(request, apikey):
    #발생한 에러를 Country(나라)별로 나누어 나타낸다.
    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 = {}

    #chart4
    temp_data = {}
    activities = []

    sql = "select count(*) count, country from instances "
    sql = sql + " where pid = %(pname)s "
    sql = sql + " and datetime > (curdate() - interval %(intervalinput)s day) "
    sql = sql + " group by country"
    sql = sql + " order by count desc"
    sql = sql + " limit 10"

    params = {'pname': projectElement.pid, 'intervalinput': retention}
    counts = CountrysbyApp.objects.raw(sql, params)

    categories = []
    temp_data = []

    for idx, pl in enumerate(counts):
        categories.append(pl.country)
        temp_data.append(pl.count)

    act_data = [{'name': 'Country', 'data': temp_data}]
    chart6 = {'categories': categories, 'data': act_data}
    result['chart6'] = chart6
    return HttpResponse(json.dumps(result), 'application/json')
Example #25
0
def viewer_delete(request, apikey):
    #Viewer를 삭제하는 루틴.
    username = request.user

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return HttpResponse(json.dumps({
            'success': False,
            'username': ''
        }), 'application/json')

    deleteusername = request.POST['username']

    try:
        deleteuser = AuthUser.objects.get(username=deleteusername)
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({
            'success': False,
            'username': ''
        }), 'application/json')

    try:
        deleteviewtuple = Viewer.objects.get(pid=projectelement.pid,
                                             uid=deleteuser.id)
        deleteviewtuple.delete()
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({
            'success': False,
            'username': ''
        }), 'application/json')

    return HttpResponse(
        json.dumps({
            'success': True,
            'username': deleteusername
        }), 'application/json')
Example #26
0
def chartdata_erbd(request, apikey):
    #발생한 에러를 Device별로 나누어 나타낸다.
    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')

    # 하루치 통계
    if retention == 1:
        sql = 'select device, count(*) as sum from instances where pid = %(pidinput)s and datetime BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() group by device order by sum desc limit 12'

    else:
        #하루 이상인 경우
        sql = 'SELECT A.device, A.sum FROM( '
        sql = sql + 'SELECT DEVICE, SUM(SUMCOUNT) as SUM FROM ERBD WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() '
        sql = sql + 'group by DEVICE ) A'
        sql = sql + ' order by sum desc limit 12'

    # query run
    params = {'pidinput': projectElement.pid, 'retentioninput': retention}
    places = Erbd.objects.raw(sql, params)

    categories = []
    temp_data = []
    for idx, pl in enumerate(places):
        categories.append(str(pl.device))
        temp_data.append(int(pl.sum))

    dev_data = [{'name': 'Device', 'data': temp_data}]
    chart3 = {'categories': categories, 'data': dev_data}
    result = {}
    result['chart3'] = chart3

    return HttpResponse(json.dumps(result), 'application/json')
Example #27
0
def viewer_delete(request, apikey):

    username = request.user

    valid, message, userelement, projectelement = validUserPjt(username, apikey)

    if not valid:
        return HttpResponse(json.dumps({"success": False, "username": ""}), "application/json")

    deleteusername = request.POST["username"]

    try:
        deleteuser = AuthUser.objects.get(username=deleteusername)
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({"success": False, "username": ""}), "application/json")

    try:
        deleteviewtuple = Viewer.objects.get(pid=projectelement.pid, uid=deleteuser.id)
        deleteviewtuple.delete()
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({"success": False, "username": ""}), "application/json")

    return HttpResponse(json.dumps({"success": True, "username": deleteusername}), "application/json")
Example #28
0
def viewer_registration(request, apikey):
    #Project의 Viewer를 등록한다.
    #Project는 하나의 Owner와 여럿의 Viewer를 가질 수 있다.
    username = request.user

    valid, message, userelement, projectelement = validUserPjt(
        username, apikey)

    if not valid:
        return HttpResponse(
            json.dumps({
                'success': False,
                'username': '',
                'message': 'Wrong Access'
            }), 'application/json')

    registusername = request.POST['username']

    #존재하지 않으면 fail
    user = AuthUser.objects.filter(username__exact=registusername)
    if not user.exists():
        return HttpResponse(
            json.dumps({
                'success': False,
                'username': '',
                'message': 'not exists user name'
            }), 'application/json')

    viewerElement = Viewer(uid=user[0], pid=projectelement)
    viewerElement.save()

    return HttpResponse(
        json.dumps({
            'success': True,
            'username': registusername,
            'message': 'success registration'
        }), 'application/json')
Example #29
0
def chartdata_erba(request,apikey):
    #발생한 에러를 Activity별로 나누어 나타낸다.
    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')

    result = {}
    # 하루치 통계
    if retention == 1:
        sql = 'select LASTACTIVITY as activity, count(*) as sum from instances where pid = %(pidinput)s and datetime BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() group by lastactivity'

    else:
    #하루 이상인 경우
        sql = 'SELECT A.LASTACTIVITY as activity, A.sum FROM( '
        sql = sql + 'SELECT LASTACTIVITY, SUM(SUMCOUNT) as SUM FROM ERBA WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() AND lastactivity > ""'
        sql = sql + 'group by LASTACTIVITY ) A'
        sql = sql + ' order by sum desc limit 12'


    categories = []
    temp_data = []
    params = {'pidinput':projectElement.pid,'retentioninput':retention}
    places = Erba.objects.raw(sql, params)

    for idx, pl in enumerate(places):
        categories.append(str(pl.activity))
        temp_data.append(int(pl.sum))

    act_data = [{'name':'Device','data':temp_data}]
    chart4 = {'categories':categories,'data':act_data}
    result['chart4'] = chart4

    return HttpResponse(json.dumps(result), 'application/json');
Example #30
0
def chartdata_erbd(request,apikey):
    #발생한 에러를 Device별로 나누어 나타낸다.
    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')
    
    # 하루치 통계
    if retention == 1:
        sql = 'select device, count(*) as sum from instances where pid = %(pidinput)s and datetime BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() group by device order by sum desc limit 12'

    else:
    #하루 이상인 경우
        sql = 'SELECT A.device, A.sum FROM( '
        sql = sql + 'SELECT DEVICE, SUM(SUMCOUNT) as SUM FROM ERBD WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() '
        sql = sql + 'group by DEVICE ) A'
        sql = sql + ' order by sum desc limit 12'

    # query run
    params = {'pidinput':projectElement.pid,'retentioninput':retention}
    places = Erbd.objects.raw(sql, params)

    categories = []
    temp_data = []
    for idx, pl in enumerate(places):
        categories.append(str(pl.device))
        temp_data.append(int(pl.sum))

    dev_data = [{'name':'Device','data':temp_data}]
    chart3 = {'categories':categories,'data':dev_data}
    result = {}
    result['chart3'] = chart3

    return HttpResponse(json.dumps(result), 'application/json');
Example #31
0
def chartdata_erba(request, apikey):
    #발생한 에러를 Activity별로 나누어 나타낸다.
    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')

    result = {}
    # 하루치 통계
    if retention == 1:
        sql = 'select LASTACTIVITY as activity, count(*) as sum from instances where pid = %(pidinput)s and datetime BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() group by lastactivity'

    else:
        #하루 이상인 경우
        sql = 'SELECT A.LASTACTIVITY as activity, A.sum FROM( '
        sql = sql + 'SELECT LASTACTIVITY, SUM(SUMCOUNT) as SUM FROM ERBA WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() AND lastactivity > ""'
        sql = sql + 'group by LASTACTIVITY ) A'
        sql = sql + ' order by sum desc limit 12'

    categories = []
    temp_data = []
    params = {'pidinput': projectElement.pid, 'retentioninput': retention}
    places = Erba.objects.raw(sql, params)

    for idx, pl in enumerate(places):
        categories.append(str(pl.activity))
        temp_data.append(int(pl.sum))

    act_data = [{'name': 'Device', 'data': temp_data}]
    chart4 = {'categories': categories, 'data': act_data}
    result['chart4'] = chart4

    return HttpResponse(json.dumps(result), 'application/json')
Example #32
0
def viewer_delete(request,apikey):
    #Viewer를 삭제하는 루틴.
    username = request.user

    valid , message , userelement, projectelement = validUserPjt(username,apikey)

    if not valid:
        return HttpResponse(json.dumps({'success' : False, 'username' : '' } ),'application/json')

    deleteusername = request.POST['username']

    try:
        deleteuser = AuthUser.objects.get(username = deleteusername)
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({'success' : False, 'username' : '' } ),'application/json')


    try:
        deleteviewtuple = Viewer.objects.get(pid = projectelement.pid , uid = deleteuser.id)
        deleteviewtuple.delete()
    except ObjectDoesNotExist:
        return HttpResponse(json.dumps({'success' : False, 'username' : '' } ),'application/json')

    return HttpResponse(json.dumps({'success' : True, 'username' : deleteusername } ),'application/json')
Example #33
0
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');
Example #34
0
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')
Example #35
0
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');
Example #36
0
def so_upload(request, apikey):
    #So file upload루틴
    #print 'so_upload',apikey

    #appver = request.POST['version']

    #print 'appversion',appver

    result, msg, userElement, projectElement = validUserPjt(
        request.user, apikey)

    #update_error_callstack(projectElement,appver)

    if not result:
        return HttpResponse(msg)
    #print request.method
    #print request.FILES
    #print request.POST

    retdat = {'result': -1, 'msg': 'Failed to Upload File'}

    if request.method == 'POST':
        if 'file' in request.FILES:
            file = request.FILES['file']
            temp_fname = file._name

            temp_path = os.path.join(
                PROJECT_DIR,
                get_config('so_pool_path') + '/%s' % apikey)
            if not os.path.isdir(temp_path):
                os.mkdir(temp_path)

            temp_path = temp_path + '/temp'  # % appver
            if not os.path.isdir(temp_path):
                os.mkdir(temp_path)

            fp = open(os.path.join(temp_path, temp_fname), 'wb')
            for chunk in file.chunks():
                fp.write(chunk)
            fp.close()

            #업로드된 SO파일에서 정보를 추출한다.
            flag, appver, so_fname, msg = extractinfo(projectElement,
                                                      temp_path, temp_fname)
            if flag:
                print appver, so_fname
            else:
                os.remove(os.path.join(temp_path, temp_fname))
                retdat = {'result': -1, 'msg': msg}
                print 'so_upload', retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json')
            #if 1:
            #    return HttpResponse('Failed to Upload File')

            #서버의 So pool Directory에 파일을 저장한다.
            so_path = os.path.join(PROJECT_DIR,
                                   get_config('so_pool_path') + '/%s' % apikey)
            if not os.path.isdir(so_path):
                os.mkdir(so_path)
            so_path = so_path + '/%s' % appver
            if not os.path.isdir(so_path):
                os.mkdir(so_path)
            print so_path
            os.rename(os.path.join(temp_path, temp_fname),
                      os.path.join(so_path, so_fname))

            #file move
            success_flag, vkey = so2sym(projectElement, appver, so_path,
                                        so_fname)
            print 'success_flag', success_flag

            #So파일에서 Sym파일을 추출 하였으므로 분석이 완료된(필요없는) so파일은 삭제한다.
            os.remove(os.path.join(
                so_path, so_fname))  #사용한 sofile 삭제, sym파일만 추출하면 so파일은 삭제해도 됨
            if success_flag:
                #정상적으로 so파일이 업로드되었기 때문에 error들의 callstack 정보를 갱신한다.
                update_error_callstack(projectElement, appver)
                retdat = {
                    'result': 0,
                    'msg': 'File successfully Uploaded, and Valid so file',
                    'vkey': vkey
                }
                print 'so_upload', retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json')
            else:
                retdat = {
                    'result': -1,
                    'msg': 'Error, this file have no debug info'
                }
                print 'so_upload', retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json')

    print 'so_upload', retdat['result'], retdat['msg']
    return HttpResponse(json.dumps(retdat), 'application/json')
Example #37
0
def proguardmap_upload(request, apikey):
    #Proguard MAP데이터를 업로드한다.
    print 'proguardmap_upload', apikey

    result, msg, userElement, projectElement = validUserPjt(
        request.user, apikey)

    if not result:
        return HttpResponse(msg)
    print request.FILES

    appver = request.POST['appversion']
    retdat = {'result': -1, 'msg': 'Failed to Upload File'}

    if request.method != 'POST':
        retdat = {'result': -1, 'msg': 'Bad request'}
    elif len(appver) == 0:
        retdat = {'result': -1, 'msg': 'Invalid App version'}
    elif not 'file' in request.FILES:
        retdat = {'result': -1, 'msg': 'You should select file'}
    else:
        file = request.FILES['file']
        temp_fname = file._name

        temp_path = os.path.join(PROJECT_DIR, get_config('proguard_map_path'))
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, apikey)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path, appver)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)

        fp = open(os.path.join(temp_path, temp_fname), 'wb')
        for chunk in file.chunks():
            fp.write(chunk)
        fp.close()
        retdat = {'result': 0, 'msg': 'File successfully Uploaded'}

    #정상적으로 Map파일이 업로드 되었다면
    if retdat['result'] == 0:
        try:
            mapElement = Proguardmap.objects.get(pid=projectElement,
                                                 appversion=appver)
            if mapElement.filename != temp_fname:
                temp_path = os.path.join(PROJECT_DIR,
                                         get_config('proguard_map_path'))
                temp_path = os.path.join(temp_path, apikey)
                temp_path = os.path.join(temp_path, appver)
                os.remove(os.path.join(temp_path, mapElement.filename))
            mapElement.filename = temp_fname
            mapElement.uploadtime = getUTCawaredatetime()
            mapElement.save()
            retdat = {'result': 1, 'msg': 'File successfully re Uploaded'}
            print 'mapping file overwrite'
        except ObjectDoesNotExist:
            print 'new mapping file'
            mapElement = Proguardmap(
                pid=projectElement,
                appversion=appver,
                filename=temp_fname,
                uploadtime=getUTCawaredatetime(),
            )
            mapElement.save()
        retdat['appversion'] = mapElement.appversion
        retdat['filename'] = mapElement.filename
        retdat['date'] = toTimezone(
            mapElement.uploadtime,
            projectElement.timezone).__format__('%Y.%m.%d')
        retdat['time'] = toTimezone(
            mapElement.uploadtime, projectElement.timezone).__format__('%H:%M')
    print retdat
    return HttpResponse(json.dumps(retdat), 'application/json')
Example #38
0
def so_upload(request, apikey):
    #print request
    print 'so_upload',apikey

    #appver = request.POST['version']

    #print 'appversion',appver

    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    #update_error_callstack(projectElement,appver)

    if not result:
        return HttpResponse(msg)
    print request.method
    print request.FILES
    print request.POST

    retdat = {'result':-1,'msg':'Failed to Upload File'}

    if request.method == 'POST':
        if 'file' in request.FILES:
            file = request.FILES['file']
            temp_fname = file._name

            temp_path = os.path.join(PROJECT_DIR,get_config('so_pool_path') +'/%s' % apikey)
            if not os.path.isdir(temp_path):
                os.mkdir(temp_path)

            temp_path = temp_path + '/temp'# % appver
            if not os.path.isdir(temp_path):
                os.mkdir(temp_path)

            fp = open(os.path.join(temp_path,temp_fname) , 'wb')
            for chunk in file.chunks():
                fp.write(chunk)
            fp.close()

            flag, appver, so_fname, msg = extractinfo(projectElement,temp_path,temp_fname)
            if flag:
                print appver, so_fname
            else:
                os.remove(os.path.join(temp_path, temp_fname))
                retdat = {'result':-1,'msg':msg}
                print 'so_upload',retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json');
            #if 1:
            #    return HttpResponse('Failed to Upload File')

            so_path = os.path.join(PROJECT_DIR,get_config('so_pool_path') +'/%s' % apikey)
            if not os.path.isdir(so_path):
                os.mkdir(so_path)
            so_path = so_path + '/%s' % appver
            if not os.path.isdir(so_path):
                os.mkdir(so_path)
            print so_path
            os.rename(os.path.join(temp_path,temp_fname),os.path.join(so_path,so_fname))

            #file move
            success_flag,vkey = so2sym(projectElement, appver, so_path, so_fname)
            print 'success_flag',success_flag

            os.remove(os.path.join(so_path, so_fname))#사용한 sofile 삭제, sym파일만 추출하면 so파일은 삭제해도 됨
            if success_flag:
                #정상적으로 so파일이 업로드되었기 때문에 error들의 callstack 정보를 갱신한다.
                update_error_callstack(projectElement,appver)
                retdat = {'result':0,'msg':'File successfully Uploaded, and Valid so file','vkey':vkey}
                print 'so_upload',retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json');
            else:
                retdat = {'result':-1,'msg':'Error, this file have no debug info'}
                print 'so_upload',retdat['result'], retdat['msg']
                return HttpResponse(json.dumps(retdat), 'application/json');

    print 'so_upload',retdat['result'], retdat['msg']
    return HttpResponse(json.dumps(retdat), 'application/json');
Example #39
0
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');

    """
Example #40
0
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')
Example #41
0
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)
Example #42
0
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))
Example #43
0
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');
Example #44
0
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')
Example #45
0
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')
    """
Example #46
0
def chartdata_ebav(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')

    # Common Data
    result = {}

    appcount_data = {}
    categories = []
    appver_data = []

    sql = "select count(*) as errorcount ,appversion, DATE_FORMAT(A.datetime, '%%m-%%d') as errorday "
    sql = sql + "from instances A, errors B "
    sql = sql + "where A.iderror = B.iderror "
    sql = sql + "and pid = %(pidinput)s "
    sql = sql + "and B.status in (0,1) "
    sql = sql + "and A.datetime > (curdate() - interval %(intervalinput)s day) "
    sql = sql + "group by DATE_FORMAT(A.datetime, '%%m%%d'),appversion"
    
    params = {'pidinput':projectElement.pid,'intervalinput':retention - 1}
    places = ErrorsbyApp.objects.raw(sql, params)

    #listing app version
    appversions = []
    for idx, pl in enumerate(places):
        appversions.append(pl.appversion)

    appversionList = list(set(appversions))
    appversionList.sort()
    #loop for retention
    dates = []
    for idx, pl in enumerate(places):
        dates.append(pl.errorday)	
    dateList = list(set(dates))
    dateList.sort()
    returnValue = []
    for version in appversionList:
        dataList = [0] * len(dateList)
        for index, date in enumerate(dateList):
            for idx, pl in enumerate(places):
                if pl.appversion == version and pl.errorday == date:
                    dataList[index] = pl.errorcount

        returnValue.append(
            {
                'name': version, 
                'data': dataList
            }
        )


    for i in range(retention-1,-1,-1):
        category_time = getTimezoneMidNight(projectElement.timezone) + datetime.timedelta(days =  -i)
        categories.append(category_time.strftime('%b-%d'))

    chart1 = {'categories':categories,'data':returnValue}
    result['chart1'] = chart1
    print >>sys.stderr, chart1
    return HttpResponse(json.dumps(result), 'application/json');
Example #47
0
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');
Example #48
0
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')
Example #49
0
def chartdata_erbv(request, apikey):
    #발생한 에러를 OSVersion / AppVersion 별로 나누어 나타낸다.
    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')

    result = {}
    categories = []
    osversions = []
    ver_data = []
    osversions2 = []
    temp_data = []

    # 하루치 통계
    if retention == 1:
        sql2 = 'select appversion, osversion, count(*) as sum from instances where pid = %(pidinput)s and datetime BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() '
        sql2 = sql2 + 'group by appversion, osversion '
        sql2 = sql2 + 'order by appversion desc, osversion desc'

    else:
        #하루 이상인 경우
        #max 12개만 가져올 appversion 구하는 쿼리
        sql = 'SELECT appversion, sum FROM ( '
        sql = sql + 'SELECT sum(sumcount) as sum, appversion from ERBV where pid = %(pidinput)s and COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() '
        sql = sql + 'group by appversion ) A '
        sql = sql + 'order by sum desc limit 12'
        params = {'pidinput': projectElement.pid, 'retentioninput': retention}
        places = ErbvApps.objects.raw(sql, params)

        arrayInput = ()
        arrayInput = list(arrayInput)
        for idx, pl in enumerate(places):
            arrayInput.append(str(pl.appversion))

        arrayInput = tuple(arrayInput)
        if len(arrayInput) == 1:
            arrayInput = str(arrayInput)[:len(str(arrayInput)) -
                                         2] + str(arrayInput)[-1]
        sql2 = 'SELECT A.appversion , A.osversion, A.sum FROM( '
        if len(arrayInput) == 0:
            sql2 = sql2 + 'SELECT appversion, osversion, SUM(SUMCOUNT) as SUM FROM ERBV WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW()  '
        else:
            sql2 = sql2 + 'SELECT appversion, osversion, SUM(SUMCOUNT) as SUM FROM ERBV WHERE PID = %(pidinput)s AND COUNTEDAT BETWEEN DATE_SUB(NOW(), INTERVAL %(retentioninput)s DAY) AND NOW() AND appversion in  ' + str(
                arrayInput)
        sql2 = sql2 + ' group by appversion, osversion ) A '
        sql2 = sql2 + ' order by appversion desc, osversion desc'

    # raw query run and make data
    params2 = {'pidinput': projectElement.pid, 'retentioninput': retention}
    places2 = Erbv.objects.raw(sql2, params2)
    #fill categories
    for idx, pl in enumerate(places2):
        if pl.appversion not in categories:
            categories.append(str(pl.appversion))

    for idx, pl in enumerate(places2):
        if pl.osversion not in osversions:
            osversions.append(str(pl.osversion))

    matrix = [[0 for i in range(len(categories))]
              for j in range(len(osversions))]
    for idx, pl in enumerate(places2):
        #get appversion's index
        index1 = categories.index(pl.appversion)
        index2 = osversions.index(pl.osversion)
        matrix[index2][index1] = int(pl.sum)

    mindex = 0
    for idx, pl in enumerate(places2):
        if pl.osversion not in osversions2:
            osversions2.append(str(pl.osversion))
            ver_data.append({'name': pl.osversion, 'data': matrix[mindex]})
            mindex = mindex + 1

    chart5 = {'categories': categories, 'data': ver_data}
    result['chart5'] = chart5

    return HttpResponse(json.dumps(result), 'application/json')
Example #50
0
def proguardmap_upload(request, apikey):
    print 'proguardmap_upload',apikey

    result, msg, userElement, projectElement = validUserPjt(request.user, apikey)

    if not result:
        return HttpResponse(msg)
    print request.FILES

    appver = request.POST['appversion']
    retdat = {'result':-1,'msg':'Failed to Upload File'}

    if request.method != 'POST':
        retdat = {'result':-1,'msg':'Bad request'}
    elif len(appver) == 0:
        retdat = {'result':-1,'msg':'Invalid App version'}
    elif not 'file' in request.FILES:
        retdat = {'result':-1,'msg':'You should select file'}
    else:
        file = request.FILES['file']
        temp_fname = file._name

        temp_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path,apikey)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)
        temp_path = os.path.join(temp_path,appver)
        if not os.path.isdir(temp_path):
            os.mkdir(temp_path)

        fp = open(os.path.join(temp_path,temp_fname) , 'wb')
        for chunk in file.chunks():
            fp.write(chunk)
        fp.close()
        retdat = {'result':0,'msg':'File successfully Uploaded'}

    if retdat['result'] == 0:
        try:
            mapElement = Proguardmap.objects.get(pid=projectElement,appversion=appver)
            if mapElement.filename != temp_fname:
                temp_path = os.path.join(PROJECT_DIR,get_config('proguard_map_path'))
                temp_path = os.path.join(temp_path,apikey)
                temp_path = os.path.join(temp_path,appver)
                os.remove(os.path.join(temp_path,mapElement.filename))
            mapElement.filename = temp_fname
            mapElement.uploadtime = getUTCawaredatetime()
            mapElement.save()
            retdat = {'result':1,'msg':'File successfully re Uploaded'}
            print 'mapping file overwrite'
        except ObjectDoesNotExist:
            print 'new mapping file'
            mapElement = Proguardmap(
                pid=projectElement,
                appversion=appver,
                filename=temp_fname,
                uploadtime=getUTCawaredatetime(),
            )
            mapElement.save();
        retdat['appversion'] = mapElement.appversion
        retdat['filename'] = mapElement.filename
        retdat['date'] = toTimezone(mapElement.uploadtime,projectElement.timezone).__format__('%Y.%m.%d')
        retdat['time'] = toTimezone(mapElement.uploadtime,projectElement.timezone).__format__('%H:%M')
    print retdat
    return HttpResponse(json.dumps(retdat), 'application/json');
Example #51
0
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')
Example #52
0
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')