thdf5.py 6.8 KB

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