Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
65 changes: 65 additions & 0 deletions derby_inventory_automation/automation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import automation_functions as af
import pandas as pd
import numpy as np
import csv








updated_inventory = pd.read_csv('updated_inventory_full.csv')
promotions_list = pd.io.json.read_json("promotionData.json")
current_inventory = pd.io.json.read_json("old_inventory_nonpromo.json")

## Initial clean and add of upce
final_table = af.clean_headers(updated_inventory)
final_table["upce"] = [af.create_upce(i) for i in final_table["upc"]]

##add crv, and sugar tax and check for taxable, adds column for sugar_tax and images column.
final_table = af.crv_column(final_table)
final_table = af.find_sugar(final_table).drop(["index"],axis=1)
final_table = af.get_taxable(final_table)


## Extract new products
def extract_new_products():
newest_products = final_table[(~final_table["upc"].isin(current_inventory["upc"]))&(~final_table["upc"].isin(promotions_list["upc"]))]
newest_products["contains_promotion"]= False
newest_products.to_json("newest_products.json",orient = "records")
return newest_products

## Extract changed promotions
def extract_changed_promo():
updated_promotions = final_table[final_table["upc"].isin(promotions_list["upc"])]
merged_promotions = updated_promotions.merge(promotions_list,left_on="upc",right_on = "upc")
changed_prices = merged_promotions[merged_promotions["sell_price_x"]!=merged_promotions["sell_price_y"]]
final_changed_promotions = updated_promotions[updated_promotions["upc"].isin(changed_prices["upc"])]
final_changed_promotions.to_json("changed_promotions.json",orient = "records")
return final_changed_promotions


##Extract changed product pricing excluding promotions
def extract_product_changes():
exclude_promos = final_table[~final_table["upc"].isin(promotions_list["upc"])]
exclude_promos_images = current_inventory[current_inventory["upc"].isin(exclude_promos["upc"])][["img","upc"]]
exclude_promos = exclude_promos.merge(exclude_promos_images, left_on=["upc"],right_on=["upc"])
merged_promotions = current_inventory.merge(exclude_promos,left_on=["upc",],right_on = ["upc"])
changed_prices = merged_promotions[round(merged_promotions["sell_price_x"],2)!=round(merged_promotions["sell_price_y"],2)]
final_changed_products = exclude_promos[exclude_promos["upc"].isin(changed_prices["upc"])]
final_changed_products["contains_promotion"] = False
final_changed_products["img"]= final_changed_products["img_y"]
final_changed_products = final_changed_products.drop(["img_x","img_y"],axis=1)
final_changed_products.to_csv("updated_changes.csv")
return final_changed_products




extract_product_changes()




118 changes: 118 additions & 0 deletions derby_inventory_automation/automation_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import pandas as pd
import numpy as np
import csv



def clean_headers(df):
df["Price"] = [float(i)/100 for i in df["cents"]]
df = df.rename(columns = {"Department":"department","Name":"product_name","Fee Multiplier": "crv_by_05_cents","Price":"sell_price"})
df = df[["upc","department","product_name","crv_by_05_cents","sell_price","size"]]
return df


def create_upce(upca2):
string = ''
length=len(str(upca2))
upca=str(upca2)
list = [ "5", "6", "7", "8" ,"9"]
upca= "0"+ upca
if len(str(upca))!=12:
return "0"
if upca[10] in list and upca[5]!="0" and upca[6]=="0"and upca[7]=="0"and upca[8]=="0" and upca[9]=="0":
string+=upca[0]
string+=upca[1]
string+=upca[2]
string+=upca[3]
string+=upca[4]
string+=upca[5]
string+=upca[10]
string+=upca[11]

if upca[5]=="0" and upca[7]=="0"and upca[8]=="0"and upca[9]=="0" and upca[4]!="0":
string+=upca[0]
string+=upca[1]
string+=upca[2]
string+=upca[3]
string+=upca[4]
string+=upca[10]
string+="4"
string+=upca[11]

