def test_get_list_workSession_amount_details(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 10:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2013-12-28 11:15:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        result_list_work_sessions = Data_processing.get_list_work_sessions(datetime_from,datetime_to,options_reason,50,self.link_to_main)

        result_list = Data_processing.get_list_workSession_amount_details(result_list_work_sessions,options_reason)

        #print result_list
        # total
        self.assertEqual(result_list[0][2],1978)
        self.assertEqual(result_list[1][2],900)
        self.assertEqual(result_list[2][2],1620)

        # amount
        self.assertEqual(result_list[0][3],4)
        self.assertEqual(result_list[1][3],2)
        self.assertEqual(result_list[2][3],2)

        # average
        self.assertEqual(result_list[0][4],494)
        self.assertEqual(result_list[1][4],450)
        self.assertEqual(result_list[2][4],810)

        # min
        self.assertEqual(result_list[0][5],179)
        self.assertEqual(result_list[1][5],300)
        self.assertEqual(result_list[2][5],720)

        # max
        self.assertEqual(result_list[0][6],1319)
        self.assertEqual(result_list[1][6],600)
        self.assertEqual(result_list[2][6],900)
def show_results(datetime_from, datetime_to,options_reason_with_screen_attribute,treshold_important_unimportant):
    options_reason = Data_processing.remove_screen_attribute(options_reason_with_screen_attribute)
    result_css = '<style media="screen" type="text/css">' + "\n"
    result_css += '\t' + 'table, td,th {' + '\n'
    result_css += '\t' + '\t' + 'border: 1px solid black; margin: 2px;border-collapse:collapse;padding: 5px;' + '\n'
    result_css += '\t' + '}' + '\n'
    result_css += '\t' + 'div {' + '\n'
    result_css += '\t' + '\t' + 'margin: 20px;'
    result_css += '\t' + '}'
    result_css += '</style>'


    important_activities = Data_processing.getListImportantActivities_V2_buckets(datetime_from,datetime_to,options_reason,'')
    unimportant_activities = Data_processing.getListUnimportantActivities_V2_buckets(datetime_from,datetime_to,'')

    darescuetime = DARescueTime_SQLite.RescueTime('')
    list_subjects = darescuetime.get_subject_period(datetime_from,datetime_to)

    result_html = "<!DOCTYPE html>" + "\n"
    result_html += "<html>" + "\n"
    result_html += "<head>" + "\n"
    result_html += "\t" + "<title>Results session</title>" + "\n"
    result_html += result_css
    result_html += "</head>" + "\n"
    result_html += "<body>" + "\n"

    # Tabel per activiteit
    result_html = add_table_per_activity_with_subjects(result_html, important_activities, unimportant_activities,list_subjects)



# Tabel per activitiet, hoeveel afgeleid, notities, ...
    result_html = add_table_userGone(datetime_from, datetime_to, options_reason, result_html, important_activities)

#Add table per activiteit user gone
    result_html = add_table_per_activiteit_userGone(options_reason, result_html, important_activities)

#tabel worksessies min max avg ...
    result_html = add_table_workSession_gem_min_max(datetime_from,datetime_to,options_reason,treshold_important_unimportant,result_html)
# tabel worksessies
    result_html = add_table_workSession(datetime_from,datetime_to,options_reason,treshold_important_unimportant,result_html)

    result_html += "<h2>Some additional information:</h2>"

    result_html += '<p>' + 'average eyes detected = ' + percentage_layout(User_gone_processing.get_eyes_detected_specific_period(datetime_from,datetime_to)) + '</p>' + '\n'
    try:
        avg_concentration_userfeedback = Userfeedback_processing.get_average_userfeedback_specific_period(datetime_from, datetime_to)
    except Exception.ListEmpty, e:
        avg_concentration_userfeedback = -1
    def test_create_list_important_activities(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2014-02-20 10:10:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        #output.show_results(datetime_from,datetime_to,options_reason,15)
        listImportantActivities = Data_processing.getListImportantActivities(
            datetime_from, datetime_to, options_reason, self.link_to_main)
        """
        print "================="
        print listImportantActivities
        print "================="
        """

        self.assertEqual(listImportantActivities[0][0], 'A')
        self.assertEqual(listImportantActivities[0][1], 1290)
        self.assertEqual(round(listImportantActivities[0][2], 2), 0.46)
        #Attention + Meditation
        self.assertEqual(round(listImportantActivities[0][5], 2), -1)
        self.assertEqual(round(listImportantActivities[0][6], 2), -1)

        self.assertEqual(listImportantActivities[1][0], 'B')
        self.assertEqual(listImportantActivities[1][1], 305)
        self.assertEqual(round(listImportantActivities[1][2], 2), 0.85)

        #Attention + Meditation
        self.assertEqual(round(listImportantActivities[1][5], 2), -1)
        self.assertEqual(round(listImportantActivities[1][6], 2), -1)
    def test_create_list_unimportant_activities(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2014-02-20 10:10:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]

        #presentation_tier.show_results(datetime_from,datetime_to,options_reason,15)
        listUnImportantActivities = Data_processing.getListUnimportantActivities(
            datetime_from, datetime_to, self.link_to_main)
        """
        print "================="
        print listUnImportantActivities
        print "================="
        """
        self.assertEqual(listUnImportantActivities[0][0], 'D')
        self.assertEqual(listUnImportantActivities[0][1], 305)
        #Attention + Meditation
        self.assertEqual(round(listUnImportantActivities[0][2], 2), 0.69)
        self.assertEqual(round(listUnImportantActivities[0][3], 2), 0.53)

        self.assertEqual(listUnImportantActivities[1][0], 'E')
        self.assertEqual(listUnImportantActivities[1][1], 200)
        #Attention + Meditation
        self.assertEqual(round(listUnImportantActivities[1][2], 2), 0.28)
        self.assertEqual(round(listUnImportantActivities[1][3], 2), 0.88)
    def test_create_list_important_activities(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2014-02-20 10:10:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        #output.show_results(datetime_from,datetime_to,options_reason,15)
        listImportantActivities = Data_processing.getListImportantActivities(datetime_from,datetime_to,options_reason,self.link_to_main)

        """
        print "================="
        print listImportantActivities
        print "================="
        """

        self.assertEqual(listImportantActivities[0][0],'A')
        self.assertEqual(listImportantActivities[0][1],1290)
        self.assertEqual(round(listImportantActivities[0][2],2),0.46)
        #Attention + Meditation
        self.assertEqual(round(listImportantActivities[0][5],2),-1)
        self.assertEqual(round(listImportantActivities[0][6],2),-1)

        self.assertEqual(listImportantActivities[1][0],'B')
        self.assertEqual(listImportantActivities[1][1],305)
        self.assertEqual(round(listImportantActivities[1][2],2),0.85)

        #Attention + Meditation
        self.assertEqual(round(listImportantActivities[1][5],2),-1)
        self.assertEqual(round(listImportantActivities[1][6],2),-1)
    def test_getListImportantActivities(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2013-12-28 08:30:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        result = Data_processing.getListImportantActivities(
            datetime_from, datetime_to, options_reason, self.link_to_main)
        """
        string_result = ""
        for line in result:
            for item in line:
                string_result += str(item) + "\t"
            string_result += "\n"
        print string_result
        """
        # afgeleid attribute
        self.assertEqual(result[0][4][0][1], 0.25)
        self.assertEqual(result[1][4][0][1], 0.55)
        self.assertEqual(result[2][4][0][1], 0.50)

        # notities attribute, A
        self.assertEqual(result[0][4][1][1], 0.20)

        # notities attribute, B
        self.assertEqual(result[1][4][1][1], 0.10)

        # Mindwave
        # A
        self.assertEqual(round(result[0][5], 2), 0.55)
    def test_getListImportantActivities(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2013-12-28 08:30:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        result = Data_processing.getListImportantActivities(datetime_from,datetime_to,options_reason,self.link_to_main)
        """
        string_result = ""
        for line in result:
            for item in line:
                string_result += str(item) + "\t"
            string_result += "\n"
        print string_result
        """
        # afgeleid attribute
        self.assertEqual(result[0][4][0][1],0.25)
        self.assertEqual(result[1][4][0][1],0.55)
        self.assertEqual(result[2][4][0][1],0.50)

        # notities attribute, A
        self.assertEqual(result[0][4][1][1],0.20)

        # notities attribute, B
        self.assertEqual(result[1][4][1][1],0.10)

        # Mindwave
        # A
        self.assertEqual(round(result[0][5],2),0.55)
    def test_list_userGone(self):
        options_reason_with_screen_attribute = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        options_reason = Data_processing.remove_screen_attribute(options_reason_with_screen_attribute)
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2013-12-28 08:30:00","%Y-%m-%d %H:%M:%S")

         # [reason,  totaal, gemiddeld, minimaal, maximaal]
        list_userGone = User_gone_processing.get_list_userGone(datetime_from,datetime_to,options_reason)
        print '---------'
        print list_userGone
        print '---------'

        #afgeleid attribuut
        self.assertEqual(list_userGone[0][1],1380)
        self.assertEqual(list_userGone[0][2],345)
        self.assertEqual(list_userGone[0][3],120)
        self.assertEqual(list_userGone[0][4],720)

        #notities attribuut
        self.assertEqual(list_userGone[1][1],240)
        self.assertEqual(list_userGone[1][2],120)
        self.assertEqual(list_userGone[1][3],120)
        self.assertEqual(list_userGone[1][4],120)

        #pauze attribuut
        self.assertEqual(list_userGone[2][1],0)
        self.assertEqual(list_userGone[2][2],0)
        self.assertEqual(list_userGone[2][3],0)
        self.assertEqual(list_userGone[2][4],0)
def add_table_workSession(datetime_from, datetime_to, options_reason,treshold_important_unimportant, result_html):
    try:
        # Tabel afgeleid, notities, ...
        list_worksessions = Data_processing.get_list_work_sessions(datetime_from, datetime_to, options_reason,treshold_important_unimportant,'')
        result_html += "<div id=\"work_session\">" + "\n"
        result_html += "<h2>This table shows an overview of your work sessions:</h2>"

        result_html += "<table>"
        result_html += "\t" + "<tr>" + "\n"
        result_html += "\t" + "\t" + "<th>From</th>" + "\n"
        result_html += "\t" + "\t" + "<th>To</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Reason</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Studying</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Time seconds</th>" + "\n"
        result_html += "\t" + "</tr>" + "\n"
        for item in list_worksessions:
            result_html += "\t" + "<tr>" + "\n"
            result_html += "\t" + "\t" + "<td>" + str(item[0].strftime("%Y-%m-%d %H:%M:%S")) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + str(item[1].strftime("%Y-%m-%d %H:%M:%S")) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + str(item[2]) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + str(item[3]) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + calculate_time_str(int(item[4])) + "</td>" + "\n"

            result_html += "\t" + "</tr>" + "\n"
        result_html += "</table>" + "\n"
        result_html += "</div>" + "\n"
    except Exception.ListEmpty, e:
        result_html += "<p>" + str(e) + "</p>"
    def test_list_work_session(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 10:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2013-12-28 11:15:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        result_list = Data_processing.get_list_work_sessions(datetime_from,datetime_to,options_reason,50,self.link_to_main)

        #presentation_tier.show_results(datetime_from,datetime_to,options_reason)
        print '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'
        print result_list
        print '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'

        # rij 0
        self.assertEqual(result_list[0][0],datetime.datetime(2013, 12, 28, 10, 0))
        self.assertEqual(result_list[0][1],datetime.datetime(2013, 12, 28, 10, 05))
        self.assertEqual(result_list[0][3],True)

        # rij 1
        self.assertEqual(result_list[1][0],datetime.datetime(2013, 12, 28, 10, 05))
        self.assertEqual(result_list[1][1],datetime.datetime(2013, 12, 28, 10, 10))
        self.assertEqual(result_list[1][3],False)

        # rij 2
        self.assertEqual(result_list[2][0],datetime.datetime(2013, 12, 28, 10, 10))
        self.assertEqual(result_list[2][1],datetime.datetime(2013, 12, 28, 10, 13,0,502000))
        self.assertEqual(result_list[2][3],True)

        # rij 3
        self.assertEqual(result_list[3][0],datetime.datetime(2013, 12, 28, 10, 13,0,502000))
        self.assertEqual(result_list[3][1],datetime.datetime(2013, 12, 28, 10, 28,0,502000))
        self.assertEqual(result_list[3][3],False)

        # rij 4
        self.assertEqual(result_list[4][0],datetime.datetime(2013, 12, 28, 10, 28,0,502000))
        self.assertEqual(result_list[4][1],datetime.datetime(2013, 12, 28, 10, 35,0,502000))
        self.assertEqual(result_list[4][3],True)

        # rij 5
        self.assertEqual(result_list[5][0],datetime.datetime(2013, 12, 28, 10, 35,0,502000))
        self.assertEqual(result_list[5][1],datetime.datetime(2013, 12, 28, 10, 43,0,502000))
        self.assertEqual(result_list[5][3],True)

        # rij 6
        self.assertEqual(result_list[6][0],datetime.datetime(2013, 12, 28, 10, 43,0,502000))
        self.assertEqual(result_list[6][1],datetime.datetime(2013, 12, 28, 10, 50))
        self.assertEqual(result_list[6][3],True)

        # rij 7
        self.assertEqual(result_list[7][0],datetime.datetime(2013, 12, 28, 10, 50))
        self.assertEqual(result_list[7][1],datetime.datetime(2013, 12, 28, 11, 00,0,502000))
        self.assertEqual(result_list[7][3],False)

        # rij 8
        self.assertEqual(result_list[8][0],datetime.datetime(2013, 12, 28, 11, 00,0,502000))
        self.assertEqual(result_list[8][1],datetime.datetime(2013, 12, 28, 11, 12,0,502000))
        self.assertEqual(result_list[8][3],False)

        # rij 9
        self.assertEqual(result_list[9][0],datetime.datetime(2013, 12, 28, 11, 12,0,502000))
        self.assertEqual(result_list[9][1],datetime.datetime(2013, 12, 28, 11, 15))
        self.assertEqual(result_list[9][3],True)
    def test_show_results(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2013-12-28 08:30:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        #presentation_tier.show_results(datetime_from,datetime_to,options_reason,15)
        #presentation_tier.showgraph(datetime_from,datetime_to,options_reason)

        result_list_work_sessions = Data_processing.get_list_work_sessions(datetime_from,datetime_to,options_reason,50,self.link_to_main)
    def test_show_results(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2013-12-28 08:30:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        #presentation_tier.show_results(datetime_from,datetime_to,options_reason,15)
        #presentation_tier.showgraph(datetime_from,datetime_to,options_reason)

        result_list_work_sessions = Data_processing.get_list_work_sessions(
            datetime_from, datetime_to, options_reason, 50, self.link_to_main)
    def test_get_list_workSession_amount_details(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 10:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2013-12-28 11:15:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        result_list_work_sessions = Data_processing.get_list_work_sessions(
            datetime_from, datetime_to, options_reason, 50, self.link_to_main)

        result_list = Data_processing.get_list_workSession_amount_details(
            result_list_work_sessions, options_reason)

        #print result_list
        # total
        self.assertEqual(result_list[0][2], 1978)
        self.assertEqual(result_list[1][2], 900)
        self.assertEqual(result_list[2][2], 1620)

        # amount
        self.assertEqual(result_list[0][3], 4)
        self.assertEqual(result_list[1][3], 2)
        self.assertEqual(result_list[2][3], 2)

        # average
        self.assertEqual(result_list[0][4], 494)
        self.assertEqual(result_list[1][4], 450)
        self.assertEqual(result_list[2][4], 810)

        # min
        self.assertEqual(result_list[0][5], 179)
        self.assertEqual(result_list[1][5], 300)
        self.assertEqual(result_list[2][5], 720)

        # max
        self.assertEqual(result_list[0][6], 1319)
        self.assertEqual(result_list[1][6], 600)
        self.assertEqual(result_list[2][6], 900)
    def test_calculate_average_mindwave_3(self):
        list_mindwave_data = []
        list_mindwave_data.append([0,"2014-02-20 09:02:00","2014-02-20 09:06:00",0.2,0.8])
        list_mindwave_data.append([0,"2014-02-20 09:06:00","2014-02-20 09:10:00",0.4,0.6])
        list_mindwave_data.append([0,"2014-02-20 09:10:00","2014-02-20 09:14:00",0.6,0.4])

        start_datetime_activitydetail = datetime.datetime.strptime("2014-02-20 09:00:00","%Y-%m-%d %H:%M:%S")
        end_datetime_activitydetail = datetime.datetime.strptime("2014-02-20 09:05:00","%Y-%m-%d %H:%M:%S")

        attention_avg, meditation_avg = Data_processing.calculate_average_mindwave(start_datetime_activitydetail,end_datetime_activitydetail,list_mindwave_data)

        self.assertEqual(round(attention_avg,2),0.20)
        self.assertEqual(round(meditation_avg,2),0.80)
def add_table_workSession_gem_min_max(datetime_from, datetime_to, options_reason,treshold_important_unimportant, result_html):

    # Tabel afgeleid, notities, ...
    try:
        list_worksessions = Data_processing.get_list_work_sessions(datetime_from, datetime_to, options_reason,treshold_important_unimportant,'')

        # [isStudying, reason, total, amount, avg, min, max]
        list_worksessions_avg_min_max = Data_processing.get_list_workSession_amount_details(list_worksessions,options_reason)

        result_html += "<div id=\"work_session\">" + "\n"
        result_html += "<h2>This table gives information about your work sessions:</h2>"

        result_html += "<table>"
        result_html += "\t" + "<tr>" + "\n"
        result_html += "\t" + "\t" + "<th></th>" + "\n"
        result_html += "\t" + "\t" + "<th>Total</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Amount</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Average duration</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Minimal duration</th>" + "\n"
        result_html += "\t" + "\t" + "<th>Maximal duration</th>" + "\n"
        result_html += "\t" + "</tr>" + "\n"

        for item in list_worksessions_avg_min_max:
            result_html += "\t" + "<tr>" + "\n"
            result_html += "\t" + "\t" + "<th>" + str(item[1]) + "</th>" + "\n"
            result_html += "\t" + "\t" + "<td>" + calculate_time_str(int(item[2])) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + str(item[3]) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + calculate_time_str(int(item[4])) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + calculate_time_str(int(item[5])) + "</td>" + "\n"
            result_html += "\t" + "\t" + "<td>" + calculate_time_str(int(item[6])) + "</td>" + "\n"

            result_html += "\t" + "</tr>" + "\n"
        result_html += "</table>" + "\n"
        result_html += "</div>" + "\n"

    except  Exception.ListEmpty, e:
        result_html += "<p>" + str(e) + "</p>" + "\n"
    def show_barchart_important_activity_details(self,date_time_from, date_time_to,options_reason):
        result_list = Data_processing.getListImportantActivities(date_time_from,date_time_to,options_reason)
        list_time = []
        list_eyes_detected =[]
        list_user_feedback = []
        list_attention_mindwave = []
        list_meditation_mindwave = []
        total_time = 0.0

        for item in result_list:
            total_time += item[1]

        x = []
        for item in result_list:
            # item = [activity, time_sec, avg_concentration_user, avg_eyes_detected, [userGone],avg_attention_mindwave, avg_meditation_mindwave]
            list_time.append(round((float(item[1]) / total_time * 100.0),0))
            list_user_feedback.append(round(item[2] * 100,0))
            list_eyes_detected.append(round(item[3] * 100,0))
            list_attention_mindwave.append(round(item[5] * 100,0))
            list_meditation_mindwave.append(round(item[6] * 100,0))
            x.append(item[0])

        N = len(result_list)

        ind = np.arange(N)  # the x locations for the groups
        width = 0.15       # the width of the bars

        fig, ax = plt.subplots()
        rects1 = ax.bar(ind, list_time, width, color='c')
        rects2 = ax.bar(ind + width, list_user_feedback, width, color='g')
        rects3 = ax.bar(ind + (2.0 * width), list_eyes_detected, width, color='b')
        rects4 = ax.bar(ind + (3.0 * width), list_attention_mindwave, width, color='r')
        rects5 = ax.bar(ind + (4.0 * width), list_meditation_mindwave, width, color='y')

        # add some
        ax.set_ylabel('percentage')
        ax.set_title('Attention + Meditation')
        ax.set_xticks(ind+width)
        ax.set_xticklabels( x )

        ax.legend( (rects1[0], rects2[0],rects3[0],rects4[0],rects5[0]), ('Relative time spent', 'Average user indicated concentration','Average eyes detected', 'Average attention mindwave','Average meditation mindwave') )
        self.autolabel(rects1,ax)
        self.autolabel(rects2,ax)
        self.autolabel(rects3,ax)
        self.autolabel(rects4,ax)
        self.autolabel(rects5,ax)
    def test_getListUnimportantActivities(self):
        datetime_from = datetime.datetime.strptime("2014-02-13 20:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2014-02-13 20:30:00","%Y-%m-%d %H:%M:%S")
        result = Data_processing.getListUnimportantActivities(datetime_from,datetime_to,self.link_to_main)
        """
        print '---------------------'
        print result
        print '---------------------'
        """
        # D
        self.assertEqual(result[0][0],'D')
        self.assertEqual(result[0][1],800)
        self.assertEqual(round(result[0][2],2),0.50)
        self.assertEqual(round(result[0][3],3),0.425)

        # E
        self.assertEqual(result[1][0],'E')
        self.assertEqual(result[1][1],200)
        self.assertEqual(round(result[1][2],2),0.70)
        self.assertEqual(round(result[1][3],2),0.25)
    def test_calculate_average_mindwave_3(self):
        list_mindwave_data = []
        list_mindwave_data.append(
            [0, "2014-02-20 09:02:00", "2014-02-20 09:06:00", 0.2, 0.8])
        list_mindwave_data.append(
            [0, "2014-02-20 09:06:00", "2014-02-20 09:10:00", 0.4, 0.6])
        list_mindwave_data.append(
            [0, "2014-02-20 09:10:00", "2014-02-20 09:14:00", 0.6, 0.4])

        start_datetime_activitydetail = datetime.datetime.strptime(
            "2014-02-20 09:00:00", "%Y-%m-%d %H:%M:%S")
        end_datetime_activitydetail = datetime.datetime.strptime(
            "2014-02-20 09:05:00", "%Y-%m-%d %H:%M:%S")

        attention_avg, meditation_avg = Data_processing.calculate_average_mindwave(
            start_datetime_activitydetail, end_datetime_activitydetail,
            list_mindwave_data)

        self.assertEqual(round(attention_avg, 2), 0.20)
        self.assertEqual(round(meditation_avg, 2), 0.80)
    def test_create_list_unimportant_activities(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2014-02-20 10:10:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]

        #presentation_tier.show_results(datetime_from,datetime_to,options_reason,15)
        listUnImportantActivities = Data_processing.getListUnimportantActivities(datetime_from,datetime_to,self.link_to_main)
        """
        print "================="
        print listUnImportantActivities
        print "================="
        """
        self.assertEqual(listUnImportantActivities[0][0],'D')
        self.assertEqual(listUnImportantActivities[0][1],305)
        #Attention + Meditation
        self.assertEqual(round(listUnImportantActivities[0][2],2),0.69)
        self.assertEqual(round(listUnImportantActivities[0][3],2),0.53)

        self.assertEqual(listUnImportantActivities[1][0],'E')
        self.assertEqual(listUnImportantActivities[1][1],200)
        #Attention + Meditation
        self.assertEqual(round(listUnImportantActivities[1][2],2),0.28)
        self.assertEqual(round(listUnImportantActivities[1][3],2),0.88)
    def test_getListUnimportantActivities(self):
        datetime_from = datetime.datetime.strptime("2014-02-13 20:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2014-02-13 20:30:00",
                                                 "%Y-%m-%d %H:%M:%S")
        result = Data_processing.getListUnimportantActivities(
            datetime_from, datetime_to, self.link_to_main)
        """
        print '---------------------'
        print result
        print '---------------------'
        """
        # D
        self.assertEqual(result[0][0], 'D')
        self.assertEqual(result[0][1], 800)
        self.assertEqual(round(result[0][2], 2), 0.50)
        self.assertEqual(round(result[0][3], 3), 0.425)

        # E
        self.assertEqual(result[1][0], 'E')
        self.assertEqual(result[1][1], 200)
        self.assertEqual(round(result[1][2], 2), 0.70)
        self.assertEqual(round(result[1][3], 2), 0.25)
Пример #21
0
    def test_list_userGone(self):
        options_reason_with_screen_attribute = [["afgeleid", "afgeleid", 0],
                                                ["notities", "notities", 1],
                                                ["screen", "screen", 1],
                                                ["pauze", "pauze", 0]]
        options_reason = Data_processing.remove_screen_attribute(
            options_reason_with_screen_attribute)
        datetime_from = datetime.datetime.strptime("2013-12-28 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2013-12-28 08:30:00",
                                                 "%Y-%m-%d %H:%M:%S")

        # [reason,  totaal, gemiddeld, minimaal, maximaal]
        list_userGone = User_gone_processing.get_list_userGone(
            datetime_from, datetime_to, options_reason)
        print '---------'
        print list_userGone
        print '---------'

        #afgeleid attribuut
        self.assertEqual(list_userGone[0][1], 1380)
        self.assertEqual(list_userGone[0][2], 345)
        self.assertEqual(list_userGone[0][3], 120)
        self.assertEqual(list_userGone[0][4], 720)

        #notities attribuut
        self.assertEqual(list_userGone[1][1], 240)
        self.assertEqual(list_userGone[1][2], 120)
        self.assertEqual(list_userGone[1][3], 120)
        self.assertEqual(list_userGone[1][4], 120)

        #pauze attribuut
        self.assertEqual(list_userGone[2][1], 0)
        self.assertEqual(list_userGone[2][2], 0)
        self.assertEqual(list_userGone[2][3], 0)
        self.assertEqual(list_userGone[2][4], 0)
    def test_worksessions(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2014-02-20 10:10:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        list_worksessions = Data_processing.get_list_work_sessions(
            datetime_from, datetime_to, options_reason, 10, self.link_to_main)
        print '=+=+=+=+=+=+=+=+=+=+=+=+=+='
        print list_worksessions
        print '=+=+=+=+=+=+=+=+=+=+=+=+=+='

        self.assertEqual(list_worksessions[0][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:00:00")
        self.assertEqual(list_worksessions[0][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:05:00")
        #self.assertEqual(list_worksessions[0][2],'studying')
        self.assertEqual(list_worksessions[0][3], False)
        self.assertEqual(list_worksessions[0][4], 300)

        self.assertEqual(list_worksessions[1][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:05:00")
        self.assertEqual(list_worksessions[1][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:08:00")
        #self.assertEqual(list_worksessions[1][2],'studying')
        self.assertEqual(list_worksessions[1][3], True)
        self.assertEqual(list_worksessions[1][4], 180)

        self.assertEqual(list_worksessions[2][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:08:00")
        self.assertEqual(list_worksessions[2][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:30:00")
        self.assertEqual(list_worksessions[2][2], 'break')
        self.assertEqual(list_worksessions[2][3], False)
        self.assertEqual(list_worksessions[2][4], 1320)

        self.assertEqual(list_worksessions[3][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 08:30:00")
        self.assertEqual(list_worksessions[3][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:00:00")
        self.assertEqual(list_worksessions[3][2], 'no tracking info')
        self.assertEqual(list_worksessions[3][3], False)
        self.assertEqual(list_worksessions[3][4], 1799)

        self.assertEqual(list_worksessions[4][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:00:00")
        self.assertEqual(list_worksessions[4][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:05:00")
        #self.assertEqual(list_worksessions[4][2],'studying')
        self.assertEqual(list_worksessions[4][3], True)
        self.assertEqual(list_worksessions[4][4], 300)

        self.assertEqual(list_worksessions[5][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:05:00")
        self.assertEqual(list_worksessions[5][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:10:00")
        #self.assertEqual(list_worksessions[5][2],'studying')
        self.assertEqual(list_worksessions[5][3], False)
        self.assertEqual(list_worksessions[5][4], 300)

        self.assertEqual(list_worksessions[6][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:10:00")
        self.assertEqual(list_worksessions[6][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:16:00")
        #self.assertEqual(list_worksessions[6][2],'notes')
        self.assertEqual(list_worksessions[6][3], True)
        self.assertEqual(list_worksessions[6][4], 360)

        self.assertEqual(list_worksessions[7][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:16:00")
        self.assertEqual(list_worksessions[7][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:18:00")
        self.assertEqual(list_worksessions[7][2], 'notes')
        self.assertEqual(list_worksessions[7][3], True)
        self.assertEqual(list_worksessions[7][4], 120)

        self.assertEqual(list_worksessions[8][0].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:18:00")
        self.assertEqual(list_worksessions[8][1].strftime("%Y-%m-%d %H:%M:%S"),
                         "2014-02-20 09:25:00")
        self.assertEqual(list_worksessions[8][2], '')
        self.assertEqual(list_worksessions[8][3], True)
        self.assertEqual(list_worksessions[8][4], 419)

        list_worksessions_amount_details = Data_processing.get_list_workSession_amount_details(
            list_worksessions, options_reason)
        print '/-/-/-/-/-/-/-//-/'
        print list_worksessions_amount_details
        print '/-/-/-/-/-/-/-//-/'

        # studying
        # total
        self.assertEqual(list_worksessions_amount_details[0][2], 1380)
        # amount
        self.assertEqual(list_worksessions_amount_details[0][3], 3)
        # gemiddeld
        self.assertEqual(list_worksessions_amount_details[0][4], 460)
        # min
        self.assertEqual(list_worksessions_amount_details[0][5], 180)
        # max
        self.assertEqual(list_worksessions_amount_details[0][6], 900)
    def test_list_work_session(self):
        datetime_from = datetime.datetime.strptime("2013-12-28 10:00:00",
                                                   "%Y-%m-%d %H:%M:%S")
        datetime_to = datetime.datetime.strptime("2013-12-28 11:15:00",
                                                 "%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid", "afgeleid", 0],
                          ["notities", "notities", 1], ["screen", "screen", 1],
                          ["pauze", "pauze", 0]]
        result_list = Data_processing.get_list_work_sessions(
            datetime_from, datetime_to, options_reason, 50, self.link_to_main)

        #presentation_tier.show_results(datetime_from,datetime_to,options_reason)
        print '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'
        print result_list
        print '*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-'

        # rij 0
        self.assertEqual(result_list[0][0],
                         datetime.datetime(2013, 12, 28, 10, 0))
        self.assertEqual(result_list[0][1],
                         datetime.datetime(2013, 12, 28, 10, 05))
        self.assertEqual(result_list[0][3], True)

        # rij 1
        self.assertEqual(result_list[1][0],
                         datetime.datetime(2013, 12, 28, 10, 05))
        self.assertEqual(result_list[1][1],
                         datetime.datetime(2013, 12, 28, 10, 10))
        self.assertEqual(result_list[1][3], False)

        # rij 2
        self.assertEqual(result_list[2][0],
                         datetime.datetime(2013, 12, 28, 10, 10))
        self.assertEqual(result_list[2][1],
                         datetime.datetime(2013, 12, 28, 10, 13, 0, 502000))
        self.assertEqual(result_list[2][3], True)

        # rij 3
        self.assertEqual(result_list[3][0],
                         datetime.datetime(2013, 12, 28, 10, 13, 0, 502000))
        self.assertEqual(result_list[3][1],
                         datetime.datetime(2013, 12, 28, 10, 28, 0, 502000))
        self.assertEqual(result_list[3][3], False)

        # rij 4
        self.assertEqual(result_list[4][0],
                         datetime.datetime(2013, 12, 28, 10, 28, 0, 502000))
        self.assertEqual(result_list[4][1],
                         datetime.datetime(2013, 12, 28, 10, 35, 0, 502000))
        self.assertEqual(result_list[4][3], True)

        # rij 5
        self.assertEqual(result_list[5][0],
                         datetime.datetime(2013, 12, 28, 10, 35, 0, 502000))
        self.assertEqual(result_list[5][1],
                         datetime.datetime(2013, 12, 28, 10, 43, 0, 502000))
        self.assertEqual(result_list[5][3], True)

        # rij 6
        self.assertEqual(result_list[6][0],
                         datetime.datetime(2013, 12, 28, 10, 43, 0, 502000))
        self.assertEqual(result_list[6][1],
                         datetime.datetime(2013, 12, 28, 10, 50))
        self.assertEqual(result_list[6][3], True)

        # rij 7
        self.assertEqual(result_list[7][0],
                         datetime.datetime(2013, 12, 28, 10, 50))
        self.assertEqual(result_list[7][1],
                         datetime.datetime(2013, 12, 28, 11, 00, 0, 502000))
        self.assertEqual(result_list[7][3], False)

        # rij 8
        self.assertEqual(result_list[8][0],
                         datetime.datetime(2013, 12, 28, 11, 00, 0, 502000))
        self.assertEqual(result_list[8][1],
                         datetime.datetime(2013, 12, 28, 11, 12, 0, 502000))
        self.assertEqual(result_list[8][3], False)

        # rij 9
        self.assertEqual(result_list[9][0],
                         datetime.datetime(2013, 12, 28, 11, 12, 0, 502000))
        self.assertEqual(result_list[9][1],
                         datetime.datetime(2013, 12, 28, 11, 15))
        self.assertEqual(result_list[9][3], True)
    def show_barchart_important_activity_details(self, date_time_from,
                                                 date_time_to, options_reason):
        result_list = Data_processing.getListImportantActivities(
            date_time_from, date_time_to, options_reason)
        list_time = []
        list_eyes_detected = []
        list_user_feedback = []
        list_attention_mindwave = []
        list_meditation_mindwave = []
        total_time = 0.0

        for item in result_list:
            total_time += item[1]

        x = []
        for item in result_list:
            # item = [activity, time_sec, avg_concentration_user, avg_eyes_detected, [userGone],avg_attention_mindwave, avg_meditation_mindwave]
            list_time.append(round((float(item[1]) / total_time * 100.0), 0))
            list_user_feedback.append(round(item[2] * 100, 0))
            list_eyes_detected.append(round(item[3] * 100, 0))
            list_attention_mindwave.append(round(item[5] * 100, 0))
            list_meditation_mindwave.append(round(item[6] * 100, 0))
            x.append(item[0])

        N = len(result_list)

        ind = np.arange(N)  # the x locations for the groups
        width = 0.15  # the width of the bars

        fig, ax = plt.subplots()
        rects1 = ax.bar(ind, list_time, width, color='c')
        rects2 = ax.bar(ind + width, list_user_feedback, width, color='g')
        rects3 = ax.bar(ind + (2.0 * width),
                        list_eyes_detected,
                        width,
                        color='b')
        rects4 = ax.bar(ind + (3.0 * width),
                        list_attention_mindwave,
                        width,
                        color='r')
        rects5 = ax.bar(ind + (4.0 * width),
                        list_meditation_mindwave,
                        width,
                        color='y')

        # add some
        ax.set_ylabel('percentage')
        ax.set_title('Attention + Meditation')
        ax.set_xticks(ind + width)
        ax.set_xticklabels(x)

        ax.legend(
            (rects1[0], rects2[0], rects3[0], rects4[0], rects5[0]),
            ('Relative time spent', 'Average user indicated concentration',
             'Average eyes detected', 'Average attention mindwave',
             'Average meditation mindwave'))
        self.autolabel(rects1, ax)
        self.autolabel(rects2, ax)
        self.autolabel(rects3, ax)
        self.autolabel(rects4, ax)
        self.autolabel(rects5, ax)
    def test_worksessions(self):
        datetime_from = datetime.datetime.strptime("2014-02-20 08:00:00","%Y-%m-%d %H:%M:%S")
        datetime_to =  datetime.datetime.strptime("2014-02-20 10:10:00","%Y-%m-%d %H:%M:%S")
        options_reason = [["afgeleid","afgeleid",0],["notities","notities",1],["screen","screen",1],["pauze","pauze",0]]
        list_worksessions = Data_processing.get_list_work_sessions(datetime_from,datetime_to,options_reason,10,self.link_to_main)
        print '=+=+=+=+=+=+=+=+=+=+=+=+=+='
        print list_worksessions
        print '=+=+=+=+=+=+=+=+=+=+=+=+=+='

        self.assertEqual(list_worksessions[0][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:00:00")
        self.assertEqual(list_worksessions[0][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:05:00")
        #self.assertEqual(list_worksessions[0][2],'studying')
        self.assertEqual(list_worksessions[0][3],False)
        self.assertEqual(list_worksessions[0][4],300)

        self.assertEqual(list_worksessions[1][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:05:00")
        self.assertEqual(list_worksessions[1][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:08:00")
        #self.assertEqual(list_worksessions[1][2],'studying')
        self.assertEqual(list_worksessions[1][3],True)
        self.assertEqual(list_worksessions[1][4],180)

        self.assertEqual(list_worksessions[2][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:08:00")
        self.assertEqual(list_worksessions[2][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:30:00")
        self.assertEqual(list_worksessions[2][2],'break')
        self.assertEqual(list_worksessions[2][3],False)
        self.assertEqual(list_worksessions[2][4],1320)

        self.assertEqual(list_worksessions[3][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 08:30:00")
        self.assertEqual(list_worksessions[3][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:00:00")
        self.assertEqual(list_worksessions[3][2],'no tracking info')
        self.assertEqual(list_worksessions[3][3],False)
        self.assertEqual(list_worksessions[3][4],1799)

        self.assertEqual(list_worksessions[4][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:00:00")
        self.assertEqual(list_worksessions[4][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:05:00")
        #self.assertEqual(list_worksessions[4][2],'studying')
        self.assertEqual(list_worksessions[4][3],True)
        self.assertEqual(list_worksessions[4][4],300)

        self.assertEqual(list_worksessions[5][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:05:00")
        self.assertEqual(list_worksessions[5][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:10:00")
        #self.assertEqual(list_worksessions[5][2],'studying')
        self.assertEqual(list_worksessions[5][3],False)
        self.assertEqual(list_worksessions[5][4],300)

        self.assertEqual(list_worksessions[6][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:10:00")
        self.assertEqual(list_worksessions[6][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:16:00")
        #self.assertEqual(list_worksessions[6][2],'notes')
        self.assertEqual(list_worksessions[6][3],True)
        self.assertEqual(list_worksessions[6][4],360)

        self.assertEqual(list_worksessions[7][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:16:00")
        self.assertEqual(list_worksessions[7][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:18:00")
        self.assertEqual(list_worksessions[7][2],'notes')
        self.assertEqual(list_worksessions[7][3],True)
        self.assertEqual(list_worksessions[7][4],120)

        self.assertEqual(list_worksessions[8][0].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:18:00")
        self.assertEqual(list_worksessions[8][1].strftime("%Y-%m-%d %H:%M:%S"),"2014-02-20 09:25:00")
        self.assertEqual(list_worksessions[8][2],'')
        self.assertEqual(list_worksessions[8][3],True)
        self.assertEqual(list_worksessions[8][4],419)

        list_worksessions_amount_details = Data_processing.get_list_workSession_amount_details(list_worksessions,options_reason)
        print '/-/-/-/-/-/-/-//-/'
        print list_worksessions_amount_details
        print '/-/-/-/-/-/-/-//-/'

        # studying
        # total
        self.assertEqual(list_worksessions_amount_details[0][2],1380)
        # amount
        self.assertEqual(list_worksessions_amount_details[0][3],3)
        # gemiddeld
        self.assertEqual(list_worksessions_amount_details[0][4],460)
        # min
        self.assertEqual(list_worksessions_amount_details[0][5],180)
        # max
        self.assertEqual(list_worksessions_amount_details[0][6],900)