123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- Created on Fri Nov 27 23:48:19 2020
- @author: bernadetteelena
- """
- import os
- import json
- import pandas as pd
- import matplotlib.pyplot as plt
- colorLookup = {
- "google": "r",
- "leaflet": "b",
- "mapbox_feature": "g",
- "mapbox_marker": "y",
- "mapgl": "m",
- "pigeons": "c"
- }
- def readFile():
- filePath = os.path.dirname(os.path.abspath(__file__)) + "/time.json"
- with open(filePath) as file:
- timeList = json.load(file)
- timeDf = pd.DataFrame(timeList)
- print("number of tests:", timeDf.shape[0])
- timeDf["markers"] = pd.to_numeric(timeDf["markers"], errors="raise")
- print(timeDf.value_counts(subset=["id"]))
- print(timeDf.value_counts(subset=["id", "type"]))
- return timeDf
- def timeMaps(df, plotTitle="maps.png"):
- fig, ax = plt.subplots(figsize=(20,12))
- for mapId, mapDf in df.groupby(["id"]):
- if mapId != "mapbox":
- ax.scatter(mapDf["markers"], mapDf["time"], color=colorLookup.get(mapId))
- mapAvgDf = mapDf.groupby(["markers"]).mean().reset_index()
- ax.plot(mapAvgDf["markers"], mapAvgDf["time"], label=mapId, color=colorLookup.get(mapId))
- else:
- for markerType, typeDf in mapDf.groupby(["type"]):
- mapTypeId = "mapbox_" + markerType
- ax.scatter(typeDf["markers"], typeDf["time"], color=colorLookup.get(mapTypeId))
- typeMapAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
- ax.plot(typeMapAvgDf["markers"], typeMapAvgDf["time"], label=mapTypeId, color=colorLookup.get(mapTypeId))
- ax.legend(title="Maps")
- ax.legend(title="Marker Type")
- ax.set_xlabel("Number of Markers", fontsize=15)
- ax.set_ylabel("Time (ms)", fontsize=15)
- ax.set_title("Map Libraries", fontsize=20)
- folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
- plt.savefig(folder + plotTitle)
- 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"]):
- mapId = "mapbox_" + markerType
- ax.scatter(typeDf["markers"], typeDf["time"], label=mapId, color=colorLookup.get(mapId))
- typeAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
- ax.plot(typeAvgDf["markers"], typeAvgDf["time"], color=colorLookup.get(mapId))
- ax.legend(title="Marker Type")
- ax.set_xlabel("Number of Markers", fontsize=15)
- ax.set_ylabel("Time (ms)", fontsize=15)
- ax.set_title("Mapbox: Markers and Features", fontsize=20)
- folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
- plt.savefig(folder + plotTitle)
- def smallValues(df):
- df = df.loc[df["markers"] < 300]
- timeMaps(df, "mapsSmall.png")
- mapboxTypes(df, "mapboxSmall.png")
- def avgPerMarkerNo(df, markerNo):
- print(f"\naverage time for {markerNo} markers")
- print("number of measurements")
- df = df.loc[df["markers"] == markerNo]
- resDf = pd.DataFrame(columns=["id", "timeMean", "rating"])
- for mapId, mapDf in df.groupby(["id"]):
- if mapId != "mapbox":
- print(mapId, mapDf.shape[0])
- resDf = resDf.append({"id": mapId, "timeMean": mapDf["time"].mean()}, ignore_index=True)
- else:
- for markerType, typeDf in mapDf.groupby(["type"]):
- print(markerType, typeDf.shape[0])
- resDf = resDf.append({"id": "mapbox_" + markerType, "timeMean": typeDf["time"].mean()}, ignore_index=True)
- resDf = resDf.assign(rating=lambda x: (round(4-((4-0)/(max(resDf["timeMean"])-min(resDf["timeMean"]))*(x["timeMean"]-max(resDf["timeMean"]))+4))))
- print(resDf)
- df = readFile()
- print(df.columns)
- avgPerMarkerNo(df, 100)
- avgPerMarkerNo(df, 1000)
- avgPerMarkerNo(df, 10000)
- timeMaps(df)
- mapboxTypes(df)
- smallValues(df)
|