scenario_reader.py 3.81 KB
Newer Older
1 2 3 4 5
import json


class VadereScenario:
    def __init__(self, path):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
6
        with open(path, "r") as f:
7 8 9 10 11 12 13 14 15 16 17
            data = json.load(f)
        self.data = data
        self.path = path

    @classmethod
    def load(cls, path):
        s = cls(path)
        return s

    @property
    def name(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
18
        return self.data["name"]
19 20 21

    @name.setter
    def name(self, val: str):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
22
        self.data["name"] = str(val)
23 24 25

    @property
    def description(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
26
        return self.data["description"]
27 28 29

    @description.setter
    def description(self, val: str):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
30
        self.data["description"] = str(val)
31 32 33

    @property
    def release(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
34
        return self.data["release"]
35 36 37

    @release.setter
    def release(self, val: str):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
38
        self.data["release"] = str(val)
39 40 41

    @property
    def process_writers(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
42
        return self.data["processWriters"]
43 44 45 46 47

    @process_writers.setter
    def process_writers(self, val: dict):
        if type(val) is not dict:
            raise ValueError("process_writer must be dict")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
48
        self.data["processWriters"] = val
49 50 51

    @property
    def scenario(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
52
        return self.data["scenario"]
53 54 55 56 57

    @scenario.setter
    def scenario(self, val: dict):
        if type(val) is not dict:
            raise ValueError("scenario must be dict")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
58
        self.data["scenario"] = val
59 60 61

    @property
    def topography(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
62
        return self.data["scenario"]["topography"]
63 64 65 66 67

    @topography.setter
    def topography(self, val: dict):
        if type(val) is not dict:
            raise ValueError("topography must be dict")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
68
        self.data["scenario"]["topography"] = val
69 70 71

    @property
    def obstacles(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
72
        return self.data["scenario"]["topography"]["obstacles"]
73 74 75 76 77

    @obstacles.setter
    def obstacles(self, val: list):
        if type(val) is not list:
            raise ValueError("obstacles must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
78
        self.data["scenario"]["topography"]["obstacles"] = val
79 80 81

    @property
    def measurement_areas(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
82
        return self.data["scenario"]["topography"]["measurementAreas"]
83 84 85 86 87

    @measurement_areas.setter
    def measurement_areas(self, val: list):
        if type(val) is not list:
            raise ValueError("measurementAreas must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
88
        self.data["scenario"]["topography"]["measurementAreas"] = val
89 90 91

    @property
    def stairs(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
92
        return self.data["scenario"]["topography"]["stairs"]
93 94 95 96 97

    @stairs.setter
    def stairs(self, val: list):
        if type(val) is not list:
            raise ValueError("stairs must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
98
        self.data["scenario"]["topography"]["stairs"] = val
99 100 101

    @property
    def targets(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
102
        return self.data["scenario"]["topography"]["targets"]
103 104 105 106 107

    @targets.setter
    def targets(self, val: list):
        if type(val) is not list:
            raise ValueError("targets must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
108
        self.data["scenario"]["topography"]["targets"] = val
109 110 111

    @property
    def absorbing_areas(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
112
        return self.data["scenario"]["topography"]["absorbingAreas"]
113 114 115 116 117

    @absorbing_areas.setter
    def absorbing_areas(self, val: list):
        if type(val) is not list:
            raise ValueError("absorbingAreas must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
118
        self.data["scenario"]["topography"]["absorbingAreas"] = val
119 120 121

    @property
    def sources(self):
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
122
        return self.data["scenario"]["topography"]["sources"]
123 124 125 126 127

    @sources.setter
    def sources(self, val: list):
        if type(val) is not list:
            raise ValueError("sources must be list of dicts")
Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
128
        self.data["scenario"]["topography"]["sources"] = val
129 130 131 132 133 134 135 136 137 138 139 140 141 142

    @property
    def raw(self):
        return self.data

    @property
    def scenario(self):
        return self.data["scenario"]

    @property
    def topography(self):
        return self.scenario["topography"]


Stefan Schuhbaeck's avatar
Stefan Schuhbaeck committed
143 144
if __name__ == "__main__":
    s = VadereScenario.load("./mf_small_2.scenario")