示例#1
0
def map():
    city = request.args.get('city')
    state = request.args.get('state')
    if request.method == 'POST':
        city = request.form['city']
        state = request.form['state']
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(30)
        qobj = thedb.MainQuery(state=state, district=city, start_date=start_date, end_date=end_date)
            
        #data for bar graph
        daily,weekly=qobj.get_barplot_data()
        response={}
        response['daily']=daily
        response['weekly']=weekly
        
        #points for map
        report = get_points(city)
        response['points'] = report
        
        #points for anomaly detection
        anomaly=get_anomaly_points(city,state)
        print(anomaly)
        response['anomaly']= anomaly
        return response

    return render_template('map.html',city=city,state=state)
示例#2
0
def ClustermapM():
    city = request.args.get('city')
    state = request.args.get('state')
    dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
    dt = dt.replace('T',' ').split('.')[0]
    end_date=dt.split(' ')[0]
    start_date = date_before_n_days(30)
    qobj = thedb.MainQuery(state=state, district=city, start_date=start_date, end_date=end_date)
    res=qobj.get_clustermap_data()
    filename=create_cluster_map(res)
    return render_template(filename)
示例#3
0
def get_anomaly_points(district,state):
    dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
    end_date = dt.replace('T',' ').split('.')[0].split(' ')[0]
    start_date = date_before_n_days(8)
    qobj = thedb.MainQuery(district=district, state=state, start_date=start_date, end_date=end_date)
    data, time_index = qobj.get_heatmaptime_data()
    an = []
    for i in range(len(data)-2):
        pts = data[i]+data[i+1]
        for j in range(len(pts)):
            for k in range(j+1,len(pts)):
                l1 = pts[j]
                l2 = pts[k]
                if geodesic(l1, l2).km*1000 < 100:
                    lat = (l1[0]+l2[0])/2
                    lng = (l1[1]+l2[1])/2
                    an.append([lat,lng])
    return(an)
示例#4
0
def graphs():
    if request.method == 'GET':
        # 'qobj' stands for query-object
        qobj = thedb.MainQuery()

        #data for pie charts
        count = qobj.get_label_count()
        c_l= count['L']
        c_m= count['M']
        c_h= count['H']
        count = qobj.get_resolved_count()
        c_resolve_on_time= count['1']
        c_resolve_late= count['2']
        c_pending=20

        #data for top 5 cities
        #clean,dirty=

        params={'c_l':c_l,'c_m':c_m,'c_h':c_h,'c_resolve_on_time':c_resolve_on_time,'c_resolve_late':c_resolve_late,'c_pending':c_pending}

    if request.method == 'POST':
        state = request.form['state']
        city = request.form['city']
        duration = request.form['duration']
        print(state,city,duration)
        # duration can be "week", "month", "3_months", "year" or "date"
        # if duration == "date" then start_date and end_date will have values
        
        if duration == 'date':
            start_date = request.form['startDate']
            end_date = request.form['endDate']
            qobj = thedb.MainQuery(state,city,start_date,end_date)

        else:
            if duration == 'week':
                dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
                dt = dt.replace('T',' ').split('.')[0]
                end_date=dt.split(' ')[0]
                start_date = date_before_n_days(7)
                qobj = thedb.MainQuery(state,city,start_date,end_date)

            elif duration == 'month':
                dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
                dt = dt.replace('T',' ').split('.')[0]
                end_date=dt.split(' ')[0]
                start_date = date_before_n_days(30)
                qobj = thedb.MainQuery(state,city,start_date,end_date)

            elif duration == '3 months':
                dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
                dt = dt.replace('T',' ').split('.')[0]
                end_date=dt.split(' ')[0]
                start_date = date_before_n_days(90)
                qobj = thedb.MainQuery(state,city,start_date,end_date)

            elif duration == 'year':
                dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
                dt = dt.replace('T',' ').split('.')[0]
                end_date=dt.split(' ')[0]
                start_date = date_before_n_days(365)
                qobj = thedb.MainQuery(state,city,start_date,end_date)

            elif duration == 'all':
                qobj = thedb.MainQuery(state,city)

        #data for bar graph
        daily,weekly=qobj.get_barplot_data()
        response={}
        response['daily']=daily
        response['weekly']=weekly

        #data for pie charts
        count = qobj.get_label_count()
        print("Count for labels",count)
        if(not (count['L'] or count['L'] or count['L'])):
            print("No data")
        c_l= count['L']
        c_m= count['M']
        c_h= count['H']
        count = qobj.get_resolved_count()
        print("Count for labels",count)
        c_resolve_on_time= count['1']
        c_resolve_late= count['2']
        c_pending=20

        # Commenting params. It has no use for now - Vinod
        # params={'c_l':c_l,'c_m':c_m,'c_h':c_h,'c_resolve_on_time':c_resolve_on_time,'c_resolve_late':c_resolve_late,'c_pending':c_pending}
        response['c_l'] = c_l
        response['c_m'] = c_m
        response['c_h'] = c_h
        response['c_resolve_on_time'] = c_resolve_on_time
        response['c_resolve_late'] = c_resolve_late
        return response

    return render_template('graphs.html',params=params)
