csvToJson.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import pandas as pd
  2. import json
  3. import os
  4. directory = os.path.dirname(os.path.abspath(__file__))
  5. df = pd.read_csv(directory + "/metrics.csv", delimiter=";")
  6. df = df.dropna(subset=["Metrik"]).reset_index(drop=True)
  7. catLookUp = {
  8. "F": "Funktionen",
  9. "B": "Benutzerfreundlichkeit",
  10. "P": "Performance",
  11. "D": "Dokumentation",
  12. "I": "Installation"
  13. }
  14. metrics = []
  15. category = ""
  16. df = df.fillna("")
  17. for i, row in df.iterrows():
  18. newCat = catLookUp.get(row.get("Nr")[0])
  19. if type(newCat) == str:
  20. category = newCat
  21. rating = {
  22. "pigeon": row.get("Pigeon"),
  23. "leaflet": row.get("Leaflet"),
  24. "mapgl": row.get("MapGL"),
  25. "mapbox": row.get("Mapbox"),
  26. "google": row.get("Google"),
  27. }
  28. comments = {
  29. "pigeon": row.get("Kommentar Pigeon"),
  30. "leaflet": row.get("Kommentar Leaflet"),
  31. "mapgl": row.get("Kommentar MapGL"),
  32. "mapbox": row.get("Kommentar Mapbox"),
  33. "google": row.get("Kommentar Google"),
  34. }
  35. metrics.append({
  36. "metric": row.get("Metrik"),
  37. "number": row.get("Nr"),
  38. "category": category,
  39. "rating": rating,
  40. "comments": comments
  41. })
  42. with open(directory + "/metrics.json", "w") as jsonFile:
  43. json.dump({"metrics": metrics}, jsonFile, indent=2)