mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-04-20 17:50:17 +00:00
impr: fallback when no chart data in database
This commit is contained in:
parent
109e635347
commit
0bd709f49e
@ -263,7 +263,13 @@ class OcrQueueModel(QAbstractListModel):
|
||||
index = self.index(row, 0)
|
||||
chart = index.data(self.ChartRole)
|
||||
score = index.data(self.ScoreRole)
|
||||
if isinstance(chart, Chart) and isinstance(score, Score):
|
||||
if (
|
||||
isinstance(chart, Chart)
|
||||
and isinstance(score, Score)
|
||||
and chart.notes
|
||||
and score.pure
|
||||
and 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)
|
||||
|
@ -93,13 +93,18 @@ class ChartDelegate(TextSegmentDelegate):
|
||||
[{self.TextRole: "Chart Invalid", self.ColorRole: QColor("#ff0000")}]
|
||||
]
|
||||
|
||||
chartConstantString = (
|
||||
f"{chart.constant / 10:.1f}"
|
||||
if chart.constant is not None and chart.constant > 0
|
||||
else "?"
|
||||
)
|
||||
return [
|
||||
[
|
||||
{self.TextRole: f"{chart.title}"},
|
||||
],
|
||||
[
|
||||
{
|
||||
self.TextRole: f"{rating_class_to_text(chart.rating_class)} {chart.constant / 10:.1f}",
|
||||
self.TextRole: f"{rating_class_to_text(chart.rating_class)} {chartConstantString}",
|
||||
self.ColorRole: self.RatingClassColors[chart.rating_class],
|
||||
},
|
||||
],
|
||||
|
@ -96,7 +96,13 @@ class ScoreDelegate(TextSegmentDelegate):
|
||||
score = self.getScore(index)
|
||||
chart = self.getChart(index)
|
||||
|
||||
if isinstance(score, Score) and isinstance(chart, Chart):
|
||||
if (
|
||||
isinstance(score, Score)
|
||||
and isinstance(chart, Chart)
|
||||
and chart.notes is not None
|
||||
and score.pure is not None
|
||||
and score.far is not None
|
||||
):
|
||||
scoreRange = calculate_score_range(chart.notes, score.pure, score.far)
|
||||
return scoreRange[0] <= score.score <= scoreRange[1]
|
||||
|
||||
|
@ -29,12 +29,26 @@ class DbScoreTableModel(DbTableModel):
|
||||
def syncDb(self):
|
||||
newScores = self._db.get_scores()
|
||||
newScores = sorted(newScores, key=lambda x: x.id)
|
||||
newCharts = [
|
||||
self._db.get_chart(score.song_id, score.rating_class) for score in newScores
|
||||
]
|
||||
newCharts = []
|
||||
for score in newScores:
|
||||
dbChart = self._db.get_chart(score.song_id, score.rating_class)
|
||||
newCharts.append(
|
||||
dbChart
|
||||
if isinstance(dbChart, Chart)
|
||||
else Chart(
|
||||
song_id=score.song_id,
|
||||
rating_class=score.rating_class,
|
||||
title=score.song_id,
|
||||
set="unknown",
|
||||
)
|
||||
)
|
||||
newPtts = []
|
||||
for chart, score in zip(newCharts, newScores):
|
||||
if isinstance(chart, Chart) and isinstance(score, Score):
|
||||
if (
|
||||
isinstance(chart, Chart)
|
||||
and chart.constant is not None
|
||||
and isinstance(score, Score)
|
||||
):
|
||||
newPtts.append(calculate_play_rating(chart.constant / 10, score.score))
|
||||
else:
|
||||
newPtts.append(None)
|
||||
@ -103,10 +117,11 @@ class DbScoreTableModel(DbTableModel):
|
||||
elif index.column() == 2 and role in [self.ChartRole, self.ScoreRole]:
|
||||
return self.__items[index.row()][role]
|
||||
elif index.column() == 3:
|
||||
potential = self.__items[index.row()][self.PttRole]
|
||||
if role == Qt.ItemDataRole.DisplayRole:
|
||||
return f"{self.__items[index.row()][self.PttRole]:.3f}"
|
||||
return f"{potential:.3f}" if potential is not None else "-"
|
||||
elif role == self.PttRole:
|
||||
return self.__items[index.row()][self.PttRole]
|
||||
return potential
|
||||
return None
|
||||
|
||||
def setData(self, index, value, role):
|
||||
@ -165,30 +180,35 @@ class DbScoreTableSortFilterProxyModel(QSortFilterProxyModel):
|
||||
Sort_C2_ScoreRole = Qt.ItemDataRole.UserRole + 75
|
||||
Sort_C2_TimeRole = Qt.ItemDataRole.UserRole + 76
|
||||
|
||||
def lessThan(self, source_left, source_right) -> bool:
|
||||
if source_left.column() != source_right.column():
|
||||
def lessThan(self, sourceLeft, sourceRight) -> bool:
|
||||
if sourceLeft.column() != sourceRight.column():
|
||||
return
|
||||
|
||||
column = source_left.column()
|
||||
column = sourceLeft.column()
|
||||
if column == 0:
|
||||
return source_left.data(DbScoreTableModel.IdRole) < source_right.data(
|
||||
return sourceLeft.data(DbScoreTableModel.IdRole) < sourceRight.data(
|
||||
DbScoreTableModel.IdRole
|
||||
)
|
||||
elif column == 2:
|
||||
score_left = source_left.data(DbScoreTableModel.ScoreRole)
|
||||
score_right = source_right.data(DbScoreTableModel.ScoreRole)
|
||||
if isinstance(score_left, Score) and isinstance(score_right, Score):
|
||||
scoreLeft = sourceLeft.data(DbScoreTableModel.ScoreRole)
|
||||
scoreRight = sourceRight.data(DbScoreTableModel.ScoreRole)
|
||||
if isinstance(scoreLeft, Score) and isinstance(scoreRight, Score):
|
||||
if self.sortRole() == self.Sort_C2_ScoreRole:
|
||||
return score_left.score < score_right.score
|
||||
return scoreLeft.score < scoreRight.score
|
||||
elif self.sortRole() == self.Sort_C2_TimeRole:
|
||||
if score_left.date and score_right.date:
|
||||
return score_left.date < score_right.date
|
||||
elif score_left.date:
|
||||
if scoreLeft.date and scoreRight.date:
|
||||
return scoreLeft.date < scoreRight.date
|
||||
elif scoreLeft.date:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
elif column == 3:
|
||||
return source_left.data(DbScoreTableModel.PttRole) < source_right.data(
|
||||
DbScoreTableModel.PttRole
|
||||
)
|
||||
return super().lessThan(source_left, source_right)
|
||||
pttLeft = sourceLeft.data(DbScoreTableModel.PttRole)
|
||||
pttRight = sourceRight.data(DbScoreTableModel.PttRole)
|
||||
if pttLeft and pttRight:
|
||||
return pttLeft < pttRight
|
||||
elif pttLeft:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return super().lessThan(sourceLeft, sourceRight)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import logging
|
||||
|
||||
from arcaea_offline.database import Database
|
||||
from arcaea_offline.models import Score
|
||||
from arcaea_offline.models import Chart, Score
|
||||
from arcaea_offline_ocr.b30.chieri.v4.ocr import ChieriBotV4Ocr
|
||||
from arcaea_offline_ocr.b30.shared import B30OcrResultItem
|
||||
from PySide6.QtGui import QImage
|
||||
@ -49,4 +49,12 @@ def b30ResultToScore(_: None, qImage: QImage, result: B30OcrResultItem):
|
||||
comment="B30 OCR",
|
||||
)
|
||||
|
||||
if not chart:
|
||||
chart = Chart(
|
||||
song_id=song_id,
|
||||
rating_class=result.rating_class,
|
||||
title=song_id,
|
||||
constant=0.0,
|
||||
)
|
||||
|
||||
return (chart, score)
|
||||
|
@ -85,4 +85,11 @@ class ScoreConverter:
|
||||
comment=f"OCR {QFileInfo(imagePath).fileName()}",
|
||||
)
|
||||
chart = db.get_chart(score.song_id, score.rating_class)
|
||||
if not chart:
|
||||
chart = Chart(
|
||||
song_id=result.song_id,
|
||||
rating_class=result.rating_class,
|
||||
title=result.song_id,
|
||||
constant=0.0,
|
||||
)
|
||||
return (chart, score)
|
||||
|
Loading…
x
Reference in New Issue
Block a user