Translate XML model into Python code
Visit our website for full documentation »
View current process
·
Report Bug
·
Request Feature
This project will assist developers in implementing custom IoT systems.
Here's why you should use this:
- Users who want to design automata with UPPAAL but have no idea what to do with the generated XML file.
- Users who want their modeled diagrams to run on a Rasberry Pi device.
- Users who want to test out IoT environment with the modeling tool (UPPAAL).
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Download UPPAAL to create your model
- Clone the repo
git clone https://github.com/TCC2021SeniorProject/ModelTranslator.git
- Download XML examples
- Run Main.py program
cd ./MdoelTranslator/src
+Rules for a valid execution
- A model must be a valid model. The validity of the model can be checked in UPPAAL software. Any invalid UPPAAL model will cause a program crash.
- All variables must be defined. Any unidentified variables may cause errors either while using the software (translation) or executing output (Python code).
- All variable declarations must be valid, according to its template.
- Every node must have a unique identifier. Duplicate identifiers will result in overwriting of functions.
├── data
│ ├── xml_input_file.xml
│ ├── output_file.py
├── img
├── README.md
└── src
├── __init__.py
├── main.py
├── objects
│ ├── model.py
│ ├── node.py
│ ├── transition.py
│ └── variable.py
├── parser
│ └── XML_parser.py
└── translator
├── class_gen.py
├── function_gen.py
├── model.py
└── py_export.py
-
The translator can handle the below features from UPPAAL
-
- Identifies Start and End node by name (This feature will be changed to tag identification)
- Change UPPAAL XML into abstract graph structure
- Parse given global declaration from UPPAAL to variables
-
Transition object can handle:
-
-
- Select (name)
- Guard (conditionals)
- Assignment (variable update in local)
-
Locate linked node sources
-
Each UPPAAL node name is converted to the function declaration in python.
-
Each transition point is converted to a function call in python
-
- When producing a model such like this in UPPAAL
- Suppose there is a XML file given like this
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.1//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_2.dtd'>
<nta>
<declaration>// Global declarations.
int status1, charge1;</declaration>
<template>
<name x="9" y="9">Simple</name>
<parameter>int &mode, int &battery</parameter>
<declaration>// Place local declarations here.
</declaration>
<location id="id0" x="-391" y="-323">
<name x="-408" y="-357">End</name>
</location>
<location id="id1" x="-603" y="-323">
<name x="-629" y="-357">Clean</name>
</location>
<location id="id2" x="-731" y="-323">
<name x="-756" y="-357">Ready</name>
</location>
<location id="id3" x="-952" y="-323">
<name x="-960" y="-357">Start</name>
</location>
<transition>
<source ref="id1"/>
<target ref="id0"/>
<label kind="guard" x="-578" y="-340">mode == 4 || battery < 10</label>
<label kind="assignment" x="-535" y="-323">mode := 4</label>
</transition>
<transition>
<source ref="id2"/>
<target ref="id1"/>
<label kind="guard" x="-705" y="-340">mode == 3</label>
</transition>
<transition>
<source ref="id3"/>
<target ref="id2"/>
<label kind="guard" x="-926" y="-340">mode == 1 && battery > 10</label>
</transition>
</template>
<system>// Place template instantiations here.
r1 = Simple(status1, charge1);
// List one or more processes to be composed into a system.
system r1;</system>
<queries>
<query>
<formula></formula>
<comment></comment>
</query>
</queries>
</nta>
- After running XML_parser, this will parse crucial data into graph objects. Below the image is output lines as a result of this conversion
- Then the parser automatically checks all the required data such as a starting state, an end state, infinity, and connectionless transitions.
- Finally, our program generates a python script file looking like below:
class TestClass:
def __init__(self, ):
print('Running constructor')
self.status1 = 0
self.charge1 = 0
self.status2 = 0
self.charge2 = 0
self.status3 = 0
self.charge3 = 0
async def End(self):
exit()
async def Dock(self):
await self.Ready()
await self.End()
async def Explore(self):
if self.mode == 4 or self.battery < 10 :
self.mode = 4
await self.Dock()
if self.mode == 3 :
await self.Clean()
async def Clean(self):
if self.mode == 4 or self.battery < 10 :
self.mode = 4
await self.Dock()
async def Ready(self):
if self.mode == 3 :
await self.Clean()
if self.mode == 2 :
await self.Explore()
async def Idle(self):
if self.battery > 10 and self.mode == 1 :
await self.Ready()
async def Start(self):
self.mode = 1
await self.Idle()
TestClass.Start()
For more examples, please refer to the Design Documentation.
For more plans, please see the plan documentation.
- Update mark down documentation.
- Create mock Python code output.
- Make UPPAAL parser.
- Program is able to traverse all the nodes through tranistion objects.
- Program is able to identify the validity of the model.
- Program is able to validate the node function (e.g. starting node, termination node, logic node, process node, etc)
- Make Python code generator/converter.
- Test simple diagram.
- Make complex diagram 1
- Update(enhance) UPPAAL parser
- Update(enhance) Python code generator/converter
- Test complex diagram 1
- Update (enhance) UPPAAL parser
- Update (enhance) Python code generator/converter
- Test complex diagram 1
See the open issues for a full list of proposed features (and known issues).
Case | Testing Responder | Due Date |
---|---|---|
Test case 1 | Tony, Cameron, Cael | Oct 9 |
Test case 2 | Tony, Cameron | Oct 17 |
Test case 3 | Tony, Cameron | Oct 23 |
Test case 4 | Tony, Cameron, Cael | Nov 21 |
Test case 7 | Tony, Cael | Dec 12 |
Test case 8 | Tony, Cameron, Cael | Dec 12 |
To view the specific testing details, click here
MCCD refers to Main Control Center Device.
- Test case 1 (Due Oct 9): Produce code from a simple model
- Test case 2 (Due Oct 17): Model comparatively massive size diagram
- Test case 3 (Due Oct 23): Build infinite loops / Redundant transitions.
- Test case 4 (Due Nov 21): Change models to python codes that MCCD accepts.
- Test case 7 (Due Dec 12): Handling devices via web application on MCCD
- Test case 8 (Due Dec 12): MCCD can be postponed until the device finishes its current job
See the following link: Style Guide for Python Code
Follow rules for better readability: Clean Code by Robert C. Martin
Getter first, setter later for function definitions.
Currently, there is no license for this repo, meaning our team retains all rights to the source code and no one may reproduce, distribute, or create derivative works from our work.
This will not be permanent until the completion of the project.
Dr. Siddhartha Bhattacharyya
Email: [email protected]
Sung-Jun Baek
Email: [email protected]
GitHub: MarcoBackman
Caelan Shoop
Email: [email protected]
GitHub: CCShoop
Cameron Wright
Email: [email protected]
GitHub: CameronWr