event_storage.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import time
  2. import json
  3. import re
  4. from memory_storage import MemoryStorage
  5. from hard_disk_storage import HardDiskStorage
  6. from configuration import Configuration
  7. class EventStorage:
  8. def __init__(self):
  9. self.config = Configuration().get_config()
  10. self.memoryStorage = MemoryStorage(self.config['memoryDatabase'])
  11. self.hardDiskStorage = HardDiskStorage(self.config['hardDiskdataBase'])
  12. def get_real_data(self, keys):
  13. data = self.memoryStorage.get_value(keys)
  14. return data
  15. def get_historical_data(self, select_info):
  16. data = self.hardDiskStorage.get_table_data(select_info)
  17. return data
  18. def real_time_data_storage(self, data):
  19. self.memoryStorage.set_value(data)
  20. def historical_data_storage(self, table_name, seve_time, data):
  21. self.hardDiskStorage.insert_column_many(table_name, seve_time, data)
  22. def get_connector_config(self):
  23. config = self.hardDiskStorage.get_connectors()
  24. for station_info in config:
  25. station_info['connector_config'] = json.loads(station_info['connector_config'])
  26. return config
  27. def get_station_info(self, station_name):
  28. return self.hardDiskStorage.get_station_info(station_name)
  29. def get_point_info(self, keys):
  30. point_list = []
  31. if keys:
  32. for key in keys:
  33. point_list.append(re.sub("\D", "", key))
  34. point_tuple = tuple(point_list)
  35. else:
  36. point_tuple = None
  37. return self.hardDiskStorage.get_point_info(point_tuple)
  38. # 获取modbus命令
  39. def get_command_info(self, station_name):
  40. return self.hardDiskStorage.get_command_info(station_name)
  41. # 历史查询接口(new)
  42. def get_total_count_and_first_id(self, select_info):
  43. data = self.hardDiskStorage.get_total_count_and_first_id(select_info)
  44. return data
  45. def get_item_by_id_offset(self, select_info):
  46. data = self.hardDiskStorage.get_item_by_id_offset(select_info)
  47. return data
  48. # 数据导出接口
  49. def quary_table_data(self, select_info):
  50. data = self.hardDiskStorage.quary_table_data(select_info)
  51. return data
  52. # 获取insitu指令
  53. def get_in_situ_command(self):
  54. data = self.hardDiskStorage.get_in_situ_command()
  55. return data
  56. # 执行自定义sql
  57. def execute_sql(self, sql):
  58. data = self.hardDiskStorage.execute_sql(sql)
  59. return data
  60. class Networkerror(RuntimeError):
  61. def __init__(self, arg):
  62. self.args = arg