Slette main.py

This commit is contained in:
Trygve 2022-02-08 20:59:30 +00:00
parent 64121fa324
commit d6ca92c183

140
main.py
View File

@ -1,140 +0,0 @@
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 import_ttime_conf(ttime_file = 'sc_2021_ttime/ttime.cnf.txt'):
courses = []
o_classes = []
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)
elif '-courses' in line:
raw_courselist = re.search(r'(?<=\")(.*?)(?=\")', line).group().split(';')
loops = 0
for n in raw_courselist:
n.split(',')
for i in n:
o_classes.append(o_class(i,courses[loops]))
loops += 1
print(o_classes[1].course.codes)
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
def print_table(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)
courses = []
o_classes = []
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')
"""