#!/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)) plt.yticks(fontsize=15) plt.xticks(fontsize=15) 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="Marker Type", fontsize=17, title_fontsize=20) ax.set_xlabel("Number of Markers", fontsize=20) ax.set_ylabel("Time (ms)", fontsize=20) ax.set_title("Map Libraries - Marker", fontsize=25) folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/" plt.savefig(folder + plotTitle, bbox_inches="tight") def mapboxTypes(df, plotTitle="mapbox.png"): mapboxDf = df.dropna(subset=["type"]) fig, ax = plt.subplots(figsize=(20,12)) plt.yticks(fontsize=15) plt.xticks(fontsize=15) 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", fontsize=17, title_fontsize=20) ax.set_xlabel("Number of Markers", fontsize=20) ax.set_ylabel("Time (ms)", fontsize=20) ax.set_title("Mapbox: Markers and Features", fontsize=25) folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/" plt.savefig(folder + plotTitle, bbox_inches="tight") 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() avgPerMarkerNo(df, 100) avgPerMarkerNo(df, 1000) avgPerMarkerNo(df, 10000) timeMaps(df) mapboxTypes(df) smallValues(df)