From ecd4ed619e95c80e8e2549200a0cbf172e796606 Mon Sep 17 00:00:00 2001 From: 283375 Date: Fri, 1 Sep 2023 04:01:14 +0800 Subject: [PATCH] wip: arcaea-offline==0.2.0 --- ui/extends/components/chartSelector.py | 4 +--- ui/extends/components/ocrQueue.py | 2 +- ui/extends/shared/delegates/chartDelegate.py | 2 +- ui/extends/shared/delegates/scoreDelegate.py | 4 ++-- ui/extends/tabs/tabOcr/tabOcr_B30.py | 13 ++++++----- ui/extends/tabs/tabOcr/tabOcr_Device.py | 23 +++++++++++++++++--- ui/implements/components/scoreEditor.py | 15 +++++-------- ui/implements/tabs/tabOcr/tabOcr_B30.py | 7 ++---- 8 files changed, 40 insertions(+), 30 deletions(-) diff --git a/ui/extends/components/chartSelector.py b/ui/extends/components/chartSelector.py index ea4437b..3a3dbca 100644 --- a/ui/extends/components/chartSelector.py +++ b/ui/extends/components/chartSelector.py @@ -26,8 +26,6 @@ class FuzzySearchCompleterModel(QStandardItemModel): item = QStandardItem(kw) item.setData(kw) item.setData(displayText, Qt.ItemDataRole.UserRole + 75) - item.setData( - f"{chart.song_id}, {chart.package_id}", Qt.ItemDataRole.UserRole + 76 - ) + item.setData(f"{chart.song_id}, {chart.set}", Qt.ItemDataRole.UserRole + 76) item.setData(chart, Qt.ItemDataRole.UserRole + 10) self.appendRow(item) diff --git a/ui/extends/components/ocrQueue.py b/ui/extends/components/ocrQueue.py index 83d1dd6..fccfb5d 100644 --- a/ui/extends/components/ocrQueue.py +++ b/ui/extends/components/ocrQueue.py @@ -236,7 +236,7 @@ class OcrQueueModel(QAbstractListModel): chart = index.data(self.ChartRole) score = index.data(self.ScoreRole) if isinstance(chart, Chart) and isinstance(score, Score): - scoreRange = calculate_score_range(chart.note, score.pure, score.far) + scoreRange = calculate_score_range(chart.notes, score.pure, score.far) scoreValidateOk = scoreRange[0] <= score.score <= scoreRange[1] self.setData(index, scoreValidateOk, self.ScoreValidateOkRole) else: diff --git a/ui/extends/shared/delegates/chartDelegate.py b/ui/extends/shared/delegates/chartDelegate.py index 3b03d88..8d68ccb 100644 --- a/ui/extends/shared/delegates/chartDelegate.py +++ b/ui/extends/shared/delegates/chartDelegate.py @@ -98,7 +98,7 @@ class ChartDelegate(TextSegmentDelegate): ], [ { - self.TextRole: f"{rating_class_to_text(chart.rating_class)} {chart.rating / 10:.1f}", + self.TextRole: f"{rating_class_to_text(chart.rating_class)} {chart.constant / 10:.1f}", self.ColorRole: self.RatingClassColors[chart.rating_class], }, ], diff --git a/ui/extends/shared/delegates/scoreDelegate.py b/ui/extends/shared/delegates/scoreDelegate.py index d9bc8a3..a56fa19 100644 --- a/ui/extends/shared/delegates/scoreDelegate.py +++ b/ui/extends/shared/delegates/scoreDelegate.py @@ -95,7 +95,7 @@ class ScoreDelegate(TextSegmentDelegate): chart = self.getChart(index) if isinstance(score, Score) and isinstance(chart, Chart): - scoreRange = calculate_score_range(chart.note, score.pure, score.far) + scoreRange = calculate_score_range(chart.notes, score.pure, score.far) return scoreRange[0] <= score.score <= scoreRange[1] def getScoreGradeGradientWrapper(self, score: int): @@ -203,7 +203,7 @@ class ScoreDelegate(TextSegmentDelegate): editor.setWindowFlag(Qt.WindowType.Sheet, True) editor.setWindowFlag(Qt.WindowType.FramelessWindowHint, True) editor.setWindowTitle( - f"{chart.name_en}({chart.song_id}) | {rating_class_to_text(chart.rating_class)} | {chart.package_id}" + f"{chart.title}({chart.song_id}) | {rating_class_to_text(chart.rating_class)} | {chart.set}" ) editor.setText(self.getScore(index)) editor.setValidateBeforeAccept(False) diff --git a/ui/extends/tabs/tabOcr/tabOcr_B30.py b/ui/extends/tabs/tabOcr/tabOcr_B30.py index b0d7b62..55b5168 100644 --- a/ui/extends/tabs/tabOcr/tabOcr_B30.py +++ b/ui/extends/tabs/tabOcr/tabOcr_B30.py @@ -1,7 +1,7 @@ import logging from arcaea_offline.database import Database -from arcaea_offline.models import Chart, Score +from arcaea_offline.models import Score from arcaea_offline_ocr.b30.chieri.v4.ocr import ChieriBotV4Ocr from arcaea_offline_ocr.b30.shared import B30OcrResultItem from PySide6.QtGui import QImage @@ -27,25 +27,26 @@ class ChieriV4OcrRunnable(OcrRunnable): self.signals.finished.emit() -def b30ResultToScoreInsert(_, qImage: QImage, result: B30OcrResultItem): +def b30ResultToScore(_: None, qImage: QImage, result: B30OcrResultItem): if not result.song_id and not result.title: raise ValueError("no title or song_id") db = Database() if not result.song_id: - song_id = db.fuzzy_search_song_id(result.title)[0][0] + raise NotImplementedError("Not supported yet.") else: song_id = result.song_id - chart = Chart.from_db_row(db.get_chart(song_id, result.rating_class)) - score = ScoreInsert( + chart = db.get_chart(song_id, result.rating_class) + score = Score( song_id=song_id, rating_class=result.rating_class, score=result.score, - time=1485014400, + date=None, pure=result.pure, far=result.far, lost=result.lost, + comment="B30 OCR", ) return (chart, score) diff --git a/ui/extends/tabs/tabOcr/tabOcr_Device.py b/ui/extends/tabs/tabOcr/tabOcr_Device.py index 0b1f93b..a1a4be0 100644 --- a/ui/extends/tabs/tabOcr/tabOcr_Device.py +++ b/ui/extends/tabs/tabOcr/tabOcr_Device.py @@ -6,7 +6,7 @@ from arcaea_offline.database import Database from arcaea_offline.models import Chart, Score from arcaea_offline_ocr.device.shared import DeviceOcrResult from arcaea_offline_ocr.device.v2.ocr import DeviceV2Ocr -from arcaea_offline_ocr.device.v2.rois import DeviceV2Rois +from arcaea_offline_ocr.device.v2.rois import DeviceV2AutoRois, DeviceV2Rois from arcaea_offline_ocr.utils import imread_unicode from PySide6.QtCore import QDateTime, QFileInfo @@ -37,6 +37,25 @@ class TabDeviceV2OcrRunnable(OcrRunnable): self.signals.finished.emit() +class TabDeviceV2AutoRoisOcrRunnable(OcrRunnable): + def __init__(self, imagePath, knnModel, siftDb): + super().__init__() + self.imagePath = imagePath + self.knnModel = knnModel + self.siftDb = siftDb + + def run(self): + try: + rois = DeviceV2AutoRois(imread_unicode(self.imagePath)) + ocr = DeviceV2Ocr(self.knnModel, self.siftDb) + result = ocr.ocr(rois) + self.signals.resultReady.emit(result) + except Exception: + logger.exception(f"DeviceV2AutoRois ocr {self.imagePath} error") + finally: + self.signals.finished.emit() + + def getImageDate(imagePath: str) -> QDateTime: datetime = None with contextlib.suppress(Exception): @@ -63,9 +82,7 @@ class ScoreConverter: lost=result.lost, date=getImageDate(imagePath).toSecsSinceEpoch(), max_recall=result.max_recall, - r10_clear_type=None, comment=f"OCR {QFileInfo(imagePath).fileName()}", ) - print(f"OCR {QFileInfo(imagePath).fileName()}") chart = db.get_chart(score.song_id, score.rating_class) return (chart, score) diff --git a/ui/implements/components/scoreEditor.py b/ui/implements/components/scoreEditor.py index 23f089e..111d187 100644 --- a/ui/implements/components/scoreEditor.py +++ b/ui/implements/components/scoreEditor.py @@ -105,10 +105,10 @@ class ScoreEditor(Ui_ScoreEditor, QWidget): def setLimits(self, chart: Chart): self.setMinimums() - self.pureSpinBox.setMaximum(chart.note) - self.farSpinBox.setMaximum(chart.note) - self.lostSpinBox.setMaximum(chart.note) - self.maxRecallSpinBox.setMaximum(chart.note) + self.pureSpinBox.setMaximum(chart.notes) + self.farSpinBox.setMaximum(chart.notes) + self.lostSpinBox.setMaximum(chart.notes) + self.maxRecallSpinBox.setMaximum(chart.notes) def resetLimits(self): self.setMinimums() @@ -132,9 +132,9 @@ class ScoreEditor(Ui_ScoreEditor, QWidget): score = self.value() - score_range = calculate_score_range(self.__chart.note, score.pure, score.far) + score_range = calculate_score_range(self.__chart.notes, score.pure, score.far) score_in_range = score_range[0] <= score.score <= score_range[1] - note_in_range = score.pure + score.far + score.lost <= self.__chart.note + note_in_range = score.pure + score.far + score.lost <= self.__chart.notes if not score_in_range or not note_in_range: return ScoreValidateResult.ScoreMismatch if score.score == 0: @@ -170,7 +170,6 @@ class ScoreEditor(Ui_ScoreEditor, QWidget): max_recall=self.maxRecallSpinBox.value() if self.maxRecallSpinBox.value() > -1 else None, - r10_clear_type=None, ) def setValue(self, score: Score): @@ -184,8 +183,6 @@ class ScoreEditor(Ui_ScoreEditor, QWidget): self.dateTimeEdit.setDateTime(QDateTime.fromSecsSinceEpoch(score.date)) if score.max_recall is not None: self.maxRecallSpinBox.setValue(score.max_recall) - if score.r10_clear_type is not None: - self.clearTypeComboBox.setCurrentIndex(score.r10_clear_type) def reset(self): self.setChart(None) diff --git a/ui/implements/tabs/tabOcr/tabOcr_B30.py b/ui/implements/tabs/tabOcr/tabOcr_B30.py index c7a4a70..5ea9ebe 100644 --- a/ui/implements/tabs/tabOcr/tabOcr_B30.py +++ b/ui/implements/tabs/tabOcr/tabOcr_B30.py @@ -14,10 +14,7 @@ from ui.designer.tabs.tabOcr.tabOcr_B30_ui import Ui_TabOcr_B30 from ui.extends.components.ocrQueue import OcrQueueModel from ui.extends.shared.cv2_utils import cv2BgrMatToQImage, qImageToCvMatBgr from ui.extends.shared.settings import Settings -from ui.extends.tabs.tabOcr.tabOcr_B30 import ( - ChieriV4OcrRunnable, - b30ResultToScoreInsert, -) +from ui.extends.tabs.tabOcr.tabOcr_B30 import ChieriV4OcrRunnable, b30ResultToScore logger = logging.getLogger(__name__) @@ -161,7 +158,7 @@ class TabOcr_B30(Ui_TabOcr_B30, QWidget): self.ocrQueueModel.setData(index, runnable, OcrQueueModel.OcrRunnableRole) self.ocrQueueModel.setData( index, - b30ResultToScoreInsert, + b30ResultToScore, OcrQueueModel.ProcessOcrResultFuncRole, ) self.ocrQueueModel.startQueue()