-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
712 lines (636 loc) · 28.3 KB
/
Copy pathutils.py
File metadata and controls
712 lines (636 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
import fitz
import json
import os
import re
import logging
import hid
from model import CLIENT,simple_llm
from jsonschema import validate, ValidationError
def init_logger(name,path,log_level=logging.DEBUG,console_level=logging.DEBUG,file_level=logging.DEBUG,silence=False):
# 创建logger对象
logger = logging.getLogger(name)
logger.setLevel(log_level) # 设置最低级别
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
# 创建控制台处理器并设置级别
if not silence:
console_handler = logging.StreamHandler()
console_handler.setLevel(console_level)
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
# 创建文件处理器并设置级别
file_handler = logging.FileHandler(path, mode='a', encoding='utf-8')
file_handler.setLevel(file_level) # 只记录错误及以上的日志
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
return logger
#deep merge,using for patch
def deep_merge(dict1, dict2):
"""
递归地合并两个字典。如果两个字典有相同的键且对应的值都是字典,
则递归合并这些子字典;否则,dict2 中的值会覆盖 dict1 中的值。
"""
for key in dict2:
if key in dict1:
if isinstance(dict1[key], dict) and isinstance(dict2[key], dict):
deep_merge(dict1[key], dict2[key])
else:
dict1[key] = dict2[key]
else:
dict1[key] = dict2[key]
return dict1
#merge a list of json dict
def merge_json_dicts(file_paths):
merged_dict = {}
for file_path in file_paths:
# print(file_path)
if not os.path.exists(file_path):
print(f"Warning: File {file_path} does not exist.")
continue
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
if isinstance(data, dict):
merged_dict = deep_merge(merged_dict, data)
else:
print(f"Warning: {file_path} does not contain a dictionary.")
return merged_dict
def get_pdf_links(pdf_path):
# 打开PDF文件
document = fitz.open(pdf_path)
links = []
for page_num in range(len(document)):
page = document[page_num]
# 获取当前页面的链接
for link in page.get_links():
links.append((page_num, link))
document.close()
return links
def get_toc(pdf_file_path):
pdf_file = pdf_file_path
pdf = fitz.open(pdf_file)
toc = pdf.get_toc()
dic = {}
for item in toc:
title = item[1]
page = item[2]
level = item[0]
dic[title] = page
#print(f"title: {title}, page: {page}, level: {level}")
if level == 1:
print(f"{title} - {page}")
elif level == 2:
print(f" {title} - {page}")
elif level == 3:
print(f" {title} - {page}")
elif level == 4:
print(f" {title} - {page}")
print(len(dic))
pdf.close()
# print(dic["2.1 - Unguided Bomb (MK-82) - CCIP / Computer Pilot"])
def clean_filename(filename):
# 替换或删除特殊字符
invalid_chars = '<>:"/\\|?*'
for char in invalid_chars:
filename = filename.replace(char, '')
return filename
def split_pdf(pdf_file_path,save_path,page_list=None):
pdf_file = pdf_file_path
pdf = fitz.open(pdf_file)
if page_list is not None:
new_pdf = fitz.open()
new_pdf.insert_pdf(pdf, from_page=page_list[0], to_page=page_list[1])
filename = clean_filename(pdf_file)
new_pdf.save(f"{save_path}\\{filename}.pdf")
else:
toc = pdf.get_toc()
dic = []
for item in toc:
title = item[1]
page = item[2]
level = item[0]
dic.append((title, page, level))
last_page = 0
last_title = ""
cnt = 1
for item in dic:
title = item[0]
page = item[1] - 1
if last_title and last_page != page:
new_pdf = fitz.open()
new_pdf.insert_pdf(pdf, from_page=last_page, to_page=page - 1)
filename = clean_filename(last_title)
new_pdf.save(f"{save_path}\{cnt:03d}_{filename}.pdf")
cnt = cnt + 1
print(f"Saved {last_title}.pdf")
new_pdf.close()
last_page = page
last_title = title
pdf.close()
def crop_pdf(pdf_file_path,save_path):
pdf_path = pdf_file_path # 这里替换成你的PDF文件路径
pdf_doc = fitz.open(pdf_path)
for page_number in range(len(pdf_doc)):
page = pdf_doc[page_number] # 获取单页
new_rect = fitz.Rect(64,54,548,740)
# 设置裁剪区域
page.set_cropbox(new_rect)
pdf_doc.save(save_path)
pdf_doc.close()
def get_text_from_pdf(filename):
pdf = fitz.open(filename)
text = ''
for page_number in range(len(pdf)):
page = pdf[page_number] # 获取单页
text = text + page.get_text() # 提取页面文本
# print(f"Page {page_number + 1}:")
# print(text)
# 关闭PDF文件
# print(text)
pdf.close()
return text
#syntax correction
def syntax_correction(data):
#data cleaning
data.replace('–','-')
cleaned_data = re.sub(r'^```json(.*?)```$', r'\1', data, flags=re.DOTALL).strip()
return cleaned_data
#always return none unless occur format wrong
def format_correction(json_data):
output = None
ve = None
#check schema
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string"},
"content":{
"type": "array",
"items": {
"type": "object",
"properties": {
"step": {"type": "integer","minimum": 1},
"agent": {"type": "string",
"enum": ["PILOT","RIO","JESTER"]},
"instruction": {"type": "string"},
"substeps": {
"type": "array",
"items": {
"type": "string"
}
},
"note": {"type": "string"}
},
"required": ["step","instruction","agent"]
}
},
"description": {"type":"string"}
},
"required": ["name","type", "content","description"]
}
try:
validate(instance=json_data, schema=schema)
except ValidationError as e:
ve = e
# print(ve)
tmp = '''
将给你一段jsonschema的报错信息,请根据报错信息修改json文件,并且最后请输出json格式的数据,除了修改后的json文件外不要输出任何信息
**error**:
{error}
**json**:
{data}
'''
tmp = tmp.format(error=ve,data=json.dumps(json_data,indent=4))
client,model = CLIENT("deepseek")
chat_completion = client.chat.completions.create(
messages=[
{
"role":"user",
"content": tmp
}
],
model=model,
response_format={"type": "json_object"},)
output = syntax_correction(chat_completion.choices[0].message.content)
return output,ve
#get single subtask from single pdf, always return null unless get error
def get_subtask_from_pdf(pdf_path,save_path,logger):
tmp1 = '''
You're a fighter pilot assistant and you'll need to learn some specialized knowledge, and you'll be given some documentation from which you'll need to extract the relevant knowledge of the sub-missions.
Please extract the complete operation steps contained in the possible subtasks in each document, give these collections of steps a suitable name and description, but do not keep the serial number for the title.
Pay attention to the format of the output, e.g. when exporting ", please replace it with ', replace – with -, etc. Do not output any other information other than that.
The output is in json format, here's an example:
**example1**
*input*:
{input1}
*output*:
{output1}
**end of example1**
Note the distinction between operations with [J], which usually refers to another form of RIO, Jester, here is an example:
**example2**
*input*:
{input2}
*output*:
{output2}
**end of example2**
Sometimes you need to combine the respective functions of the two drivers and our mission scenario to deduce who the executor of the command is, in the following example it can be inferred that the radar is operated by the backseat RIO, so it can be inferred that the executor is RIO:
**example3**
*input*:
{input3}
*output*:
{output3}
**end of example3**
'''
tmp2 ='''
This is the content of the document you need to extract:
{content}
'''
#提取PILOT/RIO操作示例
example_input1 = get_text_from_pdf('data\\pdf\\cropped_TomcatGuide_split\\099_2.7 - TALD Decoys.pdf')
with open('data\\json\\PR_example.json', 'r',encoding='utf-8') as file:
data = json.load(file)
example_output1 = json.dumps(data, indent=4,ensure_ascii=False)
#提取PILOT/JESTER操作示例
example_input2 = get_text_from_pdf('data\\pdf\\cropped_TomcatGuide_split\\015_1 - Pilot Pre-Start.pdf')
with open('data\\json\\PJ_example.json', 'r',encoding='utf-8') as file:
data = json.load(file)
example_output2 = json.dumps(data, indent=4,ensure_ascii=False)
#需要结合上下文找出单人操作示例
example_input3 = get_text_from_pdf("data\\pdf\\cropped_TomcatGuide_split\\055_2.4.4 - Pulse Doppler STT (Single Target Track) Lock.pdf")
with open('data\\json\\single_example.json', 'r',encoding='utf-8') as file:
data = json.load(file)
example_output3 = json.dumps(data, indent=4,ensure_ascii=False)
tmp1 = tmp1.format(input1 = example_input1, output1 = example_output1,
input2 = example_input2, output2 = example_output2,
input3 = example_input3, output3 = example_output3)
text = get_text_from_pdf(pdf_path)
tmp2 = tmp2.format(content = text)
client,model = CLIENT("deepseek")
chat_completion = client.chat.completions.create(
messages=[
{
"role": "system",
"content": tmp1,
},
{
"role":"user",
"content": tmp2
}
],
model=model,
response_format={"type": "json_object"},
)
llm_output = syntax_correction(chat_completion.choices[0].message.content)
if llm_output == '{}':#if output is empty
logger.info(f'[E]No subtasks found in {pdf_path}')
return
#show the output
# print(llm_output)
#load the output into json and check the format
loop_cnt = 0
while llm_output is not None:
if loop_cnt > 5:
logger.error(f"ERROR in {pdf_path}, Can't get correct format in limit times. Please check the format of the output manually:\n{llm_output}")
return
if loop_cnt > 0:
logger.warning(f"WARN in {pdf_path}, Can't get correct format in {loop_cnt} times from:\n{llm_output}\nBUG INFO:\n{ve}\n")
print(f"trying {loop_cnt} times to get correct format")
try:
new_object = json.loads(llm_output)
except json.JSONDecodeError:
logger.error(f"ERROR in {pdf_path}, Can't load into json from:\n{llm_output}")
return
llm_output,ve = format_correction(new_object)
loop_cnt += 1
#save the output to subtasks.json
with open(save_path, 'r', encoding='utf-8') as file:
data = json.load(file)
#repeat check
for obj in data:
if obj['name'] == new_object['name'] and obj['type'] == new_object['type']:
logger.info(f'[R]Subtask from {pdf_path} already exists in the database')
return
data.append(new_object)
with open(save_path, 'w', encoding='utf-8') as file:
json.dump(data, file, indent=4, ensure_ascii=False)
logger.info(f'[S]Subtasks from {pdf_path} have been saved')
return
def get_subtasks_from_pdf(folder_path,save_path,log_path,target_list = None):
pdf_cnt = 0
#init logger
logger = init_logger("debug for subtasks generate",console_level=logging.INFO)
for filename in os.listdir(folder_path):
if filename.endswith('.pdf'):
pdf_cnt += 1
if target_list is not None and pdf_cnt not in target_list:#allow user to choose target pdf manually
print(f"skip {pdf_cnt}th pdf")
continue
pdf_path = folder_path + filename
get_subtask_from_pdf(pdf_path,save_path,logger)
# print(pdf_cnt)
def get_state_list_from_pdf():
tmp ="""
You are a veteran fighter pilot, you need to classify the instruments and switches in the cockpit according to their functions or characteristics,
so that you can quickly query the status of all the instruments and switches required for a certain type of operation,
Please note that the JSON content you output should be brief, without any explanatory content, and you don't need to explain the function of each meter switch.
this is the list of instrument switches in the back cockpit(RIO) of the F-14, please convert the output to json format:
<content>
{content}
</content>
<example>
"category": "TACAN",
"description": "TACAN(Tactical Air Navigation) related information",
"items":[
"ALR-67 knob",
"SW knob",
"V/UHF 2 knob",
"TACAN CMD switch",
"Dual rotary switch",
"GO & NO-GO lights",
"BIT button",
"MODE switches",
"VOL knob",
"Mode knob"]
</example>
"""
# print(output)
output = get_text_from_pdf('data\\pdf\\TomcatManual_split\\cropped_pilot.pdf')
tmp = tmp.format(content = output)
with open('data\\txt\\test.txt', 'w', encoding='utf-8') as file:
file.write(tmp)
def show_subtasks_names(file_name,silent=True,with_tag=None):
with open(file_name, 'r',encoding='utf-8') as file:
data = json.load(file)
# 如果with_tag不为None且是文件路径,读取tag文件
tagged_tasks = []
if with_tag is not None:
try:
with open(with_tag, 'r', encoding='utf-8') as tag_file:
tagged_tasks = json.load(tag_file)
except Exception as e:
print(f"Error loading tag file: {e}")
RIO_TASKS = []
PILOT_TASKS = []
PR_TASKS = []
PJ_TASKS = []
for obj in data:
task_name = obj['name']
# 如果任务名在tag文件中,则跳过
if task_name in tagged_tasks:
continue
param = obj.get('param', '')
if param:
task_name += f'({param})'
if obj['agents'] == 'RIO':
RIO_TASKS.append(task_name)
elif obj['agents'] == 'PILOT':
PILOT_TASKS.append(task_name)
elif obj['agents'] == 'PILOT and RIO':
PR_TASKS.append(task_name)
elif obj['agents'] == 'PILOT and JESTER':
PJ_TASKS.append(task_name)
if not silent:
print("**********************RIO_TASKS:**********************")
for i in RIO_TASKS:
print(i)
print("**********************PILOT_TASKS:**********************")
for i in PILOT_TASKS:
print(i)
print("**********************PR_TASKS:**********************")
for i in PR_TASKS:
print(i)
print("**********************PJ_TASKS:**********************")
for i in PJ_TASKS:
print(i)
return RIO_TASKS,PILOT_TASKS,PR_TASKS
def rename_subtasks(file_path,save_path):
tmp = '''
You are a fighter assist system, and you need to assist two pilots, PILOT and RIO.
There are currently some records of the operation of two pilots, which are used as sub-plans for the subsequent development of the battle plan, but the titles in these records are not clear, or are not suitable for the development of the battle plan, please help me rewrite this title to make this set of operations sound like an operation that can complete a certain mission. Of course, if you think the title is already clear, you can also leave it alone.
You only need to output the modified name, you don't need to output any additional information, if you think you don't need to change it, please output the original name, be careful not to lose the information
Here's the json file you need to try to modify, with the title "name" indicated:
{content}
'''
# 读取JSON文件
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
# 处理每个对象
for obj in data:
# 使用simple_llm函数生成新的name
new_name = simple_llm("deepseek",tmp.format(content = json.dumps(obj, indent=4,ensure_ascii=False))).strip('"\'')
print(f"change old name: {obj['name']} to new one: {new_name}")
obj['name'] = new_name # 更新对象的'name'键
# 将更新后的数据写回文件
with open(save_path, 'w', encoding='utf-8') as file:
json.dump(data, file, indent=4, ensure_ascii=False)
def describe_subtasks(file_path,save_path):
tmp="""
You are a veteran fighter pilot, and I will show you some of the operations of the two pilots on the F14 fighter jet, and please give a general description of what they operated, so that I can directly know what these operations involve and what objectives are accomplished,
Make sure your answers are concise and don't generate superfluous content
Example session:
<input>
{example_json}
</input>
<output>The action involves the use of the LANTIRN (Low Altitude Navigation and Targeting Infrared for Night) pod, which provides advanced targeting and navigation capabilities, particularly in low-light or night-time conditions. The GBU-12 is a laser-guided bomb, and the LANTIRN pod is used to designate and track the target with a laser, guiding the bomb to its target.</output>
Here is the operations you need to overview:
<operations>
{op}
</operations>
"""
with open(file_path, 'r',encoding='utf-8') as file:
data = json.load(file)
for obj in data:
if obj["name"] == "GBU-12 LANTIRN-Guided Bombing Mission Execution Plan" and obj["type"] == "PILOT and RIO":
content = json.dumps(obj, indent=4,ensure_ascii=False).strip()
for obj in data:
if obj["name"] == "PRE-FLIGHT PREPARATION AND START-UP PROCEDURE" and obj["type"] == "PILOT and JESTER":
tmp = tmp.format(example_json=content,op=json.dumps(obj, indent=4,ensure_ascii=False))
# print(tmp)
descri = simple_llm("deepseek",content=tmp)
obj["description"] = descri
print(obj["name"],descri)
# with open(save_path, 'w', encoding='utf-8') as file:
# json.dump(data, file, indent=4, ensure_ascii=False)
def describe_data_category(file_path,output_file):
tmp = '''This is a certain type of data for F14 fighters, and you need to summarize this data category very briefly:
{content}
And finally output should be like <category>: <describe>format,
in description, you need to describe what this data category is first, and then describe the data contained in this category,
for example:
**AHRS**: Attitude and Heading Reference System, providing aircraft orientation and heading data.
**DDD**:Dual Digital Displays, providing radar and navigation data.
**Weapon Panel**:RIO Weapon Panel, providing weapon related data.
'''
summaries = []
cnt = 0
with open(file_path, 'r',encoding='utf-8') as file:
data = json.load(file)
for obj in data:
summ = simple_llm("volces-deepseek",tmp.format(content = json.dumps(obj, indent=4,ensure_ascii=False)))
summaries.append(summ)
cnt = cnt + 1
print(f"{cnt}: {summ}")
print(summaries)
# with open(output_file, 'w', encoding='utf-8') as file:
# for summ in summaries:
# file.write(summ + '\n')
def describe_ops(file_path, chosen_category=[], output_file=None, silent=False,redescript_path=None):
# 读取JSON文件
cnt = 0
if redescript_path is not None and os.path.exists(redescript_path):
with open(redescript_path, 'r', encoding='utf-8') as file:
redescript_data = json.load(file)
else:
print(f"no redescript file find in {redescript_path}")
if not isinstance(file_path,list):
file_path = [file_path]
data = merge_json_dicts(file_path)
if chosen_category == []:
for cate,_ in data.items():
chosen_category.append(cate)
pass
# 如果chosen_category不是列表,则将其转换为列表
if not isinstance(chosen_category, list):
chosen_category = [chosen_category]
descriptions = []
# 遍历所选类别
for category in chosen_category:
# 获取当前类别的数据
category_data = data.get(category, {})
# 存储当前类别下所有对象及其描述
descriptions.append(f"***{category}***")
if not silent:
print(f"***{category}***")
# 遍历当前类别下的所有对象
for obj, item in category_data.items():
if redescript_path is not None:
description = redescript_data.get(obj, '')
else:
description = item.get('description', '')
# print(item['inputs'])
# max_value = item['outputs'][0].get('max_value',None)
descriptions.append(f"{obj}: {description} ")#max_value:{max_value}")
# 如果不静默模式,则打印描述
if not silent:
cnt += 1
print(f"{cnt} {obj}: {description}")# max_value:{max_value}")
# 将当前类别的描述添加到结果字典中
results = descriptions
# 如果指定了输出文件,则将结果写入文件
if output_file is not None:
with open(output_file, 'w', encoding='utf-8') as out_f:
json.dump(results, out_f, ensure_ascii=False, indent=4)
return results
def filter_panel_data(file_path, output_file=None):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
# 遍历数据并收集需要删除的键
to_delete = []
for category, items in data.items():
for name, subitem in items.items():
outputs = subitem.get('outputs', [])
# 如果outputs为空或者任何一个output的最大值为65535,则标记该项为待删除
if any(output.get('max_value') == 65535 for output in outputs) or not outputs:
to_delete.append((category, name))
# 删除标记的项
for category, name in to_delete:
del data[category][name]
# 如果没有提供输出文件路径,则覆盖原文件;否则写入新的文件
output_file = output_file if output_file else file_path
with open(output_file, 'w', encoding='utf-8') as file:
json.dump(data, file, indent=2, ensure_ascii=False)
def find_empty_category(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
for category, items in data.items():
if items:
print(category)
pass
else:
print(category)
pass
def show_api_category(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
data = json.load(file)
api_category = []
for category, items in data.items():
for name, item in items.items():
if item["outputs"][0]["type"] == "string":
api_category.append(name)
print(api_category)
def list_all_hid_devices():
"""列出所有连接的 HID 设备详细信息"""
print("所有连接的 HID 设备:")
devices = hid.enumerate()
if not devices:
print("未找到 HID 设备")
return
for i, device in enumerate(devices):
print(f"{i+1}. 厂商ID: 0x{device['vendor_id']:04x}, 产品ID: 0x{device['product_id']:04x}")
print(f" 产品名称: {device.get('product_string', 'N/A')}")
print(f" 制造商: {device.get('manufacturer_string', 'N/A')}")
print(f" 接口编号: {device.get('interface_number', 'N/A')}")
print(f" 使用类型: {device.get('usage_page', 'N/A')}, {device.get('usage', 'N/A')}")
print(f" 路径: {device['path']}")
print("-----------------------------------")
def load_prefix_task(task_name, file_path="data/json/evaluation/task/task.json"):
try:
with open(file_path, 'r', encoding='utf-8') as f:
tasks = json.load(f)
for task in tasks:
if task.get('task') == task_name:
return task
print(f"警告: 在預設任務文件中找不到任務 '{task_name}'")
return None
except FileNotFoundError:
print(f"警告: 找不到預設任務文件 {file_path}")
return None
except json.JSONDecodeError as e:
print(f"警告: 預設任務文件格式錯誤: {e}")
return None
if __name__ == "__main__":
pass
# filter_panel_data("data\\json\\dcs\\F-14.json","data\\json\\dcs\\F-14_filtered.json")
# show_api_category("data\json\dcs\oringin\F-14.json")
# st= "RIO Indicator Lights"
# st = "Screen"
st = "Joystick"
# describe_ops("data\json\dcs\wo_geague\F-14_wog.json",chosen_category=st.split(','))
# describe_ops(file_path=["data\json\dcs\wo_geague\F-14_wog_re.json",
# "data\json\dcs\patch\F-14_patch.json"],
# chosen_category=st.split(','),
# redescript_path="data\\json\\dcs\\data_redescript\\F-14_wog_redescript.json")
# describe_ops(file_path=["data\\json\\dcs\\oringin\\CommonData.json"],
# chosen_category=[],
# redescript_path="data\\json\\dcs\\data_redescript\\F-14_wog_redescript.json")
# find_empty_category("data\\json\\dcs\\wo_geague\\F-14_wog_re.json")
# describe_data_category("data\json\dcs\\wo_geague\F-14_wog_re.json",output_file="data\\txt\F-14_category_summ_V3.txt")
# describe_data_category("data\json\dcs\CommonData.json",output_file="data\\txt\CommonData_category_summ.txt")
# describe_data_category("data\json\dcs\patch\F-14_patch.json",output_file="data\\txt\F-14_category_summ_V3.txt")
# crop_pdf('.\data\pdf\F-14B Manual 1.0_compressed.pdf',
# save_path='.\data\pdf\cropped_F-14B Manual 1.0_compressed.pdf')
# text = get_text_from_pdf('.\data\pdf\cropped_F-14B Manual 1.0_compressed.pdf')
# with open('data/txt/cropped_TomcatManual.txt', 'w', encoding='utf-8') as file:
# file.write(text)
# split_pdf(pdf_file_path='data\\pdf\\cropped_TomcatGuide_compressed.pdf',save_path='data\\pdf\\cropped_TomcatGuide_split')
# get_toc('data\pdf\F-14B Manual 1.0_compressed.pdf')
# get_subtask_from_pdf(pdf_path = 'data\\pdf\\cropped_TomcatGuide_split\\1_Disclaimer.pdf',
# save_path = 'data\\json\\test.json',)
# tg_list = [15,16,17,18,19,20,21,22,23,24,
# 44,48,55,68,71,73,76,
# 91,92,93,94,97,98,99,
# 100,101,102,103,104,105,106,107,108,
# 124,126,127,128,
# 141,142,143,144,145,146,151,154,157,161,162,163,164]
# get_subtasks_from_pdf(folder_path = 'data\\pdf\\cropped_TomcatGuide_split\\',
# save_path = 'data\\json\\subtasksV2.json',
# log_path='log\\test.log',
# target_list=tg_list)
# rename_subtasks(file_path='data\\json\\subtasks.json',
# save_path='data\\json\\renamed_subtasks.json')
show_subtasks_names('data\\json\\subtasksV3.json',silent=False,with_tag="data\\json\\Atag.json")
#
# describe_subtasks(file_path='data\\json\\renamed_subtasks.json',
# save_path='data\\json\\renamed_describe_subtasks.json',)
# print("if you look at this, you are a genius")
# list_all_hid_devices()
pass