def get_mindwave_data_smoothened(self, datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
            datetime_from, datetime_to)
        attention_data = []
        meditation_data = []

        for item in list_mindwave_data:
            attention_data.append(item[3])
            meditation_data.append(item[4])
        attention_data = List_operations.filter_list(attention_data)
        meditation_data = List_operations.filter_list(meditation_data)

        attention_data = List_operations.moving_median(attention_data,
                                                       self.window_median)
        meditation_data = List_operations.moving_median(
            meditation_data, self.window_median)

        attention_data = List_operations.movingaverage(attention_data,
                                                       self.window_other)
        meditation_data = List_operations.movingaverage(
            meditation_data, self.window_other)
        list_mindwave_data_modified = []
        for i in range(0, len(list_mindwave_data)):
            row = []
            row.append(list_mindwave_data[i][0])
            row.append(list_mindwave_data[i][1])
            row.append(list_mindwave_data[i][2])
            row.append(attention_data[i])
            row.append(meditation_data[i])
            row.append(list_mindwave_data[i][5])
            row.append(list_mindwave_data[i][6])

            list_mindwave_data_modified.append(row)

        return list_mindwave_data_modified
    def get_mindwave_data_smoothened(self,datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
        attention_data = []
        meditation_data = []

        for item in list_mindwave_data:
            attention_data.append(item[3])
            meditation_data.append(item[4])
        attention_data = List_operations.filter_list(attention_data)
        meditation_data = List_operations.filter_list(meditation_data)

        attention_data = List_operations.moving_median(attention_data,self.window_median)
        meditation_data = List_operations.moving_median(meditation_data,self.window_median)

        attention_data = List_operations.movingaverage(attention_data, self.window_other)
        meditation_data = List_operations.movingaverage(meditation_data, self.window_other)
        list_mindwave_data_modified = []
        for i in range(0,len(list_mindwave_data)):
            row = []
            row.append(list_mindwave_data[i][0])
            row.append(list_mindwave_data[i][1])
            row.append(list_mindwave_data[i][2])
            row.append(attention_data[i])
            row.append(meditation_data[i])
            row.append(list_mindwave_data[i][5])
            row.append(list_mindwave_data[i][6])

            list_mindwave_data_modified.append(row)

        return list_mindwave_data_modified
    def get_mindwave_data(self, datetime_from, datetime_to,window_moving_average):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
        attention_data = []
        meditation_data = []

        x = []
        index = 0
        while index < len(list_mindwave_data):
            try:
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][5] == self.treshold_poorSignalMindwave:
                attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
                meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
            else:
                attention_data.append((datetime_from_mindwave,-1))
                meditation_data.append((datetime_from_mindwave,-1))

            index += 1
        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_meditation = [value for (date, value) in meditation_data]

        y_attention = List_operations.filter_list(y_attention)
        y_meditation = List_operations.filter_list(y_meditation)

        y_attention = List_operations.moving_median(y_attention,self.window_median)
        y_meditation = List_operations.moving_median(y_meditation,self.window_median)

        y_attention = List_operations.movingaverage(y_attention, window_moving_average)
        y_meditation = List_operations.movingaverage(y_meditation, window_moving_average)

        return attention_data, x, y_attention, y_meditation
    def show_graph_attention_data_mindwave(self,datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from,datetime_to)
        attention_data = []
        meditation_data = []
        x = []
        index = 0
        while index < len(list_mindwave_data):

            try:
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except :
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
            except :
                datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][5] <= self.treshold_poorSignalMindwave:
                attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
                meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
            else:
                attention_data.append((datetime_from_mindwave,-1))
                meditation_data.append((datetime_from_mindwave,-1))
            #meditation_data.append((list_mindwave_data[index][1], list_mindwave_data[index][4]))
            index += 1

        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_meditation = [value for (date, value) in meditation_data]

        y_attention = List_operations.filter_list(y_attention)
        y_meditation = List_operations.filter_list(y_meditation)


        y_attention = List_operations.moving_median(y_attention,self.window_median)
        y_meditation = List_operations.moving_median(y_meditation,self.window_median)



        y_attention = List_operations.movingaverage(y_attention, self.window_other)
        y_meditation = List_operations.movingaverage(y_meditation, self.window_other)


        fig = plt.figure("Line chart data mindwave headset")

        graph = fig.add_subplot(111)

        # Plot the data as a red line with round markers
        graph.plot(x,y_attention,'r-o')
        graph.plot(x,y_meditation,'y-o')

        # Set the xtick locations to correspond to just the dates you entered.
        graph.set_xticks(x)

        # Set the xtick labels to correspond to just the dates you entered.
        graph.set_xticklabels(
                [date.strftime("%Y-%m-%d %H:%M:%S") for (date, value) in attention_data]
                )
    def show_graph_comparison_attention_data_mindwave_and_userfeedback(self,datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from,datetime_to)

        attention_data = []
        userfeedback_data = []
        x = []
        index = 0
        while index < len(list_mindwave_data):
            try:
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except :
                datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
            except :
                datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][5] == self.treshold_poorSignalMindwave:
                attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
            else:
                attention_data.append((datetime_from_mindwave,-1))
            try:
                avg_userfeedback = Userfeedback_processing.get_average_userfeedback_specific_period(datetime_from_mindwave,datetime_to_mindwave)
            except Exception.ListEmpty:
                avg_userfeedback = -1
            userfeedback_data.append((datetime_from_mindwave,avg_userfeedback))
            index += 1

        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_attention = List_operations.movingaverage(y_attention,10)
        y_userfeedback = [value for (date, value) in userfeedback_data]



        y_attention = List_operations.filter_list(y_attention)
        y_userfeedback = List_operations.filter_list(y_userfeedback)

        y_attention = List_operations.moving_median(y_attention,self.window_median)

        y_attention = List_operations.movingaverage(y_attention, self.window_other)


        fig = plt.figure("Comparison attention mindwave headset and user indicated concentration")

        graph = fig.add_subplot(111)

        # Plot the data as a red line with round markers
        graph.plot(x,y_attention,'r-o')
        graph.plot(x,y_userfeedback,'b-o')

        # Set the xtick locations to correspond to just the dates you entered.
        graph.set_xticks(x)

        # Set the xtick labels to correspond to just the dates you entered.
        graph.set_xticklabels(
                [date.strftime("%Y-%m-%d %H:%M:%S") for (date, value) in attention_data]
                )
