示例#1
0
    def setUp(self):
        self._states = (
            'EXCESS_RANK',
            'SHORTAGE_RANK',
            'TRAFFIC_LIGHT',
            'CLASSIFICATION',
            'FORECAST',
            'RECOMMENDATION',
            'INVENTORY_TURNS',
            'START'
            )

        self.orders_analysis = model_inventory.analyse(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'],
                                                       z_value=Decimal(1.28),
                                                       reorder_cost=Decimal(5000),
                                                       file_type='csv',
                                                       length=12,
                                                       currency='USD')

        self.forecast = deserialise_config(ABS_FILE_PATH['FORECAST_PICKLE'])

        self.recommend = SkuMachine()
        self.states = SKUStates(analysed_orders=self.orders_analysis, forecast=self.forecast)
        self.recommend.add_state("start", self.states.initialise_machine)
        self.recommend.add_state("excess_rank", self.states.excess_rank)
        self.recommend.add_state("shortage_rank", self.states.shortage_rank)
        self.recommend.add_state("inventory_turns", self.states.inventory_turns)
        self.recommend.add_state("classification", self.states.classification)
        self.recommend.add_state("traffic_light", self.states.traffic_light)
        self.recommend.add_state("forecast", self.states.forecast)
        self.recommend.add_state("recommendation", self.recommend, end_state=1)
        self.recommend.set_start("start")
示例#2
0
    def setUp(self):
        self.STATES = ('EXCESS_RANK', 'SHORTAGE_RANK', 'TRAFFIC_LIGHT', 'CLASSIFICATION', 'FORECAST', 'RECOMMENDATION',
                       'INVENTORY_TURNS', 'START')

        self.orders_analysis = model_inventory.analyse(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'],
                                                       z_value=Decimal(1.28),
                                                       reorder_cost=Decimal(5000),
                                                       file_type="csv",
                                                       length=12)

        self.forecast = deserialise_config(ABS_FILE_PATH['FORECAST_PICKLE'])

        self.recommend = SkuMachine()
        self.states = SKUStates(analysed_orders=self.orders_analysis, forecast=self.forecast)
        self.recommend.add_state("start", self.states.initialise_machine)
        self.recommend.add_state("excess_rank", self.states.excess_rank)
        self.recommend.add_state("shortage_rank", self.states.shortage_rank)
        self.recommend.add_state("inventory_turns", self.states.inventory_turns)
        self.recommend.add_state("classification", self.states.classification)
        self.recommend.add_state("traffic_light", self.states.traffic_light)
        self.recommend.add_state("forecast", self.states.forecast)
        self.recommend.add_state("recommendation", self.recommend, end_state=1)
        self.recommend.set_start("start")
示例#3
0
def run_sku_recommendation(analysed_orders: UncertainDemand,
                           forecast: dict) -> dict:
    """ Runs SKU recommendation state machine and generates recommendations for each sku.

    Args:
        analysed_orders (UncertainDemand):  Analysed Orders.
        forecast (dict):                    forecast.

    Returns:
        dict:   Recommendations for each sku.

    """
    recommend = SkuMachine()
    states = SKUStates(analysed_orders=analysed_orders, forecast=forecast)
    recommend.add_state("start", states.initialise_machine)
    recommend.add_state("excess_rank", states.excess_rank)
    recommend.add_state("shortage_rank", states.shortage_rank)
    recommend.add_state("inventory_turns", states.inventory_turns)
    recommend.add_state("classification", states.classification)
    recommend.add_state("traffic_light", states.traffic_light)
    recommend.add_state("forecast", states.forecast)
    recommend.add_state("recommendation", recommend, end_state=1)
    recommend.set_start("start")
    for sku in analysed_orders:
        recommend.run(sku.sku_id)
    return deserialise_config(ABS_FILE_PATH['RECOMMENDATION_PICKLE'])
