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

Remove several registration fields that are not required anymore #494

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 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
11 changes: 3 additions & 8 deletions heltour/tournament/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,6 @@ def team_manage_players_view(self, request, object_id):
if sp.player in old_alternates:
purple_players.add(sp.player)

expected_ratings = {sp.player: sp.expected_rating(league) for sp in season_player_objs}
season_started = Round.objects.filter(season=season, publish_pairings=True).exists()

context = {
Expand All @@ -1205,14 +1204,11 @@ def team_manage_players_view(self, request, object_id):
'red_players': red_players,
'blue_players': blue_players,
'purple_players': purple_players,
'expected_ratings': expected_ratings,
}
if teams:
context.update({
'team_rating_variance': team_rating_variance(teams, False),
'team_rating_range': team_rating_range(teams, False),
'team_expected_rating_variance': team_rating_variance(teams, True),
'team_expected_rating_range': team_rating_range(teams, True),
'team_rating_variance': team_rating_variance(teams),
'team_rating_range': team_rating_range(teams),
})
return render(request, 'tournament/admin/edit_rosters.html', context)

Expand Down Expand Up @@ -1912,8 +1908,7 @@ class RegistrationAdmin(_BaseAdmin):
def get_list_display(self, request):
return self.remove_email_if_no_dox(
request.user,
['review', 'email', 'status', 'valid', 'season', 'section', 'classical_rating',
'date_created']
['review', 'email', 'status', 'valid', 'season', 'section', 'rating', 'date_created']
)

def get_fields(self, request, obj=None):
Expand Down
23 changes: 2 additions & 21 deletions heltour/tournament/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class RegistrationForm(forms.ModelForm):
class Meta:
model = Registration
fields = (
'email', 'classical_rating',
'has_played_20_games', 'already_in_slack_group',
'previous_season_alternate',
'email',
'has_played_20_games',
'can_commit', 'friends', 'avoid', 'agreed_to_rules', 'agreed_to_tos',
'alternate_preference', 'section_preference', 'weeks_unavailable',
)
Expand All @@ -46,8 +45,6 @@ def __init__(self, *args, **kwargs):

# Rating fields
rating_type = league.get_rating_type_display()
self.fields['classical_rating'] = forms.IntegerField(required=True, label=_(
'Your Lichess %s Rating' % rating_type))

help_text_provisional = 'You may apply with a provisional rating, but your application will only be reviewed once your rating is established.'

Expand All @@ -64,22 +61,6 @@ def __init__(self, *args, **kwargs):
help_text=_(
help_text_provisional), )

# In slack
self.fields['already_in_slack_group'] = forms.TypedChoiceField(required=True, label=_(
'Are you in our Slack group?'), choices=YES_NO_OPTIONS,
widget=forms.RadioSelect,
coerce=lambda x: x == 'True')

# Previous season status
if league.competitor_type == 'team':
self.fields['previous_season_alternate'] = forms.ChoiceField(required=True,
choices=PREVIOUS_SEASON_ALTERNATE_OPTIONS,
widget=forms.RadioSelect,
label=_(
'Were you an alternate for the previous season?'))
else:
del self.fields['previous_season_alternate']

# Can commit
time_control = league.time_control
if league.rating_type != 'blitz':
Expand Down
1 change: 0 additions & 1 deletion heltour/tournament/management/commands/cleansedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def handle(self, *args, **options):
r.validation_warning = False
r.friends = ''
r.avoid = ''
r.slack_username = ''
r.save()
LeagueModerator.objects.all().delete()
Comment.objects.all().delete()
Expand Down
2 changes: 1 addition & 1 deletion heltour/tournament/migrations/0021_auto_20160724_1855.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='registration',
name='already_in_slack_group',
field=models.BooleanField(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Altering old migrations has no effect on the live database, what was the intent with this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

the intent was simply to make the new migrations revertible. as far as i can tell, that's the only thing it does, and i didn't see a downside to it. i don't mind removing the changes to the old migrations from the pull request.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am pretty sure there are ways to make the new migrations invertible that don't include modifying old migrations. The problem with modifying old migrations is that our live database will not be in sync with this change, which means that new migrations may assume they can do things that they can't and it will succeed in development, but not on prod. Let's remove the changes to old migrations and if you want the new migrations to be revertible, we can work through that.

field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='registration',
Expand Down
4 changes: 2 additions & 2 deletions heltour/tournament/migrations/0171_auto_20171030_0044.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='registration',
name='classical_rating',
field=models.PositiveIntegerField(verbose_name='rating'),
field=models.PositiveIntegerField(verbose_name='rating', default=0),
),
migrations.AlterField(
model_name='registration',
name='peak_classical_rating',
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='peak rating'),
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='peak rating', default=0),
),
migrations.AlterField(
model_name='section',
Expand Down
33 changes: 33 additions & 0 deletions heltour/tournament/migrations/0195_remove_registration_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.28 between 2023-03-12 17:28 and 2023-03-22 13:58

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('tournament', '0194_playerpairing_last_time_player_changed'),
]

