thdf5.py 7.8 KB

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