testPlot.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import time
  2. import unittest
  3. import logging
  4. from refill import time_border
  5. logging.basicConfig(filename='/var/www/html/data/log/qreader.log', level=logging.DEBUG)
  6. log = logging.getLogger('reader')
  7. class MyTestCase(unittest.TestCase):
  8. # __redis_host = '192.168.3.104'
  9. __redis_host = '192.168.3.46'
  10. def test_something(self):
  11. self.assertEqual(True, False) # add assertion here
  12. def test_listener(self):
  13. try:
  14. from refill import queueListener
  15. queueListener.set_redis(self.__redis_host,'6379')
  16. queueListener.prepare_data()
  17. except Exception as ex:
  18. log.error(ex)
  19. pass
  20. def test_timestart(self):
  21. stamp = int(time.time())
  22. for i in range(300):
  23. x = stamp + i
  24. l = time_border(300,x,True)
  25. r = time_border(300,x,False)
  26. print('l=',l,'r=',r)
  27. def testChannel(self):
  28. from refill import ChannelReader
  29. reader = ChannelReader()
  30. days = reader.days()
  31. print('days=',days)
  32. for day in days:
  33. x = reader.tuple_path(day, card_types={4, 5, 6})
  34. x1 = reader.tuple_path(day, {'chizeng', 'ainika'}, {4, 5, 6})
  35. x2 = reader.tuple_path(day, {'chizeng', 'ainika'}, {4, 5, 6}, 50)
  36. def test_chpainter(self):
  37. from refill import ChannelPainter
  38. start_time = int(time.time()) - 2 * 86400 - 3600
  39. end_time = int(time.time()) - 2 * 86400
  40. # painter = ChannelPainter(start_time=start_time, end_time=end_time, interval=300, chnames={'chizeng', 'ainika'}, card_types={4, 5, 6})
  41. painter = ChannelPainter(start_time=start_time, end_time=end_time, interval=300, chnames=set(), card_types={4, 5, 6})
  42. painter.paint()
  43. def testDays(self):
  44. from refill import MerchantReader
  45. from refill import ChannelReader
  46. try:
  47. chreader = ChannelReader()
  48. chdays = chreader.days()
  49. xlables = [time.strftime('%d-%H:%M:%S', time.localtime(d)) for d in chdays]
  50. print(xlables)
  51. reader = MerchantReader()
  52. days = reader.days()
  53. except Exception as ex:
  54. log.error(ex)
  55. pass
  56. def test_jsonLoads(self):
  57. import json
  58. try:
  59. str = 4
  60. x = json.loads(str)
  61. print(x)
  62. except Exception as ex:
  63. print(ex)
  64. def test_partial(self):
  65. from functools import partial
  66. add_five = partial()
  67. def test_key(self):
  68. def person(name, age, *, city, job):
  69. print(name, age, city, job)
  70. person('Jack', 24, city='Beijing', job='Engineer')
  71. person('Jack', 24, 'Beijing', job='Engineer')
  72. person('Jack', 24, 'Beijing', 'Engineer')
  73. def test_none(self):
  74. x = None
  75. len = len(x)
  76. print(len)
  77. def test_set(self):
  78. x = set([(4,50),(4,100)])
  79. y = set([(4,50),(5,100)])
  80. z = x | y
  81. print(z)
  82. def test_env(self):
  83. import os
  84. x = os.getenv("PYCHARM_DISPLAY_PORT", "-1")
  85. print(x)
  86. def test_matplot(self):
  87. import matplotlib
  88. x = matplotlib.__version__
  89. print(x)
  90. def test_time(self):
  91. x = int(time.time())
  92. print(x)
  93. def test_rpop(self):
  94. import redis
  95. import json
  96. pool = redis.ConnectionPool(host=self.__redis_host, port=6379, db=0)
  97. r = redis.Redis(connection_pool=pool)
  98. item = r.rpop('REFILL_MONITOR_QUEUE')
  99. if item is None:
  100. print('hello')
  101. else:
  102. try:
  103. val = json.loads(item)
  104. method = val['method']
  105. params = val['params']
  106. print(method,params)
  107. except Exception as ex:
  108. log.error(ex)
  109. def test_consumer(self):
  110. from refill import WriterConsumer
  111. class PrintHandler:
  112. def write(self,msg):
  113. log.debug(msg)
  114. handler = PrintHandler()
  115. consumer = WriterConsumer(handler)
  116. consumer.start()
  117. for i in range(1000000):
  118. consumer.put(f'index = {i}')
  119. consumer.quit()
  120. consumer.join()
  121. if __name__ == '__main__':
  122. unittest.main()