mirror of
https://github.com/TheFunny/ArisuAutoSweeper
synced 2026-10-10 15:42:16 +00:00
refactor: move func methods to the Alas class
This commit is contained in:
@@ -60,7 +60,7 @@ class ArisuAutoSweeper(AzurLaneAutoScript):
|
||||
|
||||
def momotalk(self):
|
||||
from tasks.momotalk.momotalk import MomoTalk
|
||||
MomoTalk(config=self.config, device=self.device).run()
|
||||
MomoTalk(config=self.config, device=self.device, task="Momotalk").run()
|
||||
|
||||
def mission(self):
|
||||
from tasks.mission.mission import Mission
|
||||
@@ -74,6 +74,10 @@ class ArisuAutoSweeper(AzurLaneAutoScript):
|
||||
from tasks.item.data_update import DataUpdate
|
||||
DataUpdate(config=self.config, device=self.device).run()
|
||||
|
||||
def benchmark(self):
|
||||
from module.daemon.benchmark import run_benchmark
|
||||
run_benchmark(config=self.config)
|
||||
|
||||
if __name__ == '__main__':
|
||||
aas = ArisuAutoSweeper('aas')
|
||||
aas.loop()
|
||||
|
||||
@@ -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:
|
||||
|
||||
+15
-10
@@ -104,17 +104,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)
|
||||
|
||||
+29
-13
@@ -5,8 +5,7 @@ import numpy as np
|
||||
from rich.table import Table
|
||||
from rich.text import Text
|
||||
|
||||
from module.base.utils import float2str as float2str_
|
||||
from module.base.utils import random_rectangle_point
|
||||
from module.base.utils import float2str as float2str_, random_rectangle_point
|
||||
from module.daemon.daemon_base import DaemonBase
|
||||
from module.exception import RequestHumanTakeover
|
||||
from module.logger import logger
|
||||
@@ -68,17 +67,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 +88,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 +178,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 +189,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 +229,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 +240,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,6 +5,7 @@ import threading
|
||||
from multiprocessing import Process
|
||||
from typing import Dict, List, Union
|
||||
|
||||
import inflection
|
||||
from filelock import FileLock
|
||||
from rich.console import Console, ConsoleRenderable
|
||||
|
||||
@@ -12,6 +13,7 @@ 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 module.webui.submodule.utils import get_available_func
|
||||
|
||||
|
||||
class ProcessManager:
|
||||
@@ -148,10 +150,10 @@ class ProcessManager:
|
||||
if e is not None:
|
||||
AzurLaneAutoScript.stop_event = e
|
||||
ArisuAutoSweeper(config_name=config_name).loop()
|
||||
elif func == "Momotalk":
|
||||
from tasks.momotalk.momotalk import MomoTalk
|
||||
elif func in get_available_func():
|
||||
from aas import ArisuAutoSweeper
|
||||
|
||||
MomoTalk(config=config_name, task="Momotalk").run()
|
||||
ArisuAutoSweeper(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")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
def get_available_func():
|
||||
return (
|
||||
'Momotalk',
|
||||
'Benchmark',
|
||||
)
|
||||
Reference in New Issue
Block a user