Esempio n. 1
0
def select_output():
    jid = request.args.get('jid')
    output_json = (rd_jobs.hget(jobs._generate_job_key(jid), 'output json'))

    output_df = pd.read_json(output_json)

    return output_df.to_markdown()
Esempio n. 2
0
def select_summary():
    jid = request.args.get('jid')
    summary_json = (rd_jobs.hget(jobs._generate_job_key(jid), 'summary json'))

    summary_df = pd.read_json(summary_json)

    return summary_df.to_markdown()
Esempio n. 3
0
def do_work(jid):
    update_job_status(jid, 'in progress')

    locations = get_locations()
    menus = get_menus()
    pricing = get_price()


    rd_jobs.hset(_generate_job_key(jid), 'location number', len(locations))

    max_price = max(pricing)

    columns1 = ['id', 'address', 'categories', 'menus', 'pricing']

    output = pd.DataFrame(columns = columns1)
    index = 0
    counter = 0

    subset1 = subset_.append(get_locations.loc[(get_locations['address'] == st\
atus) & (start_id <= get_locations['id']) & (end_id >= get_locations['id']), ['                                                                                       
id', 'address', 'category']])

    for index in range(len(subset1)):
        location = subset1.iloc[index]['address']
        menu = subset1.iloc[index]['menu']
        pricing = subset1.iloc[index]['pricing']

        if (index ==0):
            counter = 0
        elif(pricing != subset1.iloc[index-1]['pricing']):
            counter = 0)

       new_table =  formula(id, address, categories, menus_amountmax, menus_amountmin)

       update_job_status(jid, 'complete')
Esempio n. 4
0
def delete_job():
    jobid = request.args.get('jobid')

    for key in rd.keys():
        if jobid == (rd.hget(key, 'JOBID')).decode('utf-8'):
            casenumber = (rd.hget(key, 'CASENUMBER')).decode('utf-8')

    rd.delete(jobs._generate_job_key(jobid))
    return 'Deleted complaint! (CASENUMBER: ' + casenumber + ', JOBID: ' + jobid + ')'
Esempio n. 5
0
def get_job_form():
    job_dict = jobs.get_jobs()
    jid = request.form.get('jsonData')
    try:
        strJob = json.dumps(job_dict[jobs._generate_job_key(jid)])
        jsonData = json.loads(strJob)
        return render_template('jobReturn.html',
                               jsonData=jsonData,
                               data=strJob)
    except:
        return abort(404)
Esempio n. 6
0
def get_job(jid):
    job_dict = jobs.get_jobs()
    try:
        return json.dumps(job_dict[jobs._generate_job_key(jid)], indent=4)
    except:
        return abort(404)
Esempio n. 7
0
def delete_job():
    jid = request.args.get('jid')

    rd_jobs.delete(jobs._generate_job_key(jid))

    return 'Job ' + jid + ' has been deleted'
Esempio n. 8
0
def execute_job(jid):
    update_job_status(jid, 'in progress')

    stock_and_sales_df = get_stock_and_sales()
    products_df = get_products()

    rd_jobs.hset(_generate_job_key(jid), 'stock rows', len(stock_and_sales_df))

    #finds the maximum shelf life a product can have
    products_df = get_products()
    shelf_life_column = products_df["shelf_life"]
    max_shelf_life = shelf_life_column.max() - 2

    output_columns = ['Date', 'Store', 'Product', 'Stock', 'Sales']

    #create columns based on maximum shelf life
    for index in range(max_shelf_life):
        start_index = "start" + str(index + 1)
        end_index = "end" + str(index + 1)
        output_columns.extend([start_index, end_index])

    output_columns.extend(['total start', 'total end', 'surplus', 'gapout'])
    output_df = pd.DataFrame(columns=output_columns)

    store_input = (rd_jobs.hget(_generate_job_key(jid),
                                'store_input')).decode("utf-8")
    start_date = (rd_jobs.hget(_generate_job_key(jid),
                               'start_date')).decode("utf-8")
    end_date = (rd_jobs.hget(_generate_job_key(jid),
                             'end_date')).decode("utf-8")

    subset_df = stock_and_sales_df.loc[
        (stock_and_sales_df['Store'] == store_input)
        & (start_date <= stock_and_sales_df['Date'])
        & (stock_and_sales_df['Date'] <= end_date),
        ['Date', 'Product', 'Store', 'Stock', 'Sales']]

    rd_jobs.hset(_generate_job_key(jid), 'subset rows', len(subset_df))

    #initializes index and counter variables to know where the method is at in the for loop
    index = 0
    counter = 0

    #iterates through every row and runs surplus / gapout formulas
    for index in range(len(subset_df)):

        #creates local variables for values that carry over from subset dataframe to output dataframe
        date = subset_df.iloc[index]['Date']
        product = subset_df.iloc[index]['Product']
        store = subset_df.iloc[index]['Store']
        stock = subset_df.iloc[index]['Stock']
        sales = subset_df.iloc[index]['Sales']
        shelf_life = products_df.loc[product]['wf_shelf_life']

        #counter resets to 0 if a new product is being started
        if (index == 0):
            counter = 0
        elif (product != subset_df.iloc[index - 1]['Product']):
            counter = 0

        new_row = formulas_dynamic(index, counter, date, store, product, stock,
                                   sales, shelf_life, output_df)
        output_df = output_df.append(new_row, ignore_index=True)

        counter += 1
        index += 1

    products_df = products_df.reset_index()

    output_json = output_df.to_json()

    summary_df = summary(output_df, products_df)
    summary_json = summary_df.to_json()

    rd_jobs.hset(_generate_job_key(jid), 'output json', output_json)
    rd_jobs.hset(_generate_job_key(jid), 'summary json', summary_json)

    update_job_status(jid, 'complete')