stanley-king il y a 4 ans
Parent
commit
2c363d8f79
3 fichiers modifiés avec 23 ajouts et 13 suppressions
  1. 19 3
      plot/DataCenter.py
  2. 1 9
      plot/app.py
  3. 3 1
      plot/thdf5.py

+ 19 - 3
plot/DataCenter.py

@@ -118,7 +118,7 @@ class DataCenter(object):
                 result.append(sub.name)
         return result
 
-    def draw_plot(self, start_time, **kwargs):
+    def draw_plot(self, start_time, interval=None, **kwargs):
         hfive = h5py.File(self._file_name, 'r')
         try:
             paths = self.datasets(hfive, start_time, **kwargs)
@@ -127,6 +127,10 @@ class DataCenter(object):
             for data in self.read_data(hfive, paths):
                 predata = predata + data
                 print(type(data))
+
+            internal = 3600
+            x = np.arange(0, 86400, internal)
+            return self._draw_plot(x, predata, internal)
         except Exception as ex:
             print(ex)
         finally:
@@ -180,10 +184,22 @@ class DataCenter(object):
 
         return result
 
-    def _draw_plot(self, **args):
+    def _draw_plot(self, x, data, internal=300):
         fig = Figure()
         ax = fig.subplots()
-        ax.plot([1, 2])
+
+        # '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 = ySucc.reshape((internal, -1))
+        ySucc = np.sum(ySucc, axis=0)
+
+        ySucc = ySucc / (all + 0.00001)
+
+        ax.plot(x, ySucc)
 
         buf = BytesIO()
         fig.savefig(buf, format="png")

+ 1 - 9
plot/app.py

@@ -7,8 +7,6 @@ import base64
 from io import BytesIO
 from matplotlib.figure import Figure
 import logging
-# from plog import initLog
-
 from DataCenter import dataCenter
 
 app = Flask(__name__)
@@ -16,13 +14,7 @@ app = Flask(__name__)
 
 @app.route('/plot/index')
 def index():
-    fig = Figure()
-    ax = fig.subplots()
-    ax.plot([1, 2])
-    # Save it to a temporary buffer.
-    buf = BytesIO()
-    fig.savefig(buf, format="png")
-    # Embed the result in the html output.
+    buf = dataCenter.draw_plot(1618502478,chname='lingzh')
     data = base64.b64encode(buf.getbuffer()).decode("ascii")
     return f"<img src='data:image/png;base64,{data}'/>"
 

+ 3 - 1
plot/thdf5.py

@@ -74,7 +74,9 @@ class DataTest(unittest.TestCase):
         pass
 
     def test_data(self):
-        dataCenter.draw_plot(1618502478,chname='lingzh')
+        buf = dataCenter.draw_plot(1618502478,chname='lingzh')
+        img = Image.open(buf)
+        img.show()
 
     def dir(self, group):
         result = []