Пример #1
0
def get_hour_stats():
    """Get hour data to be rendered on charts.js"""

    map_categories = str(request.args.get("map_categories")) #put JS returned into string
    map_categories_list = map_categories.strip("]").strip("[").split(",") #put string into list
    category_list = []

    for category in map_categories_list:    #iterate through the list to strip out quotes and add to a list
        category_stripped = category.strip('"')
        category_list.append(category_stripped)

    if map_categories != "None":    #if there is no checkbox checked JS will return "None" as a string

        return Crime_Stat.get_hour_data_category(category_list) #call class method querying database by hour and provided catory and returns graph variable

    else:

        return Crime_Stat.get_hour_data() #if no categories provided, get all data regardless of category (this is what happens when page first loads)