Godheritage commited on
Commit
c610b12
·
verified ·
1 Parent(s): 07aae38

Update get_machine_from_json.py

Browse files
Files changed (1) hide show
  1. get_machine_from_json.py +49 -50
get_machine_from_json.py CHANGED
@@ -1,50 +1,49 @@
1
- from sys import exception
2
- import utils as dp # 使用别名dp,方便调用
3
- from utils import extract_json_from_string
4
- import os
5
-
6
- def format_json(input_json):
7
- try:
8
- new_clean_json=[]
9
- for json_info in input_json:
10
- new_clean_dict={}
11
- if int(json_info["id"]) not in [7,9]:
12
- new_clean_dict["id"]=str(json_info["id"])
13
- new_clean_dict["order_id"]=int(json_info["order_id"])
14
- new_clean_dict["parent"]=int(json_info["parent"])
15
- new_clean_dict["bp_id"]=int(json_info["bp_id"])
16
- else:
17
- new_clean_dict["id"]=str(json_info["id"])
18
- new_clean_dict["order_id"]=int(json_info["order_id"])
19
- new_clean_dict["parent_a"]=int(json_info["parent_a"])
20
- new_clean_dict["bp_id_a"]=int(json_info["bp_id_a"])
21
- new_clean_dict["parent_b"]=int(json_info["parent_b"])
22
- new_clean_dict["bp_id_b"]=int(json_info["bp_id_b"])
23
- new_clean_json.append(new_clean_dict)
24
- return new_clean_json
25
- except:
26
- return input_json
27
-
28
- def get_machine_from_json(solution_str,step,score,save_root):
29
-
30
-
31
- tmp_path = Rf"{save_root}/step{step}score{score}.bsg"
32
- solution_str =solution_str.replace("", "").replace("\\", "")
33
- machine_json = extract_json_from_string(solution_str)
34
-
35
- machine_json = format_json(machine_json)
36
- dp.json_to_xml(machine_json,tmp_path)
37
-
38
-
39
- def string_to_bsg(solution_str):
40
- solution_str =solution_str.replace("", "").replace("\\", "")
41
-
42
- machine_json = extract_json_from_string(solution_str)
43
- machine_json = format_json(machine_json)
44
- xml_string = dp.json_to_xml(machine_json)
45
- return xml_string
46
-
47
-
48
-
49
-
50
-
 
1
+ import utils as dp # 使用别名dp,方便调用
2
+ from utils import extract_json_from_string
3
+ import os
4
+
5
+ def format_json(input_json):
6
+ try:
7
+ new_clean_json=[]
8
+ for json_info in input_json:
9
+ new_clean_dict={}
10
+ if int(json_info["id"]) not in [7,9]:
11
+ new_clean_dict["id"]=str(json_info["id"])
12
+ new_clean_dict["order_id"]=int(json_info["order_id"])
13
+ new_clean_dict["parent"]=int(json_info["parent"])
14
+ new_clean_dict["bp_id"]=int(json_info["bp_id"])
15
+ else:
16
+ new_clean_dict["id"]=str(json_info["id"])
17
+ new_clean_dict["order_id"]=int(json_info["order_id"])
18
+ new_clean_dict["parent_a"]=int(json_info["parent_a"])
19
+ new_clean_dict["bp_id_a"]=int(json_info["bp_id_a"])
20
+ new_clean_dict["parent_b"]=int(json_info["parent_b"])
21
+ new_clean_dict["bp_id_b"]=int(json_info["bp_id_b"])
22
+ new_clean_json.append(new_clean_dict)
23
+ return new_clean_json
24
+ except:
25
+ return input_json
26
+
27
+ def get_machine_from_json(solution_str,step,score,save_root):
28
+
29
+
30
+ tmp_path = Rf"{save_root}/step{step}score{score}.bsg"
31
+ solution_str =solution_str.replace("", "").replace("\\", "")
32
+ machine_json = extract_json_from_string(solution_str)
33
+
34
+ machine_json = format_json(machine_json)
35
+ dp.json_to_xml(machine_json,tmp_path)
36
+
37
+
38
+ def string_to_bsg(solution_str):
39
+ solution_str =solution_str.replace("", "").replace("\\", "")
40
+
41
+ machine_json = extract_json_from_string(solution_str)
42
+ machine_json = format_json(machine_json)
43
+ xml_string = dp.json_to_xml(machine_json)
44
+ return xml_string
45
+
46
+
47
+
48
+
49
+