Private
Public Access
1
0
This commit is contained in:
Sander Roosendaal
2020-06-02 20:13:46 +02:00
parent b6c0b03c39
commit 76769266f3
6 changed files with 247 additions and 7 deletions

View File

@@ -2047,6 +2047,147 @@ def leaflet_chart(lat,lon,name=""):
return script,div
def leaflet_chart_compare(workoutids,labeldict={},startenddict={}):
data = []
for id in workoutids:
w = Workout.objects.get(id=id)
rowdata = rdata(w.csvfilename)
df = pd.DataFrame({
'id':id,
'lat':rowdata.df[' latitude'],
'lon':rowdata.df[' longitude']
})
data.append(f)
df = pd.concat(data,axis=0)
# Throw out 0,0
df = df.replace(0,np.nan)
df = df.loc[(df!=0).any(axis=1)]
df.fillna(method='bfill',axis=0,inplace=True)
df.fillna(method='ffill',axis=0,inplace=True)
lat = df['lat']
lon = df['lon']
if lat.empty or lon.empty:
return [0,"invalid coordinate data"]
coordinates = zip(lat,lon)
scoordinates = "["
for x,y in coordinates:
scoordinates += """[{x},{y}],
""".format(
x=x,
y=y
)
scoordinates += "]"
script = """
<script>
var streets = L.tileLayer(
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
tileSize: 512,
maxZoom: 18,
zoomOffset: -1,
id: 'mapbox/streets-v11',
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
}}
),
satellite = L.tileLayer(
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
tileSize: 512,
maxZoom: 18,
zoomOffset: -1,
id: 'mapbox/satellite-v9',
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
}}
),
outdoors = L.tileLayer(
'https://api.mapbox.com/styles/v1/{{id}}/tiles/{{z}}/{{x}}/{{y}}?access_token={{accessToken}}', {{
attribution: '© <a href="https://www.mapbox.com/about/maps/">Mapbox</a> © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> <strong><a href="https://www.mapbox.com/map-feedback/" target="_blank">Improve this map</a></strong>',
tileSize: 512,
maxZoom: 18,
zoomOffset: -1,
id: 'mapbox/outdoors-v11',
accessToken: 'pk.eyJ1Ijoic2FuZGVycm9vc2VuZGFhbCIsImEiOiJjajY3aTRkeWQwNmx6MzJvMTN3andlcnBlIn0.MFG8Xt0kDeSA9j7puZQ9hA'
}}
);
var mymap = L.map('map_canvas', {{
center: [{latmean}, {lonmean}],
zoom: 13,
layers: [streets, satellite]
}}).setView([{latmean},{lonmean}], 13);
var navionics = new JNC.Leaflet.NavionicsOverlay({{
navKey: 'Navionics_webapi_03205',
chartType: JNC.NAVIONICS_CHARTS.NAUTICAL,
isTransparent: true,
zIndex: 1
}});
var osmUrl2='http://tiles.openseamap.org/seamark/{{z}}/{{x}}/{{y}}.png';
var osmUrl='http://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png';
//create two TileLayer
var nautical=new L.TileLayer(osmUrl,{{
maxZoom:18}});
L.control.layers({{
"Streets": streets,
"Satellite": satellite,
"Outdoors": outdoors,
"Nautical": nautical,
}},{{
"Navionics":navionics,
}}).addTo(mymap);
var marker = L.marker([{latbegin}, {longbegin}]).addTo(mymap);
marker.bindPopup("<b>Start</b>");
var emarker = new L.marker([{latend}, {longend}]).addTo(mymap);
emarker.bindPopup("<b>End</b>");
var latlongs = {scoordinates}
var polyline = L.polyline(latlongs, {{color:'red'}}).addTo(mymap)
mymap.fitBounds(polyline.getBounds())
</script>
""".format(
latmean=latmean,
lonmean=lonmean,
latbegin = latbegin,
latend=latend,
longbegin=longbegin,
longend=longend,
scoordinates=scoordinates,
)
div = """
<div id="map_canvas" style="width: 100%; height: 100%; min-height: 100vh"><p>&nbsp;</p></div>
"""
return script,div
def leaflet_chart2(lat,lon,name=""):
@@ -5057,13 +5198,11 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line',
'time','pace','workoutstate',
'workoutid']
datadf = dataprep.getsmallrowdata_db(columns,ids=ids,doclean=False,compute=False)
datadf = dataprep.getsmallrowdata_db(columns,ids=ids)
datadf.dropna(axis=1,how='all',inplace=True)
datadf.dropna(axis=0,how='any',inplace=True)
nrworkouts = len(ids)
try:

View File

@@ -2920,7 +2920,8 @@ def update_duplicates_on_delete(sender, instance, **kwargs):
class VirtualRaceFollower(models.Model):
user = models.ForeignKey(User,on_delete=models.CASCADE,null=True)
race = models.ForeignKey(VirtualRace,on_delete=models.CASCADE)
emailaddress = models.EmailField(max_length=254,blank=True,null=True)
emailaddress = models.EmailField(max_length=254,blank=True,null=True,
verbose_name="Email Address")
class FollowerForm(ModelForm):
class Meta:

View File

@@ -9,9 +9,14 @@
{% block main %}
<h1>Comments {{ plannedession.name }}</h1>
<h1>Follow {{ plannedession.name }}</h1>
<ul class="main-content">
<li class="grid_2">
<p>To follow this challenge and receive all news per email, fill out your
email address and submit the form.
</li>
<li class="grid_2">
<form enctype="multipart/form-data" method="post">
<table width=100%>

View File

@@ -167,7 +167,9 @@
{% else %}
<a href="/rowers/virtualevent/{{ race.id }}/registerindoor"><h3>Register</h3></a>
{% endif %}
{% if request.user|isfollower:race.id %}
<a href="/rowers/virtualevent/{{ race.id }}/follow/"><h3>Follow this challenge</h3></a>
{% endif %}
</p>
{% else %}
<p>
@@ -186,7 +188,9 @@
{% else %}
<a href="/rowers/virtualevent/{{ race.id }}/registerindoor"><h3>Register</h3></a>
{% endif %}
{% if request.user|isfollower:race.id %}
<a href="/rowers/virtualevent/{{ race.id }}/follow/"><h3>Follow this challenge</h3></a>
{% endif %}
</p>
{% endif %}
{% if button == 'submitbutton' %}

View File

@@ -12,7 +12,8 @@ from rowers.utils import calculate_age
from rowers.models import (
course_length,WorkoutComment,
TrainingMacroCycle,TrainingMesoCycle, TrainingMicroCycle,
Rower,Workout,SiteAnnouncement, TeamInvite, TeamRequest, CoachOffer,CoachRequest
Rower,Workout,SiteAnnouncement, TeamInvite, TeamRequest, CoachOffer,CoachRequest,
VirtualRaceFollower,VirtualRace,
)
from rowers.plannedsessions import (
race_can_register, race_can_submit,race_rower_status
@@ -40,6 +41,21 @@ from django.template.defaultfilters import stringfilter
from six import string_types
@register.filter
def isfollower(user,id):
if user.is_anonymous:
return True
try:
race = VirtualRace.objects.get(id=id)
except VirtualRace.DoesNotExist:
return False
followers = VirtualRaceFollower.objects.filter(race=race,user=user)
return followers.count()==0
@register.filter
def adaptive(s):
u = s

View File

@@ -1625,6 +1625,39 @@ def virtualevent_addboat_view(request,id=0):
"You have successfully registered for this race. Good luck!"
)
otherrecords = VirtualRaceResult.objects.filter(
race = race).exclude(userid = r.id)
for otherrecord in otherrecords:
otheruser = Rower.objects.get(id=otherrecord.userid)
othername = otheruser.user.first_name+' '+otheruser.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
if otherrecord.emailnotifications:
job = myqueue(
queue,
handle_sendemail_raceregistration,
otheruser.user.email, othername,
registeredname,
race.name,
race.id
)
followers = VirtualRaceFollower.objects.filter(race = race)
for follower in followers:
othername = ''
if follower.user:
othername = follower.user.first_name+' '+follower.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
email = follower.emailaddress
job = myqueue(
queue,
handle_sendemail_raceregistration,
email, othername,
registeredname,race.name,race.id,
)
url = reverse('virtualevent_view',
kwargs = {
'id':race.id
@@ -1804,7 +1837,12 @@ def virtualevent_register_view(request,id=0):
add_rower_race(r,race)
otherrecords = IndoorVirtualRaceResult.objects.filter(
# remove followers
myfollows = VirtualRaceFollower.objects.filter(user=r.user,race=race)
for f in myfollows:
f.delete()
otherrecords = VirtualRaceResult.objects.filter(
race = race).exclude(userid = r.id)
for otherrecord in otherrecords:
@@ -1821,6 +1859,22 @@ def virtualevent_register_view(request,id=0):
race.id
)
followers = VirtualRaceFollower.objects.filter(race = race)
for follower in followers:
othername = ''
if follower.user:
othername = follower.user.first_name+' '+follower.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
email = follower.emailaddress
job = myqueue(
queue,
handle_sendemail_raceregistration,
email, othername,
registeredname,race.name,race.id,
)
messages.info(
request,
@@ -2039,6 +2093,11 @@ def indoorvirtualevent_register_view(request,id=0):
add_rower_race(r,race)
# remove followers
myfollows = VirtualRaceFollower.objects.filter(user=r.user,race=race)
for f in myfollows:
f.delete()
otherrecords = IndoorVirtualRaceResult.objects.filter(
race = race).exclude(userid = r.id)
@@ -2056,6 +2115,22 @@ def indoorvirtualevent_register_view(request,id=0):
race.id
)
followers = VirtualRaceFollower.objects.filter(race = race)
for follower in followers:
othername = ''
if follower.user:
othername = follower.user.first_name+' '+follower.user.last_name
registeredname = r.user.first_name+' '+r.user.last_name
email = follower.emailaddress
job = myqueue(
queue,
handle_sendemail_raceregistration,
email, othername,
registeredname,race.name,race.id,
)
messages.info(
request,