示例#5
0
def heatmap():
    city = request.args.get('city')
    state = request.args.get('state')
    duration = request.args.get('duration')
    start = request.args.get('start')
    end = request.args.get('end')
    # duration can be "week", "month", "3_months", "year" or "date"
    if duration=="all":
        qobj = thedb.MainQuery(state=state, district=city)
        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)

    elif duration=="week":

        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(7)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)

    elif duration=="month":
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(30)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)

    elif duration == '3 months':
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(90)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)

    elif duration == 'year':
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(365)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)

    elif duration == 'date':
        qobj = thedb.MainQuery(state,city,start,end)
        data=qobj.get_heatmap_data()
        if city=="all":
            filename=create_heatmap(data,"state")
        else:
            filename=create_heatmap(data,"district")
        return render_template(filename)
示例#6
0
def heatmapwithtime():
    city = request.args.get('city')
    state = request.args.get('state')
    duration = request.args.get('duration')
    start = request.args.get('start')
    end = request.args.get('end')

    # duration can be "week", "month", "3_months", "year" or "date"
    if duration=="all":
        qobj = thedb.MainQuery(state=state, district=city)
        # data,time_index=qobj.get_heatmaptime_data()
        # if city=="all":
        #     filename=create_heatmap_with_time(data,time_index,"state")
        # else:
        #     filename=create_heatmap_with_time(data,time_index,"district")
        # return render_template(filename)

    elif duration=="week":

        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(7)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        # data,time_index=qobj.get_heatmaptime_data()
        # if city=="all":
        #     filename=create_heatmap_with_time(data,time_index,"state")
        # else:
        #     filename=create_heatmap_with_time(data,time_index,"district")
        # return render_template(filename)


    elif duration=="month":
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(30)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        # data,time_index=qobj.get_heatmaptime_data()
        # if city=="all":
        #     filename=create_heatmap_with_time(data,time_index,"state")
        # else:
        #     filename=create_heatmap_with_time(data,time_index,"district")
        # return render_template(filename)

    elif duration == '3 months':
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(90)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        # data,time_index=qobj.get_heatmaptime_data()
        # if city=="all":
        #     filename=create_heatmap_with_time(data,time_index,"state")
        # else:
        #     filename=create_heatmap_with_time(data,time_index,"district")
        # return render_template(filename)

    elif duration == 'year':
        dt = json.loads(req.get('http://worldtimeapi.org/api/timezone/Asia/Kolkata').text)['datetime']
        dt = dt.replace('T',' ').split('.')[0]
        end_date=dt.split(' ')[0]
        start_date = date_before_n_days(365)
        qobj = thedb.MainQuery(state,city,start_date,end_date)

        # data,time_index=qobj.get_heatmaptime_data()
        # if city=="all":
        #     filename=create_heatmap_with_time(data,time_index,"state")
        # else:
        #     filename=create_heatmap_with_time(data,time_index,"district")
        # return render_template(filename)


    elif duration == 'date':
        qobj = thedb.MainQuery(state,city,start,end)

    # commented above because those things are same
    data,time_index=qobj.get_heatmaptime_data()
    if city=="all":
        filename=create_heatmap_with_time(data,time_index,"state")
    else:
        filename=create_heatmap_with_time(data,time_index,"district")
    with open(filename) as f:
        html_content = f.read()
    return html_content