pull
This commit is contained in:
parent
f0defdd918
commit
a0e1662e1d
3 changed files with 33 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
||||||
from flask import Flask, Response, jsonify, request
|
from flask import Flask, Response, jsonify, request
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from room import Room
|
from src.room import Room
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
|
|
|
@ -2,7 +2,16 @@ from dataclasses import dataclass
|
||||||
|
|
||||||
from song import Song
|
from song import Song
|
||||||
|
|
||||||
type UserScoredSong = tuple[Song, int]
|
USER_SCORE_WEIGHT = 0.7
|
||||||
|
GENRE_WEIGHT = 0.1
|
||||||
|
RANDOM_WEIGHT = 0.1
|
||||||
|
RECENT_PENALTY = 0.5
|
||||||
|
RECENT_COUNT = 10
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class UserScoredSong(Song):
|
||||||
|
user_score: int
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -14,5 +23,25 @@ class Room:
|
||||||
tags: set[str]
|
tags: set[str]
|
||||||
creative: bool
|
creative: bool
|
||||||
|
|
||||||
playlist: set[UserScoredSong]
|
songs: dict[str, UserScoredSong]
|
||||||
history: list[Song]
|
history: list[Song]
|
||||||
|
|
||||||
|
def rank_song(
|
||||||
|
self,
|
||||||
|
song: UserScoredSong,
|
||||||
|
) -> float:
|
||||||
|
rank = 0.0
|
||||||
|
song_items = self.songs.items()
|
||||||
|
|
||||||
|
lowest_score = min(song_items, key=lambda item: item[1].user_score)[1].user_score
|
||||||
|
highest_score = min(song_items, key=lambda item: item[1].user_score)[1].user_score
|
||||||
|
|
||||||
|
rank += translate(song.user_score, lowest_score, highest_score, 0.0, USER_SCORE_WEIGHT)
|
||||||
|
|
||||||
|
last10items = self.history[-10:]
|
||||||
|
|
||||||
|
return rank
|
||||||
|
|
||||||
|
|
||||||
|
def translate(value: float, in_min: float, in_max: float, out_min: float, out_max: float):
|
||||||
|
return (value - in_min) / (in_max - in_min) * (out_max - out_min) + out_min
|
||||||
|
|
1
ruff.toml
Normal file
1
ruff.toml
Normal file
|
@ -0,0 +1 @@
|
||||||
|
line-length = 200
|
Loading…
Add table
Add a link
Reference in a new issue