Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swimming #5

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Python interface for scoreboard consoles manufactured by Daktronics and Colorado
- :wrestling: Wrestling
- Colorado Time Systems System 6
- :water_polo: Water Polo
- :swimmer: Swimming

## Installation
`pip install scorebox-consoles`
Expand Down Expand Up @@ -82,6 +83,19 @@ if __name__ == '__main__':
| `ball_on` | int | Ball Location on the Field (does not include side of field) |
| `flag` | bool | Flag Status (only updated on console button push) |

#### :swimmer: Swimming
| Key | Type | Description |
| --- | --- | --- |
| `{lane # (1-9)}` . `place` | int | Final Event Placement, `0` if still swimming |
| `{lane # (1-9)}` . `split` | str | Most Recent Split Time, or Final Race Time if `place` != `0` |
| `time` | str | Running Clock Time of Current Event |
| `event` | int | Event ID Number |
| `heat` | int | Heat Number |
| `lengths` | int | Lengths of the Pool Completed by the Race Leader |

*__Notes:__ Lane information resets independently of the Event/Heat so it's probable that immediatly following a race, the event/heat will advance but the lane data will remain until the start of the next event. The running clock can keep running after all lanes have finished. The `time` value changes from `0.0` to `.0` when the starting horn is triggered. The System 6 console supports up to 12 lanes but this library only supports lanes 1-9. A disqualifed lane will have a `place` of `13`.*


#### :volleyball: Volleyball
| Key | Type | Description |
| --- | --- | --- |
Expand All @@ -105,4 +119,4 @@ if __name__ == '__main__':
| `{home/visitor}_team_score` | int | Team Score |
| `{home/visitor}_match_score` | int | Match Score |
| `clock` | str | Main Clock Time |
| `period` | str | Match Period |
| `period` | str | Match Period |
149 changes: 149 additions & 0 deletions consoles/sports.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,152 @@ def get_period(self, message, message_range) -> None:
potential = self.get_field(message, message_range, 142, 2)
if potential != '':
self.data['period'] = potential + get_ordinal(int(potential))

class Swimming (ColoradoTimeSystems):
'''Swimming as scored by a Colorado Time System 6'''
def __init__(self, port: str) -> None:
super().__init__(port)

# Scoreboard Data
self.data = {
'1': {
'place': 0,
'split': ''
},
'2': {
'place': 0,
'split': ''
},
'3': {
'place': 0,
'split': ''
},
'4': {
'place': 0,
'split': ''
},
'5': {
'place': 0,
'split': ''
},
'6': {
'place': 0,
'split': ''
},
'7': {
'place': 0,
'split': ''
},
'8': {
'place': 0,
'split': ''
},
'9': {
'place': 0,
'split': ''
},
'event': 0,
'heat': 0,
'time': '0:00',
'lengths': 0
}

self.runner()

def export(self) -> Dict:
'''Python Dictionary of Processed Score Data'''
return self.data

def process(self, channel: int, values: List[int], formats: List[int]) -> None:
data = []
data_format = []
valid = 0
for value in values:
if value != 15 and value != '':
data.append(value)
valid += 1
else:
data.append('')
for value in formats:
if value != 0 and value != '':
data_format.append(value)
else:
data_format.append('')
## Channel Dubugger
# if int(channel) == 12:
# print(f'Channel {channel} - {data} - {data_format}')

if int(channel) == 0:
self.process_running_time(data, data_format)
elif int(channel) in [1, 2, 3, 4, 5, 6, 7, 8, 9]:
self.process_lane(data, data_format)
elif int(channel) == 11 :
self.process_lengths(data, data_format)
elif int(channel) == 12:
self.process_event(data, data_format)

def process_lane(self, data, data_format):
if data_format[4] != 2 or data_format[5] != 2:
return

if data[0] != '':
lane = str(data[0])
place = data[1]

minutes = str(data[2]) + str(data[3])
seconds = str(data[4]) + str(data[5])
milliseconds = str(data[6]) + str(data[7])
if lane in self.data.keys() and milliseconds != '' and len(milliseconds) >= 2:
self.data[lane]['split'] = f'{minutes}:{seconds}.{milliseconds}'
if place:
self.data[lane]['place'] = int(place)
else:
self.data[lane]['place'] = 0

def process_event(self, data, data_format):
if data[3] != '' or data[4] != '' or data[7] == '':
return

event = str(data[0]) + str(data[1]) + str(data[2])
if event:
event = int(event)
# if event != self.data['event']:
# self.clear_lanes()
self.data['event'] = event
else:
self.data['event'] = 0
heat = str(data[5]) + str(data[6]) + str(data[7])
if heat:
heat = int(heat)
# if heat != self.data['heat']:
# self.clear_lanes()
self.data['heat'] = heat
else:
self.data['heat'] = 0

def process_running_time(self, data, data_format):
minutes = str(data[2]) + str(data[3])
seconds = str(data[4]) + str(data[5])
milliseconds = str(data[6]) + str(data[7])
if milliseconds != '':
if minutes != '':
self.data['time'] = f'{minutes}:{seconds}.{milliseconds}'
else:
self.data['time'] = f'{seconds}.{milliseconds}'
if self.data['time'] == '.0':
self.clear_lanes()

def process_lengths(self, data, data_format):
lengths = str(data[0]) + str(data[1])
if lengths:
self.data['lengths'] = int(lengths)
else:
self.data['lengths'] = 0

def clear_lanes(self):
for lane in range(1, 10):
lane = str(lane)
self.data[lane] = {
'place': 0,
'split': ''
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="scorebox-consoles",
version="1.2.0",
version="1.3.0",
author="Daniel Flanagan",
description="Python interface for scoreboard consoles manufactured by Daktronics and Colorado Time Systems",
long_description=long_description,
Expand Down
18 changes: 14 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from consoles.sports import Basketball, Football, Volleyball, WaterPolo, WaterPoloDaktronics, Wrestling
from consoles.sports import Basketball, Football, Swimming, Volleyball, WaterPolo, WaterPoloDaktronics
import time

if __name__ == '__main__':
t = Wrestling('COM9')
t = Swimming('/dev/ttyUSB0')
print()
while True:
time.sleep(0.1)
print(t.export(), end='\r')
time.sleep(0.025)
# print(t.export(), end='\r')
data = t.export()
event = data['event']
heat = data['heat']
rtime = data['time']
length = data['lengths']
la = data['2']
lb = data['3']
lc = data['4']
print(f'E{event} H{heat} T {rtime} ({length})- LA {la} - LB {lb} - LC {lc}')
# print(data['time'],end='\r')