Skip to content

Commit

Permalink
add default consumption dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
Toky Axel committed Apr 21, 2021
1 parent d117048 commit 3e8b083
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
35 changes: 32 additions & 3 deletions Demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from prophet import Prophet
from math import pi
from math import cos, floor
import pkgutil
import csv

class Demand:
"""
Expand All @@ -19,7 +21,7 @@ def __init__(self, demand: float = 20, var_per_day: float = 0.1 , var_per_season
def set_forcast_periods(self, periods) -> None:
self.__periods = periods

def set_data_csv(self, bind = None, init_date: str = "2017-01-01", delimiter: str = ";", column: str = "Total Ventes"):
def set_data_csv(self, bind = None, raw_data = None, init_date: str = "2017-01-01", delimiter: str = ";", column: str = "Total Ventes"):
"""
The method must get a dataset with at least 3 columns
- month : int,
Expand All @@ -28,8 +30,23 @@ def set_data_csv(self, bind = None, init_date: str = "2017-01-01", delimiter: st
The method also use a forcast model from prophet to predict future demand.
The periods can be set by set_forcast_periods.
"""
data = pd.read_csv(bind, delimiter = delimiter)
"""
if raw_data is not None :
data = pd.DataFrame(raw_data)
#set columns & index
header = data.iloc[0]
data = data[1:]
data.columns = header
data = data.reset_index(drop=True)
for col in data.columns.tolist():
try:
# convert numeric values
data[col] = pd.to_numeric(data[col])
except:
pass
else :
data = pd.read_csv(bind, delimiter = delimiter)

data["date"]= data ["month"].astype("str") + "-" + data ["year"].astype("str")
data["datetime"] = pd.to_datetime(data["date"])
data_to_use = pd.DataFrame()
Expand All @@ -46,6 +63,18 @@ def set_data_csv(self, bind = None, init_date: str = "2017-01-01", delimiter: st
self.data_demand = data_to_use.append(fcst,ignore_index=True)

return self.data_demand

def set_data_to(self, dataset, delimiter: str=";"):
if dataset == "Toamasina":
#by defaut we keep it "Toamasina"
data = pkgutil.get_data('mixsimulator', '/data/RIToamasina/DIR-TOAMASINA_concat.csv')
data = csv.reader(data.decode('utf-8').splitlines(), delimiter = delimiter)
self.set_data_csv(raw_data=data)
else :
#by defaut we keep it "Toamasina"
data = pkgutil.get_data('mixsimulator', '/data/RIToamasina/DIR-TOAMASINA_concat.csv')
data = csv.reader(data.decode('utf-8').splitlines(), delimiter = delimiter)
self.set_data_csv(raw_data=data)

def get_demand(self, t):
self.data_demand.reset_index()
Expand Down
2 changes: 1 addition & 1 deletion MixSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def set_data_to(self, dataset, delimiter: str=";"):
self.set_data_csv(raw_data=data)
else :
#by defaut we keep it "Toamasina"
data = pkgutil.get_data('mixsimulator', '/data/RIToamasina/dataset_RI_Toamasina.csv')
data = pkgutil.get_data('mixsimulator', '/data/RIToamasina/dataset_RI_Toamasina_v2.csv')
data = csv.reader(data.decode('utf-8').splitlines(), delimiter = delimiter)
self.set_data_csv(raw_data=data)

Expand Down
9 changes: 8 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

#Set data to use
mix.set_data_csv("MixSimulator/data/RIToamasina/dataset_RI_Toamasina_v2.csv",delimiter=";")
#or for default dataset
#mix.set_data_to("Toamasina")

#For variation limits dataset, there is not yet default dataset
# mix.set_variation_csv("MixSimulator/data/RIToamasina/dataset_RI_Toamasina_variation_template.csv",delimiter=";")

demand = dm.Demand()
data_demand = demand.set_data_csv("MixSimulator/data/RIToamasina/DIR-TOAMASINA_concat.csv", delimiter = ",")
# data_demand.to_csv("data_demand.csv")
#or for default dataset
#demand.set_data_to("Toamasina",delimiter=",")

mix.set_demand(demand)

#Optimize the mix
Expand Down

0 comments on commit 3e8b083

Please sign in to comment.