mirror of
https://github.com/283375/arcaea-offline-pyside-ui.git
synced 2025-07-01 12:26:26 +00:00
impr: TabTools_ChartRecommend
ui
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import logging
|
||||
import random
|
||||
|
||||
from arcaea_offline.calculate import calculate_constants_from_play_rating
|
||||
from arcaea_offline.database import Database
|
||||
@ -7,11 +6,17 @@ from arcaea_offline.models import Chart, ScoreBest
|
||||
from arcaea_offline.utils.rating import rating_class_to_text
|
||||
from arcaea_offline.utils.score import score_to_grade_text
|
||||
from PySide6.QtCore import Slot
|
||||
from PySide6.QtWidgets import QLabel, QWidget
|
||||
from PySide6.QtWidgets import QWidget
|
||||
|
||||
from ui.designer.tabs.tabTools.tabTools_ChartRecommend_ui import (
|
||||
Ui_TabTools_ChartRecommend,
|
||||
)
|
||||
from ui.extends.tabs.tabTools.tabTools_ChartRecommend import (
|
||||
ChartsModel,
|
||||
ChartsWithScoreBestModel,
|
||||
CustomChartDelegate,
|
||||
CustomScoreBestDelegate,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -31,11 +36,25 @@ class TabTools_ChartRecommend(Ui_TabTools_ChartRecommend, QWidget):
|
||||
|
||||
self.db = Database()
|
||||
|
||||
self.chartsByConstant = []
|
||||
self.chartsRecommendFromPlayRating = []
|
||||
self.chartsByConstantModel = ChartsModel(self)
|
||||
self.chartsRecommendFromPlayRatingModel = ChartsWithScoreBestModel(self)
|
||||
|
||||
self.numLabelFormatString = "{} charts"
|
||||
|
||||
self.chartDelegate = CustomChartDelegate(self)
|
||||
self.scoreBestDelegate = CustomScoreBestDelegate(self)
|
||||
self.chartsByConstant_modelView.setModel(self.chartsByConstantModel)
|
||||
self.chartsByConstant_modelView.setItemDelegate(self.chartDelegate)
|
||||
self.chartsRecommendFromPlayRating_modelView.setModel(
|
||||
self.chartsRecommendFromPlayRatingModel
|
||||
)
|
||||
self.chartsRecommendFromPlayRating_modelView.setItemDelegateForColumn(
|
||||
0, self.chartDelegate
|
||||
)
|
||||
self.chartsRecommendFromPlayRating_modelView.setItemDelegateForColumn(
|
||||
1, self.scoreBestDelegate
|
||||
)
|
||||
|
||||
self.chartsRecommendFromPlayRating_playRatingSpinBox.valueChanged.connect(
|
||||
self.updateChartsRecommendFromPlayRating
|
||||
)
|
||||
@ -43,81 +62,61 @@ class TabTools_ChartRecommend(Ui_TabTools_ChartRecommend, QWidget):
|
||||
self.updateChartsRecommendFromPlayRating
|
||||
)
|
||||
|
||||
self.chartsByConstant_refreshButton.clicked.connect(self.fillChartsByConstant)
|
||||
self.chartsRecommendFromPlayRating_refreshButton.clicked.connect(
|
||||
self.fillChartsRecommendFromPlayRating
|
||||
)
|
||||
|
||||
@Slot(float)
|
||||
def on_rangeFromPlayRating_playRatingSpinBox_valueChanged(self, value: float):
|
||||
try:
|
||||
result = calculate_constants_from_play_rating(value)
|
||||
exPlusLower, exPlusUpper = result.EXPlus
|
||||
exLower, exUpper = result.EX
|
||||
aaLower, aaUpper = result.AA
|
||||
|
||||
self.rangeFromPlayRating_ExPlusLabel.setText(
|
||||
f"{exPlusLower:.3f}~{exPlusUpper:.3f}"
|
||||
constant = round(
|
||||
value, self.rangeFromPlayRating_playRatingSpinBox.decimals()
|
||||
)
|
||||
self.rangeFromPlayRating_ExLabel.setText(f"{exLower:.3f}~{exUpper:.3f}")
|
||||
self.rangeFromPlayRating_AaLabel.setText(f"{aaLower:.3f}~{aaUpper:.3f}")
|
||||
result = calculate_constants_from_play_rating(constant)
|
||||
labels = [
|
||||
self.rangeFromPlayRating_ExPlusLabel,
|
||||
self.rangeFromPlayRating_ExLabel,
|
||||
self.rangeFromPlayRating_AaLabel,
|
||||
self.rangeFromPlayRating_ALabel,
|
||||
self.rangeFromPlayRating_BLabel,
|
||||
self.rangeFromPlayRating_CLabel,
|
||||
]
|
||||
|
||||
for label, constantRange in zip(
|
||||
labels,
|
||||
[result.EXPlus, result.EX, result.AA, result.A, result.B, result.C],
|
||||
):
|
||||
label.setText(f"{constantRange[0]:.3f}~{constantRange[1]:.3f}")
|
||||
except Exception:
|
||||
logging.exception("cannot calculate constant from play rating")
|
||||
logging.exception("Cannot calculate constant from play rating:")
|
||||
self.rangeFromPlayRating_ExPlusLabel.setText("...")
|
||||
self.rangeFromPlayRating_ExLabel.setText("...")
|
||||
self.rangeFromPlayRating_AaLabel.setText("...")
|
||||
|
||||
def fillChartsByConstant(self):
|
||||
while item := self.chartsByConstant_gridLayout.takeAt(0):
|
||||
item.widget().deleteLater()
|
||||
|
||||
charts = random.sample(
|
||||
self.chartsByConstant, k=min(len(self.chartsByConstant), 6)
|
||||
)
|
||||
row = 0
|
||||
for i, chart in enumerate(charts):
|
||||
if i % 3 == 0:
|
||||
row += 1
|
||||
label = QLabel(self)
|
||||
label.setText(chartToText(chart))
|
||||
self.chartsByConstant_gridLayout.addWidget(label, row, i % 3)
|
||||
|
||||
@Slot(float)
|
||||
def on_chartsByConstant_constantSpinBox_valueChanged(self, value: float):
|
||||
self.chartsByConstant = self.db.get_charts_by_constant(int(value * 10))
|
||||
chartsNum = len(self.chartsByConstant)
|
||||
self.chartsByConstant_refreshButton.setEnabled(chartsNum > 6)
|
||||
constant = round(value, self.chartsByConstant_constantSpinBox.decimals())
|
||||
charts = self.db.get_charts_by_constant(int(constant * 10))
|
||||
chartsNum = len(charts)
|
||||
self.chartsByConstant_numLabel.setText(
|
||||
self.numLabelFormatString.format(chartsNum)
|
||||
)
|
||||
self.fillChartsByConstant()
|
||||
|
||||
def fillChartsRecommendFromPlayRating(self):
|
||||
while item := self.chartsRecommendFromPlayRating_gridLayout.takeAt(0):
|
||||
item.widget().deleteLater()
|
||||
|
||||
charts = random.sample(
|
||||
self.chartsRecommendFromPlayRating,
|
||||
k=min(len(self.chartsRecommendFromPlayRating), 6),
|
||||
)
|
||||
row = 0
|
||||
for i, chart in enumerate(charts):
|
||||
if i % 3 == 0:
|
||||
row += 1
|
||||
scoreBest = self.db.get_score_best(chart.song_id, chart.rating_class)
|
||||
label = QLabel(self)
|
||||
label.setText(f"{chartToText(chart)}<br>-<br>{scoreBestToText(scoreBest)}")
|
||||
self.chartsRecommendFromPlayRating_gridLayout.addWidget(label, row, i % 3)
|
||||
self.chartsByConstantModel.setCharts(charts)
|
||||
|
||||
def updateChartsRecommendFromPlayRating(self):
|
||||
playRating = self.chartsRecommendFromPlayRating_playRatingSpinBox.value()
|
||||
bounds = self.chartsRecommendFromPlayRating_boundsSpinBox.value()
|
||||
self.chartsRecommendFromPlayRating = self.db.recommend_charts(
|
||||
playRating, bounds
|
||||
charts = self.db.recommend_charts(
|
||||
round(
|
||||
playRating,
|
||||
self.chartsRecommendFromPlayRating_playRatingSpinBox.decimals(),
|
||||
),
|
||||
round(
|
||||
bounds,
|
||||
self.chartsRecommendFromPlayRating_boundsSpinBox.decimals(),
|
||||
),
|
||||
)
|
||||
chartsNum = len(self.chartsRecommendFromPlayRating)
|
||||
self.chartsRecommendFromPlayRating_refreshButton.setEnabled(chartsNum > 6)
|
||||
chartsNum = len(charts)
|
||||
self.chartsRecommendFromPlayRating_numLabel.setText(
|
||||
self.numLabelFormatString.format(chartsNum)
|
||||
)
|
||||
self.fillChartsRecommendFromPlayRating()
|
||||
scores = [self.db.get_score_best(c.song_id, c.rating_class) for c in charts]
|
||||
self.chartsRecommendFromPlayRatingModel.setChartAndScore(charts, scores)
|
||||
self.chartsRecommendFromPlayRating_modelView.resizeRowsToContents()
|
||||
self.chartsRecommendFromPlayRating_modelView.resizeColumnsToContents()
|
||||
|
Reference in New Issue
Block a user