示例#1
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)
示例#2
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)
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")
示例#6
0
    def __init__(self, P):
        super().__init__(P)
        self.SetScrollRate(10, 10)
        self.SetMinSize((500, 300))
        self.SetScrollPos(wx.HORIZONTAL, 0)
        self.SetSize((911, 600))
        F = self.GetFont()
        F.SetPixelSize((0, 18))
        self.SetFont(F)
        self.cdb = CDB()
        self.color_rep = HEX
        self.sort_method = DARKNESS
        self.initData()
        self.Bind(wx.EVT_SIZE, self.resize)
        self.sort()
        self.Scroll(1, 1)
        self.SetTargetRect(wx.Rect((0, 0), self.Size))

        self.SetScrollPos(wx.HORIZONTAL, 0)
        pos = self.GetScrollPos(wx.HORIZONTAL)
        print(f"SCROLL al {pos}")
        self.Refresh()
示例#7
0
class CPane(wx.ScrolledWindow):
    def __init__(self, P):
        super().__init__(P)
        self.SetScrollRate(10, 10)
        self.SetMinSize((500, 300))
        self.SetScrollPos(wx.HORIZONTAL, 0)
        self.SetSize((911, 600))
        F = self.GetFont()
        F.SetPixelSize((0, 18))
        self.SetFont(F)
        self.cdb = CDB()
        self.color_rep = HEX
        self.sort_method = DARKNESS
        self.initData()
        self.Bind(wx.EVT_SIZE, self.resize)
        self.sort()
        self.Scroll(1, 1)
        self.SetTargetRect(wx.Rect((0, 0), self.Size))

        self.SetScrollPos(wx.HORIZONTAL, 0)
        pos = self.GetScrollPos(wx.HORIZONTAL)
        print(f"SCROLL al {pos}")
        self.Refresh()

    def initData(self):
        gz = wx.GridSizer(3, 5, 5)
        cm = self.cdb.colors
        for n, C in cm.items():
            p = wx.Panel(self)
            z = wx.BoxSizer()
            tag = lab(p, n, C, z)
            p.SetSizer(z)
            colorize(p, C)
            gz.Add(p, 1, wx.EXPAND, 10)
            tf = tfin(self, crep(C, self.color_rep), invert(C), gz)
            b = butt(self, f"{n} info", C, gz)
        self.SetSizer(gz)
        self.Scroll(0, -1)
        self.SetTargetRect(wx.Rect((0, 0), self.Size))

    def resize(self, e):
        w, h = self.Size
        print(f"{self.GetName()} Size = {(w,h)}")
        pos = self.GetScrollPos(wx.HORIZONTAL)
        print(f"SCROLL al {pos}")

    def pressed(self, e):
        b = e.GetEventObject()
        C = b.GetBackgroundColour()
        n = self.cdb.FindName(C)
        print(f"{n} button pressed ")

    def sort(self, method=None, rev=0):
        if not method:
            method = self.sort_method
        cm = self.cdb.colors
        cm = ct.sort(cm, method, rev)
        gz = self.GetSizer()
        kids = [c.GetWindow() for c in gz.GetChildren()]
        z = len(kids)
        z3 = z // 3
        Z = z if len(cm) == z3 else min(z, len(cm))
        nn = [n for n in cm.keys()]
        F = self.GetFont()
        for k in kids:
            k.SetFont(F)

        for k in range(0, Z, 3):
            pan = kids[k]
            tag = pan.GetSizer().GetChildren()[0].GetWindow()
            val = kids[k + 1]
            b = kids[k + 2]
            name = nn[k // 3]
            C = cm[name]
            v = ct.crep(C, self.color_rep)
            tag.SetLabelText(name)
            val.SetValue(v)
            b.SetLabelText(f'{name} info')
            colorize(tag, C)
            colorize(pan, C)
            colorize(val, invert(C))
            colorize(b, C, 0)
            colorize(tag, C)

            tag.Refresh()
        self.Refresh()
        self.Update()
示例#8
0
def regularize_combine():
    f = open("hmm_data.txt", "w")

    swipes_db = CDB()
    swipes_db.load("swipes.db")  #Load swipe data

    questions_db = CDB()
    questions_db.load("questions.db")  #load question data

    messages_db = CDB()
    messages_db.load("messages.db")  #load message data

    swipes = swipes_db.get_data(
    )  #Data on the number of other users each user has swiped on each day
    questions = questions_db.get_data(
    )  #Data on the number of questions each user has answered on each day
    messages = messages_db.get_data(
    )  #Data on the number of messages each user has sent on each day

    keys = swipes.keys()
    for key in keys:  #Where key is the userid of a user
        #Begin finding the earliest and latest days in the sequence for a specific user
        earliest_days = [
        ]  #List of earliest days of activity. Will contain days of earliest swipe, earliest question answered, and earliest message sent
        latest_days = [
        ]  #List of latest days of activity. Will contain days of latest swipe, latest question answered, and latest message sent
        key_swipes = swipes[key].keys(
        )  #A list of the days that the user swiped on at least 1 other user

        swipe_days = sorted(swipes[key].keys(
        ))  #Sorted list of days that the user swiped on at least 1 other user
        earliest_days += [
            int(swipe_days[0])
        ]  #Extract earliest day that the user swiped on at least 1 other user and add it to list of earliest days
        latest_days += [
            int(swipe_days[-1])
        ]  #Extract latest day that the user swiped on at least 1 other user and add it to list of latest days

        key_questions = {
        }  #Will be added to later if the user has answered any questions
        key_messages = {
        }  #Will be added to later if the user has sent any messages

        if key in questions:  #Check if the user has answered any questions
            key_questions = questions[key].keys(
            )  #List of days that the user has answered at least one question
            question_days = sorted(questions[key].keys())
            earliest_days += [
                int(question_days[0])
            ]  #Extract earliest day that the user answered at least 1 question and add it to list of earliest days
            latest_days += [
                int(question_days[-1])
            ]  #Extract latest day that the user answered at least 1 question and add it to list of latest days
        if key in messages:  #Check if the user has sent any messages
            key_messages = messages[key].keys(
            )  #List of days that the user has sent at least one message
            messages_days = sorted(messages[key].keys())
            earliest_days += [int(messages_days[0])]
            latest_days += [int(messages_days[-1])]
        earliest = min(
            earliest_days
        )  #Find the earliest day the user has done any of the above activities
        latest = max(
            latest_days
        )  #Find the latest day the user has done any of the above activities

        mess = [
        ]  #Sequence of number of messages sent from earliest day to latest day
        swip = [
        ]  #Sequence of number of users swiped from earliest day to latest day
        quest = [
        ]  #Sequence of number of questions answered from earliest day to latest day

        for i in range(earliest, latest +
                       1):  #Iterate through every day from earliest to latest
            i = str(i)
            if i in key_swipes:
                #Check if the user has swiped any other users on this day
                swip += [swipes[key][i]
                         ]  #if they have, add the number to the sequence
            else:
                #If they haven't, add 0 to the sequence
                swip += [0]
            if i in key_questions:
                quest += [questions[key][i]]
            else:
                quest += [0]
            if i in key_messages:
                mess += [messages[key][i]]
            else:
                mess += [0]

        swip = np.array(swip)
        mess = np.array(mess)
        quest = np.array(quest)

        participation = swip + quest  #Participation is defined as the number of other users swiped plus the number of questions answered

        #normalize participation
        part_mean = np.mean(participation)
        part_stdv = np.std(participation)
        participation = participation - part_mean
        if part_stdv != 0:
            participation = participation / part_stdv

        #Normalize messages
        mess_mean = np.mean(mess)
        mess_stdv = np.std(mess)
        mess = mess - mess_mean
        if mess_stdv != 0:
            mess = mess / mess_stdv

        #Activity is the mean of participation and messages sent
        activity = mess + participation
        activity = activity / 2
        activity = list(activity)

        #Save the sequence to hmm_data.txt
        print(json.dumps(activity), file=f)
    f.close()