def get_mindwave_data_filtered_smoothed_middle_moving_median(
        datetime_from, datetime_to, window_moving_average):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    mindwave_data_result = []
    list_dates = []
    attention_data = []
    meditation_data = []
    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")
        list_dates.append([datetime_from_mindwave, datetime_to_mindwave])

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append(list_mindwave_data[index][3])
            meditation_data.append(list_mindwave_data[index][4])
        else:
            attention_data.append(-1)
            meditation_data.append(-1)

        index += 1

    attention_data = List_operations.filter_list(attention_data)
    meditation_data = List_operations.filter_list(meditation_data)

    attention_data = List_operations.moving_median_middle(
        attention_data, window_median)
    meditation_data = List_operations.moving_median_middle(
        meditation_data, window_median)

    attention_data = List_operations.movingaverage(attention_data,
                                                   window_moving_average)
    meditation_data = List_operations.movingaverage(meditation_data,
                                                    window_moving_average)

    for i in range(0, len(attention_data)):
        mindwave_data_result.append([
            list_dates[i][0], list_dates[i][1], attention_data[i],
            meditation_data[i]
        ])

    return mindwave_data_result
def get_mindwave_data(datetime_from, datetime_to, window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    attention_data = []
    meditation_data = []

    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

        attention_data.append(
            (datetime_from_mindwave, list_mindwave_data[index][3]))
        meditation_data.append(
            (datetime_from_mindwave, list_mindwave_data[index][4]))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention, window_median)
    y_meditation = List_operations.moving_median(y_meditation, window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    return attention_data, x, y_attention, y_meditation
def get_mindwave_data( datetime_from, datetime_to,window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    attention_data = []
    meditation_data = []

    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

        attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
        meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention,window_median)
    y_meditation = List_operations.moving_median(y_meditation,window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    return attention_data, x, y_attention, y_meditation
    def get_mindwave_data(self, datetime_from, datetime_to,
                          window_moving_average):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
            datetime_from, datetime_to)
        attention_data = []
        meditation_data = []

        x = []
        index = 0
        while index < len(list_mindwave_data):
            try:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][
                    5] == self.treshold_poorSignalMindwave:
                attention_data.append(
                    (datetime_from_mindwave, list_mindwave_data[index][3]))
                meditation_data.append(
                    (datetime_from_mindwave, list_mindwave_data[index][4]))
            else:
                attention_data.append((datetime_from_mindwave, -1))
                meditation_data.append((datetime_from_mindwave, -1))

            index += 1
        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_meditation = [value for (date, value) in meditation_data]

        y_attention = List_operations.filter_list(y_attention)
        y_meditation = List_operations.filter_list(y_meditation)

        y_attention = List_operations.moving_median(y_attention,
                                                    self.window_median)
        y_meditation = List_operations.moving_median(y_meditation,
                                                     self.window_median)

        y_attention = List_operations.movingaverage(y_attention,
                                                    window_moving_average)
        y_meditation = List_operations.movingaverage(y_meditation,
                                                     window_moving_average)

        return attention_data, x, y_attention, y_meditation
