Skip to content

Commit cdf81ac

Browse files
committed
Add markdown documentation; Move python library into its own repository
1 parent fc3f676 commit cdf81ac

File tree

3 files changed

+180
-1
lines changed

3 files changed

+180
-1
lines changed

README.md

100644100755
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
# planimation-pythonAPI
1+
# Access Planimation API
2+
3+
The Planimation API provides programmatic access to Planimation, an online PDDL problem solver and visualiser. Planimation with user interface can be accessed through [here] [planimation]. A python library and a python-based command line utility are provided to easily access the API. They provide the same functionalities as the user interface.
4+
5+
### Installation
6+
Simply fork this repository and you can have access to the source code. Unfortunately, there are no `pip` or `conda` installation options available at this stage.
7+
8+
### Python Library
9+
10+
The `planimation_api.py` library provides following methods:
11+
Method | Description
12+
------------ | -------------
13+
`pddl_visualise(path of domain, path of problem, path of animation, output format)` | Submit 3 pddl files which corresponds to domain, problem, animation profile respectively and receive response in one of 5 supported formats (vfg, png, gif, webm, mp4). Similar to "Build visualisation from problem" on user interface
14+
`vfg_visualise(path of vfg, output format)` | Submit a vfg file and receive response in one of 4 supported formats (png, gif, webm, mp4). Similar to "Build visualisation from solution VFG" on user interface
15+
An example of usage is demonstrated below:
16+
```python
17+
import planimation_api as api
18+
result = api.pddl_visualise("domain.pddl", "problem.pddl", "ap.pddl", "mp4")
19+
print(result) // display the name of received file
20+
```
21+
22+
### Command Line Utility
23+
24+
The `planimation.py` command-line utility provides exactly the same functionalities as the `planimation_api.py` library:
25+
26+
`submitPDDL` submits 3 pddl files which corresponds to domain, problem, animation profile respectively and receive response in one of 5 supported formats (vfg, png, gif, webm, mp4)
27+
```sh
28+
$ planimation.py submitPDDL [path of domain] [path of problem] [path of animation profile] [output format]
29+
```
30+
`submitVFG` submits a vfg file and receive response in one of 4 supported formats (png, gif, webm, mp4)
31+
```sh
32+
$ planimation.py submitVFG [path of VFG] [output format]
33+
```
34+
35+
### Disclaimer
36+
The API should be considered to be in a very alpha phase at the moment. It's not expected to handle heavy traffic and the error messages may not be complete. Until this disclaimer is removed, we **DO NOT RECOMMEND** using the API for official business (academic or otherwise).
37+
38+
### Thanks
39+
The first version of Planimation API is developed by Changyuan Liu, Lingfeng Qiang, Mengyi Fan, Xinzhe Li and Zhaoqi Fang under Nir Lipovetzky's guidance.
40+
41+
[//]: #
42+
[planimation]:<https://planimation.planning.domains/>

planimation.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
import sys,os
3+
import planimation_api as api
4+
5+
USAGE_STRING = """
6+
No command-line options given. Usage:
7+
8+
planimation.py submitVFG [absolute path of vfg file] [download option (png/webm/gif/mp4)]
9+
planimation.py submitPDDL [absolute path of domain file] [absolute path of problem file] [absolute path of animation file] [download option (vfg/png/webm/gif/mp4)]
10+
"""
11+
12+
13+
if __name__ == "__main__":
14+
# give the usage of command line
15+
if len(sys.argv) == 1:
16+
print(USAGE_STRING)
17+
exit(0)
18+
i=1
19+
while i< len(sys.argv):
20+
#check submitVFG function
21+
if sys.argv[i] == "submitVFG":
22+
i+=1
23+
if len(sys.argv) == 4:
24+
vfg = sys.argv[i].strip()
25+
26+
if vfg.endswith('.vfg'):
27+
i+=1
28+
downloadtype = sys.argv[i].strip()
29+
30+
if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4':
31+
print("invalid download type")
32+
exit(1)
33+
else:
34+
print(vfg)
35+
print(downloadtype)
36+
api.vfg_visualise(vfg,downloadtype)
37+
exit(0)
38+
else:
39+
print("Invalid vfg file type")
40+
exit(1)
41+
else:
42+
print("Invalid argument entered for submitVFG")
43+
exit(1)
44+
# check submitPlan function
45+
elif sys.argv[i] == "submitPDDL":
46+
i+=1
47+
if len(sys.argv) == 6:
48+
domainFile = sys.argv[i].strip()
49+
i+=1
50+
problemFile = sys.argv[i].strip()
51+
i+=1
52+
animationFile = sys.argv[i].strip()
53+
if domainFile.endswith('.pddl') and problemFile.endswith('.pddl') and animationFile.endswith('.pddl'):
54+
i+=1
55+
downloadtype = sys.argv[i].strip()
56+
if downloadtype!='png' and downloadtype!='webm' and downloadtype!='gif' and downloadtype!='mp4' and downloadtype!='vfg':
57+
print("invalid download type")
58+
exit(1)
59+
else:
60+
api.pddl_visualise(domainFile,problemFile,animationFile,downloadtype)
61+
exit(0)
62+
63+
else:
64+
print("invalid input for pddls,please check your pddl files")
65+
exit(1)
66+
67+
else:
68+
print("Invalid argument numbers entered for submitPlan")
69+
exit(1)
70+
71+
else:
72+
print("no such argument input!!!")
73+
exit(1)

planimation_api.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import requests
2+
from datetime import datetime
3+
import re
4+
5+
# To be changed once deployed on actural server
6+
pddl_url = "http://127.0.0.1:8000/upload/(?P<filename>[^/]+)$"
7+
vfg_url = "http://127.0.0.1:8000/downloadVisualisation"
8+
9+
# check if the input file is in the correct format using regex
10+
def check_input(filename, format):
11+
x = re.search("^.+\."+format+"$", filename)
12+
return bool(x)
13+
14+
15+
# helper function to read file
16+
def read_file(filename):
17+
file = open(filename, "rb")
18+
content = file.read()
19+
file.close()
20+
return content
21+
22+
23+
# send 3 PDDL files and get back either vfg, png, gif, webm or mp4 file
24+
def pddl_visualise(domain_file, problem_file, animation_profile, output_format):
25+
if check_input(domain_file, "pddl") is False or check_input(problem_file, "pddl") is False \
26+
or check_input(animation_profile, "pddl") is False:
27+
print("Error: incorrect input format; all input files should be in PDDL format")
28+
return None
29+
if output_format != "png" and output_format != "webm" and output_format != "gif" and output_format != "mp4" \
30+
and output_format != "vfg":
31+
print("Error: desired output format is not supported; only vfg, png, gif, webm and mp4 are supported")
32+
return None
33+
domain = read_file(domain_file)
34+
problem = read_file(problem_file)
35+
animation = read_file(animation_profile)
36+
files = ("domain", (None, domain)), ("problem", (None, problem)), ("animation", (None, animation)), \
37+
("fileType", (None, output_format))
38+
r = requests.post(pddl_url, files=files)
39+
if output_format == "png":
40+
output_format = "zip"
41+
output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format
42+
with open(output_name, "wb") as output:
43+
for chunk in r.iter_content(chunk_size=None):
44+
output.write(chunk)
45+
return output_name
46+
47+
48+
# send a vfg file and get back either png, gif, webm or mp4 file
49+
def vfg_visualise(vfg_file, output_format):
50+
if check_input(vfg_file, "vfg") is False:
51+
print("Error: incorrect input format; input should be in vfg format")
52+
return None
53+
if output_format != "png" and output_format != "webm" and output_format != "gif" and output_format != "mp4":
54+
print("Error: desired output format is not supported; only png, gif, webm and mp4 are supported")
55+
return None
56+
vfg = read_file(vfg_file)
57+
files = ('vfg', (None, vfg)), ('fileType', (None, output_format))
58+
r = requests.post(vfg_url, files=files)
59+
if output_format == "png":
60+
output_format = "zip"
61+
output_name = "planimation " + datetime.now().strftime("%Y-%m-%d_%X.") + output_format
62+
with open(output_name, "wb") as output:
63+
for chunk in r.iter_content(chunk_size=None):
64+
output.write(chunk)
65+
return output_name

0 commit comments

Comments
 (0)