from .DataStream import DataReadStream,open_hdf5 from .DataStream import ENetPosmap as pos_map import numpy as np import re from collections import defaultdict import time as time __all__ = ['NetchkReader'] import logging log = logging.getLogger('reader') class NetchkReader(DataReadStream): def __init__(self): file = '/var/www/html/data/stdata/netchk.hdf5' hfive = open_hdf5(file,False) super(NetchkReader,self).__init__(hfive) def __del__(self): self.close() super(NetchkReader, self).__del__() def tuple_path(self, day: int, chnames: set = None): def parse(path): items = re.split(r'/', path) (_prifix, _version, today, chname) = items return chname all = True if chnames is None or len(chnames) == 0 else False channels = set() pathes = self.datasets(day) for path in pathes: _chname = parse(path) if all: channels.add(_chname) elif _chname in chnames: channels.add(_chname) else: continue return channels def many_tuple_path(self, days: list, chnames: set = None): all = set() for day in days: channels = self.tuple_path(day, chnames) all = all.union(channels) return all def init_data(self, days): dim = pos_map.dim() return np.zeros((dim, 86400 * days)) def read(self, today, chname): path = f'/{self._version}/{today}/{chname}' hfive = self.file if path in hfive: return hfive[path] else: return None pass pass