Esempio n. 1
0
def capacity():
    """Render and show capacity page """

    # Read capacity of groups from json file
    json_data = open('data/capacity_group.json')
    cap_data = json.load(json_data)['data']
    # Read current data
    cur_data = db.get_latest_data(g.cursor)
    locations = []

    # Loop to find corresponding cur_client_count with capacity
    # and store it in locations
    for cap in cap_data:

        groupName = cap['group_name']
        capacity = cap['capacity']

        for latest in cur_data:
            if latest['group_name'] == groupName:
                cur_client_count = latest['client_count']
                break
        # Cast one of the numbers into a float, get a percentile by multiplying
        # 100, round the percentage and cast it back into a int.
        percent_full = int(round(float(cur_client_count)/capacity*100))
        locations.append({"name": groupName, "fullness": percent_full})

    return render_template('capacity.html', locations=locations)
Esempio n. 2
0
def map():
    """ Render and show maps page """

    cur_data = db.get_latest_data(g.cursor)
    locations = []

    # Loop to find corresponding cur_client_count with capacity
    # and store it in locations
    for cap in FULL_CAP_DATA:
        groupName = cap['group_name']
        capacity = cap['capacity']
        parentId = cap['parent_id']
        parentName = cap['parent_name']

        for latest in cur_data:
            if latest['group_name'] == groupName:
                cur_client_count = latest['client_count']
                break
        # Cast one of the numbers into a float, get a percentile by multiplying
        # 100, round the percentage and cast it back into a int.
        percent_full = int(round(float(cur_client_count)/capacity*100))
        if percent_full > 100:
            percent_full = 100

        if groupName == 'Butler Library stk':
            groupName = 'Butler Library Stacks'

        locations.append({"name": groupName, "fullness": percent_full,
                          "parentId": parentId, "parentName": parentName})

    # Render template has an SVG image whose colors are changed by % full
    return render_template('map.html', locations=locations)
Esempio n. 3
0
def map():
    """ Render and show maps page """

    cur_data = db.get_latest_data(g.cursor)

    locations = calculate_capacity(FULL_CAP_DATA, cur_data)
    # Render template has an SVG image whose colors are changed by % full
    return render_template('map.html', locations=locations)
Esempio n. 4
0
def capacity():
    """ Render and show capacity page """
    normfmt = "%B %d %Y, %I:%M %p"
    cur_data = db.get_latest_data(g.cursor)
    last_updated = cur_data[0]["dump_time"]
    last_updated = last_updated.strftime(normfmt)
    locations = calculate_capacity(FULL_CAP_DATA, cur_data)
    return render_template("capacity.html", locations=locations, last_updated=last_updated)
Esempio n. 5
0
def capacity():
    """ Render and show capacity page """
    normfmt = '%B %d %Y, %I:%M %p'
    cur_data = db.get_latest_data(g.cursor)
    last_updated = cur_data[0]['dump_time']
    last_updated = last_updated.strftime(normfmt)
    locations = calculate_capacity(FULL_CAP_DATA, cur_data)
    return render_template('capacity.html', locations=locations,
                           last_updated=last_updated)
Esempio n. 6
0
def get_latest_data():
    """
    Gets latest dump of data for all endpoints.

    :return: Latest JSON
    :rtype: flask.Response
    """

    fetched_data = db.get_latest_data(g.cursor)

    return jsonify(data=fetched_data)
Esempio n. 7
0
def get_latest_data():
    """
    Gets latest dump of data for all endpoints.
    :return: Latest JSON
    :rtype: flask.Response
    """

    fetched_data = db.get_latest_data(g.cursor)

    # Add percentage_full
    fetched_data = annotate_fullness_percentage(fetched_data)

    return jsonify(data=fetched_data)
Esempio n. 8
0
def capacity():
    """ Render and show capacity page """

    fetched_data = db.get_latest_data(g.cursor)
    locations = []

    # Add percentage_full
    fetched_data = annotate_fullness_percentage(fetched_data)

    for data in fetched_data:

        capacity = int(round(data["percent_full"]))

        if data['group_name'] == 'Butler Library stk':
            data['group_name'] = 'Butler Library Stacks'

        locations.append({"name": data['group_name'], "fullness": capacity})

    return render_template('capacity.html', locations=locations)
Esempio n. 9
0
def capacity():
    """ Render and show capacity page """

    fetched_data = db.get_latest_data(g.cursor)
    locations = []

    # Add percentage_full
    fetched_data = annotate_fullness_percentage(fetched_data)

    for data in fetched_data:

        capacity = int(round(data["percent_full"]))

        if data['group_name'] == 'Butler Library stk':
            data['group_name'] = 'Butler Library Stacks'

        locations.append({"name": data['group_name'], "fullness": capacity})

    return render_template('capacity.html', locations=locations)
Esempio n. 10
0
def map():
    """ Render and show maps page """

    cur_data = db.get_latest_data(g.cursor)
    locations = []

    # Loop to find corresponding cur_client_count with capacity
    # and store it in locations
    for cap in FULL_CAP_DATA:
        groupName = cap['group_name']
        capacity = cap['capacity']
        parentId = cap['parent_id']
        parentName = cap['parent_name']

        for latest in cur_data:
            if latest['group_name'] == groupName:
                cur_client_count = latest['client_count']
                break
        # Cast one of the numbers into a float, get a percentile by multiplying
        # 100, round the percentage and cast it back into a int.
        percent_full = int(round(float(cur_client_count) / capacity * 100))
        if percent_full > 100:
            percent_full = 100

        if groupName == 'Butler Library stk':
            groupName = 'Butler Library Stacks'

        locations.append({
            "name": groupName,
            "fullness": percent_full,
            "parentId": parentId,
            "parentName": parentName
        })

    # Render template has an SVG image whose colors are changed by % full
    return render_template('map.html', locations=locations)