def statistics():
    default_date = datetime.now()
    default_date_array = {'year': str(default_date.year), 'month': str(default_date.strftime('%m')), 'day':str(default_date.strftime('%d'))}
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    week_day_name = default_date.strftime('%A')
    month_name = default_date.strftime('%B')
    custom_date_day = {'weekday': week_day_name + ' ' + str(default_date.day) + '/' + str(default_date.month) + '/' +
                       str(default_date.year)}
    custom_date_month = {'month': month_name + ' ' + str(default_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, default_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
def statistics_by_date(_month, _day, _year):
    chosen_date_array = {'year': _year, 'month': _month, 'day': _day}
    gs = GenerateStats()
    # Chosenyear, chosenmonth, chosenday
    # Fetch the data from the database.
    users = User.query.all()
    event = Tagevent
    default_date = datetime.now()
    selected_date = default_date.replace(day=int(_day), month=int(_month), year=int(_year))
    week_day_name = selected_date.strftime('%A')
    month_name = selected_date.strftime('%B')
    custom_date_day = {'weekday': week_day_name + ' ' + str(selected_date.day) + '/' + str(selected_date.month) + '/' + str(selected_date.year)}
    custom_date_month = {'month': month_name + ' ' + str(selected_date.year)}
    # Send the data to a method who returns an multi dimensional array with statistics.
    ret = gs.get_data(users, event, chosen_date_array)
    return render_template('statistics.html',
                           plot_paths='',
                           data=ret,
                           data2=custom_date_day,
                           data3=custom_date_month)
def get_events_from_user_by_tag_id(tag_id):
    try:
        gs = GenerateStats()
        current_year = gs.get_current_year_string()
        counter = 0
        now = datetime.now()

        users_tagins = Tagevent.query.filter(Tagevent.tag_id.contains(tag_id)).\
            filter(Tagevent.timestamp.contains(current_year)).filter(Tagevent.uid != '').filter(Tagevent.uid is not None)

        for tag_event in users_tagins:
            for days in range(1, 32):
                if tag_event.timestamp.month == now.month:
                    if tag_event.timestamp.day == days:
                        counter += 1
                        break

        return {"value": counter}
    except:
        return {"value": 0}