- updated draft with printout
- added correction to results for 10s
This commit is contained in:
@@ -44,11 +44,25 @@ def is_mobile_device():
|
||||
"""Check if the request is coming from a mobile device"""
|
||||
user_agent = request.headers.get('User-Agent', '').lower()
|
||||
mobile_patterns = [
|
||||
r'android', r'iphone', r'ipad', r'ipod', r'blackberry',
|
||||
r'android', r'iphone', r'ipad', r'ipod', r'blackberry',
|
||||
r'iemobile', r'opera mini', r'mobile', r'tablet'
|
||||
]
|
||||
return any(re.search(pattern, user_agent) for pattern in mobile_patterns)
|
||||
|
||||
def calculate_tens_from_targets(targets):
|
||||
"""Calculate the number of 10s from a targets dictionary"""
|
||||
tens_count = 0
|
||||
if not targets:
|
||||
return 0
|
||||
|
||||
for target in targets.values():
|
||||
if isinstance(target, dict):
|
||||
for shot_key, shot_value in target.items():
|
||||
if shot_key.startswith('shot') and shot_value == 10:
|
||||
tens_count += 1
|
||||
|
||||
return tens_count
|
||||
|
||||
# Define streams globally so both routes can access them
|
||||
STREAMS = [
|
||||
{'name': 'Target1', 'url': 'http://192.168.0.134:9081'},
|
||||
@@ -1020,17 +1034,21 @@ def view_archived_tournament(filename):
|
||||
# Process results for display
|
||||
participants = []
|
||||
for player_id, participant_data in results_data.get('participants', {}).items():
|
||||
targets = participant_data.get('targets', {})
|
||||
tens_count = calculate_tens_from_targets(targets)
|
||||
|
||||
participants.append({
|
||||
'id': player_id,
|
||||
'name': participant_data['name'],
|
||||
'total_score': participant_data['total_score'],
|
||||
'completed': participant_data['completed'],
|
||||
'targets': participant_data.get('targets', {})
|
||||
'targets': targets,
|
||||
'tens_count': tens_count
|
||||
})
|
||||
|
||||
# Sort by score (descending)
|
||||
participants.sort(key=lambda x: x['total_score'], reverse=True)
|
||||
|
||||
|
||||
# Sort by score (descending), then by tens (descending) as tiebreaker
|
||||
participants.sort(key=lambda x: (x['total_score'], x['tens_count']), reverse=True)
|
||||
|
||||
# Add rankings
|
||||
for i, participant in enumerate(participants):
|
||||
participant['rank'] = i + 1
|
||||
@@ -1091,16 +1109,20 @@ def mobile_view_archived_tournament(filename):
|
||||
# Process results for display
|
||||
participants = []
|
||||
for player_id, participant_data in results_data.get('participants', {}).items():
|
||||
targets = participant_data.get('targets', {})
|
||||
tens_count = calculate_tens_from_targets(targets)
|
||||
|
||||
participants.append({
|
||||
'id': player_id,
|
||||
'name': participant_data['name'],
|
||||
'total_score': participant_data['total_score'],
|
||||
'completed': participant_data['completed']
|
||||
'completed': participant_data['completed'],
|
||||
'tens_count': tens_count
|
||||
})
|
||||
|
||||
# Sort by score (descending)
|
||||
participants.sort(key=lambda x: x['total_score'], reverse=True)
|
||||
|
||||
|
||||
# Sort by score (descending), then by tens (descending) as tiebreaker
|
||||
participants.sort(key=lambda x: (x['total_score'], x['tens_count']), reverse=True)
|
||||
|
||||
# Add rankings
|
||||
for i, participant in enumerate(participants):
|
||||
participant['rank'] = i + 1
|
||||
@@ -1303,25 +1325,29 @@ def mobile_results():
|
||||
})
|
||||
|
||||
return redirect('/mobile/archive')
|
||||
|
||||
|
||||
# Priority 2: Show individual tournament results (standalone tournament only)
|
||||
elif results and results.get('tournament_finished', False):
|
||||
participants = []
|
||||
for player_id, data in results['participants'].items():
|
||||
targets = data.get('targets', {})
|
||||
tens_count = calculate_tens_from_targets(targets)
|
||||
|
||||
participants.append({
|
||||
'id': player_id,
|
||||
'name': data['name'],
|
||||
'total_score': data['total_score'],
|
||||
'completed': data['completed']
|
||||
'completed': data['completed'],
|
||||
'tens_count': tens_count
|
||||
})
|
||||
|
||||
# Sort by score (descending)
|
||||
participants.sort(key=lambda x: x['total_score'], reverse=True)
|
||||
|
||||
|
||||
# Sort by score (descending), then by tens (descending) as tiebreaker
|
||||
participants.sort(key=lambda x: (x['total_score'], x['tens_count']), reverse=True)
|
||||
|
||||
# Add rankings
|
||||
for i, participant in enumerate(participants):
|
||||
participant['rank'] = i + 1
|
||||
|
||||
|
||||
return render_template('mobile_results.html',
|
||||
results=results,
|
||||
participants=participants,
|
||||
@@ -1492,25 +1518,29 @@ def results_display():
|
||||
|
||||
# If we can't find the archive, redirect to archive page
|
||||
return redirect('/archive')
|
||||
|
||||
|
||||
# Priority 2: Show individual tournament results (standalone tournament only)
|
||||
elif results and results.get('tournament_finished', False):
|
||||
participants = []
|
||||
for player_id, data in results['participants'].items():
|
||||
targets = data.get('targets', {})
|
||||
tens_count = calculate_tens_from_targets(targets)
|
||||
|
||||
participants.append({
|
||||
'id': player_id,
|
||||
'name': data['name'],
|
||||
'total_score': data['total_score'],
|
||||
'completed': data['completed']
|
||||
'completed': data['completed'],
|
||||
'tens_count': tens_count
|
||||
})
|
||||
|
||||
# Sort by score (descending)
|
||||
participants.sort(key=lambda x: x['total_score'], reverse=True)
|
||||
|
||||
|
||||
# Sort by score (descending), then by tens (descending) as tiebreaker
|
||||
participants.sort(key=lambda x: (x['total_score'], x['tens_count']), reverse=True)
|
||||
|
||||
# Add rankings
|
||||
for i, participant in enumerate(participants):
|
||||
participant['rank'] = i + 1
|
||||
|
||||
|
||||
return render_template('results_display.html',
|
||||
results=results,
|
||||
participants=participants,
|
||||
|
||||
Reference in New Issue
Block a user