Example #1
0
def get_average_userfeedback_specific_period(start_datetime_activity_detail,
                                             end_datetime_activity_detail):
    gemiddelde_concentratie = 0.0
    totaal = 0.0
    userfeedback = DAUserFeedback_SQLite.get_data_specific_period(
        start_datetime_activity_detail, end_datetime_activity_detail)
    # gemiddelde berekenen van de userfeedback gegevens voor de periodes van activity_detail
    total_user_feedback_time = 0.0
    for item in userfeedback:
        try:
            datetime_from_userfeedback = datetime.datetime.strptime(
                item[1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_userfeedback = datetime.datetime.strptime(
                item[1], "%Y-%m-%d %H:%M:%S")

        datetime_to_userfeedback = datetime_from_userfeedback + datetime.timedelta(
            seconds=item[4])

        if (datetime_from_userfeedback < end_datetime_activity_detail) and (
                datetime_to_userfeedback > start_datetime_activity_detail):
            if datetime_from_userfeedback < start_datetime_activity_detail:
                datetime_from_userfeedback = start_datetime_activity_detail
            if datetime_to_userfeedback > end_datetime_activity_detail:
                datetime_to_userfeedback = end_datetime_activity_detail

            difference = datetime_to_userfeedback - datetime_from_userfeedback
            total_user_feedback_time += difference.seconds

    if total_user_feedback_time <= 0:
        raise Exception.ListEmpty('Geen user_feedback gegevens gevonden')
    for item in userfeedback:
        try:
            datetime_from_userfeedback = datetime.datetime.strptime(
                item[1], "%Y-%m-%d %H:%M:%S.%f")
        except:
            datetime_from_userfeedback = datetime.datetime.strptime(
                item[1], "%Y-%m-%d %H:%M:%S")
        datetime_to_userfeedback = datetime_from_userfeedback + datetime.timedelta(
            seconds=item[4])

        if datetime_from_userfeedback < end_datetime_activity_detail:
            if datetime_from_userfeedback < start_datetime_activity_detail:
                datetime_from_userfeedback = start_datetime_activity_detail
            if datetime_to_userfeedback > end_datetime_activity_detail:
                datetime_to_userfeedback = end_datetime_activity_detail

            difference = datetime_to_userfeedback - datetime_from_userfeedback

            gemiddelde_concentratie += float(
                item[2] *
                (float(difference.seconds) / float(total_user_feedback_time)))

    return gemiddelde_concentratie
def get_sublist(mindwave_data, datetime_from, datetime_to):
    index_from = -1
    index_to = -1
    for i in range(0, len(mindwave_data)):
        if mindwave_data[i][0] >= datetime_from and index_from == -1:
            index_from = i
        else:
            if mindwave_data[i][1] <= datetime_to and index_from != -1:
                index_to = i

    if datetime_from == -1 or datetime_to == -1:
        raise Exception.ListEmpty(
            "datetime_from or datetime_to is outside the range of the mindwave data"
        )
    return mindwave_data[index_from:index_to + 1]
def get_average_sample_interval(list_mindwave_data, start_index, start_date,
                                end_date):
    sublist, end_index = get_list_interval_mindwave_data(
        list_mindwave_data, start_index, start_date, end_date)
    total = 0.0
    attention_acc = 0.0
    meditation_acc = 0.0
    for index_sublist in range(0, len(sublist)):
        attention_acc += sublist[index_sublist][3]
        meditation_acc += sublist[index_sublist][4]
        total += 1.0
    if total > 0:
        attention_avg = attention_acc / total
        meditation_avg = meditation_acc / total
    else:
        raise Exception.ListEmpty("no mindwave data for this interval")
    datetime_start_mindwave = sublist[0][1]
    datetime_end_mindwave = sublist[len(sublist) - 1][1]
    return attention_avg, meditation_avg, end_index, datetime_start_mindwave, datetime_end_mindwave