|
@@ -154,11 +154,31 @@ class MchDataCenter(object):
|
|
result.append(sub.name)
|
|
result.append(sub.name)
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
+ def _all_none(self, **kwargs):
|
|
|
|
+ for key, val in kwargs.items():
|
|
|
|
+ if val is not None:
|
|
|
|
+ return False
|
|
|
|
+ return True
|
|
|
|
+
|
|
|
|
+ def _merge_path(self,paths):
|
|
|
|
+ result = {}
|
|
|
|
+ for path in paths:
|
|
|
|
+ items = re.split(r'/', path)
|
|
|
|
+ if len(items) != 6:
|
|
|
|
+ continue
|
|
|
|
+ (_, _sday, _mchid, _quality, _card_type, _amount) = items
|
|
|
|
+
|
|
|
|
+ _mchid = int(_mchid)
|
|
|
|
+ if _mchid not in result:
|
|
|
|
+ result[_mchid] = []
|
|
|
|
+ result[_mchid].append(path)
|
|
|
|
+
|
|
|
|
+ return result
|
|
|
|
+
|
|
def draw_plot(self, start_time, interval=300, **kwargs):
|
|
def draw_plot(self, start_time, interval=300, **kwargs):
|
|
logger = logging.getLogger('app')
|
|
logger = logging.getLogger('app')
|
|
hfive = h5py.File(self._file_name, 'r')
|
|
hfive = h5py.File(self._file_name, 'r')
|
|
try:
|
|
try:
|
|
- filer_text, paths = self.datasets(hfive, start_time, **kwargs)
|
|
|
|
day_stamp = self.day_stamp(start_time)
|
|
day_stamp = self.day_stamp(start_time)
|
|
start_pos = start_time - day_stamp
|
|
start_pos = start_time - day_stamp
|
|
|
|
|
|
@@ -175,13 +195,23 @@ class MchDataCenter(object):
|
|
x = np.arange(0, 86400, interval)
|
|
x = np.arange(0, 86400, interval)
|
|
|
|
|
|
sub_count = 0
|
|
sub_count = 0
|
|
- for path, data in self.read_data(hfive, paths):
|
|
|
|
- data = np.array(data)
|
|
|
|
- predata = predata + data
|
|
|
|
- ret = self._draw_plot(ax, x, day_stamp, start_pos, end_pos, data, interval, path)
|
|
|
|
- if ret:
|
|
|
|
- sub_count += 1
|
|
|
|
-
|
|
|
|
|
|
+ filer_text, paths = self.datasets(hfive, start_time, **kwargs)
|
|
|
|
+ if self._all_none(**kwargs):
|
|
|
|
+ paths = self._merge_path(paths)
|
|
|
|
+ for mchid, data in self._read_dict_data(hfive, paths):
|
|
|
|
+ predata = predata + data
|
|
|
|
+ path = f'{mchid}'
|
|
|
|
+ ret = self._draw_plot(ax, x, day_stamp, start_pos, end_pos, data, interval, path)
|
|
|
|
+ if ret:
|
|
|
|
+ sub_count += 1
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ for path, data in self.read_data(hfive, paths):
|
|
|
|
+ data = np.array(data)
|
|
|
|
+ predata = predata + data
|
|
|
|
+ ret = self._draw_plot(ax, x, day_stamp, start_pos, end_pos, data, interval, path)
|
|
|
|
+ if ret:
|
|
|
|
+ sub_count += 1
|
|
if sub_count > 1:
|
|
if sub_count > 1:
|
|
self._draw_plot(ax, x, day_stamp, start_pos, end_pos, predata, interval, filer_text)
|
|
self._draw_plot(ax, x, day_stamp, start_pos, end_pos, predata, interval, filer_text)
|
|
|
|
|
|
@@ -204,6 +234,13 @@ class MchDataCenter(object):
|
|
for path in paths:
|
|
for path in paths:
|
|
yield path, hfive[path]
|
|
yield path, hfive[path]
|
|
|
|
|
|
|
|
+ def _read_dict_data(self, hfive, mchPaths):
|
|
|
|
+ for mchid, paths in mchPaths.items():
|
|
|
|
+ predata = np.zeros((2, 86400))
|
|
|
|
+ for path in paths:
|
|
|
|
+ predata += hfive[path]
|
|
|
|
+ yield mchid, predata
|
|
|
|
+
|
|
def datasets(self, hfive, start_time, **kwargs):
|
|
def datasets(self, hfive, start_time, **kwargs):
|
|
logger = logging.getLogger('app')
|
|
logger = logging.getLogger('app')
|
|
|
|
|
|
@@ -221,7 +258,6 @@ class MchDataCenter(object):
|
|
for key, val in kwargs.items():
|
|
for key, val in kwargs.items():
|
|
if val is None:
|
|
if val is None:
|
|
continue
|
|
continue
|
|
-
|
|
|
|
if key == 'mchid':
|
|
if key == 'mchid':
|
|
mchid = val
|
|
mchid = val
|
|
elif key == 'quality':
|
|
elif key == 'quality':
|