Exemplo n.º 1
0
def deleteyear(year):
	counter = 0
	for key in rd.keys():
		if rd.hget(key,'year') == year: 
			rd.delete(key)		
			counter = counter+1	
	return "Year Deleted: " + str(counter) + " items total\n"
Exemplo n.º 2
0
def execute_job(jid):
    update_job_status(jid, 'in progress')
    start, end = job.hmget(generate_job_key(jid), 'start', 'end')
    start = int(start)
    end = int(end)
    years = list(range(start, end + 1))
    numpoints = (end + 1 - start)
    total = [0] * numpoints
    count = [0] * numpoints
    for key in rd.keys():
        year = int(rd.hget(key, 'year'))
        if year >= start and year <= end:
            index = year - start
            lettertotal = len(str(rd.hget(key, 'entity')))
            total[index] = total[index] + lettertotal
            count[index] = count[index] + 1

    avg = [i / j for i, j in zip(total, count)]
    title = "Average length of names in Oscar films between " + str(
        start) + " and " + str(end)

    plt.plot(years, avg, 'g-o', label="Nominees")

    plt.xlabel("Years")
    plt.ylabel("Average Num. Letters")
    plt.title(title)

    plt.savefig('/oscarlength.png')

    with open('/oscarlength.png', 'rb') as f:
        img = f.read()

    job.hset(generate_job_key(jid), 'image', img)

    update_job_status(jid, 'complete')
Exemplo n.º 3
0
def showyearcat(year,category):
	filmlist = []
	category = category.replace("_", " ")
	for key in rd.keys():
		if rd.hget(key,'year') == year and category == rd.hget(key,'category'):
			filmlist.append(rd.hgetall(key))
	return jsonify(filmlist)
Exemplo n.º 4
0
def showname(entity):
	filmlist = []
	entity = entity.replace("_", " ")
	for key in rd.keys():
		if entity == rd.hget(key,'entity'):
			filmlist.append(rd.hgetall(key))
	return jsonify(filmlist)
Exemplo n.º 5
0
def deletename(entity):
	counter = 0
	entity = entity.replace("_", " ")
	for key in rd.keys():
		if entity == rd.hget(key,'entity'):
			rd.delete(key)	
			counter = counter+1
	return "Entity Deleted: " + str(counter) + " items total\n"
Exemplo n.º 6
0
def deleteyearcat(year,category):
	category = category.replace("_", " ")
	counter = 0
	for key in rd.keys():
		if rd.hget(key,'year') == year and category == rd.hget(key,'category'):
			rd.delete(key)	
			counter = counter + 1
	return "Category Deleted: " + str(counter) + " items total\n"
Exemplo n.º 7
0
def deleterange():
	start = request.args.get('start')
	end = request.args.get('end')
	counter = 0
	for key in rd.keys():
		year = rd.hget(key,'year')
		if year >= start and year <= end:
			rd.delete(key)		
			counter = counter+1	
	return "Range Deleted: " + str(counter) + " items total\n"
Exemplo n.º 8
0
def showrange():
	start = request.args.get('start')
	end = request.args.get('end')
	rangelist = []
	for key in rd.keys():
		year = rd.hget(key,'year')
		if year >= start and year <= end:
			rangelist.append(rd.hgetall(key))
	
	return "\n".join([str(x) for x in rangelist])
Exemplo n.º 9
0
def _find_by_iso_and_prodt(in_string):
    """
    Returns a list of all keys (from "data" database) with inputted PRODT (product type) abbreviation (both production and consumption).

    Input:
    in_string = "ISO-PRODT"
    """

    keys = []

    for key in rd.keys():
        if key[0:3] == in_string[0:3] and key[
                9:5 + len(in_string)] == in_string[4:len(in_string)]:
            keys.append(key)

    return keys
Exemplo n.º 10
0
def _find_by_actt(in_string):
    """
    Returns a list of all the keys (from "data" database) with a given ACTT (activity type) abbreviation. Product type can be appended

    Input: Any of the following
    in_string = "ACTT" returns all keys with matching activity (ACTT: either PROD or CONS) type
    in_string = "ACTT-PRODT" returns all keys with matching activity and product type (TOTAL, NG, COAL, etc.)
    """

    keys = []

    for key in rd.keys():
        if key[4:4 + len(in_string)] == in_string:
            keys.append(key)

    return keys
Exemplo n.º 11
0
def _find_by_iso(in_string):
    """
    Returns a list of all keys (from "data" database) that match in_string for the length of in_string

    Input: Any of the following
    in_string = "ISO" returns all keys with matching country abbreviation (ISO)
    in_string = "ISO-ACTT" returns all keys with matching ISO and activity type (either PROD or CONS)
    in_string = "ISO-ACTT-PRODT" returns keys with matching ISO, activity type, and product type (TOTAL, NG, COAL, etc.)
    """

    keys = []

    for key in rd.keys():
        if key[0:len(in_string)] == in_string:
            keys.append(key)

    return keys
Exemplo n.º 12
0
def execute_job(jid):
    update_job_status(jid, 'in progress')
    restaurant = rd_plot.hget(f'job.{jid}', 'restaurant').decode('utf-8')
    dates = []
    scores = []
    for key in rd.keys():
        if rd.hget(key, 'Restaurant Name').decode('utf-8') == restaurant:
            date = rd.hget(key, 'Date of Inspection').decode('utf-8')
            score = rd.hget(key, 'Inspection Score').decode('utf-8')
            dates.append(datetime.datetime.strptime(date, "%m/%d/%Y"))
            scores.append(int(score))
    x = dates
    y = scores
    plt.figure(figsize=(10, 10))
    plt.plot_date(x, y)
    restaurant = restaurant.replace(' ', '-')
    plt.savefig(str(restaurant) + '.png')
    file_bytes = open(str(restaurant) + '.png', 'rb').read()
    rd_plot.set(str(restaurant) + '_plot', file_bytes)
    print('Plot Key: ' + str(restaurant) + '_plot' + "\n")
    update_job_status(jid, 'complete')
Exemplo n.º 13
0
def _find_by_prodt(in_string):
    """
    Returns a list of all keys (from "data" database) with inputted PRODT (product type) abbreviation (both production and consumption).

    Input:
    in_string = "PRODT"

    "PRODT" options:
    "TOTAL" = total energy
    "COAL" = coal
    "NGAS" = natural gas
    "PETRO" = petroleum and other liquids
    "NUCLEAR" = nuclear
    "NRO" = nuclear, renewables and others
    "RENEW" = Renewables and others
    """

    keys = []

    for key in rd.keys():
        if key[9:9 + len(in_string)] == in_string:
            keys.append(key)

    return keys
Exemplo n.º 14
0
def showyear(year):
	filmlist = []
	for key in rd.keys():
		if rd.hget(key,'year') == year: 
			filmlist.append(rd.hgetall(key))	
	return "\n".join([str(x) for x in filmlist])
Exemplo n.º 15
0
def reset():
	for key in rd.keys():
		rd.delete(key)
	getdata()
	return "Data Reset\n"