|
@@ -98,7 +98,7 @@ class DataCenter(object):
|
|
today = stamp - diff.total_seconds()
|
|
today = stamp - diff.total_seconds()
|
|
return int(today)
|
|
return int(today)
|
|
|
|
|
|
- def days(self, root):
|
|
|
|
|
|
+ def _days(self, root):
|
|
result = []
|
|
result = []
|
|
try:
|
|
try:
|
|
for name, sub in root.items():
|
|
for name, sub in root.items():
|
|
@@ -109,6 +109,17 @@ class DataCenter(object):
|
|
finally:
|
|
finally:
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
+ def days(self):
|
|
|
|
+ try:
|
|
|
|
+ hfive = h5py.File(self._file_name, 'r')
|
|
|
|
+ root = hfive.require_group('/')
|
|
|
|
+ days = self._days(root)
|
|
|
|
+ hfive.close()
|
|
|
|
+ return days
|
|
|
|
+ except Exception as ex:
|
|
|
|
+ print(ex)
|
|
|
|
+ return []
|
|
|
|
+
|
|
def dir(self, group):
|
|
def dir(self, group):
|
|
result = []
|
|
result = []
|
|
for name, sub in group.items():
|
|
for name, sub in group.items():
|
|
@@ -118,19 +129,29 @@ class DataCenter(object):
|
|
result.append(sub.name)
|
|
result.append(sub.name)
|
|
return result
|
|
return result
|
|
|
|
|
|
- def draw_plot(self, start_time, interval=None, **kwargs):
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def draw_plot(self, start_time, interval=300, **kwargs):
|
|
hfive = h5py.File(self._file_name, 'r')
|
|
hfive = h5py.File(self._file_name, 'r')
|
|
try:
|
|
try:
|
|
- paths = self.datasets(hfive, start_time, **kwargs)
|
|
|
|
|
|
+ filer_text, paths = self.datasets(hfive, start_time, **kwargs)
|
|
|
|
+
|
|
|
|
+ fig = Figure(figsize=(16, 9))
|
|
|
|
+ ax = fig.subplots()
|
|
|
|
|
|
predata = np.zeros((5, 86400))
|
|
predata = np.zeros((5, 86400))
|
|
- for data in self.read_data(hfive, paths):
|
|
|
|
|
|
+ x = np.arange(0, 86400, interval)
|
|
|
|
+ for path, data in self.read_data(hfive, paths):
|
|
|
|
+ data = np.array(data)
|
|
predata = predata + data
|
|
predata = predata + data
|
|
|
|
+ self._draw_plot(ax,x, data, interval,path)
|
|
print(type(data))
|
|
print(type(data))
|
|
|
|
|
|
- internal = 3600
|
|
|
|
- x = np.arange(0, 86400, internal)
|
|
|
|
- return self._draw_plot(x, predata, internal)
|
|
|
|
|
|
+ self._draw_plot(ax,x, predata, interval,filer_text)
|
|
|
|
+ ax.legend()
|
|
|
|
+ buf = BytesIO()
|
|
|
|
+ fig.savefig(buf, format="png")
|
|
|
|
+ return buf
|
|
except Exception as ex:
|
|
except Exception as ex:
|
|
print(ex)
|
|
print(ex)
|
|
finally:
|
|
finally:
|
|
@@ -138,13 +159,13 @@ class DataCenter(object):
|
|
|
|
|
|
def read_data(self, hfive, paths):
|
|
def read_data(self, hfive, paths):
|
|
for path in paths:
|
|
for path in paths:
|
|
- yield hfive[path]
|
|
|
|
|
|
+ yield path, hfive[path]
|
|
|
|
|
|
def datasets(self, hfive, start_time, **kwargs):
|
|
def datasets(self, hfive, start_time, **kwargs):
|
|
day_stamp = self.day_stamp(start_time)
|
|
day_stamp = self.day_stamp(start_time)
|
|
sday = f'{day_stamp}'
|
|
sday = f'{day_stamp}'
|
|
root = hfive.require_group('/')
|
|
root = hfive.require_group('/')
|
|
- days = self.days(root)
|
|
|
|
|
|
+ days = self._days(root)
|
|
if sday not in days:
|
|
if sday not in days:
|
|
return False
|
|
return False
|
|
|
|
|
|
@@ -166,7 +187,17 @@ class DataCenter(object):
|
|
return self._filter(dsets, chname=chname, quality=quality, card_type=card_type, amount=amount)
|
|
return self._filter(dsets, chname=chname, quality=quality, card_type=card_type, amount=amount)
|
|
|
|
|
|
def _filter(self, dsets, chname=None, quality=None, card_type=None, amount=None):
|
|
def _filter(self, dsets, chname=None, quality=None, card_type=None, amount=None):
|
|
- result = []
|
|
|
|
|
|
+ filer_text = ''
|
|
|
|
+ if chname is not None:
|
|
|
|
+ filer_text = chname
|
|
|
|
+ if quality is not None:
|
|
|
|
+ filer_text = filer_text + f"-qua:{quality}"
|
|
|
|
+ if card_type is not None:
|
|
|
|
+ filer_text = filer_text + f"-type:{card_type}"
|
|
|
|
+ if amount is not None:
|
|
|
|
+ filer_text = filer_text + f"-amount:{amount}"
|
|
|
|
+
|
|
|
|
+ paths = []
|
|
for text in dsets:
|
|
for text in dsets:
|
|
items = re.split(r'/', text)
|
|
items = re.split(r'/', text)
|
|
if len(items) != 6:
|
|
if len(items) != 6:
|
|
@@ -180,30 +211,32 @@ class DataCenter(object):
|
|
continue
|
|
continue
|
|
if (amount is not None) and (_amount != amount):
|
|
if (amount is not None) and (_amount != amount):
|
|
continue
|
|
continue
|
|
- result.append(text)
|
|
|
|
-
|
|
|
|
- return result
|
|
|
|
|
|
+ paths.append(text)
|
|
|
|
|
|
- def _draw_plot(self, x, data, internal=300):
|
|
|
|
- fig = Figure()
|
|
|
|
- ax = fig.subplots()
|
|
|
|
|
|
+ return filer_text, paths
|
|
|
|
|
|
|
|
+ def _draw_plot(self,ax, x, data, internal=300,path=''):
|
|
# 'commit-succ': 0, 'commit-fail': 1, 'notify-succ': 2, 'notify-fail': 3, 'user_succ': 4
|
|
# 'commit-succ': 0, 'commit-fail': 1, 'notify-succ': 2, 'notify-fail': 3, 'user_succ': 4
|
|
- all = data[2] + data[3]
|
|
|
|
- all = all.reshape((internal, -1))
|
|
|
|
- all = np.sum(all, axis=0)
|
|
|
|
|
|
+
|
|
|
|
|
|
ySucc = data[2]
|
|
ySucc = data[2]
|
|
ySucc = ySucc.reshape((internal, -1))
|
|
ySucc = ySucc.reshape((internal, -1))
|
|
ySucc = np.sum(ySucc, axis=0)
|
|
ySucc = np.sum(ySucc, axis=0)
|
|
|
|
|
|
|
|
+ pos = np.where(ySucc >= 1)
|
|
|
|
+ # ySucc = ySucc[pos]
|
|
|
|
+
|
|
|
|
+ all = data[2] + data[3]
|
|
|
|
+ all = all.reshape((internal, -1))
|
|
|
|
+ all = np.sum(all, axis=0)
|
|
|
|
+ # all = all[pos]
|
|
|
|
+
|
|
ySucc = ySucc / (all + 0.00001)
|
|
ySucc = ySucc / (all + 0.00001)
|
|
|
|
+ # x = x[pos]
|
|
|
|
+ ax.plot(x, ySucc,label=path)
|
|
|
|
+ # ax.scatter(x, ySucc)
|
|
|
|
|
|
- ax.plot(x, ySucc)
|
|
|
|
|
|
|
|
- buf = BytesIO()
|
|
|
|
- fig.savefig(buf, format="png")
|
|
|
|
- return buf
|
|
|
|
|
|
|
|
|
|
|
|
dataCenter = DataCenter(debug=False)
|
|
dataCenter = DataCenter(debug=False)
|