-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
72 lines (58 loc) · 2.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from numpy import product
import numpy as np
import pandas as pd
from sympy import re
import matplotlib.pyplot as plt
def calculating(inventory,recipe,sold):
inventoryDF = pd.read_csv(inventory,index_col=0)
recipeDF = pd.read_csv(recipe,index_col=0).transpose()
soldDF = pd.read_csv(sold,index_col=0).transpose()
rec=list(recipeDF.columns)
used=pd.DataFrame()
for i in rec:
prod=soldDF[i]
used[i]=recipeDF[i]*prod[0]
used["sum"] = used.sum(axis=1)
remaining=pd.DataFrame()
remaining["Food_Waste"]=inventoryDF["Count"]-used["sum"]
remaining["Cost_of_Waste"]=remaining["Food_Waste"]*inventoryDF["Unit Price"]
return remaining
# Takes in a DataFrame object containing month and food waste per month
def linReg(df):
# Lin reg for every ingredient
columns = df.columns
# Declaring x axis (months)
x = [1, 2, 3] # Months
print(x)
# Y axis (waste)
# yDF = pd.MultiIndex.from_frame(df["Waste"]) # Getting data from dataFrame inside dataFrame df
# print(yDF)
bunWaste = []
bunWaste.append(df["Jan"]["bun"])
bunWaste.append(df["Feb"]["bun"])
bunWaste.append(df["Mar"]["bun"])
print(bunWaste)
coef = np.polyfit(x,bunWaste,1)
poly1d_fn = np.poly1d(coef) # Function that takes in x and returns an extimate for y
# Plotting
plt.plot(x, bunWaste, 'yo', poly1d_fn(x), '--k') # 'yo' = yellow circle marker, '--k' = black dashed line
plt.xlim(1,3)
plt.show()
pass # TEMP. Remove when done
remaining = calculating("dummyProduct.csv","dummyRecipe.csv","dummySold.csv")
Jan = calculating("dummyProduct.csv","dummyRecipe.csv","dummySold.csv")
Feb = calculating("dummyProduct2.csv","dummyRecipe.csv","dummySold2.csv")
Mar = calculating("dummyProduct3.csv","dummyRecipe.csv","dummySold3.csv")
monthRemaining = pd.concat([Jan.T[0:1], Feb.T[0:1], Mar.T[0:1]])
monthRemaining = monthRemaining.rename_axis("Month", axis="columns")
monthRemaining = monthRemaining.set_axis(['Jan', 'Feb', 'Mar'], axis=0)
#monthRemaining.insert(0, 'index', [*range(len(monthRemaining))])
print(monthRemaining.info())
# Testing linReg()
linRegXYData = pd.DataFrame()
#linRegXYData["Month"] = ([1], [2], [3])
linRegXYData["Jan"] = Jan["Food_Waste"]
linRegXYData["Feb"] = Feb["Food_Waste"]
linRegXYData["Mar"] = Mar["Food_Waste"]
print(linRegXYData)
linReg(linRegXYData)