operations = [
migrations.RemoveField(
model_name='registration',
name='classical_rating',
),
migrations.RemoveField(
model_name='registration',
name='peak_classical_rating',
),
migrations.RemoveField(
model_name='registration',
name='already_in_slack_group',
),
migrations.RemoveField(
model_name='registration',
name='previous_season_alternate',
),
migrations.RemoveField(
model_name='registration',
name='slack_username',
),
]
43 changes: 8 additions & 35 deletions heltour/tournament/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ def extract(sp):
if reg is not None:
info.update({
'date_created': reg.date_created.isoformat(),
'peak_classical_rating': reg.peak_classical_rating,
'friends': reg.friends,
'avoid': reg.avoid,
'prefers_alt': reg.alternate_preference == 'alternate',
Expand Down Expand Up @@ -1112,22 +1111,19 @@ def boards(self):
return [(n, find(team_members, board_number=n)) for n in
Season.objects.get(pk=self.season_id).board_number_list()]

def average_rating(self, expected_rating=False):
def average_rating(self):
n = 0
total = 0.0
for _, board in self.boards():
if board is not None:
if expected_rating:
rating = board.expected_rating()
else:
rating = board.player.rating_for(self.season.league)
rating = board.player.rating_for(self.season.league)
if rating is not None:
n += 1
total += rating
return total / n if n > 0 else None

def get_mean(self, expected_rating=False):
return self.average_rating(expected_rating)
def get_mean(self):
return self.average_rating()

def captain(self):
return self.teammember_set.filter(is_captain=True).first()
Expand Down Expand Up @@ -1727,15 +1723,6 @@ def refresh_ranks(self, rank_dict=None):
('rejected', 'Rejected'),
)

PREVIOUS_SEASON_ALTERNATE_OPTIONS = (
('alternate', 'Yes, I was an alternate at the end of the last season.'),
('alternate_to_full_time',
'Yes, but I was able to find a consistent team (did not simply fill in for a week or two).'),
('full_time', 'No, I was not an alternate for the last season. I played the season.'),
('new',
'No, I was not an alternate for the last season. I am a new member / I took last season off.'),
)

ALTERNATE_PREFERENCE_OPTIONS = (
('alternate', 'Alternate'),
('full_time', 'Full Time'),
Expand All @@ -1750,17 +1737,9 @@ class Registration(_BaseModel):
status_changed_date = models.DateTimeField(blank=True, null=True)

lichess_username = models.CharField(max_length=255, validators=[username_validator])
slack_username = models.CharField(max_length=255, blank=True)
email = models.EmailField(max_length=255)

classical_rating = models.PositiveIntegerField(verbose_name='rating')
peak_classical_rating = models.PositiveIntegerField(blank=True, null=True,
verbose_name='peak rating')

has_played_20_games = models.BooleanField()
already_in_slack_group = models.BooleanField()
previous_season_alternate = models.CharField(blank=True, max_length=255,
choices=PREVIOUS_SEASON_ALTERNATE_OPTIONS)

can_commit = models.BooleanField()
friends = models.CharField(blank=True, max_length=1023)
avoid = models.CharField(blank=True, max_length=1023)
Expand Down Expand Up @@ -1789,6 +1768,9 @@ def other_seasons(self):
def player(self):
return Player.objects.filter(lichess_username__iexact=self.lichess_username).first()

def rating(self):
return self.player().rating

@classmethod
def can_register(cls, user, season):
if not season or not season.registration_open:
Expand Down Expand Up @@ -1877,15 +1859,6 @@ def save(self, *args, **kwargs):

super(SeasonPlayer, self).save(*args, **kwargs)

def expected_rating(self, league=None):
rating = self.player.rating_for(league)
if rating is None:
return None
if self.registration is not None:
peak = max(self.registration.peak_classical_rating or 0, rating)
return (rating + peak) / 2
return rating

def seed_rating_display(self, league=None):
if self.seed_rating is not None:
return self.seed_rating
Expand Down
4 changes: 2 additions & 2 deletions heltour/tournament/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def registration_saved(instance, created, **kwargs):
instance.season.pk))
pending_count = instance.season.registration_set.filter(status='pending',
season=instance.season).count()
message = '@%s (%s) has <%s|registered> for %s. <%s|%d pending>' % (
instance.lichess_username, instance.classical_rating, reg_url, league.name, list_url,
message = '@%s has <%s|registered> for %s. <%s|%d pending>' % (
instance.lichess_username, reg_url, league.name, list_url,
pending_count)

pre_season = instance.season.start_date and timezone.now() < instance.season.start_date
Expand Down
5 changes: 0 additions & 5 deletions heltour/tournament/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,15 +429,10 @@ def validate_registration(reg_id):
defaults={
'lichess_username': reg.lichess_username})
player.update_profile(user_meta)
reg.classical_rating = player.rating_for(reg.season.league)
reg.peak_classical_rating = lichessapi.get_peak_rating(reg.lichess_username,
reg.season.league.rating_type)
reg.has_played_20_games = not player.provisional_for(reg.season.league)
if player.account_status != 'normal':
fail_reason = 'The lichess user "%s" has the "%s" mark.' % (
reg.lichess_username, player.account_status)
if reg.already_in_slack_group and not player.slack_user_id:
reg.already_in_slack_group = False
except lichessapi.ApiWorkerError:
fail_reason = 'The lichess user "%s" could not be found.' % reg.lichess_username

