thdf5.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. import unittest
  2. import redis
  3. import h5py
  4. import time
  5. from datetime import timedelta
  6. import re
  7. import numpy as np
  8. from DataCenter import dataCenter
  9. from MchDataCenter import mchDataCenter
  10. from SpeedDataCenter import speedDataCenter
  11. from PIL import Image
  12. import json
  13. import logging
  14. logging.basicConfig(filename='/var/www/html/data/log/qreader.log',
  15. format='%(levelname)10s %(asctime)s %(name)10s %(thread)d %(message)s',
  16. level=logging.INFO)
  17. log = logging.getLogger('starter')
  18. class DataTest(unittest.TestCase):
  19. # __redis_host = '192.168.3.104'
  20. __redis_host = '192.168.3.46'
  21. def test_parase(self):
  22. try:
  23. dataCenter.parase('succ-lingzh-1-4-50-1618184676', '1')
  24. except Exception as ex:
  25. print(ex)
  26. # docker-compose up pythoncli python -m unittest thdf5.DataTest.test_predata
  27. def test_predata(self):
  28. try:
  29. dataCenter.prepare_data()
  30. except Exception as ex:
  31. print(ex)
  32. def test_connect(self):
  33. pool = redis.ConnectionPool(host='121.89.223.81', port=57649, db=0)
  34. r = redis.Redis(connection_pool=pool)
  35. for item in r.hscan_iter('nc_channel_monitor_commit'):
  36. key = item[0]
  37. val = item[1]
  38. print(str(key, encoding="utf-8"), str(val, encoding="utf-8"))
  39. def test_regex(self):
  40. text = 'succm-lingzh-1-4-30-1618291260'
  41. result = re.split(r'-', text)
  42. pass
  43. def day(self, time):
  44. pass
  45. def test_today(self):
  46. stamp = 1617908681
  47. stamp = int(stamp)
  48. x = time.gmtime(stamp + 8 * 3600)
  49. diff = timedelta(hours=x.tm_hour, minutes=x.tm_min, seconds=x.tm_sec)
  50. today = stamp - diff.total_seconds()
  51. y = stamp - today
  52. pass
  53. def test_days(self):
  54. days = dataCenter.days()
  55. days = days[0:30]
  56. result = json.dumps(days)
  57. print(days)
  58. def test_chplot(self):
  59. # buf = dataCenter.draw_plot(start_time=1619654400, interval=900, chname='yunling', card_type=5, amount=200)
  60. buf = dataCenter.draw_plot(start_time=1619654400, interval=900)
  61. img = Image.open(buf)
  62. img.show()
  63. def dir(self, group):
  64. result = []
  65. for name, sub in group.items():
  66. if isinstance(sub, h5py.Group):
  67. result.extend(self.dir(sub))
  68. else:
  69. print(sub.name)
  70. result.append(sub.name)
  71. return result
  72. def test_h5pyr(self):
  73. try:
  74. file_name = '/var/www/html/data/stdata/data.hdf5'
  75. f = h5py.File(file_name, 'r')
  76. root = f.require_group('/')
  77. result = self.dir(group=root)
  78. f.close()
  79. except Exception as ex:
  80. print(ex)
  81. def test_fig(self):
  82. buf = dataCenter.draw()
  83. img = Image.open(buf)
  84. img.show()
  85. def test_numpy(self):
  86. x = np.arange(0, 86400)
  87. y = x.reshape((-1, 300))
  88. y = np.sum(y, axis=1)
  89. pos = np.where(x >= 25890)
  90. x = x[pos]
  91. pos = np.where(x < 85400)
  92. x = x[pos]
  93. print(x)
  94. def test_mchdays(self):
  95. dates = mchDataCenter.days()
  96. dates.reverse()
  97. dates = dates[0:30]
  98. def test_mchpaths(self):
  99. time_stamp = int(time.time() - 86400)
  100. paths = mchDataCenter.paths(time_stamp)
  101. print(paths)
  102. def test_mchplot(self):
  103. time_stamp = int(time.time())
  104. buf = mchDataCenter.draw_plot(start_time=time_stamp, interval=900)
  105. img = Image.open(buf)
  106. img.show()
  107. def test_curmin(self):
  108. time_sec = int(time.time())
  109. cur_min = time_sec - time_sec % 60
  110. print('cur_min=', cur_min)
  111. def test_ratio(self):
  112. dataCenter.set_redis('192.168.1.220','6379')
  113. dataCenter.calc_ratio()
  114. def test_mchpath(self):
  115. time_stamp = int(time.time() - 86400)
  116. mchDataCenter.set_redis('192.168.1.220','6379')
  117. mchDataCenter.mratios(time_stamp)
  118. def test_mratio(self):
  119. mchDataCenter.set_redis('192.168.1.220','6379')
  120. mchDataCenter.calc_ratio()
  121. def test_mratios(self):
  122. mchDataCenter.set_redis('192.168.1.220','6379')
  123. mchDataCenter.calc_ratios()
  124. def test_mechcounts(self):
  125. mchDataCenter.set_redis('192.168.1.220','6379')
  126. mchDataCenter.mch_counts()
  127. def test_pubRatio(self):
  128. dataCenter.set_redis('192.168.1.220','6379')
  129. dataCenter.pub_ratio()
  130. def test_speedReader(self):
  131. speedDataCenter.set_redis('192.168.1.220','6379')
  132. speedDataCenter.prepare_data()
  133. def test_calcSpeed(self):
  134. speedDataCenter.set_redis('192.168.1.220','6379')
  135. speedDataCenter.channl_speed()
  136. def test_profitPrepare(self):
  137. from refill import queueListener
  138. queueListener.set_redis(self.__redis_host,'6379')
  139. queueListener.prepare_data()
  140. def test_mamount(self):
  141. from refill import MerchantCalc
  142. calc = MerchantCalc()
  143. calc.set_redis(self.__redis_host,'6379')
  144. calc.run()
  145. def test_json(self):
  146. try:
  147. x = {'method': 'commit', 'params': {'inprice': 4.5, 'outprice': 12}}
  148. print(x)
  149. # x = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
  150. data = json.dumps(x)
  151. print(data)
  152. y = json.loads(data)
  153. print(y)
  154. except Exception as ex:
  155. print(ex)
  156. finally:
  157. pass
  158. def test_setcache(self):
  159. r = None
  160. try:
  161. pool = redis.ConnectionPool(host='192.168.1.220', port=6379, db=0)
  162. r = redis.Redis(connection_pool=pool)
  163. r.set(f"nc_channel_ratios", "{\"time\": 1624298880, \"ratios\": {\"feinimoshu_hf-100-4-1\": [0, 0, 0, 0], \"feinimoshu_hf-200-4-1\": [0, 0, 0, 0], \"feinimoshu_hf-50-4-1\": [0, 0, 0, 0], \"feinimoshu_hf-100-6-1\": [0, 0, 0, 0], \"gftd-100-2-5\": [0, 0, 38, 77], \"gftd-200-2-5\": [0, 0, 13, 45], \"gftd-500-2-5\": [0, 0, 14, 0], \"gftdsinop-100-2-5\": [6, 0, 0, 0], \"gftdsinop-200-2-5\": [2, 0, 0, 0], \"gftdsinop-500-2-5\": [0, 0, 0, 0], \"lingzh-100-4-1\": [0, 0, 0, 0], \"lingzh-30-4-1\": [6, 0, 0, 6], \"lingzh-50-4-1\": [0, 0, 0, 0], \"lingzh-100-5-1\": [0, 0, 0, 0], \"lingzh-200-5-1\": [0, 0, 0, 0], \"lingzh-30-5-1\": [4, 0, 1, 3], \"lingzh-50-5-1\": [2, 0, 0, 3], \"lingzh-100-6-1\": [0, 0, 0, 0], \"lingzh-200-6-1\": [0, 0, 0, 0], \"lingzh-30-6-1\": [0, 0, 0, 0], \"lingzh-300-6-1\": [0, 0, 0, 0], \"lingzh-50-6-1\": [0, 0, 0, 0], \"lingzh-100-4-5\": [0, 0, 0, 0], \"lingzh-200-4-5\": [0, 0, 0, 0], \"lingzh-100-5-5\": [0, 0, 0, 0], \"lingzh-200-5-5\": [0, 0, 0, 0], \"lingzh-100-6-5\": [0, 0, 0, 0], \"lingzhoil-100-2-1\": [0, 0, 0, 0], \"lingzhoil-200-2-1\": [1, 0, 0, 1], \"moxj-30-5-1\": [5, 0, 2, 1], \"moxj-50-5-1\": [3, 0, 3, 1], \"moxj_fs-50-4-1\": [0, 0, 0, 0], \"qianqian-100-4-1\": [0, 0, 0, 0], \"qianqian-200-4-1\": [0, 0, 0, 0], \"qianqian-30-4-1\": [7, 0, 0, 7], \"qianqian-50-4-1\": [0, 0, 0, 0], \"qianqian-50-5-1\": [0, 0, 0, 0], \"qianqian-100-6-1\": [0, 0, 0, 0], \"weiyiwt-100-4-1\": [0, 0, 0, 0], \"weiyiwt-200-4-1\": [0, 0, 0, 0], \"weiyiwt-30-4-1\": [8, 0, 0, 8], \"weiyiwt-50-4-1\": [0, 0, 0, 0], \"weiyiwt-100-5-1\": [0, 0, 0, 0], \"weiyiwt-100-6-1\": [0, 0, 0, 0], \"weiyiwt-200-6-1\": [0, 0, 0, 0], \"weiyiwt-30-6-1\": [1, 0, 0, 1], \"weiyiwt-50-6-1\": [0, 0, 0, 0], \"yinteng-100-6-1\": [0, 0, 0, 0], \"yinteng-200-6-1\": [0, 0, 0, 0], \"yinteng-30-6-1\": [0, 1, 0, 0], \"yinteng-50-6-1\": [0, 0, 0, 0], \"yunling-100-4-1\": [0, 0, 0, 0], \"yunling-200-4-1\": [0, 0, 0, 0], \"yunling-30-4-1\": [8, 0, 0, 9], \"yunling-50-4-1\": [0, 0, 0, 0], \"yunling-100-5-1\": [0, 0, 0, 0], \"yunling-30-5-1\": [6, 0, 2, 3], \"yunling-50-5-1\": [4, 0, 3, 3], \"yunling-100-6-1\": [0, 0, 0, 0], \"yunling-50-6-1\": [0, 0, 0, 0], \"yunsuoyao-100-4-1\": [0, 0, 0, 0], \"yunsuoyao-30-4-1\": [1, 0, 0, 0], \"yunsuoyao-50-4-1\": [0, 0, 0, 0], \"zanzanquick-30-4-1\": [0, 0, 0, 0], \"zanzanquick-100-5-1\": [0, 0, 0, 0], \"zanzanquick-200-5-1\": [0, 0, 0, 0], \"zanzanquick-30-5-1\": [0, 0, 0, 0], \"zanzanquick-50-5-1\": [0, 0, 0, 0], \"zanzanquick-100-6-1\": [0, 0, 0, 0], \"zanzanquick-200-6-1\": [0, 0, 0, 0], \"zanzanquick-30-6-1\": [0, 0, 0, 0]}}")
  164. except Exception as ex:
  165. print(ex)
  166. if __name__ == '__main__':
  167. unittest.main()