Skip to content

Commit 10b50e6

Browse files
committed
json ok
1 parent 7b51334 commit 10b50e6

2 files changed

Lines changed: 32 additions & 29 deletions

File tree

_private/createjson.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,37 @@
44
import os
55

66
models = []
7-
for root, dirs, files in os.walk("."):
8-
for file in files:
9-
if file.endswith(".py") and "PARSER" not in file.upper() and file not in ["createjson.py", "readme.py", "searchmodels.py"]:
10-
model = os.path.join(root, file)[2:]
11-
type = "CSP"
12-
name = os.path.basename(model).split(".")[0]
13-
f = open(model, "r")
14-
lines = f.readlines()
15-
constraints = []
16-
tags = []
17-
links = []
18-
start = False
19-
for line in lines:
20-
stripped = line.strip()
21-
if stripped.startswith("minimize(") or stripped.startswith("maximize("):
22-
type = "COP"
23-
if stripped.startswith("- http"):
24-
links.append(stripped.split("-")[1].strip())
25-
if stripped.startswith("constraints") or stripped.startswith("Constraints"):
26-
constraints = [c.strip() for c in stripped.split(":")[1].split(',')]
27-
if stripped.startswith("## Tags"):
28-
start = True
29-
elif start:
30-
tags = [t.strip().rstrip(",") for t in stripped.split(" ")]
31-
start = False
32-
f.close()
33-
models.append({"name": name, "fullname": os.path.dirname(model), "constraints" : constraints, "type": type, "tags": tags, "links": links})
7+
directories = ["academic", "single", "realistic", "crafted", "recreational"]
8+
9+
for thedir in directories:
10+
problems = sorted([name for name in os.listdir(thedir) if os.path.isdir(os.path.join(thedir, name))])
11+
12+
for p in problems:
13+
dir = f"{thedir}/{p}"
14+
model = f"{p}.py" if os.path.isfile(f"{dir}/{p}.py") else f"{p}1.py"
15+
model = dir + "/" + model
16+
type = "CSP"
17+
lines = open(model, "r").readlines()
18+
constraints = []
19+
tags = []
20+
links = []
21+
start = False
22+
for line in lines:
23+
stripped = line.strip()
24+
if stripped.startswith("minimize(") or stripped.startswith("maximize("):
25+
type = "COP"
26+
if stripped.startswith("- http"):
27+
links.append(stripped.split("-")[1].strip())
28+
if stripped.startswith("constraints") or stripped.startswith("Constraints"):
29+
constraints = [c.strip() for c in stripped.split(":")[1].split(',')]
30+
if stripped.startswith("## Tags"):
31+
start = True
32+
elif start:
33+
tags = [t.strip().rstrip(",") for t in stripped.split(" ")]
34+
start = False
35+
models.append(
36+
{"name": p, "fullname": model, "constraints": constraints, "type": type, "tags": tags,
37+
"links": links})
3438

3539
models.sort(key=lambda model: model["name"])
3640
print(json.dumps(models))
37-

_private/models.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)