forked from Trygve/otime
Bedre organisering og mindre innsekter
This commit is contained in:
parent
29321676e2
commit
b063a61c7e
35
cli.py
Normal file
35
cli.py
Normal file
@ -0,0 +1,35 @@
|
||||
import otime
|
||||
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
def print_runners(Runners):
|
||||
table = Table(title="Runners")
|
||||
table.add_column("Name", justify="right", style="cyan", no_wrap=True)
|
||||
table.add_column("club", style="magenta")
|
||||
table.add_column("card", style="red")
|
||||
table.add_column("class", justify="right", style="green")
|
||||
|
||||
for i in Runners:
|
||||
table.add_row(i.fullname(), i.club ,str(i.card), i.o_class)
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
def print_o_classes(class_list):
|
||||
table = Table(title="Classes")
|
||||
table.add_column("Class", justify="right", style="cyan", no_wrap=True)
|
||||
table.add_column("Course", style="magenta")
|
||||
table.add_column("Controls", justify="right", style="green")
|
||||
|
||||
for i in class_list:
|
||||
table.add_row(i.name, i.course.name , str(i.course.codes))
|
||||
|
||||
console = Console()
|
||||
console.print(table)
|
||||
|
||||
if __name__ == "__main__":
|
||||
courses = otime.courses_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt')
|
||||
o_classes = otime.classes_from_ttime_conf('sc_2021_ttime/ttime.cnf.txt', courses)
|
||||
Runners = otime.xml_to_class()
|
||||
|
||||
print_runners(Runners)
|
||||
print_o_classes(o_classes)
|
130
otime.py
Normal file
130
otime.py
Normal file
@ -0,0 +1,130 @@
|
||||
import datetime
|
||||
import csv
|
||||
import sqlite3
|
||||
import re
|
||||
from rich.console import Console
|
||||
from rich.table import Table
|
||||
from rich.traceback import install
|
||||
import xml.etree.ElementTree as ET
|
||||
install(show_locals=True)
|
||||
class runner:
|
||||
def __init__(self, first, last, club, country, card, o_class, controls, splits):
|
||||
self.first = first
|
||||
self.last = last
|
||||
self.club = club
|
||||
self.country = country
|
||||
self.card = card
|
||||
self.o_class = o_class
|
||||
self.controls = controls
|
||||
self.splits = splits
|
||||
|
||||
def fullname(self):
|
||||
return '{} {}'.format(self.first, self.last)
|
||||
|
||||
class course:
|
||||
def __init__(self, name, codes):
|
||||
self.name = name
|
||||
self.codes = codes
|
||||
|
||||
class o_class:
|
||||
def __init__(self, name, course):
|
||||
self.name = name
|
||||
self.course = course
|
||||
|
||||
def courses_from_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
|
||||
courses = []
|
||||
conf = open(ttime_file).readlines()
|
||||
for line in conf:
|
||||
if '-codes' in line:
|
||||
code_list = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
||||
loops = 0
|
||||
for n in code_list:
|
||||
n = n.split(',')
|
||||
loops += 1
|
||||
courses.append(course('course_'+str(loops), n))
|
||||
print(n)
|
||||
print(courses)
|
||||
print(courses[1].name)
|
||||
return courses
|
||||
def classes_from_ttime_conf(ttime_file, courses):
|
||||
o_classes = []
|
||||
conf = open(ttime_file).readlines()
|
||||
for line in conf:
|
||||
if '-courses' in line:
|
||||
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
|
||||
loops = 0
|
||||
for n in raw_courselist:
|
||||
n = n.split(',')
|
||||
for i in n:
|
||||
o_classes.append(o_class(i,courses[loops]))
|
||||
loops += 1
|
||||
|
||||
print(o_classes[1].course.codes)
|
||||
|
||||
return o_classes
|
||||
|
||||
def xml_to_class(xml_file = 'entries_KOK_Sommercup,_løp_2.xml'):
|
||||
tree = ET.parse(xml_file)
|
||||
root = tree.getroot()
|
||||
runnerarray = []
|
||||
|
||||
for person_root in root[1:]:
|
||||
first = person_root[1][1][1].text
|
||||
last = person_root[1][1][0].text
|
||||
try:
|
||||
club = person_root[2][1].text
|
||||
except:
|
||||
club = "None"
|
||||
country = person_root[1][3].text
|
||||
try:
|
||||
card = int(person_root[3].text)
|
||||
except:
|
||||
card = 0
|
||||
try:
|
||||
o_class = person_root[4][1].text
|
||||
except:
|
||||
o_class = "None"
|
||||
runnerarray.append(runner(first, last, club, country, card, o_class, [], []))
|
||||
return runnerarray
|
||||
def ttime_mtr_to_class(csv_file, runnerarray):
|
||||
csvreader = csv.reader(open(csv_file))
|
||||
fields = next(csvreader)
|
||||
|
||||
fields = []
|
||||
rows = []
|
||||
# hver rad er brikkenummer med tilhørende info
|
||||
for row in csvreader:
|
||||
rows.append(row)
|
||||
for row in rows:
|
||||
controls = []
|
||||
splits = []
|
||||
# postkodene kommer på oddetall fra og med den 11. De blir hevet inn i controls
|
||||
for item in row[11::2]:
|
||||
if item != '000' and item != '0000' and item != '00000':
|
||||
controls.append(int(item))
|
||||
# strekktidene kommer på partall fra og med den 12. De blir hevet i splits.
|
||||
for item in row[12::2]:
|
||||
if item != '000' and item != '0000' and item != '00000':
|
||||
splits.append(int(item))
|
||||
print(row[6])
|
||||
# looper gjonnom løperobjektene og legger til poster og strekktider
|
||||
for runner in runnerarray:
|
||||
if runner.card == int(row[6]):
|
||||
runner.controls = controls
|
||||
runner.splits = splits
|
||||
|
||||
if __name__ == "__main__":
|
||||
import_ttime_conf()
|
||||
Runners = xml_to_class()
|
||||
#print(Runners[4].last)
|
||||
#print_table(Runners)
|
||||
#ttime_mtr_to_class('sc_2021_ttime/mtr.csv', Runners)
|
||||
"""
|
||||
for i in Runners:
|
||||
print(i.first + ' ' + i.last)
|
||||
print(i.controls)
|
||||
#print(i.splits)
|
||||
try:
|
||||
print(str(datetime.timedelta(seconds = i.splits[-1])))
|
||||
except: print('ikke deltatt')
|
||||
"""
|
Loading…
Reference in New Issue
Block a user