def holts_trend_corrected_exponential_smoothing_forecast_from_file(file_path: str, file_type: str, length: int, alpha: float, gamma: float, **kwargs): item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row(raw_data, length)) elif file_type == FileFormats.csv.name: with open(file_path) as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv(raw_data, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get("sku_id"), sku.get("unit_cost"), sku.get( "lead_time"), sku.get("retail_price"), sku.get("quantity_on_hand") orders = [int(i) for i in sku.get("demand")] if kwargs['optimise']: log.log(logging.WARNING, "An OPTIMISED Holts trend exponential smoothing forecast has been completed for SKU {}.".format(sku_id)) yield {sku_id: holts_trend_corrected_exponential_smoothing_forecast(demand=orders, alpha=alpha, gamma=gamma, forecast_length=4, initial_period=18, optimise=True)} else: log.log(logging.WARNING, "A STANDARD Holts trend exponential smoothing forecast has been complete for SKU {}.".format(sku_id)) yield {sku_id: holts_trend_corrected_exponential_smoothing_forecast(demand=orders, alpha=alpha, gamma=gamma, forecast_length=4, initial_period=18, optimise=False)}
def setUp(self): self._data_set = { 'jan': 25, 'feb': 25, 'mar': 25, 'apr': 25, 'may': 25, 'jun': 25, 'jul': 75, 'aug': 75, 'sep': 75, 'oct': 75, 'nov': 75, 'dec': 75 } self._orders = [ 165, 171, 147, 143, 164, 160, 152, 150, 159, 169, 173, 203, 169, 166, 162, 147, 188, 161, 162, 169, 185, 188, 200, 229, 189, 218, 185, 199, 210, 193, 211, 208, 216, 218, 264, 304 ] self.ses_components = [ 'mape', 'regression', 'forecast', 'forecast_breakdown', 'alpha', 'statistics', 'standard_error', 'optimal_alpha' ] with open(ABS_FILE_PATH['COMPLETE_CSV_XSM'], 'r') as raw_data: self.item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=12) self.sku_id = [] for sku in self.item_list: self.sku_id.append(sku.get("sku_id"))
def _clean_file(file_type: str, file_path: str, interval_length: int) -> dict: """ Cleans-up csv and txt files and validates the format. Args: file_type (str): 'csv' or 'txt' file type. file_path (str) : Absolute path to file. interval_length (int): The number of periods included in raw data. Returns: dict: Sanitised source data. """ if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row( raw_data, interval_length)) return item_list elif file_type == FileFormats.csv.name: with open(file_path, 'r') as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=interval_length) return item_list else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file)
def setUp(self): self._data_set = { 'jan': 25, 'feb': 25, 'mar': 25, 'apr': 25, 'may': 25, 'jun': 25, 'jul': 75, 'aug': 75, 'sep': 75, 'oct': 75, 'nov': 75, 'dec': 75 } self._orders = [ 165, 171, 147, 143, 164, 160, 152, 150, 159, 169, 173, 203, 169, 166, 162, 147, 188, 161, 162, 169, 185, 188, 200, 229, 189, 218, 185, 199, 210, 193, 211, 208, 216, 218, 264, 304 ] self.ses_components = [ 'mape', 'regression', 'forecast', 'forecast_breakdown', 'alpha', 'statistics', 'standard_error', 'optimal_alpha' ] with open(ABS_FILE_PATH['COMPLETE_CSV_XSM'], 'r') as raw_data: self.item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=12) self.sku_id = [] for sku in self.item_list: self.sku_id.append(sku.get("sku_id")) self.ses_forecast = [ i for i in simple_exponential_smoothing_forecast_from_file( file_path=ABS_FILE_PATH['COMPLETE_CSV_XSM'], file_type='csv', length=12, smoothing_level_constant=0.5, optimise=True) ] self.keys = [list(i.keys()) for i in self.ses_forecast] self.unpack_keys = [i[0] for i in self.keys] self.htces_forecast = [ i for i in holts_trend_corrected_exponential_smoothing_forecast_from_file( file_path=ABS_FILE_PATH['COMPLETE_CSV_XSM'], file_type='csv', length=12, alpha=0.5, gamma=0.5, smoothing_level_constant=0.5, optimise=True) ] self.keys = [list(i.keys()) for i in self.htces_forecast] self.unpack_keys_htces = [i[0] for i in self.keys]
def simple_exponential_smoothing_forecast_from_file(file_path: str, file_type: str, length: int, smoothing_level_constant: float, forecast_length=5, **kwargs) -> dict: """ Args: file_path (str): file_type (str): length (int): smoothing_level_constant (int): forecast_length (int): **optimise (bool) Optimisation flag for exponential smoothing forecast. Returns: """ item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row(file=raw_data, length=length)) elif file_type == FileFormats.csv.name: with open(file_path) as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv(file=raw_data, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get("sku_id"), sku.get("unit_cost"), sku.get( "lead_time"), sku.get("retail_price"), sku.get("quantity_on_hand") orders = [int(i) for i in sku.get("demand")] if kwargs['optimise']: log.log(logging.WARNING, "An OPTIMISED simple exponential smoothing forecast has been completed for SKU {}.".format(sku_id)) yield {sku_id: simple_exponential_smoothing_forecast(demand=orders, forecast_length=forecast_length, smoothing_level_constant=smoothing_level_constant, optimise=True)} else: log.log(logging.WARNING, "A STANDARD simple exponential smoothing forecast has been completed for SKU {}.".format(sku_id)) yield {sku_id: simple_exponential_smoothing_forecast(demand=orders, forecast_length=forecast_length, smoothing_level_constant=smoothing_level_constant)}
def _clean_file(file_type: str, file_path: str, interval_length: int) -> dict: """ Cleans-up csv and txt files and validates the format. Args: file_type (str): 'csv' or 'txt' file type. file_path (str) : Absolute path to file. interval_length (int): The number of periods included in raw data. Returns: dict: Sanitised source data. """ if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row(raw_data, interval_length)) return item_list elif file_type == FileFormats.csv.name: with open(file_path, 'r') as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv(raw_data, length=interval_length) return item_list else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file)
def setUp(self): self._data_set = {'jan': 25, 'feb': 25, 'mar': 25, 'apr': 25, 'may': 25, 'jun': 25, 'jul': 75, 'aug': 75, 'sep': 75, 'oct': 75, 'nov': 75, 'dec': 75} self._orders = [165, 171, 147, 143, 164, 160, 152, 150, 159, 169, 173, 203, 169, 166, 162, 147, 188, 161, 162, 169, 185, 188, 200, 229, 189, 218, 185, 199, 210, 193, 211, 208, 216, 218, 264, 304] self.ses_components = ['mape', 'regression', 'forecast', 'forecast_breakdown', 'alpha', 'statistics' ] with open(ABS_FILE_PATH['COMPLETE_CSV_XSM'], 'r') as raw_data: self.item_list = _data_cleansing.clean_orders_data_row_csv(raw_data, length=12) self.sku_id = [] for sku in self.item_list: self.sku_id.append(sku.get("sku_id")) self.ses_forecast = [i for i in simple_exponential_smoothing_forecast_from_file( file_path=ABS_FILE_PATH['COMPLETE_CSV_XSM'], file_type='csv', length=12, smoothing_level_constant=0.5, optimise=True)] self.keys = [list(i.keys()) for i in self.ses_forecast] self.unpack_keys = [i[0] for i in self.keys] self.htces_forecast = [i for i in holts_trend_corrected_exponential_smoothing_forecast_from_file( file_path=ABS_FILE_PATH['COMPLETE_CSV_XSM'], file_type='csv', length=12, alpha=0.5, gamma=0.5, smoothing_level_constant=0.5, optimise=True)] self.keys = [list(i.keys()) for i in self.htces_forecast] self.unpack_keys_htces = [i[0] for i in self.keys]
def test_incorrect_row_length(self): """ Tests for incorrect specification of number of columns after initial SKU identification. """ with open(ABS_FILE_PATH['COMPLETE_CSV_XSM']) as f: for i in range(0, 11): with self.assertRaises(expected_exception=Exception): _data_cleansing.clean_orders_data_row_csv(f, length=i)
def holts_trend_corrected_exponential_smoothing_forecast_from_file( file_path: str, file_type: str, length: int, alpha: float, gamma: float, **kwargs) -> dict: """ Args: file_path: Path to source file. file_type: File type. length: Number of periods in data source (Jan..Dec = 12). alpha: gamma: **kwargs: Returns: """ item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row( raw_data, length)) elif file_type == FileFormats.csv.name: with open(file_path) as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get( "sku_id"), sku.get("unit_cost"), sku.get("lead_time"), sku.get( "retail_price"), sku.get("quantity_on_hand") orders = [int(i) for i in sku.get("demand")] if kwargs['optimise']: log.log( logging.WARNING, "An OPTIMISED Holts trend exponential smoothing forecast has been completed for SKU {}." .format(sku_id)) yield { sku_id: holts_trend_corrected_exponential_smoothing_forecast( demand=orders, alpha=alpha, gamma=gamma, forecast_length=4, initial_period=18, optimise=True) } else: log.log( logging.WARNING, "A STANDARD Holts trend exponential smoothing forecast has been complete for SKU {}." .format(sku_id)) yield { sku_id: holts_trend_corrected_exponential_smoothing_forecast( demand=orders, alpha=alpha, gamma=gamma, forecast_length=4, initial_period=18, optimise=False) }
def simple_exponential_smoothing_forecast_from_file( file_path: str, file_type: str, length: int, smoothing_level_constant: float = 0.5, forecast_length=5, optimise: bool = True) -> dict: """Performs a simple exponential smoothing forecast on historical demand from file using a generator. Args: file_path (str): Path to source file. file_type (str): File type. length (int): Number of periods in data source (Jan..Dec = 12). smoothing_level_constant (int): Alpha value for forecast. forecast_length (int): Number of periods to extend the forecast. optimise (bool): Optimisation flag for exponential smoothing forecast. Returns: dict: Simple exponential forecast. """ item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row( file=raw_data, length=length)) elif file_type == FileFormats.csv.name: with open(file_path) as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv( file=raw_data, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get( "sku_id"), sku.get("unit_cost"), sku.get("lead_time"), sku.get( "retail_price"), sku.get("quantity_on_hand") orders = [int(i) for i in sku.get("demand")] if optimise: log.log( logging.WARNING, "An OPTIMISED simple exponential smoothing forecast has been completed for SKU {}." .format(sku_id)) yield { sku_id: simple_exponential_smoothing_forecast( demand=orders, forecast_length=forecast_length, smoothing_level_constant=smoothing_level_constant, optimise=True) } else: log.log( logging.WARNING, "A STANDARD simple exponential smoothing forecast has been completed for SKU {}." .format(sku_id)) yield { sku_id: simple_exponential_smoothing_forecast( demand=orders, forecast_length=forecast_length, smoothing_level_constant=smoothing_level_constant) }
def analyse_orders_abcxyz_from_file(file_path: str, z_value: Decimal, reorder_cost: Decimal, file_type: str = FileFormats.text.name, period: str = "month", length: int = 12, currency: str = 'USD') -> list: """ Analyse orders data from file and returns ABCXYZ analysis Analyses orders data for a single sku, using the values from a file arranged in columns.The data should be arranged in two columns, 1 for the period and the other for the corresponding data-point. Args: file_path (str): The path to the file containing two columns of data, 1 period and 1 data-point for 1 sku. reorder_cost (Decimal): The average lead-time for the sku over the period represented by the data, in the same unit. length (int): The number of periods in the data-ser referenced from the second column of the row onwards. reorder_cost (Decimal): The cost to place a reorder. This is usually the cost of the operation divided by number of purchase orders placed in the previous period. z_value (Decimal): The service level required to calculate the safety stock file_type (str): Type of 'file csv' or 'text' period (str): The period of time the data points are bucketed into. currency (str): Returns: list: An AbcXyz class object is returned. Raises: Exception: Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter. Exception: Unspecified file type, Please specify 'csv' or 'text' for file_type parameter. Examples: >>> from decimal import Decimal >>> from supplychainpy.model_inventory import analyse_orders_from_file_col >>> from supplychainpy.sample_data.config import ABS_FILE_PATH >>> abc = 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") """ warnings.warn( 'Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning) analysed_orders_collection = [] item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row( raw_data, length)) elif file_type == FileFormats.csv.name: with open(file_path) as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: orders = {} sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get( "sku_id", "UNKNOWN_SKU"), sku.get("unit_cost"), sku.get( "lead_time"), sku.get("retail_price"), sku.get( "quantity_on_hand") orders['demand'] = sku.get("demand") total_orders = 0 if quantity_on_hand is None: quantity_on_hand = 0.0 for order in orders['demand']: total_orders += int(order) analysed_orders = analyse_uncertain_demand.UncertainDemand( orders=orders, sku=sku_id, lead_time=lead_time, unit_cost=unit_cost, reorder_cost=Decimal(reorder_cost), z_value=Decimal(z_value), retail_price=retail_price, quantity_on_hand=quantity_on_hand, currency=currency) average_orders = analysed_orders.average_orders reorder_quantity = analysed_orders.fixed_order_quantity eoq = economic_order_quantity.EconomicOrderQuantity( total_orders=float(total_orders), reorder_quantity=float(reorder_quantity), holding_cost=float(0.25), reorder_cost=float(reorder_cost), average_orders=average_orders, unit_cost=float(unit_cost)) analysed_orders.economic_order_qty = eoq.economic_order_quantity analysed_orders.economic_order_variable_cost = eoq.minimum_variable_cost analysed_orders_collection.append(analysed_orders) AbcXyz(analysed_orders_collection) return analysed_orders_collection
def analyse_orders_from_file_row(file_path: str, z_value: Decimal, reorder_cost: Decimal, retail_price: Decimal, file_type: str = FileFormats.text.name, period: str = "month", length: int = 12, currency: str = 'USD') -> list: """ Analyse multiple SKUs from a file with data arranged by row. Args: file_path (file): The path to the file containing two columns of data, 1 period and 1 data-point for 1 sku. reorder_cost (Decimal): The cost to place a reorder. This is usually the cost of the operation divided by number of purchase orders placed in the previous period. z_value (Decimal): The service level required to calculate the safety stock file_type (str): Type of 'file csv' or 'text' period (str): The period of time the data points are bucketed into. length (int): The length of the period. Returns: list: A list of summaries containint Raises: Exception: Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter. Exception: Unspecified file type, Please specify 'csv' or 'text' for file_type parameter. Examples: >>> from supplychainpy.model_inventory import analyse_orders_from_file_row >>> from supplychainpy.sample_data.config import ABS_FILE_PATH >>> analysed_data = analyse_orders_from_file_row(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], ... reorder_cost=Decimal(45), ... z_value=Decimal(1.28), ... file_type="csv", ... retail_price=Decimal(30), ... currency='USD') """ warnings.warn( 'Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning) orders = {} analysed_orders_summary = [] analysed_orders_collection = [] item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row( raw_data, length=length)) elif file_type == FileFormats.csv.name: with open(file_path, 'r') as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv( raw_data, length=length) else: unspecified_file = "Unspecified file type, Please specify 'csv' or 'text' for file_type parameter." raise Exception(unspecified_file) # maybe use an iterable instead of unpacking for constructor try: for sku in item_list: sku_id = sku.get("sku_id") unit_cost = sku.get("unit_cost") lead_time = sku.get("lead_time") quantity_on_hand = sku.get("quantity_on_hand") if quantity_on_hand is None: quantity_on_hand = 0.0 orders['demand'] = sku.get("demand") analysed_orders = analyse_uncertain_demand.UncertainDemand( orders=orders, sku=sku_id, lead_time=lead_time, unit_cost=unit_cost, reorder_cost=reorder_cost, z_value=z_value, retail_price=retail_price, quantity_on_hand=quantity_on_hand, currency=currency) analysed_orders_collection.append(analysed_orders) analysed_orders_summary.append(analysed_orders.orders_summary()) orders = {} del analysed_orders except KeyError: print("The csv file is incorrectly formatted") return analysed_orders_summary
def analyse_orders_abcxyz_from_file(file_path: str, z_value: Decimal, reorder_cost: Decimal, file_type: str = FileFormats.text.name, period: str = "month", length: int = 12, currency: str = 'USD') -> list: """ Analyse orders data from file and returns ABCXYZ analysis Analyses orders data for a single sku, using the values from a file arranged in columns.The data should be arranged in two columns, 1 for the period and the other for the corresponding data-point. Args: file_path (str): The path to the file containing two columns of data, 1 period and 1 data-point for 1 sku. reorder_cost (Decimal): The average lead-time for the sku over the period represented by the data, in the same unit. length (int): The number of periods in the data-ser referenced from the second column of the row onwards. reorder_cost (Decimal): The cost to place a reorder. This is usually the cost of the operation divided by number of purchase orders placed in the previous period. z_value (Decimal): The service level required to calculate the safety stock file_type (str): Type of 'file csv' or 'text' period (str): The period of time the data points are bucketed into. currency (str): Returns: list: An AbcXyz class object is returned. Raises: Exception: Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter. Exception: Unspecified file type, Please specify 'csv' or 'text' for file_type parameter. Examples: >>> from decimal import Decimal >>> from supplychainpy.model_inventory import analyse_orders_from_file_col >>> from supplychainpy.sample_data.config import ABS_FILE_PATH >>> abc = 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") """ warnings.warn('Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning) analysed_orders_collection = [] item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: f = open(file_path, 'r') item_list = (_data_cleansing.clean_orders_data_row(f, length)) elif file_type == FileFormats.csv.name: f = open(file_path) item_list = _data_cleansing.clean_orders_data_row_csv(f, length=length) else: incorrect_file = "Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter." raise Exception(incorrect_file) for sku in item_list: orders = {} sku_id, unit_cost, lead_time, retail_price, quantity_on_hand = sku.get("sku_id", "UNKNOWN_SKU"), sku.get( "unit_cost"), sku.get( "lead_time"), sku.get("retail_price"), sku.get("quantity_on_hand") orders['demand'] = sku.get("demand") total_orders = 0 if quantity_on_hand is None: quantity_on_hand = 0.0 for order in orders['demand']: total_orders += int(order) analysed_orders = analyse_uncertain_demand.UncertainDemand(orders=orders, sku=sku_id, lead_time=lead_time, unit_cost=unit_cost, reorder_cost=Decimal(reorder_cost), z_value=Decimal(z_value), retail_price=retail_price, quantity_on_hand=quantity_on_hand, currency=currency) average_orders = analysed_orders.average_orders reorder_quantity = analysed_orders.fixed_order_quantity eoq = economic_order_quantity.EconomicOrderQuantity(total_orders=float(total_orders), reorder_quantity=float(reorder_quantity), holding_cost=float(0.25), reorder_cost=float(reorder_cost), average_orders=average_orders, unit_cost=float(unit_cost)) analysed_orders.economic_order_qty = eoq.economic_order_quantity analysed_orders.economic_order_variable_cost = eoq.minimum_variable_cost analysed_orders_collection.append(analysed_orders) AbcXyz(analysed_orders_collection) return analysed_orders_collection
def analyse_orders_from_file_row(file_path: str, z_value: Decimal, reorder_cost: Decimal, retail_price: Decimal, file_type: str = FileFormats.text.name, period: str = "month", length: int = 12, currency: str = 'USD') -> list: """ Analyse multiple SKUs from a file with data arranged by row. Args: file_path (file): The path to the file containing two columns of data, 1 period and 1 data-point for 1 sku. reorder_cost (Decimal): The cost to place a reorder. This is usually the cost of the operation divided by number of purchase orders placed in the previous period. z_value (Decimal): The service level required to calculate the safety stock file_type (str): Type of 'file csv' or 'text' period (str): The period of time the data points are bucketed into. length (int): The length of the period. Returns: list: A list of summaries containint Raises: Exception: Incorrect file type specified. Please specify 'csv' or 'text' for the file_type parameter. Exception: Unspecified file type, Please specify 'csv' or 'text' for file_type parameter. Examples: >>> from supplychainpy.model_inventory import analyse_orders_from_file_row >>> from supplychainpy.sample_data.config import ABS_FILE_PATH >>> analysed_data = analyse_orders_from_file_row(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'], ... reorder_cost=Decimal(45), ... z_value=Decimal(1.28), ... file_type="csv", ... retail_price=Decimal(30), ... currency='USD') """ warnings.warn('Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning) orders = {} analysed_orders_summary = [] analysed_orders_collection = [] item_list = {} if check_extension(file_path=file_path, file_type=file_type): if file_type == FileFormats.text.name: with open(file_path, 'r') as raw_data: item_list = (_data_cleansing.clean_orders_data_row(raw_data, length=length)) elif file_type == FileFormats.csv.name: with open(file_path, 'r') as raw_data: item_list = _data_cleansing.clean_orders_data_row_csv(raw_data, length=length) else: unspecified_file = "Unspecified file type, Please specify 'csv' or 'text' for file_type parameter." raise Exception(unspecified_file) # maybe use an iterable instead of unpacking for constructor try: for sku in item_list: sku_id = sku.get("sku_id") unit_cost = sku.get("unit_cost") lead_time = sku.get("lead_time") quantity_on_hand = sku.get("quantity_on_hand") if quantity_on_hand is None: quantity_on_hand = 0.0 orders['demand'] = sku.get("demand") analysed_orders = analyse_uncertain_demand.UncertainDemand(orders=orders, sku=sku_id, lead_time=lead_time, unit_cost=unit_cost, reorder_cost=reorder_cost, z_value=z_value, retail_price=retail_price, quantity_on_hand=quantity_on_hand, currency=currency) analysed_orders_collection.append(analysed_orders) analysed_orders_summary.append(analysed_orders.orders_summary()) orders = {} del analysed_orders except KeyError: print("The csv file is incorrectly formatted") return analysed_orders_summary
def test_incorrect_row_length(self): """ Tests for incorrect specification of number of columns after initial SKU identification. """ with open(ABS_FILE_PATH['COMPLETE_CSV_SM']) as f: for i in range(0, 11): with self.assertRaises(expected_exception=Exception): _data_cleansing.clean_orders_data_row_csv(f, length=i)