From 1fbda6c8787aa73a5224c43a2d4091cf0048d6d0 Mon Sep 17 00:00:00 2001 From: pur1fy <2274916027@qq.com> Date: Thu, 11 Jul 2024 19:48:00 +0800 Subject: [PATCH] update develop tools --- .gitignore | 1 + develop_tools/explore_task_data_generator.py | 196 +++++++++++++++++++ develop_tools/update_student_name.py | 58 ++++++ 3 files changed, 255 insertions(+) create mode 100644 develop_tools/explore_task_data_generator.py create mode 100644 develop_tools/update_student_name.py diff --git a/.gitignore b/.gitignore index dd06aa030..22ff604d4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ !core !device_operation !.github +!develop_tools !.editorconfig !.gitignore diff --git a/develop_tools/explore_task_data_generator.py b/develop_tools/explore_task_data_generator.py new file mode 100644 index 000000000..40822d867 --- /dev/null +++ b/develop_tools/explore_task_data_generator.py @@ -0,0 +1,196 @@ +# this script is used to generate explore task data which can be used +# in function common_gird_method in module.explore_normal_task, the function is under this line +from module.explore_normal_task import common_gird_method + + +import json + +stage_data = {} + +input_record = "" + + +def get_input(): + global input_record + temp = input() + input_record += temp + "\n" + return temp + + +def get_stage_name(): + print("Please enter stage name : ") + stage_name = get_input() + return stage_name + + +def get_team_info(): + valid_team_attr = { + "burst1": True, + "burst2": True, + "pierce1": True, + "pierce2": True, + "mystic1": True, + "mystic2": True, + "shock1": True, + "shock2": True, + } + + char2attr = { + "b": "burst", + "p": "pierce", + "m": "mystic", + "s": "shock", + } + print("Please enter the team count : ") + cnt = int(get_input()) + teams = [] + while cnt > 0: + print("left teams : ", cnt) + + print(f"Please enter the team name : \n b : burst \n p : pierce \n m : mystic \n s : shock \n swipe : swipe") + char = get_input().replace(" ", "") + if char == "swipe": + print("Please enter the swipe position and duration : format [ x1 y1 x2 y2 duration ]") + t = get_input().split() + if len(t) < 5: + print("Invalid swipe data") + continue + x1, y1, x2, y2 = map(int, t[:4]) + duration = float(t[4]) + teams.append(["swipe", (x1, y1, x2, y2, duration)]) + elif char in ["b", "p", "m", "s"]: + temp = char2attr[char] + "1" + if valid_team_attr[temp]: + print("Please enter the position : ") + pos = get_one_position() + teams.append([temp, pos]) + cnt -= 1 + valid_team_attr[char] = False + else: + temp = char2attr[char] + "2" + if valid_team_attr[temp]: + print("Please enter the position : ") + pos = tuple(map(int, get_input().split())) + teams.append([temp, pos]) + cnt -= 1 + valid_team_attr[char] = False + else: + print("Invalid team attribute") + continue + print('successfully add team : ', temp) + print('--------------------------------------------------') + print("current teams : ", teams) + print('--------------------------------------------------') + else: + print("Invalid team attribute") + continue + return teams + + +def has_position(tp): + if tp in ["2", "3", "4", "5", "6"]: + return 1 + return 0 + + +def get_one_position(): + print("please enter position : format [ x y ]") + temp = get_input().split() + if len(temp) != 2: + print("Invalid position") + return get_one_position() + try: + ret = tuple(map(int, temp)) + return ret + except Exception as e: + print("Invalid position : " + str(temp)) + return get_one_position() + + +def get_y_n(): + temp = get_input() + if temp != "y" and temp != "n": + print("Invalid input") + return get_y_n() + if temp == "y": + return True + return False + + +def get_actions(team_cnt): + action = [] + action_name = { + "0": "exchange", + "1": "exchange_twice", + "2": "click", + "3": "exchange_and_click", + "4": "exchange_twice_and_click", + "5": "click_and_teleport", + "6": "choose_and_change", + "7": "end-turn", + "8": "retreat" + } + while True: + one_action = { + + } + print("please enter the action type : \n 0 : exchange \n 1 : exchange_twice \n 2 : click \n 3 : exchange_and_click \n 4 : exchange_twice_and_click \n 5 : click_and_teleport \n 6 : choose_and_change \n 7 : end-turn \n 8 : retreat") + print("q : quit") + tp = get_input() + + if tp == "q": + break + temp = tp.split() + p_cnt = 0 + if len(temp) == 1: + one_action["t"] = action_name[temp[0]] + else: + t = [] + for i in temp: + if i == "8": + print("please enter total fights and which fight to retreat : format [ total_fights fight_to_retreat ]") + one_action["retreat"] = get_one_position() + t.append(action_name[i]) + one_action["t"] = t + for i in temp: + p_cnt += has_position(i) + print("total position required : ", p_cnt) + if p_cnt == 1: + one_action["p"] = get_one_position() + else: + one_action["p"] = [] + for i in range(p_cnt): + one_action["p"].append(get_one_position()) + + if team_cnt > 1: + print("Will formation number change after this action ? [y/n]") + if get_y_n(): + one_action["ec"] = True + + print("Need wait-over after this action ? [y/n]") + if get_y_n(): + one_action["wait-over"] = True + print("please enter the desc : ") + one_action["desc"] = get_input() + print("current action : \n", one_action) + action.append(one_action) + return action + + +try: + stage_name = get_stage_name() + stage_data[stage_name] = {} + stage_data[stage_name]["start"] = get_team_info() + stage_data[stage_name]["action"] = get_actions(len(stage_data[stage_name]["start"])) +except Exception as e: + print(json.dumps(stage_data, indent=2)) + print("Invalid input") + print(e) + + +print("---------------------------------") +print("input record : ") +print(input_record) +print("---------------------------------") + +print(json.dumps(stage_data, indent=2)) diff --git a/develop_tools/update_student_name.py b/develop_tools/update_student_name.py new file mode 100644 index 000000000..cade05117 --- /dev/null +++ b/develop_tools/update_student_name.py @@ -0,0 +1,58 @@ +# Usage: this script is used to update the student name list from shacleDB, updated data should be paste into +# core/default_config.py "student_names" +# +# TODO: 1.change default_config.py "student_names" to a json file 2.auto write +# the updated data into the json file instead of paste it manually +import urllib.request +import json + + +def download_json(url, file_path): + response = urllib.request.urlopen(url) + data = response.read().decode('utf-8') + data = json.loads(data) + with open(file_path, 'w') as file: + json.dump(data, file) + + +server = ['cn', 'en', 'jp'] + +url = "https://raw.githubusercontent.com/SchaleDB/SchaleDB/main/data/" +end = "/students.json" +file_path = "../src/student_name_raw/" +for i in range(0, len(server)): + download_json(url + server[i] + end, file_path + server[i] + "_student.json") +serverid = { + "cn": "CN", + "en": "Global", + "jp": "JP" +} +servernumber = { + "CN": 2, + "Global": 1, + "JP": 0 +} +updated = [] +data = [] +for i in range(0, len(server)): + with open(file_path + server[i] + "_student.json", 'r') as file: + data.append(json.load(file)) +for j in range(0, len(data[1])): + dic = {} + for i in range(0, len(server)): + IsReleased = data[i][j]['IsReleased'][servernumber[serverid[server[i]]]] + name = data[i][j]['Name'].replace("(", "(").replace(")", ")") + dic[serverid[server[i]] + "_name"] = name + dic[serverid[server[i]] + "_implementation"] = IsReleased + updated.insert(0, dic) +for i in range(0, len(updated)): + print(updated[i]) +result = { + "student_names": updated +} +str = json.dumps(result, ensure_ascii=False, indent=2) +print(str) # paste output into core/default_config.py "student_names" + + + +