testPlot.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 ChannelCumPainter
  38. start_time = int(time.time()) - 10 * 86400 - 3600
  39. end_time = int(time.time()) - 8 * 86400
  40. painter = ChannelCumPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6})
  41. painter.paint()
  42. def test_chcov(self):
  43. from refill import ChannelCovPainter
  44. start_time = int(time.time()) - 10 * 86400 - 3600
  45. end_time = int(time.time()) - 10 * 86400
  46. painter = ChannelCovPainter(start_time=start_time, end_time=end_time, chnames=set(), card_types={4, 5, 6},filter_wave=3600)
  47. painter.paint()
  48. def testDays(self):
  49. from refill import MerchantReader
  50. from refill import ChannelReader
  51. try:
  52. chreader = ChannelReader()
  53. chdays = chreader.days()
  54. xlables = [time.strftime('%d-%H:%M:%S', time.localtime(d)) for d in chdays]
  55. print(xlables)
  56. reader = MerchantReader()
  57. days = reader.days()
  58. except Exception as ex:
  59. log.error(ex)
  60. pass
  61. def test_jsonLoads(self):
  62. import json
  63. try:
  64. str = 4
  65. x = json.loads(str)
  66. print(x)
  67. except Exception as ex:
  68. print(ex)
  69. def test_partial(self):
  70. from functools import partial
  71. add_five = partial()
  72. def test_key(self):
  73. def person(name, age, *, city, job):
  74. print(name, age, city, job)
  75. person('Jack', 24, city='Beijing', job='Engineer')
  76. person('Jack', 24, 'Beijing', job='Engineer')
  77. person('Jack', 24, 'Beijing', 'Engineer')
  78. def test_none(self):
  79. x = None
  80. len = len(x)
  81. print(len)
  82. def test_set(self):
  83. x = set([(4, 50), (4, 100)])
  84. y = set([(4, 50), (5, 100)])
  85. z = x | y
  86. print(z)
  87. def test_env(self):
  88. import os
  89. x = os.getenv("PYCHARM_DISPLAY_PORT", "-1")
  90. print(x)
  91. def test_matplot(self):
  92. import matplotlib
  93. x = matplotlib.__version__
  94. print(x)
  95. def test_time(self):
  96. x = int(time.time())
  97. print(x)
  98. def test_rpop(self):
  99. import redis
  100. import json
  101. pool = redis.ConnectionPool(host=self.__redis_host, port=6379, db=0)
  102. r = redis.Redis(connection_pool=pool)
  103. item = r.rpop('REFILL_MONITOR_QUEUE')
  104. if item is None:
  105. print('hello')
  106. else:
  107. try:
  108. val = json.loads(item)
  109. method = val['method']
  110. params = val['params']
  111. print(method, params)
  112. except Exception as ex:
  113. log.error(ex)
  114. def test_consumer(self):
  115. from refill import WriterConsumer
  116. class PrintHandler:
  117. def write(self, method, msg):
  118. log.debug(msg)
  119. time.sleep(0.01)
  120. handler = PrintHandler()
  121. consumer = WriterConsumer(handler,'PrintHandler')
  122. consumer.start()
  123. for i in range(100000):
  124. consumer.put('test', f'index = {i}')
  125. consumer.quit()
  126. consumer.join()
  127. def test_merge(self):
  128. from collections import defaultdict
  129. import time as time
  130. def merge(l,r):
  131. for name,ls in l.items():
  132. if name in r:
  133. ls.extend(r[name])
  134. k = set(ls)
  135. r[name] = list(k)
  136. else:
  137. r[name] = ls
  138. return r
  139. all = defaultdict(list)
  140. a = {'yunchonggongfs': [(4, 100), (4, 30), (4, 50)]}
  141. b = {'yunchonggongfs': [(4, 100), (4, 200), (4, 50)]}
  142. all = merge(a,all)
  143. all = merge(b,all)
  144. x = 0;
  145. if __name__ == '__main__':
  146. unittest.main()