dbAnalyser.py 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Fri Nov 27 23:48:19 2020
  5. @author: bernadetteelena
  6. """
  7. import os
  8. import json
  9. import pandas as pd
  10. import matplotlib.pyplot as plt
  11. colorLookup = {
  12. "google": "r",
  13. "leaflet": "b",
  14. "mapbox_feature": "g",
  15. "mapbox_marker": "y",
  16. "mapgl": "m",
  17. "pigeons": "c"
  18. }
  19. nameLookup = {
  20. "google": "Google Map React",
  21. "leaflet": "React Leaflet",
  22. "mapbox_feature": "ReactMapboxGL Feature",
  23. "mapbox_marker": "ReactMapboxGL Marker",
  24. "mapgl": "react-map-gl",
  25. "pigeons": "Pigeon Maps"
  26. }
  27. def readFile():
  28. filePath = os.path.dirname(os.path.abspath(__file__)) + "/time.json"
  29. with open(filePath) as file:
  30. timeList = json.load(file)
  31. timeDf = pd.DataFrame(timeList)
  32. print("number of tests:", timeDf.shape[0])
  33. timeDf["markers"] = pd.to_numeric(timeDf["markers"], errors="raise")
  34. print(timeDf.value_counts(subset=["id"]))
  35. print(timeDf.value_counts(subset=["id", "type"]))
  36. return timeDf
  37. def timeMaps(df, plotTitle="maps.png"):
  38. fig, ax = plt.subplots(figsize=(20,12))
  39. plt.yticks(fontsize=15)
  40. plt.xticks(fontsize=15)
  41. for mapId, mapDf in df.groupby(["id"]):
  42. if mapId != "mapbox":
  43. ax.scatter(mapDf["markers"], mapDf["time"], color=colorLookup.get(mapId))
  44. mapAvgDf = mapDf.groupby(["markers"]).mean().reset_index()
  45. ax.plot(mapAvgDf["markers"], mapAvgDf["time"], label=nameLookup.get(mapId), color=colorLookup.get(mapId))
  46. else:
  47. for markerType, typeDf in mapDf.groupby(["type"]):
  48. mapTypeId = "mapbox_" + markerType
  49. ax.scatter(typeDf["markers"], typeDf["time"], color=colorLookup.get(mapTypeId))
  50. typeMapAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
  51. ax.plot(typeMapAvgDf["markers"], typeMapAvgDf["time"], label=nameLookup.get(mapTypeId), color=colorLookup.get(mapTypeId))
  52. ax.legend(title="Marker Type", fontsize=17, title_fontsize=20)
  53. ax.set_xlabel("Number of Markers", fontsize=20)
  54. ax.set_ylabel("Time (ms)", fontsize=20)
  55. ax.set_title("Map Libraries - Marker", fontsize=25)
  56. folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
  57. plt.savefig(folder + plotTitle, bbox_inches="tight")
  58. def mapboxTypes(df, plotTitle="mapbox.png"):
  59. mapboxDf = df.dropna(subset=["type"])
  60. fig, ax = plt.subplots(figsize=(20,12))
  61. plt.yticks(fontsize=15)
  62. plt.xticks(fontsize=15)
  63. for markerType, typeDf in mapboxDf.groupby(["type"]):
  64. mapId = "mapbox_" + markerType
  65. ax.scatter(typeDf["markers"], typeDf["time"], label=nameLookup.get(mapId), color=colorLookup.get(mapId))
  66. typeAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
  67. ax.plot(typeAvgDf["markers"], typeAvgDf["time"], color=colorLookup.get(mapId))
  68. ax.legend(title="Marker Type", fontsize=17, title_fontsize=20)
  69. ax.set_xlabel("Number of Markers", fontsize=20)
  70. ax.set_ylabel("Time (ms)", fontsize=20)
  71. ax.set_title("ReactMapboxGL: Markers and Features", fontsize=25)
  72. folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
  73. plt.savefig(folder + plotTitle, bbox_inches="tight")
  74. def smallValues(df):
  75. df = df.loc[df["markers"] < 300]
  76. timeMaps(df, "mapsSmall.png")
  77. mapboxTypes(df, "mapboxSmall.png")
  78. timeMapsHighlight(df, "mapsSmallHighlight.png")
  79. def avgPerMarkerNo(df, markerNo):
  80. print(f"\nresult of {markerNo} markers\n")
  81. print("number of measurements:")
  82. df = df.loc[df["markers"] == markerNo]
  83. resDf = pd.DataFrame(columns=["id", "timeMean", "rating"])
  84. for mapId, mapDf in df.groupby(["id"]):
  85. if mapId != "mapbox":
  86. print(mapId, mapDf.shape[0])
  87. resDf = resDf.append({"id": mapId, "timeMean": mapDf["time"].mean()}, ignore_index=True)
  88. else:
  89. for markerType, typeDf in mapDf.groupby(["type"]):
  90. print(markerType, typeDf.shape[0])
  91. resDf = resDf.append({"id": "mapbox_" + markerType, "timeMean": typeDf["time"].mean()}, ignore_index=True)
  92. resDf = resDf.assign(rating=lambda x: (round(4-((4-0)/(max(resDf["timeMean"])-min(resDf["timeMean"]))*(x["timeMean"]-max(resDf["timeMean"]))+4))))
  93. print("\naverage time:")
  94. print(resDf)
  95. print("--------------------------------------")
  96. def timeMapsHighlight(df, plotTitle="mapsHightlight.png"):
  97. fig, ax = plt.subplots(figsize=(20,12))
  98. plt.yticks(fontsize=15)
  99. plt.xticks(fontsize=15)
  100. for mapId, mapDf in df.groupby(["id"]):
  101. if mapId != "mapbox":
  102. if mapId == "leaflet":
  103. ax.scatter(mapDf["markers"], mapDf["time"], color=colorLookup.get(mapId))
  104. mapAvgDf = mapDf.groupby(["markers"]).mean().reset_index()
  105. ax.plot(mapAvgDf["markers"], mapAvgDf["time"], label=mapId, color=colorLookup.get(mapId), linewidth=2)
  106. else:
  107. ax.scatter(mapDf["markers"], mapDf["time"], color=colorLookup.get(mapId), alpha=0.3)
  108. mapAvgDf = mapDf.groupby(["markers"]).mean().reset_index()
  109. ax.plot(mapAvgDf["markers"], mapAvgDf["time"], label=mapId, color=colorLookup.get(mapId), linewidth=1, alpha=0.3)
  110. else:
  111. for markerType, typeDf in mapDf.groupby(["type"]):
  112. mapTypeId = "mapbox_" + markerType
  113. if markerType == "feature":
  114. ax.scatter(typeDf["markers"], typeDf["time"], color=colorLookup.get(mapTypeId))
  115. typeMapAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
  116. ax.plot(typeMapAvgDf["markers"], typeMapAvgDf["time"], label=mapTypeId, color=colorLookup.get(mapTypeId), linewidth=2)
  117. else:
  118. ax.scatter(typeDf["markers"], typeDf["time"], color=colorLookup.get(mapTypeId), alpha=0.3)
  119. typeMapAvgDf = typeDf.groupby(["markers"]).mean().reset_index()
  120. ax.plot(typeMapAvgDf["markers"], typeMapAvgDf["time"], label=mapTypeId, color=colorLookup.get(mapTypeId), linewidth=1, alpha=0.3)
  121. ax.legend(title="Marker Type", fontsize=17, title_fontsize=20)
  122. ax.set_xlabel("Number of Markers", fontsize=20)
  123. ax.set_ylabel("Time (ms)", fontsize=20)
  124. ax.set_title("Map Libraries - Marker", fontsize=25)
  125. folder = os.path.dirname(os.path.abspath(__file__)) + "/plots/"
  126. plt.savefig(folder + plotTitle, bbox_inches="tight")
  127. df = readFile()
  128. avgPerMarkerNo(df, 100)
  129. avgPerMarkerNo(df, 1000)
  130. avgPerMarkerNo(df, 10000)
  131. timeMaps(df)
  132. timeMapsHighlight(df)
  133. mapboxTypes(df)
  134. smallValues(df)