def get_mindwave_data_filtered_smoothed_middle_moving_median( datetime_from, datetime_to,window_moving_average):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    mindwave_data_result = []
    list_dates = []
    attention_data = []
    meditation_data = []
    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")
        list_dates.append([datetime_from_mindwave,datetime_to_mindwave])

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append(list_mindwave_data[index][3])
            meditation_data.append(list_mindwave_data[index][4])
        else:
            attention_data.append(-1)
            meditation_data.append(-1)

        index += 1

    attention_data = List_operations.filter_list(attention_data)
    meditation_data = List_operations.filter_list(meditation_data)

    attention_data = List_operations.moving_median_middle(attention_data,window_median)
    meditation_data = List_operations.moving_median_middle(meditation_data,window_median)

    attention_data = List_operations.movingaverage(attention_data, window_moving_average)
    meditation_data = List_operations.movingaverage(meditation_data, window_moving_average)

    for i in range(0,len(attention_data)):
        mindwave_data_result.append([list_dates[i][0],list_dates[i][1],attention_data[i],meditation_data[i]])

    return mindwave_data_result
    def analyse_list_for_reading_patterns(self,x_coordinates_iris,datetime_array,title):
        filtered_list = self.filter_list(x_coordinates_iris)
        #filtered_list = list_operations.moving_median(filtered_list,self.median_window)

        if self.threshold_window_selection == -1:
            smoothened_list = self.smooth_list(filtered_list)
        else:
            smoothened_list = List_operations.movingaverage(filtered_list,self.threshold_window_selection)

        dataset = self.analyse_list_for_reading_patterns_smooth_list(smoothened_list,datetime_array)

        try:
            self.show_plot(datetime_array,filtered_list,smoothened_list,title)
        except Exception, e:
            print str(e)
    def analyse_list_for_reading_patterns_2(self,x_coordinates_iris,datetime_array,title):
        filtered_list = self.filter_list(x_coordinates_iris)
        #filtered_list = list_operations.moving_median(filtered_list,self.median_window)

        if self.threshold_window_selection == -1:
            smoothened_list = self.smooth_list(filtered_list)
        else:
            smoothened_list = List_operations.movingaverage(filtered_list,self.threshold_window_selection)

        dataset = self.analyse_list_for_reading_patterns_smooth_list_2(smoothened_list,datetime_array)
        """
        try:
            self.show_plot(datetime_array,filtered_list,smoothened_list,title)
        except Exception, e:
            print str(e)
        """
        for item in dataset:
            self.dareading.insert_row_reading(item[0],item[1],item[2],item[3])
        return dataset
    def smooth_list(self,list):
        derivative_list = self.calculate_derivative(list)
        list_copy = []
        for item in list:
            list_copy.append(item)
        index = 0
        teller_pos = 0
        teller_pos_acc = 0.0
        teller_pos_total = 0.0
        current_window = 0.0
        start_index = 0
        result = []
        while index < len(list):

            if derivative_list[index] > 0:
                teller_pos += 1
            else:
                if teller_pos > 0:
                    if teller_pos < self.threshold_window_accept_pos:
                        teller_pos = 0
                    else:
                        teller_pos_acc += teller_pos
                        teller_pos_total += 1
                        teller_pos = 0
                        # Eerst gemiddelde van teller_pos nemen over enkele momenten dat de functie stijgt, weer daalt en weer stijgt.
                        # Dan gebaseerd daarop nieuw window berekenen door die avg_pos te vermenigvuldigen met percentage
                        # Dan kijken of het new_window binnen de marges van verschil liggen tov oud window
                        # Zo niet, lijst meegeven aan movingaverage tot deze index met oud window, dan oud window op new window zetten en alles resetten.
                        if teller_pos_total > self.threshold_window_selection_total_pos:
                            avg_pos = teller_pos_acc / teller_pos_total
                            new_window = math.ceil(float(avg_pos * self.threshold_scale_factor_teller_pos_for_window))

                            if new_window > 0:
                                if current_window == 0: # and new_window != 0
                                    current_window = new_window
                                if (float(abs(current_window - new_window))/float(current_window)) > self.threshold_window_selection_relative_marge_difference_amount_pos: #(new_window > 0) and
                                    if start_index - current_window >= 0:
                                        start_index_with_current_window_marge = int(start_index - current_window)
                                    else:
                                        start_index_with_current_window_marge = start_index
                                    temp_smoothed_list = List_operations.movingaverage(list[start_index_with_current_window_marge:index],int(current_window))

                                    # het resultaat van movingaverage gaat op het einde steeds dalend zijn omdat, als er minder items over zijn dan de size van de window, gaat het movingaverage foutief berekent worden. Om dit tegen te gaan worden den laatste elementen van subarray eraf geknipt
                                    for index_restore in range(0,index):
                                        list[index_restore] = list_copy[index_restore]
                                    if(index - current_window) > 0:
                                        end_index = int(index - current_window)
                                    else:
                                        end_index = index
                                    if(len(temp_smoothed_list) - current_window ) > 0:
                                        end_index_smooth = int(len(temp_smoothed_list)  - current_window)
                                    else:
                                        end_index_smooth = len(temp_smoothed_list)

                                    if start_index >= (1 * current_window) and current_window < end_index_smooth:
                                        start_index_smooth_temp = int(current_window)
                                    else:
                                        start_index_smooth_temp = 0

                                    for index_temp_list in range(start_index_smooth_temp,end_index_smooth):
                                        result.append(temp_smoothed_list[index_temp_list])
                                        if (len(result) >= 337):
                                            True
                                    current_window = new_window
                                    start_index = len(result)

                            teller_pos = 0
                            teller_pos_total = 0.0
                            teller_pos_acc = 0.0
            index += 1

        if start_index < len(list) and current_window > 0:
            temp_smoothed_list = List_operations.movingaverage(list[int(start_index - current_window):len(list)],current_window)
            for index in range(int(current_window),len(temp_smoothed_list)):
                result.append(temp_smoothed_list[index])
        return result
    def show_graph_comparison_attention_data_mindwave_and_userfeedback(
            self, datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
            datetime_from, datetime_to)

        attention_data = []
        userfeedback_data = []
        x = []
        index = 0
        while index < len(list_mindwave_data):
            try:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_to_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][
                    5] == self.treshold_poorSignalMindwave:
                attention_data.append(
                    (datetime_from_mindwave, list_mindwave_data[index][3]))
            else:
                attention_data.append((datetime_from_mindwave, -1))
            try:
                avg_userfeedback = Userfeedback_processing.get_average_userfeedback_specific_period(
                    datetime_from_mindwave, datetime_to_mindwave)
            except Exception.ListEmpty:
                avg_userfeedback = -1
            userfeedback_data.append(
                (datetime_from_mindwave, avg_userfeedback))
            index += 1

        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_attention = List_operations.movingaverage(y_attention, 10)
        y_userfeedback = [value for (date, value) in userfeedback_data]

        y_attention = List_operations.filter_list(y_attention)
        y_userfeedback = List_operations.filter_list(y_userfeedback)

        y_attention = List_operations.moving_median(y_attention,
                                                    self.window_median)

        y_attention = List_operations.movingaverage(y_attention,
                                                    self.window_other)

        fig = plt.figure(
            "Comparison attention mindwave headset and user indicated concentration"
        )

        graph = fig.add_subplot(111)

        # Plot the data as a red line with round markers
        graph.plot(x, y_attention, 'r-o')
        graph.plot(x, y_userfeedback, 'b-o')

        # Set the xtick locations to correspond to just the dates you entered.
        graph.set_xticks(x)

        # Set the xtick labels to correspond to just the dates you entered.
        graph.set_xticklabels([
            date.strftime("%Y-%m-%d %H:%M:%S")
            for (date, value) in attention_data
        ])
