time zone magic around virtualevent
This commit is contained in:
@@ -16,6 +16,7 @@ import xml.etree.ElementTree as et
|
|||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from timezonefinder import TimezoneFinder
|
||||||
|
|
||||||
import dataprep
|
import dataprep
|
||||||
from rowers.utils import geo_distance
|
from rowers.utils import geo_distance
|
||||||
@@ -38,6 +39,24 @@ class InvalidTrajectoryError(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
|
def get_course_timezone(course):
|
||||||
|
polygons = GeoPolygon.objects.filter(course = course)
|
||||||
|
points = GeoPoint.objects.filter(polygon = polygons[0])
|
||||||
|
lat = points[0].latitude
|
||||||
|
lon = points[0].longitude
|
||||||
|
|
||||||
|
tf = TimezoneFinder()
|
||||||
|
try:
|
||||||
|
timezone_str = tf.timezone_at(lng=lon,lat=lat)
|
||||||
|
except ValueError:
|
||||||
|
timezone_str = 'UTC'
|
||||||
|
|
||||||
|
if timezone_str is None:
|
||||||
|
timezone_str = tf.closest_timezone_at(lng=lon,lat=lat)
|
||||||
|
if timezone_str is None:
|
||||||
|
timezone_str = 'UTC'
|
||||||
|
|
||||||
|
return timezone_str
|
||||||
|
|
||||||
def polygon_to_path(polygon):
|
def polygon_to_path(polygon):
|
||||||
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
points = GeoPoint.objects.filter(polygon=polygon).order_by("order_in_poly")
|
||||||
|
|||||||
@@ -1074,7 +1074,7 @@ class VirtualRace(PlannedSession):
|
|||||||
contact_phone = models.CharField(validators=[phone_regex], max_length=17, blank=True)
|
contact_phone = models.CharField(validators=[phone_regex], max_length=17, blank=True)
|
||||||
|
|
||||||
contact_email = models.EmailField(max_length=254,
|
contact_email = models.EmailField(max_length=254,
|
||||||
validators=[validate_email])
|
validators=[validate_email],blank=True)
|
||||||
|
|
||||||
# Date input utility
|
# Date input utility
|
||||||
class DateInput(forms.DateInput):
|
class DateInput(forms.DateInput):
|
||||||
|
|||||||
@@ -86,6 +86,30 @@ def timefield_to_seconds_duration(t):
|
|||||||
|
|
||||||
return duration
|
return duration
|
||||||
|
|
||||||
|
|
||||||
|
def get_virtualrace_times(virtualrace):
|
||||||
|
geocourse = GeoCourse.objects.get(id = virtualrace.course.id)
|
||||||
|
timezone_str = courses.get_course_timezone(geocourse)
|
||||||
|
|
||||||
|
startdatetime = datetime.datetime.combine(
|
||||||
|
virtualrace.startdate,virtualrace.start_time)
|
||||||
|
enddatetime = datetime.datetime.combine(
|
||||||
|
virtualrace.enddate,virtualrace.end_time)
|
||||||
|
|
||||||
|
startdatetime = pytz.timezone(timezone_str).localize(
|
||||||
|
startdatetime
|
||||||
|
)
|
||||||
|
enddatetime = pytz.timezone(timezone_str).localize(
|
||||||
|
enddatetime
|
||||||
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
'startdatetime':startdatetime,
|
||||||
|
'enddatetime':enddatetime,
|
||||||
|
'evaluation_closure':virtualrace.evaluation_closure,
|
||||||
|
'registration_closure':virtualrace.registration_closure,
|
||||||
|
}
|
||||||
|
|
||||||
def get_session_metrics(ps):
|
def get_session_metrics(ps):
|
||||||
rowers = ps.rower.all()
|
rowers = ps.rower.all()
|
||||||
rscore = []
|
rscore = []
|
||||||
|
|||||||
@@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
<div class="grid_12 alpha">
|
<div class="grid_12 alpha">
|
||||||
|
|
||||||
|
<h1>New Virtual Race</h1>
|
||||||
|
|
||||||
|
|
||||||
<div class="grid_8 alpha">
|
<div class="grid_8 alpha">
|
||||||
<h1>New Virtual Race</h1>
|
|
||||||
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
|
||||||
{% if form.errors %}
|
{% if form.errors %}
|
||||||
<p style="color: red;">
|
<p style="color: red;">
|
||||||
@@ -28,10 +28,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="grid_4 omega">
|
||||||
<div class="grid_6 prefix_6" id="id_guidance">
|
<p>
|
||||||
|
<ul>
|
||||||
|
<li>All times are local times in the race course time zone</li>
|
||||||
|
<li>Adding a contact phone number and email is not mandatory, but we
|
||||||
|
strongly recommend it.</li>
|
||||||
|
<li>If your event has a registration closure deadline, participants
|
||||||
|
have to enter (and can withdraw) before the registration closure time.</li>
|
||||||
|
<li>Participants can submit results until the evaluation closure time.</li>
|
||||||
|
</ul>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block scripts %}
|
{% block scripts %}
|
||||||
|
|||||||
@@ -148,6 +148,7 @@ import matplotlib.pyplot as plt
|
|||||||
from rowers.emails import send_template_email
|
from rowers.emails import send_template_email
|
||||||
|
|
||||||
from pytz import timezone as tz,utc
|
from pytz import timezone as tz,utc
|
||||||
|
from timezonefinder import TimezoneFinder
|
||||||
import dateutil
|
import dateutil
|
||||||
import mpld3
|
import mpld3
|
||||||
from mpld3 import plugins
|
from mpld3 import plugins
|
||||||
@@ -13324,7 +13325,28 @@ def virtualevent_create_view(request):
|
|||||||
contact_phone = cd['contact_phone']
|
contact_phone = cd['contact_phone']
|
||||||
contact_email = cd['contact_email']
|
contact_email = cd['contact_email']
|
||||||
|
|
||||||
|
# correct times
|
||||||
|
|
||||||
geocourse = GeoCourse.objects.get(id= course.id)
|
geocourse = GeoCourse.objects.get(id= course.id)
|
||||||
|
timezone_str = courses.get_course_timezone(geocourse)
|
||||||
|
|
||||||
|
startdatetime = datetime.datetime.combine(startdate,start_time)
|
||||||
|
enddatetime = datetime.datetime.combine(enddate,end_time)
|
||||||
|
|
||||||
|
startdatetime = pytz.timezone(timezone_str).localize(
|
||||||
|
startdatetime
|
||||||
|
)
|
||||||
|
enddatetime = pytz.timezone(timezone_str).localize(
|
||||||
|
enddatetime
|
||||||
|
)
|
||||||
|
evaluation_closure = pytz.timezone(timezone_str).localize(
|
||||||
|
evaluation_closure.replace(tzinfo=None)
|
||||||
|
)
|
||||||
|
registration_closure = pytz.timezone(timezone_str).localize(
|
||||||
|
registration_closure.replace(tzinfo=None)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vs = VirtualRace(
|
vs = VirtualRace(
|
||||||
name=name,
|
name=name,
|
||||||
|
|||||||
Reference in New Issue
Block a user