Skip to content

feat: add custom defined reveal time for unlisted unranked races - #219

Open
TreZc0 wants to merge 10 commits into
racetimeGG:masterfrom
TreZc0:scheduled-reveal
Open

feat: add custom defined reveal time for unlisted unranked races#219
TreZc0 wants to merge 10 commits into
racetimeGG:masterfrom
TreZc0:scheduled-reveal

Conversation

@TreZc0

@TreZc0 TreZc0 commented Jul 19, 2025

Copy link
Copy Markdown
Contributor

Premise:
Many communities with team racing use unlisted races for async functionality.
Currently, unranked unlisted races that cannot be recorded are instantly set to be listed after the race in done, as that's the final step of the race's lifecycle.

This can reveal info before it's convenient for tournaments.

Implementation
With this, races only get revealed instantly if no reveal_at time is set.
Through a hidden field timezone_conversion, the local timezone of the user is tracked, so they can enter their time in local timezone. the database saves the time in UTC:

To facility the process of making races visible after reveal_at time is reached, I suggest wrapping racetime/management/commands/reveal_hidden_races.py in a cronjob, probably running every 10 minutes.

@TreZc0 TreZc0 changed the title feat: add custom defined reveal time for unlisted unraked races feat: add custom defined reveal time for unlisted unranked races Jul 19, 2025

@deains deains left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking forever on this.

Comment thread racetime/forms.py

if cleaned_data.get('reveal_at') and self.data.get('timezone_offset'):
try:
from datetime import timedelta

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is unnecessary as timedelta is already imported at the top of the file

Comment thread racetime/forms.py
timezone_offset = 0

local_time = cleaned_data['reveal_at']
utc_time = local_time + timedelta(minutes=timezone_offset)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't strictly speaking the right way to timezone-shift a datetime in Python, although since local_time should already be in UTC, I think this will still work? Might have to test it.

Comment on lines +13 to +17
races_to_reveal = Race.objects.filter(
unlisted=True,
recordable=False,
reveal_at__lte=now,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also want to filter this to only include completed races

state__in=[RaceStates.finished, RaceStates.cancelled, RaceStates.partitioned],

for race in races_to_reveal:
race.unlisted = False
race.reveal_at = None
race.save()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use race.increment_version() instead of save() so the update is broadcast correctly to websocket listeners.


race.add_message(
'This race has been automatically revealed as scheduled.',
highlight=True,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think highlight is necessary for this.

from django.db import migrations, models


class Migration(migrations.Migration):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this migration will need to be remade/merged

Comment thread racetime/models/race.py
Comment on lines +138 to +139
'Define when this race should be publicly visible, in your local timezone. '
'Only available for races that are both unlisted and unranked.'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add something like "If blank, race will be revealed on finish."

$('#id_ranked')
.prop('checked', rankedWasChecked)
.prop('disabled', false);
$('#id_ranked').prop('checked', true).prop('disabled', false);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing ranked to be ticked when it should be off if you edit an unranked race. Also, the "reveal at" field comes up blank.

Submitted on race create:
image

Edit form:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants