def gather_swipes(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,liked,lastseen FROM mit.apprecommendation")# WHERE createddate < '2017-08-25 00:00:00' AND createddate > '2017-08-01 00:00:00';")
    data = cur.fetchone()
    swipes = {}

    #Count number of users swiped by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has swiped on 2 other users on day "0", and 4 other users on day "5"
    while data != None:
        swipes = {}
        user = data[0]
        createddate = data[2]
        if swiped != 0:
            date = Date(createddate.month,createddate.day,createddate.year)
            day = get_day(date,days)
            if user in swipes:
                if day in swipes[user]:
                    swipes[user][day] += 1
                else:
                    swipes[user][day] = 1
            else:
                swipes[user] = {}
                swipes[user][day] = 1
        data = cur.fetchone()

    d = Data()
    d.set_data(swipes)
    db = CDB()
    db.set_data(d)
    db.save("swipes.db")
def gather_questions(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,createddate FROM mit.appuserquestion")
    data = cur.fetchone()
    questions = {}
    db = CDB()

    #Count number of questioin answered by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has answered 2 questions on day "0", and 4 questions on day "5"
    while data != None:
        user = data[0]
        date = data[1]
        day = get_day(Date(date.month,date.day,date.year),days)
        if user in questions:
            if day in questions[user]:
                questions[user][day] += 1
            else:
                questions[user][day] = 1
        else:
            questions[user] = {}
            questions[user][day] = 1
        data = cur.fetchone()
    d = Data()
    d.set_data(questions)
    db.set_data(d)
    db.save("questions.db")
def gather_messages(days,con):
    cur = con.cursor()
    cur.execute("SELECT userid,eventdate FROM mit.appmessages WHERE eventdate < '2017-09-26 00:00:00' AND eventdate > '2016-12-06 00:00:00'")#Execute query
    data = cur.fetchone()
    messages = {}
    db = CDB()

    #Count number of messages sent by each user on each day, where a user is a dictioinary of days.
    #e.g. user "1" could look like: "1":{0:2, 5:4}
    #In this example, User 1 has sent 2 messages on day "0", and 4 messages on day "5"
    while data != None:
        user = data[0]
        date = data[1]
        day = get_day(Date(date.month,date.day,date.year),days)
        if user in messages:
            if day in messages[user]:
                messages[user][day] += 1
            else:
                messages[user][day] = 1
        else:
            messages[user] = {}
            messages[user][day] = 1
        data = cur.fetchone()
    d = Data()
    d.set_data(messages)
    db.set_data(d)
    db.save("messages.db")
Esempio n. 4
0
def delete_empty_dicts():
    db = CDB()
    db.load(file_name)
    swipes = db.get_data()
    keys = list(swipes.keys())
    for key in keys:
        if len(swipes[key].keys()) == 0:
            swipes.pop(key)
    d = Data()
    d.set_data(swipes)
    db.set_data(d)
    db.save(file_name)
Esempio n. 5
0
def get_days_over_100(file_name):
    #Function to Remove Data from days before day 100.
    #This function is required because the Message data
    #supplied to us starts 100 days after the swipe and question data.
    db = CDB()
    db.load(file_name)
    swipes = db.get_data()
    keys = swipes.keys()
    for key in keys:
        days = sorted(swipes[key].keys())
        for day in days:
            if int(day) < 100:
                swipes[key].pop(day)
    d = Data()
    d.set_data(swipes)
    db.set_data(d)
    db.save(file_name)