|
@@ -5,6 +5,7 @@ import h5py
|
|
|
from os import path
|
|
|
import re
|
|
|
from datetime import timedelta
|
|
|
+from datetime import datetime
|
|
|
import numpy as np
|
|
|
|
|
|
class SpeedDataCenter(object):
|
|
@@ -23,18 +24,24 @@ class SpeedDataCenter(object):
|
|
|
pass
|
|
|
|
|
|
def prepare_data(self):
|
|
|
+ pool = redis.ConnectionPool(host=self._mRHost, port=self._mRPort, db=0)
|
|
|
+ r = redis.Redis(connection_pool=pool)
|
|
|
+
|
|
|
while self._mquit == False:
|
|
|
try:
|
|
|
- pool = redis.ConnectionPool(host=self._mRHost, port=self._mRPort, db=0)
|
|
|
- r = redis.Redis(connection_pool=pool)
|
|
|
+ print('open file:', datetime.now())
|
|
|
if path.exists(self._file_name):
|
|
|
hfive = h5py.File(self._file_name, 'a')
|
|
|
else:
|
|
|
hfive = h5py.File(self._file_name, 'w')
|
|
|
+
|
|
|
+ print('read redis:', datetime.now())
|
|
|
self.read_redis(hfive, r, 'nc_commit_speed_monitor')
|
|
|
hfive.close()
|
|
|
|
|
|
+ print('del redis:', datetime.now())
|
|
|
self.del_redis(r, 'nc_commit_speed_monitor')
|
|
|
+ print('del redis:', datetime.now())
|
|
|
except Exception as ex:
|
|
|
print(ex)
|
|
|
finally:
|
|
@@ -76,7 +83,6 @@ class SpeedDataCenter(object):
|
|
|
|
|
|
diff = time - today
|
|
|
hfive[path][0, diff] = val
|
|
|
- print(path, 0, diff, val, hfive[path][0, diff])
|
|
|
pass
|
|
|
|
|
|
def day_stamp(self, stamp):
|
|
@@ -101,13 +107,14 @@ class SpeedDataCenter(object):
|
|
|
try:
|
|
|
time_stamp = int(stime.time())
|
|
|
paths = self.paths(time_stamp)
|
|
|
- pos_range = self._pos_range(time_stamp)
|
|
|
+ day_stamp = self.day_stamp(time_stamp)
|
|
|
+ (pos_start, pos_end) = self._pos_range(time_stamp - day_stamp)
|
|
|
|
|
|
hfive = h5py.File(self._file_name, 'r')
|
|
|
result = {}
|
|
|
for path in paths:
|
|
|
key = self._parse_path(path)
|
|
|
- speed = self._calc_speed(hfive, path, pos_range)
|
|
|
+ speed = self._calc_speed(hfive, path, pos_start, pos_end)
|
|
|
result[key] = speed
|
|
|
pass
|
|
|
hfive.close()
|
|
@@ -131,22 +138,25 @@ class SpeedDataCenter(object):
|
|
|
|
|
|
def _pos_range(self,end):
|
|
|
pos_day = np.arange(0, 86400, 1)
|
|
|
- day_stamp = self.day_stamp(end)
|
|
|
+
|
|
|
period = 60
|
|
|
- if end - period > day_stamp:
|
|
|
+ if end - period > 0:
|
|
|
start = end - period
|
|
|
- pos_range = np.where(pos_day > start)
|
|
|
+ pos_start = np.where(pos_day > start)
|
|
|
else:
|
|
|
- start = day_stamp
|
|
|
- pos_range = np.where(pos_day >= start)
|
|
|
- pos_range = np.where(pos_range <= end)
|
|
|
+ start = 0
|
|
|
+ pos_start = np.where(pos_day >= start)
|
|
|
+
|
|
|
+ pos_day = pos_day[pos_start]
|
|
|
+ pos_end = np.where(pos_day <= end)
|
|
|
|
|
|
- return pos_range
|
|
|
+ return pos_start, pos_end
|
|
|
|
|
|
- def _calc_speed(self,hFive,path,pos_range):
|
|
|
+ def _calc_speed(self,hFive,path,pos_start, pos_end):
|
|
|
datas = hFive[path]
|
|
|
commit = datas[0]
|
|
|
- commit = commit[pos_range]
|
|
|
+ commit = commit[pos_start]
|
|
|
+ commit = commit[pos_end]
|
|
|
speed = int(np.sum(commit))
|
|
|
return speed
|
|
|
|