Expand Down
8 changes: 4 additions & 4 deletions heltour/tournament/team_rating_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ def variance(mean, xs):


# -------------------------------------------------------------------------------
def team_rating_variance(teams, expected_rating=False):
means = [team.get_mean(expected_rating) for team in teams]
def team_rating_variance(teams):
means = [team.get_mean() for team in teams]
league_mean = sum(means) / len(teams)
return variance(league_mean, means)


# -------------------------------------------------------------------------------
def team_rating_range(teams, expected_rating=False):
means = [team.get_mean(expected_rating) for team in teams]
def team_rating_range(teams):
means = [team.get_mean() for team in teams]
return max(means) - min(means)
4 changes: 1 addition & 3 deletions heltour/tournament/teamgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def changeBoard(self, board, new_player):
new_player.team.boards[board] = None
new_player.team = self

def get_mean(self, expected_rating=False):
# expected_rating is an unused parameter in this version.
# it is used by the tournament.models.Team.get_mean method.
def get_mean(self):
ratings = [board.rating for board in self.boards]
mean = sum(ratings) / len(ratings)
return mean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@
{{ original.lichess_username }}
</div>

<div class="form-row">
<label>Slack username:</label>
{{ original.slack_username }}
</div>

{% if perms.tournament.dox %}
<div class="form-row">
<label>Email:</label>
Expand Down
13 changes: 1 addition & 12 deletions heltour/tournament/templates/tournament/admin/edit_rosters.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,24 @@
</p>
<h2>Actions</h2>
<p>
Show: {{ form.rating_type }}
{% if not season_started %}
<a class="button" href="{% url 'admin:create_teams' original.pk %}">(re)Build teams</a>
{% endif %}
<a class="button" href="{% url 'admin:export_players' original.pk %}">Export Players</a>
</p>
{% if team_rating_variance and team_rating_range and team_expected_rating_variance and team_expected_rating_range %}
{% if team_rating_variance and team_rating_range %}
<h2>Stats</h2>
<table>
<thead>
<tr>
<th>Team Rating Variance</th>
<th>Team Rating Range</th>
<th>Team Expected Rating Variance</th>
<th>Team Expected Rating Range</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ team_rating_variance|floatformat:2 }}</td>
<td>{{ team_rating_range|floatformat:2 }}</td>
<td>{{ team_expected_rating_variance|floatformat:2 }}</td>
<td>{{ team_expected_rating_range|floatformat:2 }}</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -75,7 +70,6 @@ <h2>Teams</h2>
data-url="{% leagueurl 'player_profile' original.league.tag original.tag board.player.lichess_username %}"
data-info-url="{% url 'admin:edit_rosters_player_info' original.pk board.player.lichess_username %}"
data-rating="{% player_rating board.player %}"
data-exp-rating="{{ expected_ratings|get_item:board.player }}"
data-toggle="popover">
<span class="name">{{ board.player.lichess_username }}</span>
<span class="rating-container">(<span class="rating"></span>)</span>
Expand Down Expand Up @@ -105,9 +99,6 @@ <h2>Teams</h2>
<td>
<span class="average-rating"></span>
</td>
<td>
<span class="average-exp-rating"></span>
</td>
</tr>
{% endif %}
</tbody>
Expand Down Expand Up @@ -138,7 +129,6 @@ <h2>Alternates</h2>
data-url="{% leagueurl 'player_profile' original.league.tag original.tag alt.season_player.player.lichess_username %}"
data-info-url="{% url 'admin:edit_rosters_player_info' original.pk alt.season_player.player.lichess_username %}"
data-rating="{% player_rating alt.season_player %}"
data-exp-rating="{{ expected_ratings|get_item:alt.season_player.player }}"
data-toggle="popover">
<span class="name">{{ alt.season_player.player.lichess_username }}</span>
<span class="rating-container">(<span class="rating"></span>)</span>
Expand Down Expand Up @@ -181,7 +171,6 @@ <h2>Unassigned</h2>
data-url="{% leagueurl 'player_profile' original.league.tag original.tag player.lichess_username %}"
data-rating="{% player_rating player %}"
data-info-url="{% url 'admin:edit_rosters_player_info' original.pk player.lichess_username %}"
data-exp-rating="{{ expected_ratings|get_item:player }}"
data-toggle="popover">
<span class="name">{{ player.lichess_username }}</span>
(<span class="rating"></span>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
<td>Rating:</td>
<td>{% player_rating player %}</td>
</tr>
<tr>
<td>Exp Rating:</td>
<td>{% expected_rating season_player %}</td>
</tr>
{% if reg %}
<tr>
<td>Peak Rating:</td>
<td>{{ reg.peak_classical_rating }}</td>
</tr>
<tr>
<td>Registration date:</td>
<td>{{ reg.date_created.date }}</td>
Expand Down
Loading