示例#4
0
class TestRecommendations(TestCase):
    def setUp(self):
        self.STATES = ('EXCESS_RANK', 'SHORTAGE_RANK', 'TRAFFIC_LIGHT', 'CLASSIFICATION', 'FORECAST', 'RECOMMENDATION',
                       'INVENTORY_TURNS', 'START')

        self.orders_analysis = model_inventory.analyse(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'],
                                                       z_value=Decimal(1.28),
                                                       reorder_cost=Decimal(5000),
                                                       file_type="csv",
                                                       length=12)

        self.forecast = deserialise_config(ABS_FILE_PATH['FORECAST_PICKLE'])

        self.recommend = SkuMachine()
        self.states = SKUStates(analysed_orders=self.orders_analysis, forecast=self.forecast)
        self.recommend.add_state("start", self.states.initialise_machine)
        self.recommend.add_state("excess_rank", self.states.excess_rank)
        self.recommend.add_state("shortage_rank", self.states.shortage_rank)
        self.recommend.add_state("inventory_turns", self.states.inventory_turns)
        self.recommend.add_state("classification", self.states.classification)
        self.recommend.add_state("traffic_light", self.states.traffic_light)
        self.recommend.add_state("forecast", self.states.forecast)
        self.recommend.add_state("recommendation", self.recommend, end_state=1)
        self.recommend.set_start("start")

    def test_add_states(self):
        self.assertEqual(8, len(self.recommend.handlers))

    def test_add_states_key(self):
        for state in self.recommend.handlers.keys():
            self.assertIn(state, self.STATES)

    def test_recommendations(self):
        completed_recommendations =[]
        for sku in self.orders_analysis:
            completed_recommendations.append(self.recommend.run(sku.sku_id))
        self.assertEqual(len(completed_recommendations), len(self.orders_analysis))

    def test_recommendations_coverage(self):
        completed_recommendations =[]
        sku_ids = [i.sku_id for i in self.orders_analysis]
        for sku in self.orders_analysis:
            completed_recommendations.append(self.recommend.run(sku.sku_id)[1])
        for i in completed_recommendations:
            self.assertIn(i, sku_ids)
示例#5
0
class TestRecommendations(TestCase):
    """A class for testing the Recommendations generator for reporting"""
    def setUp(self):
        self._states = (
            'EXCESS_RANK',
            'SHORTAGE_RANK',
            'TRAFFIC_LIGHT',
            'CLASSIFICATION',
            'FORECAST',
            'RECOMMENDATION',
            'INVENTORY_TURNS',
            'START'
            )

        self.orders_analysis = model_inventory.analyse(file_path=ABS_FILE_PATH['COMPLETE_CSV_SM'],
                                                       z_value=Decimal(1.28),
                                                       reorder_cost=Decimal(5000),
                                                       file_type='csv',
                                                       length=12,
                                                       currency='USD')

        self.forecast = deserialise_config(ABS_FILE_PATH['FORECAST_PICKLE'])

        self.recommend = SkuMachine()
        self.states = SKUStates(analysed_orders=self.orders_analysis, forecast=self.forecast)
        self.recommend.add_state("start", self.states.initialise_machine)
        self.recommend.add_state("excess_rank", self.states.excess_rank)
        self.recommend.add_state("shortage_rank", self.states.shortage_rank)
        self.recommend.add_state("inventory_turns", self.states.inventory_turns)
        self.recommend.add_state("classification", self.states.classification)
        self.recommend.add_state("traffic_light", self.states.traffic_light)
        self.recommend.add_state("forecast", self.states.forecast)
        self.recommend.add_state("recommendation", self.recommend, end_state=1)
        self.recommend.set_start("start")

    def test_add_states(self):
        """Checks length of loaded states"""
        self.assertEqual(8, len(self.recommend.handlers))

    def test_add_states_key(self):
        """Checks all states are present"""
        for state in self.recommend.handlers.keys():
            self.assertIn(state, self._states)

    def test_recommendations(self):
        """Checks recommendations generated"""
        completed_recommendations = []
        for sku in self.orders_analysis:
            completed_recommendations.append(self.recommend.run(sku.sku_id))
        self.assertEqual(len(completed_recommendations), len(self.orders_analysis))

    def test_recommendations_coverage(self):
        """Checks coverage of recommendations"""
        completed_recommendations = []
        sku_ids = [i.sku_id for i in self.orders_analysis]
        for sku in self.orders_analysis:
            completed_recommendations.append(self.recommend.run(sku.sku_id)[1])
        for i in completed_recommendations:
            self.assertIn(i, sku_ids)
def run_sku_recommendation(analysed_orders:UncertainDemand, forecast: dict)->dict:
    """ Runs SKU recommendation state machine and generates recommendations for each sku.

    Args:
        analysed_orders (UncertainDemand):  Analysed Orders.
        forecast (dict):                    forecast.

    Returns:
        dict:   Recommendations for each sku.

    """
    recommend = SkuMachine()
    states = SKUStates(analysed_orders=analysed_orders, forecast=forecast)
    recommend.add_state("start", states.initialise_machine)
    recommend.add_state("excess_rank", states.excess_rank)
    recommend.add_state("shortage_rank", states.shortage_rank)
    recommend.add_state("inventory_turns", states.inventory_turns)
    recommend.add_state("classification", states.classification)
    recommend.add_state("traffic_light", states.traffic_light)
    recommend.add_state("forecast", states.forecast)
    recommend.add_state("recommendation", recommend, end_state=1)
    recommend.set_start("start")
    for sku in analysed_orders:
        recommend.run(sku.sku_id)
    return deserialise_config(ABS_FILE_PATH['RECOMMENDATION_PICKLE'])