Exemplo n.º 1
0
    def test_5(self):
        test_data = [[0, {}], [10, {
            0: 200
        }], [20, {
            0: 190
        }], [30, {
            0: 150
        }], [40, {
            0: 40,
            1: 100
        }], [55, {
            1: 80
        }], [70, {
            0: 40,
            1: 40
        }], [85, {
            1: 20
        }], [100, {
            0: 40,
            1: 40
        }], [110, {
            0: 120,
            1: 100
        }], [120, {
            0: 170
        }], [130, {}], [150, {}]]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 4)
        self.assertEqual(len(interactions[0].records), 4)
        self.assertEqual(len(interactions[1].records), 1)
        self.assertEqual(len(interactions[2].records), 3)
        self.assertEqual(len(interactions[3].records), 6)
Exemplo n.º 2
0
 def __init__(self, params):
     self.params = params
     self._interaction_splitter = InteractionSplitter(self.params)
     if self.params.use_nn_estimator:
         self._event_type_determiner = NNEventTypeDeterminer(self.params)
     else:
         self._event_type_determiner = HeuristicsEventTypeDeterminer(
             self.params)
Exemplo n.º 3
0
    def test_9(self):
        test_data = [
            [0, {}],
            [10, {
                0: 200
            }],
            [20, {
                0: 190
            }],
            [30, {
                0: 150
            }],
            [35, {}],
            [40, {
                0: 40
            }],
            [50, {
                0: 40
            }],
            [60 + self.params.session_timeout, {
                0: 40
            }],
            [70 + self.params.session_timeout, {
                0: 120
            }],
            [80 + self.params.session_timeout, {
                0: 170
            }],
            [90 + self.params.session_timeout, {
                0: 180
            }],
            [100 + self.params.session_timeout, {
                0: 200
            }],
        ]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 2)
        self.assertEqual(len(interactions[0].records), 6)
        self.assertEqual(len(interactions[1].records), 5)

        self.assertEqual(interactions[0].time_before_next_interaction,
                         60 + self.params.session_timeout - 50)
        self.assertEqual(interactions[1].time_before_next_interaction,
                         sys.maxint)
Exemplo n.º 4
0
    def test_11(self):
        test_data = [
            [10, {
                0: 200
            }],
            [20, {
                0: 190
            }],
            [30, {
                0: 150
            }],
            [50, {}],
        ]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 1)
        self.assertEqual(len(interactions[0].records), 3)
        self.assertEqual(interactions[0].time_before_next_interaction, 20)
Exemplo n.º 5
0
    def test_3(self):
        test_data = [
            [0, {}],
            [10, {
                0: 200
            }],
            [20, {
                0: 190
            }],
            [30, {
                0: 150
            }],
            [40, {
                0: 40
            }],
            ###############
            [70, {
                0: 40
            }],
            ###############
            [100, {
                0: 40
            }],
            [110, {
                0: 120
            }],
            [120, {
                0: 170
            }],
            [130, {
                0: 180
            }],
            [140, {
                0: 200
            }],
        ]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 3)
        self.assertEqual(len(interactions[0].records), 4)
        self.assertEqual(len(interactions[1].records), 1)
        self.assertEqual(len(interactions[2].records), 5)
Exemplo n.º 6
0
    def test_8(self):
        test_data = [
            [0, {}],
            [10, {
                0: 200
            }],
            [20, {
                0: 190
            }],
            [30, {
                0: 150
            }],
            [40, {
                0: 40
            }],
            [50, {
                0: 40
            }],
            [self.params.session_timeout / 2, {}],
            [60 + self.params.session_timeout, {
                0: 40
            }],
            [70 + self.params.session_timeout, {
                0: 120
            }],
            [80 + self.params.session_timeout, {
                0: 170
            }],
            [90 + self.params.session_timeout, {
                0: 180
            }],
            [100 + self.params.session_timeout, {
                0: 200
            }],
        ]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 2)
        self.assertEqual(len(interactions[0].records), 5)
        self.assertEqual(len(interactions[0].records), 5)
Exemplo n.º 7
0
    def test_1(self):
        test_data = [
            [0, {}],
            [10, {
                0: 200
            }],
            [20, {
                0: 190
            }],
            [30, {
                0: 150
            }],
            [40, {
                0: 40
            }],
            [50, {
                0: 40
            }],
            [60, {
                0: 40
            }],
            [70, {
                0: 120
            }],
            [80, {
                0: 170
            }],
            [90, {
                0: 180
            }],
            [100, {
                0: 200
            }],
        ]

        splitter = InteractionSplitter(self.params)
        interactions = list(splitter(map(self.format_rec, test_data)))
        self.assertEqual(len(interactions), 1)
        self.assertEqual(len(interactions[0].records), 10)