123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #!/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"
- }
- nameLookup = {
- "google": "Google Map React",
- "leaflet": "React Leaflet",
- "mapbox_feature": "ReactMapboxGL Feature",
- "mapbox_marker": "ReactMapboxGL Marker",
- "mapgl": "react-map-gl",
- "pigeons": "Pigeon Maps"
- }
- 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=nameLookup.get(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=nameLookup.get(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=nameLookup.get(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("ReactMapboxGL: 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")
- timeMapsHighlight(df, "mapsSmallHighlight.png")
- def avgPerMarkerNo(df, markerNo):
- print(f"\nresult of {markerNo} markers\n")
- 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("\naverage time:")
- print(resDf)
- print("--------------------------------------")
- def timeMapsHighlight(df, plotTitle="mapsHightlight.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":
- if mapId == "leaflet":
- 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), linewidth=2)
- else:
- ax.scatter(mapDf["markers"], mapDf["time"], color=colorLookup.get(mapId), alpha=0.3)
- mapAvgDf = mapDf.groupby(["markers"]).mean().reset_index()
- ax.plot(mapAvgDf["markers"], mapAvgDf["time"], label=mapId, color=colorLookup.get(mapId), linewidth=1, alpha=0.3)
-
- else:
- for markerType, typeDf in mapDf.groupby(["type"]):
- mapTypeId = "mapbox_" + markerType
- if markerType == "feature":
- 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), linewidth=2)
- else:
- ax.scatter(typeDf["markers"], typeDf["time"], color=colorLookup.get(mapTypeId), alpha=0.3)
- typeMapAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
- ax.plot(typeMapAvgDf["markers"], typeMapAvgDf["time"], label=mapTypeId, color=colorLookup.get(mapTypeId), linewidth=1, alpha=0.3)
- 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")
- df = readFile()
- avgPerMarkerNo(df, 100)
- avgPerMarkerNo(df, 1000)
- avgPerMarkerNo(df, 10000)
- timeMaps(df)
- timeMapsHighlight(df)
- mapboxTypes(df)
- smallValues(df)
|