コード例 #1
0
ファイル: views.py プロジェクト: ravdawg/liamg
def getjson(request, datatype):
    req = request.REQUEST

    start = req.get('start', None)
    end = req.get('end', None)
    daysofweek = req.get('daysofweek', '')
    reply = req.get('reply', None)
    lat = bool(req.get('lat', False))
    email = req.get('email', None)
    granularity = req.get('granularity', None)

    if start: start = parse(start)
    if end: end = parse(end)
    if daysofweek: daysofweek = daysofweek.split(",")
    if reply is not None: reply = bool(reply)
    

    curruser = User.objects.get(username=request.user)

    #ATTENTION: going to need to change the host once we deploy live
    #conn_string = "host=localhost dbname=liamg user=liamg password=liamg"

    #connect to db to get the data
    #conn = psycopg2.connect(conn_string)
    conn = connection

    #DEPRECATED: for the sqlite prototype database
    #conn = sqlite3.connect(curruser.dbname, detect_types=sqlite3.PARSE_DECLTYPES)


    #get the curruser id so that you can pass it to the functions below
    curridsql = "select id from accounts where user_id = %s"
    c = conn.cursor()
    c.execute(curridsql, (request.user.pk,))
    currid = c.fetchone()[0]



    #get the top people who respond to the user
    if datatype == 'topsenders':
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get ('end', None)
        top = 10       
        email = curruser.username
        data = topsenders.get_top_senders(top, start, end, email, conn)
    
    #get the sent top ten people who the user contacts
    elif datatype == "topsent":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        top = 10 
        email = curruser.username
        data = topsent.get_top_sent(top, start, end, email, conn)

    #get the rate for a specifc user (filtered) and for the general population
    elif datatype == "getrate":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        emailAddy = curruser.username
        replyAddy = req.get('email', None)
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end, emailAddy, replyAddy, conn)


    #use this to get the count in the first graph and maybe the second graph?
    elif datatype == "byhour":
        ebh = RepliesByHour()
        queries = []

        queries.append(('y', ebh.get_sql(lat=lat, reply=reply, start=start, end=end,
                                         daysofweek=daysofweek, email=email, currid = currid)))
        ld = LineData()
        data = ld.get_data(queries, conn)

    #not sure what this does yet?
    elif datatype == "contacts":
        contacts = Contacts()
        data = contacts.get_data(conn)

    #get the second graph that shows the response time
    elif datatype == "getlatency":
        bd = ByDay()
        queries = []
        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end,
                                        granularity=granularity, email=email)))
        ld = BDLineData()

        chartdata, maxval = ld.get_data(queries, conn, 0, granularity=granularity, start=start, end=end)
        data = [chartdata, maxval]

    #use this to get the small graph next to the top ten
    elif datatype == "getcount":
        bd = ByDayNorm()
        queries = []
        
        #get the queries for the line charts in the top ten
        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end, granularity=granularity, email=email, currid=currid)))
        ld = BDLineData()

        chartdata, maxval = ld.get_data(queries, conn, 1, granularity=granularity, start=start, end=end)
        data = [chartdata, maxval]

    else:
        return HttpResponse('json call not recognized')

    # return data as json
    return HttpResponse(json.dumps(data), mimetype="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: melty710/liamg
def getjson(request, datatype):
    req = request.REQUEST

    start = req.get('start', None)
    end = req.get('end', None)
    daysofweek = req.get('daysofweek', '')
    reply = req.get('reply', None)
    lat = bool(req.get('lat', False))
    email = req.get('email', None)
    granularity = req.get('granularity', None)

    if start: start = parse(start)
    if end: end = parse(end)
    if daysofweek: daysofweek = daysofweek.split(",")
    if reply is not None: reply = bool(reply)

    curruser = Userdbs.objects.get(username=request.user)
    print request.user
    print curruser.dbname

    conn = sqlite3.connect(curruser.dbname, detect_types=sqlite3.PARSE_DECLTYPES)

    # db call to get data
    if datatype == 'topsenders':
        
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get ('end', None)
        top = 10       
        data = topsenders.get_top_senders(top, start, end, conn)
    
    elif datatype == "getrate":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        emailAddy = curruser.username
        replyAddy = req.get('replyAddy', None)
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end, emailAddy, replyAddy, conn)

    elif datatype == "byhour":
        ebh = RepliesByHour()
        queries = []
        print "EMAIL", email
        queries.append(('y', ebh.get_sql(lat=lat, reply=reply, start=start, end=end,
                                         daysofweek=daysofweek, email=email)))
        ld = LineData()
        data = ld.get_data(queries, conn)

    elif datatype == "contacts":
        contacts = Contacts()
        data = contacts.get_data(conn)

    elif datatype == "getlatency":
        bd = ByDay()
        queries = []
        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end,
                                        granularity=granularity, email=email)))
        ld = BDLineData()
        data = ld.get_data(queries, conn, 0, granularity=granularity, start=start, end=end)

    elif datatype == "getcount":
        bd = ByDayNorm()
        queries = []
        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end,
                                        granularity=granularity, email=email)))
        ld = BDLineData()
        data = ld.get_data(queries, conn, 1, granularity=granularity, start=start, end=end)

    else:
        return HttpResponse('json call not recognized')

    # return data as json
    return HttpResponse(json.dumps(data), mimetype="application/json")
コード例 #3
0
ファイル: views.py プロジェクト: sirrice/liamg
def getjson(request, datatype):
    req = request.REQUEST

    start = req.get('start', None)
    end = req.get('end', None)
    daysofweek = req.get('daysofweek', '')
    reply = req.get('reply', None)
    lat = bool(req.get('lat', False))
    email = req.get('email', None)
    granularity = req.get('granularity', None)

    if start: start = parse(start)
    if end: end = parse(end)
    if daysofweek: daysofweek = daysofweek.split(",")
    if reply is not None: reply = bool(reply)
    

    curruser = User.objects.get(username=request.user)

    #ATTENTION: going to need to change the host once we deploy live
    #conn_string = "host=localhost dbname=liamg user=liamg password=liamg"

    #connect to db to get the data
    #conn = psycopg2.connect(conn_string)
    conn = connection


    #get the curruser id so that you can pass it to the functions below
    curridsql = "select id from accounts where user_id = %s"
    c = conn.cursor()
    c.execute(curridsql, (request.user.pk,))
    currid = c.fetchone()[0]

###################
#This portion of the code will be to retrieve the graph data for the rec'd tab
###################

    #get the top people who respond to the user
    if datatype == 'topsenders':
        req = request.REQUEST
        start = req.get('start', None)
        print start
        end = req.get ('end', None)
        top = 10       
        email = curruser.username
        data = topsenders.get_top_senders(top, start, end, email, conn)

    #use this to get the mini graph next to the top ten that displays count
    elif datatype == "getcount":
        #called from timeline.py
        bd = ByDayNorm()
        queries = []
        
        #get the queries for the line charts in the top ten
        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end, granularity=granularity, email=email, currid=currid)))
        ld = BDLineData()
        chartdata, maxval = ld.get_data(queries, conn, 1, granularity=granularity, start=start, end=end)
        data = [chartdata, maxval]

    #get the rate for a specifc user (filtered) and for the general population
    elif datatype == "getrate":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        emailAddy = curruser.username
        replyAddy = req.get('email', 'ALL')
        #if there is an empty email string, then set the replyAddy to ALL - this
        #will filter for the entire database
        if replyAddy == "":
            replyAddy = 'ALL'
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end, emailAddy, replyAddy, conn)

    #use this to get the count in the first graph for the rec'd tab
    elif datatype == "byhour":
        #called from statsbyhour.py
        ebh = RepliesByHour()
        queries = []
        queries.append(('y', ebh.get_sql(lat=lat, reply=reply, start=start, end=end,
                                         daysofweek=daysofweek, email=email, currid = currid)))
        ld = LineData()
        data = ld.get_data(queries, conn)
    
    #Update: WHAT DOES THIS DO?
#    elif datatype == "contacts":
#        contacts = Contacts()
#        data = contacts.get_data(conn)

    #Update: NOT SURE WHAT THIS DOES?
#    elif datatype == "getlatency":
#        bd = ByDay()
#        queries = []
#        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end,
#                                        granularity=granularity, email=email)))
#        ld = BDLineData()

#        chartdata, maxval = ld.get_data(queries, conn, 0, granularity=granularity, start=start, end=end)
#        data = [chartdata, maxval]

 
########################
#This portion of the code will be for the sent tab
########################

    #get the sent top ten people who the user contacts
    elif datatype == "topsent":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        top = 10 
        email = curruser.username
        data = topsent.get_top_sent(top, start, end, email, conn)

   #TODO: use this to get the mini charts for the sent tab
    elif datatype == "countmini":
        print 'hello' #enter code here
    
    #Use this to get the count of emails that a person sends to others
    elif datatype == "countsent":
        queries = []
        user = curruser.username
        
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        to_email = req.get('email', None)
        queries.append(('y',sent_tab.get_count_sent_sql(start, end, user, to_email, conn)))
        ld = LineData()
        data = ld.get_data(queries, conn)

    #TODO: use this to get the delay between when user responds to emails that others send to them
    elif datatype == "delay_sent":
        print 'hello'#enter code here that gets the delay
    
    elif datatype == "rate_sent":
        #WIP: working on the connection to the already made algorithm for determining rate
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        replyAddy = curruser.username
        emailAddy = req.get('email', 'ALL')
        #if there is an empty email string, then set the replyAddy to ALL - this
        #will filter for the entire database
        if emailAddy == "":
            emailAddy = 'ALL'
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end, emailAddy, replyAddy, conn)

    else:
        return HttpResponse('json call not recognized')

    # return data as json
    return HttpResponse(json.dumps(data), mimetype="application/json")
