Przeglądaj źródła

db analyser: fixed paths

Bernadette Elena Hammerle 3 lat temu
rodzic
commit
0fda79dca1
1 zmienionych plików z 11 dodań i 7 usunięć
  1. 11 7
      src/database/dbAnalyser.py

+ 11 - 7
src/database/dbAnalyser.py

@@ -5,6 +5,7 @@ Created on Fri Nov 27 23:48:19 2020
 
 @author: bernadetteelena
 """
+import os
 import json
 import pandas as pd
 import matplotlib.pyplot as plt
@@ -20,7 +21,8 @@ colorLookup = {
 
 
 def readFile():
-    with open("time.json") as file:
+    filePath = os.path.dirname(os.path.abspath(__file__)) + "/time.json"
+    with open(filePath) as file:
         timeList = json.load(file)
 
     timeDf = pd.DataFrame(timeList)
@@ -31,7 +33,7 @@ def readFile():
     return timeDf
 
 
-def timeMaps(df, plotTitle="plots/maps.png"):
+def timeMaps(df, plotTitle="maps.png"):
     fig, ax = plt.subplots(figsize=(20,12))
     for mapId, mapDf in df.groupby(["id"]):
         if mapId != "mapbox":
@@ -50,10 +52,11 @@ def timeMaps(df, plotTitle="plots/maps.png"):
     ax.set_xlabel("Number of Markers", fontsize=15)
     ax.set_ylabel("Time (ms)", fontsize=15)
     ax.set_title("Map Libraries", fontsize=20)
-    plt.savefig(plotTitle)
+    folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
+    plt.savefig(folder + plotTitle)
 
 
-def mapboxTypes(df, plotTitle="plots/mapbox.png"):
+def mapboxTypes(df, plotTitle="mapbox.png"):
     mapboxDf = df.dropna(subset=["type"])
     fig, ax = plt.subplots(figsize=(20,12))
     for markerType, typeDf in mapboxDf.groupby(["type"]):
@@ -67,13 +70,14 @@ def mapboxTypes(df, plotTitle="plots/mapbox.png"):
     ax.set_xlabel("Number of Markers", fontsize=15)
     ax.set_ylabel("Time (ms)", fontsize=15)
     ax.set_title("Mapbox: Markers and Features", fontsize=20)
-    plt.savefig(plotTitle)
+    folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
+    plt.savefig(folder + plotTitle)
 
 
 def smallValues(df):
     df = df.loc[df["markers"] < 300]
-    timeMaps(df, "plots/mapsSmall.png")
-    mapboxTypes(df, "plots/mapboxSmall.png")
+    timeMaps(df, "mapsSmall.png")
+    mapboxTypes(df, "mapboxSmall.png")
 
 
 df = readFile()