123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #!/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
- colorLookup = {
- "google": "r",
- "leaflet": "b",
- "mapbox_feature": "g",
- "mapbox_marker": "y",
- "mapgl": "m",
- "pigeons": "c"
- }
- def readFile():
- with open("time.json") 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="plots/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")
- plt.savefig(plotTitle)
- def mapboxTypes(df, plotTitle="plots/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")
- plt.savefig(plotTitle)
- def smallValues(df):
- df = df.loc[df["markers"] < 300]
- timeMaps(df, "plots/mapsSmall.png")
- mapboxTypes(df, "plots/mapboxSmall.png")
- df = readFile()
- timeMaps(df)
- mapboxTypes(df)
- smallValues(df)
|