Initial commit
This commit is contained in:
commit
9a846094ec
6 changed files with 116 additions and 0 deletions
9
LICENSE
Normal file
9
LICENSE
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2025 Mike
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
4
ParaUtils/__init__.py
Normal file
4
ParaUtils/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from .utils import *
|
||||
|
||||
__version__ = "0.1.3"
|
||||
__all__ = 't2f ft2 CSG parse_WPS_rankings'.split()
|
||||
67
ParaUtils/utils.py
Normal file
67
ParaUtils/utils.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
#Bits and bobs used for many different projects. Junk drawer module
|
||||
import pandas
|
||||
import numpy
|
||||
|
||||
|
||||
#Useful functions for parsing race-like durations, and normalizing their string reps
|
||||
def t2f(S):
|
||||
if not(S or False):
|
||||
return None
|
||||
m,s = ('0:%s' % S).split(':')[-2:]
|
||||
try:
|
||||
return numpy.round(60*int(m) + float(s),2)
|
||||
except:
|
||||
return -1
|
||||
|
||||
def f2t(S):
|
||||
if not(S or False) or (int(''.join([c for c in '0'+str(S) if c.isdigit()])) == 0) or (S <= 0):
|
||||
return ''
|
||||
S = float(S)
|
||||
m = int(S/60)
|
||||
s = S-60*m
|
||||
hs = s-int(s)
|
||||
s = int(s)
|
||||
return f'{m:02}:{s:02}.{round(hs*100):02}'
|
||||
|
||||
#Canada Summer Games eligible events
|
||||
CSG = pandas.DataFrame([
|
||||
{'Stroke':'Butterfly','Distance':50,'SportClass':[1,2,3,4,5,6,7]},
|
||||
{'Stroke':'Butterfly','Distance':100,'SportClass':[8,9,10,11,12,13,14]},
|
||||
{'Stroke':'Backstroke','Distance':50,'SportClass':[1,2,3,4,5]},
|
||||
{'Stroke':'Backstroke','Distance':100,'SportClass':[1,2,6,7,8,9,10,11,12,13,14]},
|
||||
{'Stroke':'Breaststroke','Distance':50,'SportClass':[1,2,3]},
|
||||
{'Stroke':'Breaststroke','Distance':100,'SportClass':[4,5,6,7,8,9,11,12,13,14]},
|
||||
{'Stroke':'Medley','Distance':150,'SportClass':[1,2,3,4]},
|
||||
{'Stroke':'Medley','Distance':200,'SportClass':[5,6,7,8,9,10,11,12,13,14]},
|
||||
{'Stroke':'Freestyle','Distance':50,'SportClass':[1,2,3,4,5,6,7,8,9,10,11,12,13,14]},
|
||||
{'Stroke':'Freestyle','Distance':100,'SportClass':[1,2,3,4,5,6,7,8,9,10,11,12,13,14]},
|
||||
{'Stroke':'Freestyle','Distance':200,'SportClass':[1,2,3,4,5,14]},
|
||||
{'Stroke':'Freestyle','Distance':400,'SportClass':[6,7,8,9,10,11,12,13]},
|
||||
]).explode('SportClass').reset_index(drop=True)
|
||||
|
||||
def parse_WPS_rankings(DF):
|
||||
'''Takes a pandas dataframe, usually loaded from an excel file, and cleans it up for use'''
|
||||
return (
|
||||
DF
|
||||
#Makes .dot notation easier
|
||||
.pipe(lambda df: df.rename(columns={c:c.replace(' ','_') for c in df.columns}))
|
||||
|
||||
#Drop VACANT events and relay results
|
||||
.pipe(lambda df: df[df.SDMS_ID.notnull()])
|
||||
|
||||
#Parse out event information into useful columns
|
||||
.pipe(lambda df: pd.concat([df,df.Event.str.extract(r"'s (?P<Distance>\d+) m (Individual )*(?P<Stroke>[A-z]+) [SBM]+(?P<SportClass>\d+)")],axis=1))
|
||||
|
||||
#Cleanup column dtypes
|
||||
.assign(Date=lambda df: pd.to_datetime(df.Date))
|
||||
.assign(Year=lambda df: df.Date.dt.year)
|
||||
.assign(Seconds=lambda df: df.Result.apply(t2f))
|
||||
.astype({'SportClass':int,'Distance':int,'SDMS_ID':int})
|
||||
|
||||
#Drop excess columns
|
||||
.pipe(lambda df: df['Gender SportClass Distance Stroke Result Seconds SDMS_ID NPC Given_Name Family_Name Date'.split()])
|
||||
)
|
||||
|
||||
|
||||
|
||||
__version__ = "0.1.1"
|
||||
3
README.md
Normal file
3
README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# ParaUtils
|
||||
|
||||
Utility functions for para swimming related activities
|
||||
27
pyproject.toml
Normal file
27
pyproject.toml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
[build-system]
|
||||
requires = ["setuptools>=45", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "ParaUtils"
|
||||
description = "Bits and bobs useful for many para swimming data manipulation projects"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
dynamic = ["version"]
|
||||
|
||||
dependencies = [
|
||||
"pandas",
|
||||
"numpy"
|
||||
]
|
||||
requires-python = ">=3.8"
|
||||
|
||||
authors = [
|
||||
{name = "Michael Edey", email = "mike@edey.org"}
|
||||
]
|
||||
maintainers = [
|
||||
{name = "Michael Edey", email = "mike@edey.org"}
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://git.edey.org/Mike/ParaUtils.git"
|
||||
Repository = "https://git.edey.org/Mike/ParaUtils.git"
|
||||
6
setup.py
Normal file
6
setup.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="ParaUtils",
|
||||
packages=find_packages(),
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue