Ejemplo n.º 1
0
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)}
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
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)}
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
            }
Ejemplo n.º 6
0
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)
            }
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
def analyse_orders_from_file_col(file_path,
                                 sku_id: str,
                                 lead_time: Decimal,
                                 unit_cost: Decimal,
                                 reorder_cost: Decimal,
                                 z_value: Decimal,
                                 retail_price: Decimal,
                                 file_type: str = FileFormats.text.name,
                                 period: str = PeriodFormats.months.name,
                                 currency='USD') -> dict:
    """ Analyse orders from file arranged in a single column.

    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.
        sku_id (str):                 The unique id of the sku.
        lead_time (Decimal):          The average lead-time for the sku over the period represented by the data, in the same unit.
        unit_cost (Decimal):          The unit cost of the sku to the organisation.
        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
        retail_price (Decimal):       The price at which the sku is retailed.
        file_type (str):              Type of 'file csv' or 'text'
        period (int):                 The period of time the data points are bucketed into.
        currency (str):               The currency of the source data.

    Returns:
        dict:   The summary of the analysis.

                `{'ABC_XYZ_Classification': 'AX', 'reorder_quantity': '258', 'revenue': '2090910.44',
                'average_order': '539', 'reorder_level': '813', 'economic_order_quantity': '277', 'sku': 'RR381-33',
                'demand_variability': '0.052', 'economic_order_variable_cost': '29557.61',
                'standard_deviation': '28', 'safety_stock': '51'}`

    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
    >>> # text file
    >>> RX9304_43_analysis_txt = analyse_orders_from_file_col(file_path=ABS_FILE_PATH['PARTIAL_COL_TXT_SM'],
    ...                                                   sku_id='RX9304-43',
    ...                                                   lead_time=Decimal(2),
    ...                                                   unit_cost=Decimal(400),
    ...                                                   reorder_cost=Decimal(45),
    ...                                                   z_value=Decimal(1.28),
    ...                                                   file_type='text',
    ...                                                   retail_price=Decimal(30))
    >>> #csv file
    >>> RX9304_43_analysis_csv = analyse_orders_from_file_col(ABS_FILE_PATH['PARTIAL_COL_CSV_SM'], 'RX9304-43',
    ...                                                     reorder_cost=Decimal(45),
    ...                                                     unit_cost=Decimal(400),
    ...                                                     lead_time=Decimal(45),
    ...                                                     z_value=Decimal(1.28),
    ...                                                     file_type="csv",
    ...                                                     retail_price=Decimal(30))


    """
    orders = {}
    file_type_processed = ''
    # warnings.warn('Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning)
    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:
                orders = _data_cleansing.clean_orders_data_col_txt(raw_data)
            file_type_processed = 'txt'
        elif file_type == FileFormats.csv.name:
            with open(file_path) as raw_data:
                orders = _data_cleansing.clean_orders_data_col_csv(raw_data)
            file_type_processed = 'csv'
    else:
        raise Exception(
            'Unspecified file type, Please specify \'csv\' or \'text\' for file_type parameter.'
        )

    d = 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,
                                                 period=period,
                                                 retail_price=retail_price,
                                                 currency=currency)
    log.debug('Raw data columnar from {} analysed'.format(file_type_processed))

    return d.orders_summary()
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
def analyse_orders_from_file_col(file_path, sku_id: str, lead_time: Decimal, unit_cost: Decimal,
                                 reorder_cost: Decimal, z_value: Decimal, retail_price: Decimal,
                                 file_type: str = FileFormats.text.name,
                                 period: str = PeriodFormats.months.name, currency='USD') -> dict:
    """ Analyse orders from file arranged in a single column.

    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.
        sku_id (str):                 The unique id of the sku.
        lead_time (Decimal):          The average lead-time for the sku over the period represented by the data, in the same unit.
        unit_cost (Decimal):          The unit cost of the sku to the organisation.
        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
        retail_price (Decimal):       The price at which the sku is retailed.
        file_type (str):              Type of 'file csv' or 'text'
        period (int):                 The period of time the data points are bucketed into.
        currency (str):               The currency of the source data.

    Returns:
        dict:   The summary of the analysis.

                `{'ABC_XYZ_Classification': 'AX', 'reorder_quantity': '258', 'revenue': '2090910.44',
                'average_order': '539', 'reorder_level': '813', 'economic_order_quantity': '277', 'sku': 'RR381-33',
                'demand_variability': '0.052', 'economic_order_variable_cost': '29557.61',
                'standard_deviation': '28', 'safety_stock': '51'}`

    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
    >>> # text file
    >>> RX9304_43_analysis_txt = analyse_orders_from_file_col(file_path=ABS_FILE_PATH['PARTIAL_COL_TXT_SM'],
    ...                                                   sku_id='RX9304-43',
    ...                                                   lead_time=Decimal(2),
    ...                                                   unit_cost=Decimal(400),
    ...                                                   reorder_cost=Decimal(45),
    ...                                                   z_value=Decimal(1.28),
    ...                                                   file_type='text',
    ...                                                   retail_price=Decimal(30))
    >>> #csv file
    >>> RX9304_43_analysis_csv = analyse_orders_from_file_col(ABS_FILE_PATH['PARTIAL_COL_CSV_SM'], 'RX9304-43',
    ...                                                     reorder_cost=Decimal(45),
    ...                                                     unit_cost=Decimal(400),
    ...                                                     lead_time=Decimal(45),
    ...                                                     z_value=Decimal(1.28),
    ...                                                     file_type="csv",
    ...                                                     retail_price=Decimal(30))


    """
    orders = {}
    file_type_processed = ''
    # warnings.warn('Analyse orders function has been deprecated. Please use the analyse function', DeprecationWarning)
    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:
                orders = _data_cleansing.clean_orders_data_col_txt(raw_data)
            file_type_processed = 'txt'
        elif file_type == FileFormats.csv.name:
            with open(file_path) as raw_data:
                orders = _data_cleansing.clean_orders_data_col_csv(raw_data)
            file_type_processed = 'csv'
    else:
        raise Exception('Unspecified file type, Please specify \'csv\' or \'text\' for file_type parameter.')

    d = 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,
                                                 period=period, retail_price=retail_price, currency=currency)
    log.debug('Raw data columnar from {} analysed'.format(file_type_processed))

    return d.orders_summary()