コード例 #4
0
def getjson(request, datatype):
    req = request.REQUEST

    start = req.get('start', None)
    end = req.get('end', None)
    daysofweek = req.get('daysofweek', '')
    reply = req.get('reply', None)
    lat = bool(req.get('lat', False))
    email = req.get('email', None)
    granularity = req.get('granularity', None)

    if start: start = parse(start)
    if end: end = parse(end)
    if daysofweek: daysofweek = daysofweek.split(",")
    if reply is not None: reply = bool(reply)

    curruser = User.objects.get(username=request.user)

    #ATTENTION: going to need to change the host once we deploy live
    #conn_string = "host=localhost dbname=liamg user=liamg password=liamg"

    #connect to db to get the data
    #conn = psycopg2.connect(conn_string)
    conn = connection

    #get the curruser id so that you can pass it to the functions below
    curridsql = "select id from accounts where user_id = %s"
    c = conn.cursor()
    c.execute(curridsql, (request.user.pk, ))
    currid = c.fetchone()[0]

    ###################
    #This portion of the code will be to retrieve the graph data for the rec'd tab
    ###################

    #get the top people who respond to the user
    if datatype == 'topsenders':
        req = request.REQUEST
        start = req.get('start', None)
        print start
        end = req.get('end', None)
        top = 10
        email = curruser.username
        data = topsenders.get_top_senders(top, start, end, email, conn)

    #use this to get the mini graph next to the top ten that displays count
    elif datatype == "getcount":
        #called from timeline.py
        bd = ByDayNorm()
        queries = []

        #get the queries for the line charts in the top ten
        queries.append(('y',
                        bd.get_sql(lat=lat,
                                   reply=reply,
                                   start=start,
                                   end=end,
                                   granularity=granularity,
                                   email=email,
                                   currid=currid)))
        ld = BDLineData()
        chartdata, maxval = ld.get_data(queries,
                                        conn,
                                        1,
                                        granularity=granularity,
                                        start=start,
                                        end=end)
        data = [chartdata, maxval]

    #get the rate for a specifc user (filtered) and for the general population
    elif datatype == "getrate":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        emailAddy = curruser.username
        replyAddy = req.get('email', 'ALL')
        #if there is an empty email string, then set the replyAddy to ALL - this
        #will filter for the entire database
        if replyAddy == "":
            replyAddy = 'ALL'
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end,
                                                    emailAddy, replyAddy, conn)

    #use this to get the count in the first graph for the rec'd tab
    elif datatype == "byhour":
        #called from statsbyhour.py
        ebh = RepliesByHour()
        queries = []
        queries.append(('y',
                        ebh.get_sql(lat=lat,
                                    reply=reply,
                                    start=start,
                                    end=end,
                                    daysofweek=daysofweek,
                                    email=email,
                                    currid=currid)))
        ld = LineData()
        data = ld.get_data(queries, conn)

    #Update: WHAT DOES THIS DO?
#    elif datatype == "contacts":
#        contacts = Contacts()
#        data = contacts.get_data(conn)

#Update: NOT SURE WHAT THIS DOES?
#    elif datatype == "getlatency":
#        bd = ByDay()
#        queries = []
#        queries.append(('y', bd.get_sql(lat=lat, reply=reply, start=start, end=end,
#                                        granularity=granularity, email=email)))
#        ld = BDLineData()

#        chartdata, maxval = ld.get_data(queries, conn, 0, granularity=granularity, start=start, end=end)
#        data = [chartdata, maxval]

########################
#This portion of the code will be for the sent tab
########################

#get the sent top ten people who the user contacts
    elif datatype == "topsent":
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        top = 10
        email = curruser.username
        data = topsent.get_top_sent(top, start, end, email, conn)

#TODO: use this to get the mini charts for the sent tab
    elif datatype == "countmini":
        print 'hello'  #enter code here

    #Use this to get the count of emails that a person sends to others
    elif datatype == "countsent":
        queries = []
        user = curruser.username

        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        to_email = req.get('email', None)
        queries.append(
            ('y', sent_tab.get_count_sent_sql(start, end, user, to_email,
                                              conn)))
        ld = LineData()
        data = ld.get_data(queries, conn)

    #TODO: use this to get the delay between when user responds to emails that others send to them
    elif datatype == "delay_sent":
        print 'hello'  #enter code here that gets the delay

    elif datatype == "rate_sent":
        #WIP: working on the connection to the already made algorithm for determining rate
        req = request.REQUEST
        start = req.get('start', None)
        end = req.get('end', None)
        replyAddy = curruser.username
        emailAddy = req.get('email', 'ALL')
        #if there is an empty email string, then set the replyAddy to ALL - this
        #will filter for the entire database
        if emailAddy == "":
            emailAddy = 'ALL'
        mode = req.get('mode', None)
        data = responseRateByTime.get_response_rate(mode, start, end,
                                                    emailAddy, replyAddy, conn)

    else:
        return HttpResponse('json call not recognized')

    # return data as json
    return HttpResponse(json.dumps(data), mimetype="application/json")