mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-21 16:28:17 +00:00
Chore: [ALAS] Move func methods to the Alas class
This commit is contained in:
parent
0dd8c6b921
commit
8dfac73f30
@ -28,6 +28,8 @@ class ModuleBase:
|
||||
"""
|
||||
if isinstance(config, AzurLaneConfig):
|
||||
self.config = config
|
||||
if task is not None:
|
||||
self.config.init_task(task)
|
||||
elif isinstance(config, str):
|
||||
self.config = AzurLaneConfig(config, task=task)
|
||||
else:
|
||||
|
@ -106,17 +106,22 @@ class AzurLaneConfig(ConfigUpdater, ManualConfig, GeneratedConfig, ConfigWatcher
|
||||
logger.info("Using template config, which is read only")
|
||||
self.auto_update = False
|
||||
self.task = name_to_function("template")
|
||||
self.init_task(task)
|
||||
|
||||
def init_task(self, task=None):
|
||||
if self.is_template_config:
|
||||
return
|
||||
|
||||
self.load()
|
||||
if task is None:
|
||||
# Bind `Alas` by default which includes emulator settings.
|
||||
task = name_to_function("Alas")
|
||||
else:
|
||||
self.load()
|
||||
if task is None:
|
||||
# Bind `Alas` by default which includes emulator settings.
|
||||
task = name_to_function("Alas")
|
||||
else:
|
||||
# Bind a specific task for debug purpose.
|
||||
task = name_to_function(task)
|
||||
self.bind(task)
|
||||
self.task = task
|
||||
self.save()
|
||||
# Bind a specific task for debug purpose.
|
||||
task = name_to_function(task)
|
||||
self.bind(task)
|
||||
self.task = task
|
||||
self.save()
|
||||
|
||||
def load(self):
|
||||
self.data = self.read_file(self.config_name)
|
||||
|
@ -68,17 +68,19 @@ class Benchmark(DaemonBase):
|
||||
if not isinstance(cost, (float, int)):
|
||||
return Text(cost, style="bold bright_red")
|
||||
|
||||
if cost < 0.10:
|
||||
if cost < 0.025:
|
||||
return Text('Insane Fast', style="bold bright_green")
|
||||
if cost < 0.100:
|
||||
return Text('Ultra Fast', style="bold bright_green")
|
||||
if cost < 0.20:
|
||||
if cost < 0.200:
|
||||
return Text('Very Fast', style="bright_green")
|
||||
if cost < 0.30:
|
||||
if cost < 0.300:
|
||||
return Text('Fast', style="green")
|
||||
if cost < 0.50:
|
||||
if cost < 0.500:
|
||||
return Text('Medium', style="yellow")
|
||||
if cost < 0.75:
|
||||
if cost < 0.750:
|
||||
return Text('Slow', style="red")
|
||||
if cost < 1.00:
|
||||
if cost < 1.000:
|
||||
return Text('Very Slow', style="bright_red")
|
||||
return Text('Ultra Slow', style="bold bright_red")
|
||||
|
||||
@ -87,11 +89,11 @@ class Benchmark(DaemonBase):
|
||||
if not isinstance(cost, (float, int)):
|
||||
return Text(cost, style="bold bright_red")
|
||||
|
||||
if cost < 0.1:
|
||||
if cost < 0.100:
|
||||
return Text('Fast', style="bright_green")
|
||||
if cost < 0.2:
|
||||
if cost < 0.200:
|
||||
return Text('Medium', style="yellow")
|
||||
if cost < 0.4:
|
||||
if cost < 0.400:
|
||||
return Text('Slow', style="red")
|
||||
return Text('Very Slow', style="bright_red")
|
||||
|
||||
@ -177,7 +179,9 @@ class Benchmark(DaemonBase):
|
||||
return [l for l in screenshot if l not in args]
|
||||
|
||||
# No ascreencap on Android > 9
|
||||
if device in ['emulator_android_12', 'android_phone_12']:
|
||||
sdk = self.device.sdk_ver
|
||||
logger.info(f'sdk_ver: {sdk}')
|
||||
if not (21 <= sdk <= 28):
|
||||
screenshot = remove('aScreenCap', 'aScreenCap_nc')
|
||||
# No nc loopback
|
||||
if device in ['plone_cloud_with_adb']:
|
||||
@ -186,6 +190,8 @@ class Benchmark(DaemonBase):
|
||||
if device == 'android_phone_vmos':
|
||||
screenshot = ['ADB', 'aScreenCap', 'DroidCast', 'DroidCast_raw']
|
||||
click = ['ADB', 'Hermit', 'MaaTouch']
|
||||
if self.device.nemu_ipc_available():
|
||||
screenshot.append('nemu_ipc')
|
||||
|
||||
scene = self.config.Benchmark_TestScene
|
||||
if 'screenshot' not in scene:
|
||||
@ -224,6 +230,8 @@ class Benchmark(DaemonBase):
|
||||
screenshot = remove('aScreenCap', 'aScreenCap_nc')
|
||||
if self.device.is_chinac_phone_cloud:
|
||||
screenshot = remove('ADB_nc', 'aScreenCap_nc')
|
||||
if self.device.nemu_ipc_available():
|
||||
screenshot.append('nemu_ipc')
|
||||
screenshot = tuple(screenshot)
|
||||
|
||||
self.TEST_TOTAL = 3
|
||||
@ -233,6 +241,15 @@ class Benchmark(DaemonBase):
|
||||
return method
|
||||
|
||||
|
||||
def run_benchmark(config):
|
||||
try:
|
||||
Benchmark(config, task='Benchmark').run()
|
||||
return True
|
||||
except RequestHumanTakeover:
|
||||
logger.critical('Request human takeover')
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
b = Benchmark('alas', task='Benchmark')
|
||||
b = Benchmark('src', task='Benchmark')
|
||||
b.run()
|
||||
|
@ -5,12 +5,15 @@ import threading
|
||||
from multiprocessing import Process
|
||||
from typing import Dict, List, Union
|
||||
|
||||
import inflection
|
||||
from filelock import FileLock
|
||||
from rich.console import Console, ConsoleRenderable
|
||||
|
||||
from module.config.utils import filepath_config
|
||||
from module.logger import logger, set_file_logger, set_func_logger
|
||||
from module.webui.fake import get_config_mod, mod_instance
|
||||
from module.webui.setting import State
|
||||
from rich.console import Console, ConsoleRenderable
|
||||
from module.webui.submodule.utils import get_available_func
|
||||
|
||||
|
||||
class ProcessManager:
|
||||
@ -147,14 +150,10 @@ class ProcessManager:
|
||||
if e is not None:
|
||||
AzurLaneAutoScript.stop_event = e
|
||||
StarRailCopilot(config_name=config_name).loop()
|
||||
elif func == "Daemon":
|
||||
from tasks.base.daemon import Daemon
|
||||
elif func in get_available_func():
|
||||
from src import StarRailCopilot
|
||||
|
||||
Daemon(config=config_name, task="Daemon").run()
|
||||
elif func == "PlannerScan":
|
||||
from tasks.planner.scan import PlannerScan
|
||||
|
||||
PlannerScan(config=config_name, task="PlannerScan").run()
|
||||
StarRailCopilot(config_name=config_name).run(inflection.underscore(func))
|
||||
else:
|
||||
logger.critical(f"No function matched: {func}")
|
||||
logger.info(f"[{config_name}] exited. Reason: Finish\n")
|
||||
|
6
module/webui/submodule/utils.py
Normal file
6
module/webui/submodule/utils.py
Normal file
@ -0,0 +1,6 @@
|
||||
def get_available_func():
|
||||
return (
|
||||
'Daemon',
|
||||
'Benchmark',
|
||||
'PlannerScan',
|
||||
)
|
12
src.py
12
src.py
@ -58,6 +58,18 @@ class StarRailCopilot(AzurLaneAutoScript):
|
||||
from tasks.rogue.rogue import Rogue
|
||||
Rogue(config=self.config, device=self.device).run()
|
||||
|
||||
def benchmark(self):
|
||||
from module.daemon.benchmark import run_benchmark
|
||||
run_benchmark(config=self.config)
|
||||
|
||||
def daemon(self):
|
||||
from tasks.base.daemon import Daemon
|
||||
Daemon(config=self.config, device=self.device, task="Daemon").run()
|
||||
|
||||
def planner_scan(self):
|
||||
from tasks.planner.scan import PlannerScan
|
||||
PlannerScan(config=self.config, device=self.device, task="PlannerScan").run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
src = StarRailCopilot('src')
|
||||
|
Loading…
Reference in New Issue
Block a user