def get_mindwave_userfeedback_data( datetime_from, datetime_to,window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    userfeedback_data = []
    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except :
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
            meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave,-1))
            meditation_data.append((datetime_from_mindwave,-1))

        try:
            avg_userfeedback = Userfeedback_processing.get_average_userfeedback_specific_period(datetime_from_mindwave,datetime_to_mindwave)
        except Exception.ListEmpty:
            avg_userfeedback = -1
        userfeedback_data.append((datetime_from_mindwave,avg_userfeedback))
        #meditation_data.append((list_mindwave_data[index][1], list_mindwave_data[index][4]))
        index += 1

    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention,window_median)
    y_meditation = List_operations.moving_median(y_meditation,window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_userfeedback = List_operations.filter_list([value for (date, value) in userfeedback_data])

    return attention_data, x, y_attention, y_meditation,y_userfeedback
    def show_graph_attention_data_mindwave(self, datetime_from, datetime_to):
        list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
            datetime_from, datetime_to)
        attention_data = []
        meditation_data = []
        x = []
        index = 0
        while index < len(list_mindwave_data):

            try:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_to_mindwave = datetime.datetime.strptime(
                    list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

            if list_mindwave_data[index][5] <= self.treshold_poorSignalMindwave:
                attention_data.append(
                    (datetime_from_mindwave, list_mindwave_data[index][3]))
                meditation_data.append(
                    (datetime_from_mindwave, list_mindwave_data[index][4]))
            else:
                attention_data.append((datetime_from_mindwave, -1))
                meditation_data.append((datetime_from_mindwave, -1))
            #meditation_data.append((list_mindwave_data[index][1], list_mindwave_data[index][4]))
            index += 1

        x = [date2num(date) for (date, value) in attention_data]
        y_attention = [value for (date, value) in attention_data]
        y_meditation = [value for (date, value) in meditation_data]

        y_attention = List_operations.filter_list(y_attention)
        y_meditation = List_operations.filter_list(y_meditation)

        y_attention = List_operations.moving_median(y_attention,
                                                    self.window_median)
        y_meditation = List_operations.moving_median(y_meditation,
                                                     self.window_median)

        y_attention = List_operations.movingaverage(y_attention,
                                                    self.window_other)
        y_meditation = List_operations.movingaverage(y_meditation,
                                                     self.window_other)

        fig = plt.figure("Line chart data mindwave headset")

        graph = fig.add_subplot(111)

        # Plot the data as a red line with round markers
        graph.plot(x, y_attention, 'r-o')
        graph.plot(x, y_meditation, 'y-o')

        # Set the xtick locations to correspond to just the dates you entered.
        graph.set_xticks(x)

        # Set the xtick labels to correspond to just the dates you entered.
        graph.set_xticklabels([
            date.strftime("%Y-%m-%d %H:%M:%S")
            for (date, value) in attention_data
        ])
def get_mindwave_manual_logged_activities_data(self, datetime_from,
                                               datetime_to, list_manual_logs,
                                               selected_activity, window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    selectedActivity = []
    userGoneStudying = []
    x = []
    index = 0
    listUserGone = DAUserGone_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == self.treshold_poorSignalMindwave:
            attention_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][3]))
            meditation_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave, -1))
            meditation_data.append((datetime_from_mindwave, -1))

        canAddMatchedActivity = False

        for item in list_manual_logs:
            datetime_from_log = item[0]
            datetime_to_log = item[1]

            if datetime_from_mindwave >= datetime_from_log and datetime_to_mindwave <= datetime_to_log and item[
                    2] == selected_activity:
                canAddMatchedActivity = True

        if canAddMatchedActivity is True:
            selectedActivity.append((datetime_from_mindwave, 1))
        else:
            selectedActivity.append((datetime_from_mindwave, 0))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention, window_median)
    y_meditation = List_operations.moving_median(y_meditation, window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"
    y_selectedActivity = List_operations.filter_list(
        [value for (date, value) in selectedActivity])

    return attention_data, x, y_attention, y_meditation, y_selectedActivity
def get_mindwave_activity_data( datetime_from, datetime_to,activity_details,window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    activityDuration_data = []
    x = []
    index = 0

    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except :
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
            meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave,-1))
            meditation_data.append((datetime_from_mindwave,-1))

        added = False
        for activityDetail in activity_details:
            start_datetime_RescueTime = datetime.datetime.strptime(activityDetail[0], "%Y-%m-%d %H:%M:%S")
            end_datetime_rescueTime = start_datetime_RescueTime + datetime.timedelta(minutes=5)

            if datetime_from_mindwave >=start_datetime_RescueTime and datetime_to_mindwave <= end_datetime_rescueTime and added is False:
                activityDuration_data.append((datetime_from_mindwave,float((activityDetail[1]) / 300.0)))
                added = True
        if added is False:
            activityDuration_data.append((datetime_from_mindwave,-1))




        index += 1

    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention,window_median)
    y_meditation = List_operations.moving_median(y_meditation,window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_activityDuration = List_operations.filter_list([value for (date, value) in activityDuration_data])

    return attention_data, x, y_attention, y_meditation,y_activityDuration
def get_mindwave_activity_data(datetime_from, datetime_to, activity_details,
                               window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    activityDuration_data = []
    x = []
    index = 0

    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][3]))
            meditation_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave, -1))
            meditation_data.append((datetime_from_mindwave, -1))

        added = False
        for activityDetail in activity_details:
            start_datetime_RescueTime = datetime.datetime.strptime(
                activityDetail[0], "%Y-%m-%d %H:%M:%S")
            end_datetime_rescueTime = start_datetime_RescueTime + datetime.timedelta(
                minutes=5)

            if datetime_from_mindwave >= start_datetime_RescueTime and datetime_to_mindwave <= end_datetime_rescueTime and added is False:
                activityDuration_data.append(
                    (datetime_from_mindwave, float(
                        (activityDetail[1]) / 300.0)))
                added = True
        if added is False:
            activityDuration_data.append((datetime_from_mindwave, -1))

        index += 1

    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention, window_median)
    y_meditation = List_operations.moving_median(y_meditation, window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_activityDuration = List_operations.filter_list(
        [value for (date, value) in activityDuration_data])

    return attention_data, x, y_attention, y_meditation, y_activityDuration
def get_mindwave_userGone_data(datetime_from, datetime_to, window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    userGoneNotStudying = []
    userGoneStudying = []
    x = []
    index = 0
    listUserGone = DAUserGone_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][3]))
            meditation_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave, -1))
            meditation_data.append((datetime_from_mindwave, -1))

        canAddUserGoneNotStudyingEntry = False
        canAddUserGoneStudyingEntry = False
        for item in listUserGone:
            try:
                datetime_from_userGone = datetime.datetime.strptime(
                    item[1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_userGone = datetime.datetime.strptime(
                    item[1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_userGone = datetime.datetime.strptime(
                    item[2], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_to_userGone = datetime.datetime.strptime(
                    item[2], "%Y-%m-%d %H:%M:%S")

            if datetime_from_mindwave >= datetime_from_userGone and datetime_to_mindwave <= datetime_to_userGone and item[
                    5] == 0:
                canAddUserGoneNotStudyingEntry = True

            if datetime_from_mindwave >= datetime_from_userGone and datetime_to_mindwave <= datetime_to_userGone and item[
                    5] == 1:
                canAddUserGoneStudyingEntry = True
        if canAddUserGoneNotStudyingEntry is True:
            userGoneNotStudying.append((datetime_from_mindwave, 1))
        else:
            userGoneNotStudying.append((datetime_from_mindwave, 0))

        if canAddUserGoneStudyingEntry is True:
            userGoneStudying.append((datetime_from_mindwave, 1))
        else:
            userGoneStudying.append((datetime_from_mindwave, 0))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention, window_median)
    y_meditation = List_operations.moving_median(y_meditation, window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_userGoneNotStudying = List_operations.filter_list(
        [value for (date, value) in userGoneNotStudying])
    y_userGoneStudying = List_operations.filter_list(
        [value for (date, value) in userGoneStudying])

    return attention_data, x, y_attention, y_meditation, y_userGoneNotStudying, y_userGoneStudying
def get_mindwave_userfeedback_data(datetime_from, datetime_to, window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(
        datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    userfeedback_data = []
    x = []
    index = 0
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_to_mindwave = datetime.datetime.strptime(
                list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")

        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][3]))
            meditation_data.append(
                (datetime_from_mindwave, list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave, -1))
            meditation_data.append((datetime_from_mindwave, -1))

        try:
            avg_userfeedback = Userfeedback_processing.get_average_userfeedback_specific_period(
                datetime_from_mindwave, datetime_to_mindwave)
        except Exception.ListEmpty:
            avg_userfeedback = -1
        userfeedback_data.append((datetime_from_mindwave, avg_userfeedback))
        #meditation_data.append((list_mindwave_data[index][1], list_mindwave_data[index][4]))
        index += 1

    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]

    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention, window_median)
    y_meditation = List_operations.moving_median(y_meditation, window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_userfeedback = List_operations.filter_list(
        [value for (date, value) in userfeedback_data])

    return attention_data, x, y_attention, y_meditation, y_userfeedback
def get_mindwave_userGone_data(datetime_from, datetime_to,window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    userGoneNotStudying = []
    userGoneStudying = []
    x = []
    index = 0
    listUserGone = DAUserGone_SQLite.get_data_specific_period(datetime_from,datetime_to)
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except :
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")


        if list_mindwave_data[index][5] == treshold_poorSignalMindwave:
            attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
            meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave,-1))
            meditation_data.append((datetime_from_mindwave,-1))

        canAddUserGoneNotStudyingEntry = False
        canAddUserGoneStudyingEntry = False
        for item in listUserGone:
            try:
                datetime_from_userGone = datetime.datetime.strptime(item[1], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_from_userGone = datetime.datetime.strptime(item[1], "%Y-%m-%d %H:%M:%S")

            try:
                datetime_to_userGone = datetime.datetime.strptime(item[2], "%Y-%m-%d %H:%M:%S.%f")
            except:
                datetime_to_userGone = datetime.datetime.strptime(item[2], "%Y-%m-%d %H:%M:%S")

            if datetime_from_mindwave >= datetime_from_userGone and datetime_to_mindwave <= datetime_to_userGone and item[5] == 0:
                canAddUserGoneNotStudyingEntry = True

            if datetime_from_mindwave >= datetime_from_userGone and datetime_to_mindwave <= datetime_to_userGone and item[5] == 1:
                canAddUserGoneStudyingEntry = True
        if canAddUserGoneNotStudyingEntry is True:
            userGoneNotStudying.append((datetime_from_mindwave,1))
        else:
            userGoneNotStudying.append((datetime_from_mindwave,0))

        if canAddUserGoneStudyingEntry is True:
            userGoneStudying.append((datetime_from_mindwave,1))
        else:
            userGoneStudying.append((datetime_from_mindwave,0))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]


    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention,window_median)
    y_meditation = List_operations.moving_median(y_meditation,window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"

    y_userGoneNotStudying = List_operations.filter_list([value for (date, value) in userGoneNotStudying])
    y_userGoneStudying = List_operations.filter_list([value for (date, value) in userGoneStudying])

    return attention_data, x, y_attention, y_meditation,y_userGoneNotStudying,y_userGoneStudying
def get_mindwave_manual_logged_activities_data(self, datetime_from, datetime_to,list_manual_logs,selected_activity,window):
    list_mindwave_data = DAMindwave_SQLite.get_data_specific_period(datetime_from, datetime_to)
    attention_data = []
    meditation_data = []
    selectedActivity = []
    userGoneStudying = []
    x = []
    index = 0
    listUserGone = DAUserGone_SQLite.get_data_specific_period(datetime_from,datetime_to)
    while index < len(list_mindwave_data):
        try:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_mindwave = datetime.datetime.strptime(list_mindwave_data[index][1], "%Y-%m-%d %H:%M:%S")
        try:
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S.%f")
        except :
            datetime_to_mindwave = datetime.datetime.strptime(list_mindwave_data[index][2], "%Y-%m-%d %H:%M:%S")


        if list_mindwave_data[index][5] == self.treshold_poorSignalMindwave:
            attention_data.append((datetime_from_mindwave,list_mindwave_data[index][3]))
            meditation_data.append((datetime_from_mindwave,list_mindwave_data[index][4]))
        else:
            attention_data.append((datetime_from_mindwave,-1))
            meditation_data.append((datetime_from_mindwave,-1))

        canAddMatchedActivity = False

        for item in list_manual_logs:
            datetime_from_log = item[0]
            datetime_to_log = item[1]

            if datetime_from_mindwave >= datetime_from_log and datetime_to_mindwave <= datetime_to_log and item[2] == selected_activity:
                canAddMatchedActivity = True

        if canAddMatchedActivity is True:
            selectedActivity.append((datetime_from_mindwave,1))
        else:
            selectedActivity.append((datetime_from_mindwave,0))

        index += 1
    x = [date2num(date) for (date, value) in attention_data]
    y_attention = [value for (date, value) in attention_data]
    y_meditation = [value for (date, value) in meditation_data]


    print "--------------------------------"
    print "original"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    y_attention = List_operations.filter_list(y_attention)
    y_meditation = List_operations.filter_list(y_meditation)

    print "after filter_list"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.moving_median(y_attention,window_median)
    y_meditation = List_operations.moving_median(y_meditation,window_median)

    print "after moving_median"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))

    y_attention = List_operations.movingaverage(y_attention, window)
    y_meditation = List_operations.movingaverage(y_meditation, window)

    print "after movingaverage"
    print str("length y_attention: " + str(len(y_attention)))
    print str("length y_meditation: " + str(len(y_meditation)))
    print "---------------------------"
    y_selectedActivity = List_operations.filter_list([value for (date, value) in selectedActivity])

    return attention_data, x, y_attention, y_meditation,y_selectedActivity
 def test_statistics(self):
     input_list = [1,3,3,4,5,7,9,10,11,15,16]
     window_size = 4
     output_list = List_operations.movingaverage(input_list,window_size)
     print output_list
 def test_statistics(self):
     input_list = [1, 3, 3, 4, 5, 7, 9, 10, 11, 15, 16]
     window_size = 4
     output_list = List_operations.movingaverage(input_list, window_size)
     print output_list