fix: typo caculate -> calculate

This commit is contained in:
283375 2023-06-02 17:08:42 +08:00
parent d16c25726a
commit a4f995a6aa
5 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "arcaea-offline" name = "arcaea-offline"
version = "0.1.0" version = "0.1.0"
authors = [{ name = "283375", email = "log_283375@163.com" }] authors = [{ name = "283375", email = "log_283375@163.com" }]
description = "Caculate your B30 & R10 locally." description = "Calculate your B30 & R10 locally."
readme = "README.md" readme = "README.md"
requires-python = ">=3.8" requires-python = ">=3.8"
dependencies = [] dependencies = []

View File

@ -1,5 +0,0 @@
from .models import Score, Caculated
from typing import List
def calculate_b30(caculated_list: List[Caculated]):
scores = []

View File

@ -0,0 +1,5 @@
from .models import Score, Calculated
from typing import List
def calculate_b30(calculated_list: List[Calculated]):
scores = []

View File

@ -1,6 +1,6 @@
import os import os
from .utils.singleton import Singleton from .utils.singleton import Singleton
from .models import DbChartRow, DbPackageRow, DbScoreRow, DbCaculatedRow, DbAliasRow from .models import DbChartRow, DbPackageRow, DbScoreRow, DbCalculatedRow, DbAliasRow
import sqlite3 import sqlite3
from typing import Union, List, Optional from typing import Union, List, Optional
from dataclasses import fields, is_dataclass from dataclasses import fields, is_dataclass
@ -134,7 +134,7 @@ class Database(metaclass=Singleton):
) )
""", """,
""" """
CREATE VIEW IF NOT EXISTS caculated AS CREATE VIEW IF NOT EXISTS calculated AS
SELECT SELECT
scores.song_id, scores.song_id,
scores.rating_class, scores.rating_class,
@ -280,14 +280,14 @@ class Database(metaclass=Singleton):
DbScoreRow(*row) for row in conn.execute(final_sql, params).fetchall() DbScoreRow(*row) for row in conn.execute(final_sql, params).fetchall()
] ]
def get_caculated( def get_calculated(
self, self,
*, *,
song_id: Optional[List[str]] = None, song_id: Optional[List[str]] = None,
rating_class: Optional[List[int]] = None, rating_class: Optional[List[int]] = None,
): ):
with self.conn as conn: with self.conn as conn:
columns = ",".join([f"[{field.name}]" for field in fields(DbCaculatedRow)]) columns = ",".join([f"[{field.name}]" for field in fields(DbCalculatedRow)])
where_clauses = [] where_clauses = []
params = [] params = []
if song_id: if song_id:
@ -298,12 +298,12 @@ class Database(metaclass=Singleton):
f"rating_class IN ({','.join('?'*len(rating_class))})" f"rating_class IN ({','.join('?'*len(rating_class))})"
) )
params.extend(rating_class) params.extend(rating_class)
final_sql = f"SELECT {columns} FROM caculated" final_sql = f"SELECT {columns} FROM calculated"
if where_clauses: if where_clauses:
final_sql += " WHERE " final_sql += " WHERE "
final_sql += " AND ".join(where_clauses) final_sql += " AND ".join(where_clauses)
return [ return [
DbCaculatedRow(*row) DbCalculatedRow(*row)
for row in conn.execute(final_sql, params).fetchall() for row in conn.execute(final_sql, params).fetchall()
] ]
@ -317,7 +317,7 @@ class Database(metaclass=Singleton):
rating_class, rating_class,
MAX(potential) AS max_potential MAX(potential) AS max_potential
FROM FROM
caculated calculated
GROUP BY GROUP BY
song_id, song_id,
rating_class rating_class
@ -329,7 +329,7 @@ class Database(metaclass=Singleton):
SELECT SELECT
c.* c.*
FROM FROM
caculated c calculated c
JOIN max_potential m ON c.song_id = m.song_id AND c.rating_class = m.rating_class AND c.potential = m.max_potential JOIN max_potential m ON c.song_id = m.song_id AND c.rating_class = m.rating_class AND c.potential = m.max_potential
ORDER BY ORDER BY
potential DESC potential DESC

View File

@ -124,7 +124,7 @@ class Score:
@dataclass @dataclass
class DbCaculatedRow: class DbCalculatedRow:
song_id: str song_id: str
rating_class: int rating_class: int
score: int score: int
@ -139,7 +139,7 @@ class DbCaculatedRow:
@dataclass(kw_only=True) @dataclass(kw_only=True)
class Caculated: class Calculated:
song_id: str song_id: str
rating_class: int rating_class: int
score: int score: int
@ -153,5 +153,5 @@ class Caculated:
potential: float potential: float
@classmethod @classmethod
def from_db_row(cls, row: DbCaculatedRow): def from_db_row(cls, row: DbCalculatedRow):
return cls(**asdict(row)) return cls(**asdict(row))