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