def main(): start_time = time.time() orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path="data.csv", z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) sim_window = simulate.summarize_window(simulation_frame=sim, period_length=12) sim_frame = simulate.summarise_frame(sim_window) optimised = simulate.optimise_service_level( service_level=95.0, frame_summary=sim_frame, orders_analysis=orders_analysis.orders, runs=1, percentage_increase=1.30) for s in optimised: print(s.orders_summary()) end_time = time.time() elapsed = end_time - start_time print(elapsed)
def setUp(self): self.__skus = ['KR202-209', 'KR202-210', 'KR202-211'] self.__orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12) self.__categories = ['excess_stock', 'shortages', 'revenue'] self.__abc_classification = ('AX', 'AY', 'AZ', 'BX', 'BY', 'BZ', 'CX', 'CY', 'CZ') self.__analysis_summary = Inventory( processed_orders=self.__orders_analysis) self.__describe_sku = [ 'excess_cost', 'percentage_contribution_revenue', 'markup_percentage', 'shortage_rank', 'unit_cost', 'max_order', 'retail_price', 'classification', 'excess_rank', 'average_orders', 'revenue_rank', 'excess_units', 'safety_stock_units', 'shortage_cost', 'revenue', 'min_order', 'safety_stock_rank', 'safety_stock_cost', 'sku_id', 'gross_profit_margin', 'shortage_units' ] self.__abc_raw = self.__analysis_summary.abc_xyz_raw
def test_file_path_abcxyz_extension(self): with self.assertRaises(expected_exception=Exception): abc = model_inventory.analyse_orders_abcxyz_from_file( file_path='test.ts', z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv")
def test_normal_distribution_mean(self): """ Verifies mean and variance for random normal distribution. """ # arrange app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) # act orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = monte_carlo.SetupMonteCarlo( analysed_orders=orders_analysis.orders, period_length=1) for sku in orders_analysis.orders: item = sku.orders_summary() if item['sku'] == 'KR202-209': # assertd diff = abs( float(item['average_order']) - float( np.mean(sim.normal_random_distribution[0]['KR202-209'] [0][0]))) self.assertLess(diff, float(item['standard_deviation']))
def main(): start_time = time.time() orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path="data.csv", z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv" ) sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) sim_window = simulate.summarize_window(simulation_frame=sim, period_length=12) sim_frame = simulate.summarise_frame(sim_window) optimised = simulate.optimise_service_level( service_level=95.0, frame_summary=sim_frame, orders_analysis=orders_analysis.orders, runs=1, percentage_increase=1.30, ) for s in optimised: print(s.orders_summary()) end_time = time.time() elapsed = end_time - start_time print(elapsed)
def setUp(self): self.__skus = ['KR202-209', 'KR202-210', 'KR202-211'] self.__orders_analysis = analyse_orders_abcxyz_from_file(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12)
def setUp(self): self.__skus = ['KR202-209', 'KR202-210', 'KR202-211'] self.__orders_analysis = analyse_orders_abcxyz_from_file(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12) self.sim = simulate.run_monte_carlo(orders_analysis=self.__orders_analysis, runs=1, period_length=12)
def test_file_path_abcxyz_extension(self): # arrange, act app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.sv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) # assert with self.assertRaises(expected_exception=Exception): abc = model_inventory.analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv")
def test_abcxyz_classification(self): abc = model_inventory.analyse_orders_abcxyz_from_file(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") for sku in abc: item = sku.orders_summary() if item['sku'] == 'KR202-209': self.assertEqual(item['ABC_XYZ_Classification'], 'BY')
def test_file_path_abcxyz(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) abc = model_inventory.analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") for sku in abc.orders: item = sku.orders_summary() if item['sku'] == 'KR202-209': self.assertEqual(item['ABC_XYZ_Classification'], 'CZ')
def setUp(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data2.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) self.__skus = ['KR202-209', 'KR202-210', 'KR202-211'] self.__orders_analysis = analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12)
def setUp(self): self.__skus = ["KR202-209", "KR202-210", "KR202-211"] self.__orders_analysis = analyse_orders_abcxyz_from_file( file_path=ABS_FILE_PATH["COMPLETE_CSV_SM"], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12, ) self.__sim = monte_carlo.SetupMonteCarlo(analysed_orders=self.__orders_analysis, period_length=1)
def test_run_simulation(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data2.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = model_inventory.analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") simulation_windows = simulate.run_monte_carlo(orders_analysis=orders_analysis, runs=1) self.assertEqual(len(simulation_windows), 384)
def test_po_quantity_zero(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) for period in sim: if int(period[0].get("closing_stock")) == 0: self.assertGreater(int(period[0].get("po_quantity")), 0)
def test_summarize_simulation(self): orders_analysis = analyse_orders_abcxyz_from_file( file_path=ABS_FILE_PATH["COMPLETE_CSV_SM"], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", ) simulation_windows = simulate.run_monte_carlo(orders_analysis=orders_analysis, runs=1, period_length=12) collect_sim = [] for i in simulate.summarize_window(simulation_frame=simulation_windows): collect_sim.append(i) self.assertEqual(len(collect_sim), 39)
def test_summarize_simulation(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data2.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") simulation_windows = simulate.run_monte_carlo(orders_analysis=orders_analysis, runs=1, period_length=12) collect_sim = [] for i in simulate.summarize_window(simulation_frame=simulation_windows): collect_sim.append(i) self.assertEqual(len(collect_sim), 32)
def test_po_raised_regex(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) po_regex = re.compile('[P][O] \d+') orders_analysis = analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) for period in sim: if int(period[0].get("closing_stock")) == 0 and int(period[0].get("backlog")) > 0: self.assertRegex(period[0].get("po_raised"), expected_regex=po_regex, msg='True')
def test_run_simulation(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") simulation_windows = simulate.run_monte_carlo( orders_analysis=orders_analysis.orders, runs=1) self.assertEqual(len(simulation_windows), 384)
def test_po_quantity_zero(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) for period in sim: if int(period[0].get("closing_stock")) == 0: self.assertGreater(int(period[0].get("po_quantity")), 0)
def test_summarize_simulation(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") simulation_windows = simulate.run_monte_carlo( orders_analysis=orders_analysis.orders, runs=1, period_length=12) collect_sim = [] for i in simulate.summarize_window( simulation_frame=simulation_windows): collect_sim.append(i) self.assertEqual(len(collect_sim), 32)
def setUp(self): self.__skus = ['KR202-209', 'KR202-210', 'KR202-211'] self.__orders_analysis = model_inventory.analyse_orders_abcxyz_from_file(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv", length=12) self.__categories = ['excess_stock', 'shortages', 'revenue'] self.__abc_classification = ('AX', 'AY', 'AZ', 'BX', 'BY', 'BZ', 'CX', 'CY', 'CZ') self.__analysis_summary = Inventory( processed_orders =self.__orders_analysis) self.__describe_sku = ['excess_cost', 'percentage_contribution_revenue', 'markup_percentage', 'shortage_rank', 'unit_cost', 'max_order', 'retail_price', 'classification', 'excess_rank', 'average_orders', 'revenue_rank', 'excess_units', 'safety_stock_units', 'shortage_cost', 'revenue', 'min_order', 'safety_stock_rank', 'safety_stock_cost', 'sku_id', 'gross_profit_margin', 'shortage_units'] self.__abc_raw = self.__analysis_summary.abc_xyz_raw
def test_build_window(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = model_inventory.analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") period_length = 12 sim_collection = [] for k in range(0, 1): simulation = monte_carlo.SetupMonteCarlo( analysed_orders=orders_analysis.orders) random_demand = simulation.generate_normal_random_distribution( period_length=period_length) for sim_window in simulation.build_window( random_normal_demand=random_demand, period_length=period_length): sim_dict = { "index": "{:.0f}".format(sim_window.index), "period": "{:.0f}".format(sim_window.position), "sku_id": sim_window.sku_id, "opening_stock": "{:.0f}".format(sim_window.opening_stock), "demand": "{:.0f}".format(sim_window.demand), "closing_stock": "{:.0f}".format(sim_window.closing_stock), "delivery": "{:.0f}".format(sim_window.purchase_order_receipt_qty), "backlog": "{:.0f}".format(sim_window.backlog) } sim_collection.append([sim_dict]) self.assertEqual(len(sim_collection), 1)
def test_normal_distribution_mean(self): """ Verifies mean and variance for random normal distribution. """ # arrange app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) # act orders_analysis = model_inventory.analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = monte_carlo.SetupMonteCarlo(analysed_orders=orders_analysis.orders, period_length=1) for sku in orders_analysis.orders: item = sku.orders_summary() if item['sku'] == 'KR202-209': # assertd diff = abs( float(item['average_order']) - float(np.mean(sim.normal_random_distribution[0]['KR202-209'][0][0]))) self.assertLess(diff, float(item['standard_deviation']))
def test_po_raised_regex(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) po_regex = re.compile('[P][O] \d+') orders_analysis = analyse_orders_abcxyz_from_file( file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") sim = simulate.run_monte_carlo(orders_analysis=orders_analysis.orders, runs=1, period_length=12) for period in sim: if int(period[0].get("closing_stock")) == 0 and int( period[0].get("backlog")) > 0: self.assertRegex(period[0].get("po_raised"), expected_regex=po_regex, msg='True')
def test_build_window(self): app_dir = os.path.dirname(__file__, ) rel_path = 'supplychainpy/data2.csv' abs_file_path = os.path.abspath(os.path.join(app_dir, '..', rel_path)) orders_analysis = model_inventory.analyse_orders_abcxyz_from_file(file_path=abs_file_path, z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv") period_length = 12 sim_collection = [] for k in range(0, 1): simulation = monte_carlo.SetupMonteCarlo(analysed_orders=orders_analysis) random_demand = simulation.generate_normal_random_distribution(period_length=period_length) for sim_window in simulation.build_window(random_normal_demand=random_demand, period_length=period_length): sim_dict = {"index": "{:.0f}".format(sim_window.index), "period": "{:.0f}".format(sim_window.position), "sku_id": sim_window.sku_id, "opening_stock": "{:.0f}".format(sim_window.opening_stock), "demand": "{:.0f}".format(sim_window.demand), "closing_stock": "{:.0f}".format(sim_window.closing_stock), "delivery": "{:.0f}".format(sim_window.purchase_order_receipt_qty), "backlog": "{:.0f}".format(sim_window.backlog)} sim_collection.append([sim_dict]) self.assertEqual(len(sim_collection), 1)
def test_file_path_abcxyz_extension(self): with self.assertRaises(expected_exception=Exception): abc = model_inventory.analyse_orders_abcxyz_from_file(file_path='test.ts', z_value=Decimal(1.28), reorder_cost=Decimal(5000), file_type="csv")