dockers/API/restV1.py
def hour_histogram():
    '''
    Returns the data for the hour histogram
    '''
    conn = connect()
    mycursor = conn.cursor()
    mycursor.execute("SELECT * FROM kamernet_log")
    all_data = mycursor.fetchall()

    # Make hour avarage
    d_hour = {}
    for i in all_data:
        if i[1] > 30:
            continue
        hour = i[2].hour
        if hour in d_hour:
            d_hour[hour][0] += i[1]
            d_hour[hour][1] += 1
        else:
            d_hour[hour] = [i[1], 1]

    # Time stamp
    now = datetime.datetime.now()
    date_time = now.strftime("%Y-%m-%d 00:00:00")

    # Get this days data --> currently using only last one
    mycursor.execute("SELECT * FROM kamernet_log WHERE date>'{}'"
                .format(date_time))
    last = mycursor.fetchall()
    count = last[-1][1]
    hour = last[-1][2].hour
    hist_data = []

    # Parse data and return
    for i in d_hour:
        # I recently found out the date on my server is 2 hours behind....
        HOURS_BIHIND = 2
        hist_data.append({'hours':(i+HOURS_BIHIND)%24,
                          'values':round((d_hour[i][0]/d_hour[i][1]), 2)})

    return jsonify({"data":
                    {'histogram': hist_data,
                     "current":
                        {"hour":hour,"value":count}
                   }}), 200

    Returns the data for the hour histogram
    
Returns the data for the hour histogram
Returns the data for the hour histogram
def hour_histogram():
    conn = connect()
    mycursor = conn.cursor()
    mycursor.execute("SELECT * FROM kamernet_log")
    all_data = mycursor.fetchall()
    d_hour = {}
    for i in all_data:
        if i[1] > 30:
            continue
        hour = i[2].hour
        if hour in d_hour:
            d_hour[hour][0] += i[1]
            d_hour[hour][1] += 1
        else:
            d_hour[hour] = [i[1], 1]
    now = datetime.datetime.now()
    date_time = now.strftime("%Y-%m-%d 00:00:00")
    mycursor.execute("SELECT * FROM kamernet_log WHERE date>'{}'"
                .format(date_time))
    last = mycursor.fetchall()
    count = last[-1][1]
    hour = last[-1][2].hour
    hist_data = []
    for i in d_hour:
        HOURS_BIHIND = 2
        hist_data.append({'hours':(i+HOURS_BIHIND)%24,
                          'values':round((d_hour[i][0]/d_hour[i][1]), 2)})
    return jsonify({"data":
                    {'histogram': hist_data,
                     "current":
                        {"hour":hour,"value":count}
                   }}), 200
def hour_histogram ( ) : conn = connect ( ) mycursor = conn . cursor ( ) mycursor . execute ( "SELECT * FROM kamernet_log" ) all_data = mycursor . fetchall ( ) d_hour = { } for i in all_data : if i [ 1 ] > 30 : continue hour = i [ 2 ] . hour if hour in d_hour : d_hour [ hour ] [ 0 ] += i [ 1 ] d_hour [ hour ] [ 1 ] += 1 else : d_hour [ hour ] = [ i [ 1 ] , 1 ] now = datetime . datetime . now ( ) date_time = now . strftime ( "%Y-%m-%d 00:00:00" ) mycursor . execute ( "SELECT * FROM kamernet_log WHERE date>'{}'" . format ( date_time ) ) last = mycursor . fetchall ( ) count = last [ - 1 ] [ 1 ] hour = last [ - 1 ] [ 2 ] . hour hist_data = [ ] for i in d_hour : HOURS_BIHIND = 2 hist_data . append ( { 'hours' : ( i + HOURS_BIHIND ) % 24 , 'values' : round ( ( d_hour [ i ] [ 0 ] / d_hour [ i ] [ 1 ] ) , 2 ) } ) return jsonify ( { "data" : { 'histogram' : hist_data , "current" : { "hour" : hour , "value" : count } } } ) , 200
Returns the data for the hour histogram
Returns the data for the hour histogram
'''
    Returns the data for the hour histogram
    ''' # Make hour avarage # Time stamp # Get this days data --> currently using only last one # Parse data and return # I recently found out the date on my server is 2 hours behind....