thdf5.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 matplotlib.figure import Figure
  12. from PIL import Image
  13. from io import BytesIO
  14. from PIL import Image
  15. import json
  16. class DataTest(unittest.TestCase):
  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. result = json.dumps(days)
  52. print(days)
  53. def test_data(self):
  54. buf = dataCenter.draw_plot(1619020800, chname='lingzh')
  55. img = Image.open(buf)
  56. img.show()
  57. def dir(self, group):
  58. result = []
  59. for name, sub in group.items():
  60. if isinstance(sub, h5py.Group):
  61. result.extend(self.dir(sub))
  62. else:
  63. print(sub.name)
  64. result.append(sub.name)
  65. return result
  66. def test_h5pyr(self):
  67. try:
  68. file_name = '/var/www/html/data/stdata/data.hdf5'
  69. f = h5py.File(file_name, 'r')
  70. root = f.require_group('/')
  71. result = self.dir(group=root)
  72. f.close()
  73. except Exception as ex:
  74. print(ex)
  75. def test_fig(self):
  76. buf = dataCenter.draw()
  77. img = Image.open(buf)
  78. img.show()
  79. def test_numpy(self):
  80. x = np.arange(0, 86400)
  81. y = x.reshape((-1, 300))
  82. y = np.sum(y, axis=1)
  83. pos = np.where(x >= 25890)
  84. x = x[pos]
  85. pos = np.where(x < 85400)
  86. x = x[pos]
  87. print(x)
  88. if __name__ == '__main__':
  89. unittest.main()