ソースを参照

added db analyser

Bernadette Elena Hammerle 3 年 前
コミット
146ff7ddd7
1 ファイル変更45 行追加0 行削除
  1. 45 0
      src/database/dbAnalyser.py

+ 45 - 0
src/database/dbAnalyser.py

@@ -0,0 +1,45 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Nov 27 23:48:19 2020
+
+@author: bernadetteelena
+"""
+import json
+import pandas as pd
+import matplotlib.pyplot as plt
+
+
+def readFile():
+    with open("time.json") as file:
+        timeList = json.load(file)
+    
+    timeDf = pd.DataFrame(timeList)
+    timeDf["markers"] = pd.to_numeric(timeDf["markers"], errors="raise")
+    return timeDf
+
+def avgTimeMaps(df):
+    avgDf = df.groupby(["id", "markers"]).mean().reset_index()
+    avgDf = avgDf.pivot(index="markers", columns="id", values="time")
+    avgDf.plot()
+    plt.savefig("plots/mapsAvg.png")
+
+def timeMaps(df):
+    fig, ax = plt.subplots(figsize=(10,4))
+    for key, grp in df.groupby(["id"]):
+        ax.scatter(grp["markers"], grp["time"], label=key)#
+    ax.legend(title="Maps")
+    plt.savefig("plots/maps.png")
+
+def mapboxTypes(df):
+    mapboxDf = df.dropna(subset=["type"])
+    fig, ax = plt.subplots(figsize=(10,4))
+    for key, grp in mapboxDf.groupby(["type"]):
+        ax.scatter(grp["markers"], grp["time"], label=key)#
+    ax.legend(title="Marker Type")
+    plt.savefig("plots/mapbox.png")
+
+df = readFile()
+avgTimeMaps(df)
+timeMaps(df)
+mapboxTypes(df)