thdf5.py 7.3 KB

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