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 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 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_data_filtered_smoothed(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(attention_data,
                                                   window_median)
    meditation_data = List_operations.moving_median(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 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(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( 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(attention_data,window_median)
    meditation_data = List_operations.moving_median(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 test_moving_median_mindwave_array_3(self):
        mindwaveArray = [0.20,0.10,0.30,0.80,0.40,0.21,0.54,0.25,0.45,0.90]
        result = List_operations.moving_median(mindwaveArray,1)

        self.assertEqual(round(result[0],2),round(0.20,2))
        self.assertEqual(round(result[1],2),round(0.1,2))
        self.assertEqual(round(result[2],2),round(0.3,2))
        self.assertEqual(round(result[3],2),round(0.80,2))
        self.assertEqual(round(result[4],2),round(0.4,2))
        self.assertEqual(round(result[5],2),round(0.21,2))
        self.assertEqual(round(result[6],2),round(0.54,2))
        self.assertEqual(round(result[7],2),round(0.25,2))
        self.assertEqual(round(result[8],2),round(0.45,2))
        self.assertEqual(round(result[9],2),round(0.90,2))
    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 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_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_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_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_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_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_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