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

29 configure controller colors #17

Merged
merged 4 commits into from
Oct 19, 2021
Merged
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ You can check via `ioreg -c IOSerialBSDClient | grep usb` where the serial conne

## Changes

### 20210524
Small changes for season handling

### 20201111
Update to python 3.9, restructure the code handling track communication and race management.
Add result pages for race types.
Expand Down
5 changes: 5 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from wtforms import StringField, TextField, SubmitField, SelectField, FieldList, FormField, HiddenField
from wtforms.validators import ValidationError, DataRequired, Optional
from wtforms.fields.html5 import DateField
from wtforms_components import ColorField
from app.models import Racer, Car


Expand Down Expand Up @@ -63,4 +64,8 @@ class SeasonForm(FlaskForm):
description = TextField(_l('description'), validators=[DataRequired()])
started_at = DateField(_l('season_from'), format='%Y-%m-%d')
ended_at = DateField(_l('season_to'), format='%Y-%m-%d', validators=(Optional(),))
controller_0_color = TextField(_l('controller_0_color'), validators=[Optional()])
controller_1_color = TextField(_l('controller_1_color'), validators=[Optional()])
controller_2_color = TextField(_l('controller_2_color'), validators=[Optional()])
controller_3_color = TextField(_l('controller_3_color'), validators=[Optional()])
submit = SubmitField(_l('Save Season'))
32 changes: 32 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def denormalize_laps(self):
def statistics(self):
return Statistics(self)

def season(self):
season = None
if(self.created_at is not None):
season = Season.containing_date(self.created_at)
if(season is None):
return Season.current()

@staticmethod
def current():
current_race = next(iter(Race.query.filter(Race.status == 'started').all()), None)
Expand Down Expand Up @@ -230,10 +237,35 @@ class Season(db.Model):
started_at = db.Column(db.DateTime)
ended_at = db.Column(db.DateTime)
description = db.Column(db.String(64), index=False, unique=False)
controller_0_color = db.Column(db.String(6), index=False, unique=False)
controller_1_color = db.Column(db.String(6), index=False, unique=False)
controller_2_color = db.Column(db.String(6), index=False, unique=False)
controller_3_color = db.Column(db.String(6), index=False, unique=False)

def __repr__(self):
return '<Season {} - {}>'.format(self.started_at, self.ended_at)

def controller_color(self, id):
options = {
0: self.controller_0_color,
1: self.controller_1_color,
2: self.controller_2_color,
3: self.controller_3_color
}

if int(id) not in options:
return '000000'

return options[int(id)]

@staticmethod
def containing_date(date):
return Season.query.filter(Season.started_at > date).order_by(Season.started_at.asc()).first()

@staticmethod
def current():
return Season.query.filter(Season.ended_at.is_(None)).order_by(Season.started_at.desc()).first()


class Timing(object):
def __init__(self, num):
Expand Down
6 changes: 2 additions & 4 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ def cars():
def car(car_id):
car = Car.query.get(car_id)
last_season = Season.query.filter(Season.ended_at.isnot(None)).order_by(Season.ended_at.desc()).first()
current_season = Season.query.filter(Season.ended_at.is_(None)).order_by(Season.started_at.desc()).first()
return render_template('car.html', title='Auto', car=car, last_season=last_season, current_season=current_season)
return render_template('car.html', title='Auto', car=car, last_season=last_season, current_season=Season.current())


@app.route('/racers')
def racers():
racers = Racer.query.all()
last_season = Season.query.filter(Season.ended_at.isnot(None)).order_by(Season.ended_at.desc()).first()
current_season = Season.query.filter(Season.ended_at.is_(None)).order_by(Season.started_at.desc()).first()
app.logger.info('got racers:' + repr(racers))
return render_template('racers.html', title='Fahrer', racers=racers, last_season=last_season, current_season=current_season)
return render_template('racers.html', title='Fahrer', racers=racers, last_season=last_season, current_season=Season.current())


@app.route('/races')
Expand Down
16 changes: 16 additions & 0 deletions app/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ tr {
font-size: 0.5rem;
}

.controller_color_list {
width: 100%;
overflow: hidden;
padding: 0;
margin: 0;
}

.controller_color_number {
width: 20px;
vertical-align: middle;
}

.controller_color_field {
width: 100px;
vertical-align: middle;
}

