From 8d52b37206d3c7343f1213bc0c5a0d3d8c4473b8 Mon Sep 17 00:00:00 2001 From: Andres Ladino Date: Mon, 22 Nov 2021 22:51:53 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=A7=20Initial=20templating=20optio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- symupy/preprocess/templates/restitution.xml | 0 symupy/preprocess/templates/simulation.xml | 1 + symupy/preprocess/wrapper_input.py | 16 ++++++++++++++++ 3 files changed, 17 insertions(+) create mode 100644 symupy/preprocess/templates/restitution.xml create mode 100644 symupy/preprocess/templates/simulation.xml create mode 100644 symupy/preprocess/wrapper_input.py diff --git a/symupy/preprocess/templates/restitution.xml b/symupy/preprocess/templates/restitution.xml new file mode 100644 index 0000000..e69de29 diff --git a/symupy/preprocess/templates/simulation.xml b/symupy/preprocess/templates/simulation.xml new file mode 100644 index 0000000..fffd397 --- /dev/null +++ b/symupy/preprocess/templates/simulation.xml @@ -0,0 +1 @@ +{% for veh in vehicles %}{% endfor %}{% for veh in vehicles %}{% endfor %} \ No newline at end of file diff --git a/symupy/preprocess/wrapper_input.py b/symupy/preprocess/wrapper_input.py new file mode 100644 index 0000000..d00218e --- /dev/null +++ b/symupy/preprocess/wrapper_input.py @@ -0,0 +1,16 @@ + +from jinja2 import Environment, PackageLoader, select_autoescape + +env = Environment( + loader=PackageLoader("ensemble", "templates"), + autoescape=select_autoescape( + [ + "xml", + ] + ), +) + +def transform_data(TEST): + VEHICLES = [dict(zip(KEYS, v)) for v in TEST] + template = env.get_template("restitution.xml") + return bytes(template.render(vehicles=VEHICLES), encoding="UTF8") From be774cc9019566ff9d6544b82eb5cf832c7ff148 Mon Sep 17 00:00:00 2001 From: Andres Ladino Date: Thu, 25 Nov 2021 14:27:34 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=9A=A7=20Prototype=20XML=20creator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- symupy/parser/inputxml.py | 79 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 symupy/parser/inputxml.py diff --git a/symupy/parser/inputxml.py b/symupy/parser/inputxml.py new file mode 100644 index 0000000..3c75ad6 --- /dev/null +++ b/symupy/parser/inputxml.py @@ -0,0 +1,79 @@ +""" +Parser for Input XML file +========================= + This is a parser +""" + +class XMLObject(object): + def __init__(self, args: dict): + self.attrs = args + self.childs = [] + self.level = 0 + + def add_child(self, child): + self.childs.append(child) + child.level = self.level + 1 + + def __str__(self): + if self.attrs: + attr = " "+" ".join([f'{key}="{val}"' for key, val in self.attrs.items()]) + balise = "\t"*self.level+f"<{self.__class__.__name__}{attr}" + else: + balise = "\t"*self.level+f"<{self.__class__.__name__}" + if self.childs: + res = "\n".join([balise+">"]+[child.__str__() for child in self.childs]+["\t"*self.level+f""]) + else: + res = balise + "/>" + return res + + +class ROOT_SYMUBRUIT(XMLObject): + def __init__(self, xmlnsxsi="http://www.w3.org/2001/XMLSchema-instance", xsi_noNamespaceSchemaLocation="reseau.xsd", version="2.05"): + super(ROOT_SYMUBRUIT, self).__init__({"xmlns:xsi":xmlnsxsi, "xsi:noNamespaceSchemaLocation":xsi_noNamespaceSchemaLocation, "version": version}) + + +class PLAGES_TEMPORELLES(XMLObject): + def __init__(self, debut, type): + super(PLAGES_TEMPORELLES, self).__init__({"debut": debut, "type": type}) + + +class PLAGE_TEMPORELLE(XMLObject): + def __init__(self, id, debut, fin): + super(PLAGE_TEMPORELLE, self).__init__({"id": id, "debut": debut, "fin": fin}) + + +class SIMULATIONS(XMLObject): + def __init__(self): + super(SIMULATIONS, self).__init__({}) + + +class SIMULATION(XMLObject): + def __init__(self, id, pasdetemps, debut, fin, loipoursuite='exact', comportementflux="iti", date="1985-01-17", titre="", proc_decelation="false", seed="1"): + super(SIMULATION, self).__init__(dict(id=id, pasdetemps=pasdetemps, debut=debut, fin=fin, loipoursuite=loipoursuite, + comportementflux=comportementflux, date=date, titre=titre, proc_decelation=proc_decelation, + seed=seed)) + + +class RESTITUTION(XMLObject): + def __init__(self, trace_route="false", trajectoires="true", debug="false", debug_matrice_OD="false", debug_SAS="false"): + super(RESTITUTION, self).__init__(dict(trace_route=trace_route, trajectoires=trajectoires, debug=debug, + debug_matrice_OD=debug_matrice_OD, debug_SAS=debug_SAS)) + + +if __name__ == "__main__": + + root = ROOT_SYMUBRUIT() + + plage = PLAGES_TEMPORELLES("06:00:00", "horaire") + root.add_child(plage) + plage.add_child(PLAGE_TEMPORELLE("P01", "06:00:00", "07:00:00")) + plage.add_child(PLAGE_TEMPORELLE("P02", "07:00:00", "08:00:00")) + + sims = SIMULATIONS() + root.add_child(sims) + + sim = SIMULATION("simID", "1", "06:00:00", "07:00:00") + sims.add_child(sim) + sim.add_child(RESTITUTION()) + + print(root) \ No newline at end of file