thdf5.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 PIL import Image
  9. import json
  10. import logging
  11. logging.basicConfig(filename='/var/www/html/data/log/plot_test.log',
  12. format='%(levelname)10s %(asctime)s %(name)10s %(thread)d %(message)s',
  13. level=logging.DEBUG)
  14. logger = logging.getLogger('test_log')
  15. class DataTest(unittest.TestCase):
  16. # __redis_host = '192.168.3.104'
  17. __redis_host = '192.168.3.226'
  18. def test_connect(self):
  19. pool = redis.ConnectionPool(host=self.__redis_host, port=6379, db=0)
  20. r = redis.Redis(connection_pool=pool)
  21. for item in r.hscan_iter('nc_channel_monitor_commit'):
  22. key = item[0]
  23. val = item[1]
  24. print(str(key, encoding="utf-8"), str(val, encoding="utf-8"))
  25. def test_regex(self):
  26. text = 'succm-lingzh-1-4-30-1618291260'
  27. result = re.split(r'-', text)
  28. pass
  29. def day(self, time):
  30. pass
  31. def test_today(self):
  32. stamp = 1617908681
  33. stamp = int(stamp)
  34. x = time.gmtime(stamp + 8 * 3600)
  35. diff = timedelta(hours=x.tm_hour, minutes=x.tm_min, seconds=x.tm_sec)
  36. today = stamp - diff.total_seconds()
  37. y = stamp - today
  38. pass
  39. def dir(self, group):
  40. result = []
  41. for name, sub in group.items():
  42. if isinstance(sub, h5py.Group):
  43. result.extend(self.dir(sub))
  44. else:
  45. print(sub.name)
  46. result.append(sub.name)
  47. return result
  48. def test_h5pyr(self):
  49. try:
  50. file_name = '/var/www/html/data/stdata/data.hdf5'
  51. f = h5py.File(file_name, 'r')
  52. root = f.require_group('/')
  53. result = self.dir(group=root)
  54. f.close()
  55. except Exception as ex:
  56. print(ex)
  57. def test_numpy(self):
  58. x = np.arange(0, 86400)
  59. y = x.reshape((-1, 300))
  60. y = np.sum(y, axis=1)
  61. pos = np.where(x >= 25890)
  62. x = x[pos]
  63. pos = np.where(x < 85400)
  64. x = x[pos]
  65. print(x)
  66. def test_curmin(self):
  67. time_sec = int(time.time())
  68. cur_min = time_sec - time_sec % 60
  69. print('cur_min=', cur_min)
  70. def test_profitPrepare(self):
  71. from refill import queueListener
  72. queueListener.set_redis(self.__redis_host,'6379')
  73. queueListener.prepare_data()
  74. def test_mamount(self):
  75. from refill import MAmountCalc
  76. calc = MAmountCalc()
  77. calc.set_redis(self.__redis_host,'6379')
  78. logger.debug('start log.')
  79. calc.run()
  80. def test_json(self):
  81. try:
  82. x = {'method': 'commit', 'params': {'inprice': 4.5, 'outprice': 12}}
  83. print(x)
  84. # x = [ { 'a' : 1, 'b' : 2, 'c' : 3, 'd' : 4, 'e' : 5 } ]
  85. data = json.dumps(x)
  86. print(data)
  87. y = json.loads(data)
  88. print(y)
  89. except Exception as ex:
  90. print(ex)
  91. finally:
  92. pass
  93. def test_setcache(self):
  94. r = None
  95. try:
  96. pool = redis.ConnectionPool(host='192.168.1.220', port=6379, db=0)
  97. r = redis.Redis(connection_pool=pool)
  98. 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]}}")
  99. except Exception as ex:
  100. print(ex)
  101. if __name__ == '__main__':
  102. unittest.main()