improvement to situation_long based on todays ethias race

This commit is contained in:
cube
2026-06-02 15:04:42 +01:00
parent 9c27da9265
commit c65fbbb476
2 changed files with 59 additions and 32 deletions

View File

@@ -1,14 +1,17 @@
from pcslive import LiveStats
import time
stats = LiveStats()
# if there are live races...
if len(stats.races) > 0:
race = stats.races[0]
from pcslive import LiveStats
race.get_situation_long()
stats = LiveStats()
race = stats.find_race("ethias")
race.get_situation_long()
# whats the situation? :)
for x in race.situation_long:
print(x, race.situation_long[x])
if race.situation_long:
for group in race.situation_long:
for item in group:
print(item)
print("================")
else:
print("No situation data")

View File

@@ -202,36 +202,60 @@ class Race:
# creates a dictionary containing time gaps as keys and each
# timegap points to a list of riders in that group
# def get_situation_long(self):
# page = self.get_race_page()
# if page:
# all = page.find_all(attrs={"class":"situCont"})
# live = all[0]
# situation_long = live.find_all("li")
# # create the dictionary
# self.situation_long = {}
# # last_timegap is used for grouping riders together
# last_timegap = None
# for item in situation_long:
# time_gap = item.find(attrs={"class":"time"})
# rider = item.find(attrs={"class":"maxw200"})
# # time gap is only listed once and subsequent riders in that
# # group don't have one (None)
# if time_gap:
# tg = self.remove_tags(time_gap) # get rid of html tags
# self.situation_long[tg] = [] # create the list inside the dict
# last_timegap = tg # set last timegap for the loop
# rider_name = self.remove_tags(rider) # remove tags from rider name
# # the leading rider is basically the group name i guess?
# # anyway we dont need it twice
# if rider_name not in self.situation_long[last_timegap]:
# # add rider to list of riders under that timegap/group
# self.situation_long[last_timegap].append(rider_name)
def get_situation_long(self):
page = self.get_race_page()
if page:
all = page.find_all(attrs={"class":"situCont"})
live = all[0]
situation_long = live.find_all("li")
if all:
live = all[0]
groups = live.find_all(attrs={"class":"group"})
self.situation_long = []
for group in groups:
group_name = group.find(attrs={"class":"groupname"})
time = group.find(attrs={"class":"time"})
riders = group.find_all("li")
riders_clean = []
for rider in riders:
rider_name = rider.find(attrs={"class":"maxw180"})
riders_clean.append(self.remove_tags(rider_name))
group_name_clean = self.remove_tags(group_name)
time_clean = self.remove_tags(time).strip("??")
self.situation_long.append([group_name_clean, time_clean, riders_clean])
else:
self.situation_long = None
# create the dictionary
self.situation_long = {}
# last_timegap is used for grouping riders together
last_timegap = None
for item in situation_long:
time_gap = item.find(attrs={"class":"time"})
rider = item.find(attrs={"class":"maxw200"})
# time gap is only listed once and subsequent riders in that
# group don't have one (None)
if time_gap:
tg = self.remove_tags(time_gap) # get rid of html tags
self.situation_long[tg] = [] # create the list inside the dict
last_timegap = tg # set last timegap for the loop
rider_name = self.remove_tags(rider) # remove tags from rider name
# the leading rider is basically the group name i guess?
# anyway we dont need it twice
if rider_name not in self.situation_long[last_timegap]:
# add rider to list of riders under that timegap/group
self.situation_long[last_timegap].append(rider_name)
# remove surrounding html tags from final data points,
# like rider names, race names, etc.