if upca[4]=="0" and upca[5]=="0"and upca[6]=="0"and upca[7]=="0" and upca[3]=="1" or upca[3]=="2" or upca[3]=="0":
string+=upca[0]
string+=upca[1]
string+=upca[2]
string+=upca[8]
string+=upca[9]
string+=upca[10]
string+=upca[3]
string+=upca[11]
lister2=["3","4","5","6","7","8","9"]
if upca[3] in lister2 and upca[4]=="0" and upca[5]=="0" and upca[6]=="0" and upca[7]=="0" and upca[8]=="0":
string+=upca[0]
string+=upca[1]
string+=upca[2]
string+=upca[3]
string+=upca[9]
string+=upca[10]
string+="3"
string+=upca[11]

return string


## df = crv_column(df)
def crv_column(df):
has_crv=[]
departments = ["Soda","Water/Juices","Energy","Sports Drinks","Drinks","Teas/coffees"]
for i in range(len(df["upc"])):
if df["department"][i] in departments:
has_crv.append(True)

elif df["department"][i] not in departments:
has_crv.append(False)
df["has_crv"]=has_crv
return df


## returns the full table, including those without sugar
def find_sugar (df):
##table66 = table[(table["department"]=="Soda") | (table["department"]=="Water/Juices") | (table["department"]=="Sports Drinks")| (table["department"]=="Energy")].reset_index()
table4 = df[(df["department"]=="Soda") | (df["department"]=="Water/Juices") | (df["department"]=="Sports Drinks") | (df["department"]=="Energy") | (df["department"]=="Drinks")| (df["department"]=="Kombucha")].reset_index()
sugar_column=[]
for i in range(len(table4["product_name"])):
if "diet" in table4["product_name"][i] or "Diet" in table4["product_name"][i] or "Sugar" in table4["product_name"][i] or "sugar" in table4["product_name"][i] or "Fresh" in table4["product_name"][i] or "Zero" in table4["product_name"][i] or "zero" in table4["product_name"][i] or "water" in table4["product_name"][i] or "Water" in table4["product_name"][i] or "Organic" in table4["product_name"][i] or "organic" in table4["product_name"][i] or "real" in table4["product_name"][i] or "Real" in table4["product_name"][i] or "Geyser" in table4["product_name"][i]:
sugar_column.append(False)
else:
sugar_column.append(True)
table4["has_sugar_tax"] = sugar_column

df_not_sugar= df[~df["upc"].isin(table4["upc"])]
df_not_sugar["has_sugar_tax"]=False
combined= df_not_sugar.append(table4)

return combined


def add_images(df):
df["img"]= ""
return df


##Gets whats taxable and whats not and returns a table with all the data, including a column to indicate taxabilty
def get_taxable(df):
table44 = df[(df["department"]=="Energy") |(df["department"]=="Pets") |(df["department"]=="Soda") | (df["department"]=="Household Essentials")|(df["department"]=="Health & Wellness")]
table44["has_sales_tax"]=True

other_department = df[~df["upc"].isin(table44["upc"])]
other_department["has_sales_tax"]=False

finalized= table44.append(other_department)
finalized["img"]=""
finalized["sugar_tax"]=0

return finalized



1 change: 1 addition & 0 deletions derby_inventory_automation/changed_products.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions derby_inventory_automation/changed_promotions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"upc":12000016721,"department":"Teas\/coffees","product_name":"Starbucks Frappuccino Caramel Intense Chilled Coffee Drink","crv_by_05_cents":1.0,"sell_price":4.94,"size":"13.70 oz","upce":"01267201","has_crv":true,"has_sugar_tax":false,"has_sales_tax":false,"img":"","sugar_tax":0},{"upc":28400199612,"department":"Chips","product_name":"Lays BBQ Chips","crv_by_05_cents":1.0,"sell_price":4.09,"size":"7.75 oz","upce":"","has_crv":false,"has_sugar_tax":false,"has_sales_tax":false,"img":"","sugar_tax":0},{"upc":28400199636,"department":"Chips","product_name":"Lays Sour Cream & Onion","crv_by_05_cents":1.0,"sell_price":4.09,"size":"7.75 Oz","upce":"","has_crv":false,"has_sugar_tax":false,"has_sales_tax":false,"img":"","sugar_tax":0}]
Loading