39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
|
|
from pathlib import Path
|
|
module_dir = Path(__file__).parent
|
|
|
|
SNC_Seeds = (
|
|
#pd.read_excel(module_dir / 'SNC_Seeds.xlsx')
|
|
pd.read_excel(module_dir / '2025 Swimming Canada Para Points Calculator.xlsx')
|
|
.assign(SportClass=lambda df: df.SportClass.astype(str))
|
|
)
|
|
def SNC_Score(DF):
|
|
Score = lambda x,scale: 1000*(((1-np.exp(-0.4*(np.exp(scale*x)-1)))/0.95)**3)
|
|
prepped = (
|
|
DF
|
|
.merge(SNC_Seeds,on='Gender Course Stroke Distance SportClass'.split(),how='left')
|
|
.assign(V=lambda df: df.Distance/df.Seconds)
|
|
)
|
|
return (
|
|
prepped
|
|
.assign(Score=lambda df: df.apply(lambda S: Score(S.V,S.Scale),axis=1).fillna(0).astype(int))
|
|
.drop('Scale',axis=1)
|
|
)
|
|
|
|
WPS_Seeds = (
|
|
pd.read_excel(module_dir / '2024 World Para Swimming Points Calculator.xlsx',sheet_name='Parameters')
|
|
.assign(Gender=lambda df: df.Gender.apply(lambda S: S[0]))
|
|
.pipe(lambda df: pd.concat([df,df.Event.str.extract(r"(?P<Distance>\d+) m (Individual )*(?P<Stroke>[A-z]+)")],axis=1))
|
|
.assign(SportClass=lambda df: df.Class.apply(lambda S: ''.join([c for c in str(S) if c.isdigit()])))
|
|
.astype({'Distance':int})
|
|
.assign(Course='LCM')
|
|
.pipe(lambda df: df['Gender Course SportClass Distance Stroke a b c'.split()])
|
|
)
|
|
def WPS_Score(DF):
|
|
return (
|
|
DF.merge(WPS_Seeds,on='Gender Course SportClass Distance Stroke'.split(),how='left')
|
|
.assign(WPS_Score=lambda df: (df.a*np.exp(-np.exp(df.b-(df.c/df.Seconds)))).fillna(0).astype(int))
|
|
.drop('a b c'.split(),axis=1)
|
|
)
|