LoanMaikon's picture
Add files using upload-large-folder tool
07444d1 verified
Raw
History Blame Contribute Delete
2.19 kB
import json
from Constants import Constants
from EnumParkingStatus import EnumParkingStatus
class JSonEditor:
def __init__(self, jsonPath):
self.jsonPath = jsonPath
with open(jsonPath, 'r') as file:
self.json = json.load(file)
def check_structure(self):
for key in self.json.keys():
print(key)
def remove_keys_json(self, list_remove):
for str in list_remove:
print("Removing: ", str)
del self.json[str]
def save_json(self, filename):
with open(filename, 'w') as file:
json.dump(self.json, file)
def generate_lightweight_segmentation(self):
pass
# dont delete tags
def update_tags(self):
climates = self.json["climates"]
for cl in climates:
if(cl["id"] == 5):
cl["name"] = "no_rain "
try:
del self.json["parkingSpots"]
except:
pass
def consolidateValInfoJson(self):
annotations = self.json[Constants.JSON_ANNOTATIONS_KEY]
for annot in annotations:
if (annot[Constants.JSON_LINK_CATEG_KEY] == Constants.JSON_PARKING_SPACE_KEY):
status = int(annot[Constants.JSON_PARKING_STATUS_ID_KEY])
if(status == EnumParkingStatus.EMPTY_NEED_VAL.value):
annot[Constants.JSON_PARKING_STATUS_ID_KEY] = EnumParkingStatus.EMPTY.value
elif(status == EnumParkingStatus.OCCUPIED_NEED_VAL.value):
annot[Constants.JSON_PARKING_STATUS_ID_KEY] = EnumParkingStatus.OCCUPIED.value
# del self.json[Constants.JSON_STATUSES_KEY]
# dictStatusEmpty = {}
# dictStatusEmpty["id"] = 1
# dictStatusEmpty["name"] = "empty"
# dictStatusOccupied = {}
# dictStatusOccupied["id"] = 2
# dictStatusOccupied["name"] = "occupied"
# listStatus = [dictStatusEmpty, dictStatusOccupied]
# self.json[Constants.JSON_STATUSES_KEY] = listStatus
def generate_final_json(self):
self.update_tags()
#self.generate_lightweight_segmentation() #some apis may not recognize the light version of the JSON