Ejemplo n.º 1
0
    def test_db_stat_time(self):
        DAY_MIN = 24 * 60 * 60

        board = PriceBoardDB()

        start_time, end_time = board.start_time()

        start_midnight = (int(start_time / (DAY_MIN)) + 1) * DAY_MIN
        end_midnight = (int(end_time / (DAY_MIN))) * DAY_MIN -1

        print(start_time, end_time, start_midnight, end_midnight)

        if(start_time < start_midnight and end_midnight < end_time):
            print('good data')
            # todo do something

        width = end_midnight - start_midnight

        time  = start_midnight
        while time < end_midnight:
            file = (int(time/60)*60)

            if file == time:
                file_path = date_string(file, '/')
                print(file_path, time_stamp_string(time))

            time += 1
Ejemplo n.º 2
0
    def test_get_positoin(self):
        board = PriceBoardDB()
        board.set_origin_time(1000)
        board.set_center_price(1000)

        x, y = board.get_position(999, 1000.5)
        self.assertEqual(x, 1)
        self.assertEqual(y, 17)

        x, y = board.get_position(1000, 1000)
        self.assertEqual(x,0)
        self.assertEqual(y, 16)
Ejemplo n.º 3
0
    def test_calc_variance(self):
        a = np.array([[0.1, 0, 0, 0, 1],
                     [0, 0, 1, 0, 2],
                     [0, 0, 1, 0, 3],
                     [0, 0, 0, 0, 4]])

        print(a)

        non_zero_count = np.nonzero(a)[0].size
        sum_a   = np.sum(a)
        mean = sum_a/non_zero_count

        print("average", sum_a/non_zero_count, sum_a, non_zero_count)

        b = np.square(a)
        square_sum_a = np.sum(b)

        print("square average", square_sum_a/non_zero_count, square_sum_a, non_zero_count)

        s = square_sum_a/non_zero_count - (sum_a/non_zero_count)**2

        # standard dev(non zero factor only)
        print(s**0.5)

        board = PriceBoardDB()
        mean2, stddev2 = board.calc_static(a)
        self.assertEqual(mean, mean2)
        self.assertEqual(s**0.5, stddev2)

        # clipping 3
        c = np.clip(a, 0, 3)
        print(c)

        d = np.ceil(a)
        print(d)

        e = (a / 3)*255
        f = np.ceil(np.clip(e, 0, 255))
        print(f)

        g = f.astype('uint8')

        print(g)
Ejemplo n.º 4
0
    def test_load_tf_record(self):
        board = PriceBoardDB()

        board.load_tf_record()
Ejemplo n.º 5
0
    def test_save_tf_record(self):
        board = PriceBoardDB()

        board.normalize()

        board.save_tf_record()
Ejemplo n.º 6
0
    def test_save(self):
        board = PriceBoardDB()

        board.save("/tmp/boarddump.npz")
Ejemplo n.º 7
0
 def test_current_time(self):
     board = PriceBoardDB()
     board.set_origin_time(1000)
     time = board.get_origin_time()
     self.assertEqual(1000, time)
Ejemplo n.º 8
0
 def test_set_center_price(self):
     PRICE = 4000.5
     board = PriceBoardDB()
     board.set_center_price(PRICE)
     price = board.get_center_price()
     self.assertEqual(price, PRICE)