All checks were successful
ci/woodpecker/push/check_format Pipeline was successful
89 lines
2.4 KiB
Python
Executable file
89 lines
2.4 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
"""
|
|
Copyright (c) 2024 Elaina <2901432375@qq.com>
|
|
Copyright (c) 2024 zhbaor <zhbaor@zhaozuohong.vip>
|
|
|
|
This file is part of mower-ng (https://git.zhaozuohong.vip/mower-ng/mower-ng).
|
|
|
|
Mower-ng is free software: you may copy, redistribute and/or modify it
|
|
under the terms of the GNU General Public License as published by the
|
|
Free Software Foundation, version 3 or later.
|
|
|
|
This file is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
with open("mower/data/scene.json", "r", encoding="utf-8") as f:
|
|
scene_list = json.load(f)
|
|
|
|
scene_class = "class Scene:"
|
|
scene_comment = "SceneComment = {"
|
|
|
|
for scene, data in scene_list.items():
|
|
id = int(scene)
|
|
label = data["label"]
|
|
comment = data["comment"]
|
|
scene_class += f'\n {label} = {id}\n "{comment}"'
|
|
scene_comment += f'\n {id}: "{comment}",'
|
|
|
|
scene_comment += "\n}"
|
|
code = scene_class + "\n\n\n" + scene_comment + "\n"
|
|
|
|
with open("mower/utils/scene.py", "w", encoding="utf-8") as f:
|
|
f.write(code)
|
|
|
|
|
|
res_path_name = "mower/resources/"
|
|
res_path = Path(res_path_name)
|
|
|
|
data = "from typing import Literal\n\nRes = Literal[\n"
|
|
|
|
for i in sorted(res_path.glob("**/*"), key=lambda x: x.as_posix()):
|
|
if not i.is_file():
|
|
continue
|
|
res_name = i.as_posix()
|
|
res_name = res_name.replace(res_path_name, "")
|
|
res_name = res_name.replace(".png", "")
|
|
data += f' "{res_name}",\n'
|
|
|
|
data += "]\n"
|
|
|
|
with open("mower/utils/typealias/res.py", "w", encoding="utf-8") as f:
|
|
f.write(data)
|
|
|
|
|
|
color = {}
|
|
template_matching = {}
|
|
template_matching_score = {}
|
|
|
|
data_path = "mower/utils/recognize/data.py"
|
|
|
|
|
|
def print_dict(data):
|
|
data = list(data.items())
|
|
data.sort(key=lambda x: x[0])
|
|
result = "{\n"
|
|
for key, value in data:
|
|
result += f' "{key}": {value},\n'
|
|
result += "}\n"
|
|
return result
|
|
|
|
|
|
with open(data_path, "r+", encoding="utf-8") as f:
|
|
exec(f.read())
|
|
f.seek(0)
|
|
f.write("color = ")
|
|
f.write(print_dict(color))
|
|
f.write("\ntemplate_matching = ")
|
|
f.write(print_dict(template_matching))
|
|
f.write("\ntemplate_matching_score = ")
|
|
f.write(print_dict(template_matching_score))
|