diff --git a/massranker/state.py b/massranker/state.py index 1068630..bbecabe 100644 --- a/massranker/state.py +++ b/massranker/state.py @@ -1,9 +1,8 @@ +import math import random from collections.abc import Callable -from datetime import datetime, UTC, timedelta -from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, Field from massranker.elo import expected, elo @@ -11,6 +10,7 @@ class ItemT(BaseModel): name: str elo: float enabled: bool + times_seen: int = Field(default=0) class StateT(BaseModel): @@ -46,7 +46,22 @@ class StateT(BaseModel): if len(possible_entrants) < 2: raise ValueError("need at least two things to compare") - entrants = random.sample(possible_entrants, k=min(len(possible_entrants), 8)) + # build a sample + sample_size = min(len(possible_entrants), 8) + if sample_size == len(possible_entrants): + entrants = random.sample(possible_entrants, k=sample_size) + else: + # this is a messy way to take a weighted random sample + picked = [] + while len(picked) < sample_size: + remaining_possible_entrants = [i for i in possible_entrants if i not in picked] + weights = [1/(e.times_seen + 1) for e in remaining_possible_entrants] + for i in random.choices(remaining_possible_entrants, weights=weights, k=sample_size - len(picked)): + if i not in picked: + picked.append(i) + random.shuffle(picked) + entrants = picked + expected_score = [0.0] * len(entrants) score = [0.0] * len(entrants) @@ -61,6 +76,7 @@ class StateT(BaseModel): for e, entrant in enumerate(entrants): entrant.elo = elo(entrant.elo, expected_score[e], score[e]) + entrant.times_seen += 1 def dump_rankings(self) -> list[tuple[str, int]]: return [ diff --git a/massranker/storage.py b/massranker/storage.py index bcc4548..2a3bb9b 100644 --- a/massranker/storage.py +++ b/massranker/storage.py @@ -50,7 +50,7 @@ class Storage(object): """ DELETE FROM states WHERE id NOT IN - (SELECT id FROM states ORDER BY id DESC LIMIT 100); + (SELECT id FROM states ORDER BY id DESC LIMIT 10); """, ) c.execute("COMMIT;") diff --git a/ontologies/music/names.txt b/ontologies/music/names.txt index b914de1..c121910 100644 --- a/ontologies/music/names.txt +++ b/ontologies/music/names.txt @@ -69,3 +69,106 @@ Song For Dan Treacy - MGMT Eyesore - Women Paris 1919 - John Cale Baby Hotline - Jack Stauber +Condition Boy - Susumu Hirasawa +Shutterbugg - Big Boi +Good King Moggle Mog - ??? +Superman - Goldfinger +The Chase - Giorgio Moroder +Oh Klahoma - Jack Stauber +I'm The President - KNOWER +Elephant Gun - Beirut +Atomic Dog - George Clinton +Oh Ana - Mother Mother +The Chain - Fleetwood Mac +Dreams - Fleetwood Mac +Spanish Stroll - Mink DeVille +Under Pressure - Queen & David Bowie +Dr. Mabuse - Propaganda +Paranoid Android - Radiohead +Idioteque - Radiohead +There Is a Light That Never Goes Out - The Smiths +A Rush and a Push and the Land Is Ours - The Smiths +This Charming Man - The Smiths +Youkali - Teresa Stratas & Kurt Weill +Killing Me Softly With His Song - Fugees +Shallow - Lady Gaga & Bradley Cooper +Notjustmoreidlechatter - Paul Lansky +Fantasy Is Reality - Parliament +All I Do - Stevie Wonder +Alabama Song - Kurt Weill +Drain You - Nirvana +Swirls - Alex Seropian +Werewolf - CocoRosie +Beautiful Boyz - CocoRosie +Teen Pregnancy - Blank Banshee +Death of Samantha - Yoko Ono +Bonnie And Clyde - Brigitte Bardot & Serge Gainsbourg +Ella, elle l'a - France Gall +Marcia Baila - Les Rita Mitsouko +Your Way - Netsky +I Wish - Skee-Lo +Hey Ya! - Outkast +Roses - Outkast +Ms. Jackson - Outkast +Bombs Over Baghdad - Outkast +Waters of March - Antonio Carlos Jobim +Gotta Get Up - Harry Nilsson +Life During Wartime - Talking Heads +Computer Age - Newcleus +Popcorn - Gershon Kingsley +Doctor Worm - They Might Be Giants +Mermaid Sashimi - Juan Son +Rock Lobster - The B-52s +Electric To Me Turn - Bruce Haack +Ana Ng - They Might Be Giants +The Alcoholic - Royksopp +Senior Living - Royksopp +Smack My Bitch Up - The Prodigy +Fill Your Heart - David Bowie +Oh! You Pretty Things - David Bowie +Little Dark Age - MGMT +Drain You - Nirvana +Jugband Blues - Pink Floyd +Hotel California - Eagles +Angela - Bob James +Les Fleurs - Minnie Riperton +Fare Thee Well, Miss Carousel - Townes Van Zandt +Randy - Justice +DANCE - Justice +Canon - Justice +Eid Ma Clack Shaw - Bill Callahan +Das Modell - Kraftwerk +Zum Projekt - Paniq +Rattengift - Paniq +Talkin' Like You - Connie Converse +Playboy of the Western World - Connie Converse +Laura - Bat For Lashes +Breathe - Prodigy +Didn't You Hear? - Mort Garson +Girl, You'll Be a Woman Soon - Urge Overkill +The Chain - Fleetwood Mac +Dear Angie - Badfinger +Vincent - Don McLean +American Pie - Don McLean +Rhiannon - Fleetwood Mac +Big Kitten - Feed Me +Komm, Susser Tod - Arianne +Misty - Erroll Garner +Couldn't Call It Unexpected No. 4 - Elvis Costello +Radio Radio - Elvis Costello +Long Road Home - Oneohtrix Point Never +Sexy Sadie - The Beatles +Money Don't Matter 2 Night - Prince +Fanfare for naran ratan - naran ratan +Plantasia - Mort Garson +Lay Down (Candles In The Rain) - Melanie & The Edwin Hawkins Singers +Promises I've Made - Emitt Rhodes +Harakiri - Serj Tankian +Ordinary Joe - Terry Callier +Red Alert - Basement Jaxx +Rock 'n' Roll Suicide - David Bowie +Where's Your Head At? - Basement Jaxx +Strangers - The Kinks +High On A Rocky Ledge - Moondog +Starman - David Bowie +Born Slippy - Underworld \ No newline at end of file