@keyframes blinker {
50% { opacity: 0; }
Expand Down
6 changes: 3 additions & 3 deletions app/templates/current_race.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>{{ _('Current race') }}</h1>
<div class="d-flex flex-row justify-content-left mb-3 bd-highlight ">
{% for grid_entry in current_race.parsed_grid()%}
<div class= "p-2 flex-fill grid-entry">
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}">
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}" style="background-color: #{{current_race.season().controller_color(grid_entry['controller'])}};">
</div>
<div class= "racer-and-car">
<p class= "racer-name">{{ grid_entry['racer'].name }}</p>
Expand All @@ -51,7 +51,7 @@ <h1>{{ _('Current race') }}</h1>
<p class="lap-number" id = "lap-number-{{ grid_entry['controller'] }}">0</p>
</div>
</div>
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}">
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}" style="background-color: #{{current_race.season().controller_color(grid_entry['controller'])}};">
</div>
<div class = "d-flex flex-row lap-data">
<div id = "fuel-gauge-{{ grid_entry['controller'] }}" class = "d-flex flex-row">
Expand Down Expand Up @@ -101,7 +101,7 @@ <h1>{{ _('Current race') }}</h1>
<p class="lap-time" id = "best-time-{{ grid_entry['controller'] }}">0 s</p>
</div>
</div>
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}">
<div class="horizontal-line" id="grid-entry-{{grid_entry['controller']}}" style="background-color: #{{current_race.season().controller_color(grid_entry['controller'])}};">
</div>
</div>
{% endfor %}
Expand Down
22 changes: 22 additions & 0 deletions app/templates/season.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,27 @@
<h1>{{ _('Season') }} {{season.started_at.strftime('%d.%m.%Y')}} - {% if season.ended_at != None %}{{ season.ended_at.strftime('%d.%m.%Y') }}{% endif %}</h1>

<p>{{ season.description }}</p>
<p>
{{ _('Controller Colors')}}<br />
<div>
<div style= "display: flex;">
<div class= "controller_color_number"> 1: </div>
<div class="controller_color_field", style="background-color: #{{season.controller_0_color}};" />
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 2: </div>
<div class="controller_color_field", style="background-color: #{{season.controller_1_color}};" />
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 3: </div>
<div class="controller_color_field", style="background-color: #{{season.controller_2_color}};" />
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 4: </div>
<div class="controller_color_field", style="background-color: #{{season.controller_3_color}};" />
</div>
</div>
</p>


{% endblock %}
49 changes: 48 additions & 1 deletion app/templates/season_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,59 @@ <h1>{{ title }}</h1>
{% endfor %}
</p>
<p>
{{ form.description.label }}<br>
{{ form.description.label }}<br />
{{ form.description(size=64) }}
{% for error in form.description.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</p>
<p>
{{ _('Controller Colors') }}</br>
<div style= "display: flex;">
<div class= "controller_color_number"> 1: </div>
<div>
#{{ form.controller_0_color(size=6) }}
{% for error in form.controller_0_color.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</div>
<div id="color_0_color_field" class="controller_color_field", style="background-color: #{{form.controller_0_color.data}};" />
</div>
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 2: </div>
<div>
#{{ form.controller_1_color(size=6) }}
{% for error in form.controller_1_color.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</div>
<div id="color_1_color_field" class="controller_color_field", style="background-color: #{{form.controller_1_color.data}};" />
</div>
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 3: </div>
<div>
#{{ form.controller_2_color(size=6) }}
{% for error in form.controller_2_color.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</div>
<div id="color_2_color_field" class="controller_color_field", style="background-color: #{{form.controller_2_color.data}};" />
</div>
</div>
<div style= "display: flex;">
<div class= "controller_color_number"> 4: </div>
<div>
#{{ form.controller_3_color(size=6) }}
{% for error in form.controller_3_color.errors %}
<span style="color: red;">[{{ error }}]</span>
{% endfor %}
</div>
<div id="color_3_color_field" class="controller_color_field", style="background-color: #{{form.controller_3_color.data}};" />
</div>
</div>
</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}
4 changes: 3 additions & 1 deletion app/templates/seasons.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ <h1>{{ _('Seasons') }}</h1>
{% for season in seasons %}
<li>
<a href="{{ url_for('season', season_id=season.id) }}">
<p> {{ season.started_at.strftime('%d.%m.%Y') }} - {% if season.ended_at != None %}{{ season.ended_at.strftime('%d.%m.%Y') }}{% endif %}: {{ season.description }}</p>
{{ season.started_at.strftime('%d.%m.%Y') }} - {% if season.ended_at != None %}{{ season.ended_at.strftime('%d.%m.%Y') }}{% endif %}
</a>:
<p>{{ season.description }}</p>
</a>
</li>
{% endfor %}
Expand Down
Binary file modified app/translations/de/LC_MESSAGES/messages.mo
Binary file not shown.
Loading