thdf5.py 8.0 KB

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