detection of nearest METAR
This commit is contained in:
6693
rowers/data/metarlatlon.csv
Normal file
6693
rowers/data/metarlatlon.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -52,6 +52,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_2 omega">
|
<div class="grid_2 omega">
|
||||||
|
<p>Closest Airport Weather: {{ airport }}
|
||||||
|
({{ airportdistance | floatformat:-1 }} km)</p>
|
||||||
<a class="button green small" href="/rowers/workout/{{ workout.id }}/darkskywind">Dark Sky Data</a>
|
<a class="button green small" href="/rowers/workout/{{ workout.id }}/darkskywind">Dark Sky Data</a>
|
||||||
<p>
|
<p>
|
||||||
Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a>
|
Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a>
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ urlpatterns = [
|
|||||||
url(r'^workout/(?P<id>\d+)/wind/c/(?P<message>\w+.*)$',views.workout_wind_view),
|
url(r'^workout/(?P<id>\d+)/wind/c/(?P<message>\w+.*)$',views.workout_wind_view),
|
||||||
url(r'^workout/(?P<id>\d+)/wind/s/(?P<successmessage>\w+.*)$',views.workout_wind_view),
|
url(r'^workout/(?P<id>\d+)/wind/s/(?P<successmessage>\w+.*)$',views.workout_wind_view),
|
||||||
url(r'^workout/(?P<id>\d+)/darkskywind$',views.workout_downloadwind_view),
|
url(r'^workout/(?P<id>\d+)/darkskywind$',views.workout_downloadwind_view),
|
||||||
|
url(r'^workout/(?P<id>\d+)/darkskywind/airport/(?P<airportcode>\w+)$',views.workout_downloadwind_view),
|
||||||
url(r'^workout/(\d+)/stream$',views.workout_stream_view),
|
url(r'^workout/(\d+)/stream$',views.workout_stream_view),
|
||||||
url(r'^workout/(?P<id>\d+)/stream/c/(?P<message>\w+.*)$',views.workout_stream_view),
|
url(r'^workout/(?P<id>\d+)/stream/c/(?P<message>\w+.*)$',views.workout_stream_view),
|
||||||
url(r'^workout/(\d+)/crewnerdsummary$',views.workout_crewnerd_summary_view),
|
url(r'^workout/(\d+)/crewnerdsummary$',views.workout_crewnerd_summary_view),
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ import mpld3
|
|||||||
from mpld3 import plugins
|
from mpld3 import plugins
|
||||||
import stravalib
|
import stravalib
|
||||||
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||||
from weather import get_wind_data
|
from weather import get_wind_data,get_airport_code
|
||||||
|
|
||||||
from oauth2_provider.models import Application,Grant,AccessToken
|
from oauth2_provider.models import Application,Grant,AccessToken
|
||||||
|
|
||||||
@@ -2435,7 +2435,9 @@ def workout_crewnerd_summary_view(request,id=0,message="",successmessage=""):
|
|||||||
'id':row.id})
|
'id':row.id})
|
||||||
|
|
||||||
# Get weather for given location and date/time
|
# Get weather for given location and date/time
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||||
|
def workout_downloadwind_view(request,id=0,
|
||||||
|
airportcode=None,
|
||||||
message="",successmessage=""):
|
message="",successmessage=""):
|
||||||
try:
|
try:
|
||||||
row = Workout.objects.get(id=id)
|
row = Workout.objects.get(id=id)
|
||||||
@@ -2536,6 +2538,15 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
|
|||||||
rowdata.add_bearing()
|
rowdata.add_bearing()
|
||||||
rowdata.write_csv(f1,gzip=True)
|
rowdata.write_csv(f1,gzip=True)
|
||||||
|
|
||||||
|
|
||||||
|
if hascoordinates:
|
||||||
|
avglat = rowdata.df[' latitude'].mean()
|
||||||
|
avglon = rowdata.df[' longitude'].mean()
|
||||||
|
airportcode,newlat,newlon,airportdistance = get_airport_code(avglat,avglon)
|
||||||
|
airportcode = airportcode.upper()
|
||||||
|
airportdistance = airportdistance[0]
|
||||||
|
else:
|
||||||
|
airportcode = 'UNKNOWN'
|
||||||
airportdistance = 0
|
airportdistance = 0
|
||||||
|
|
||||||
|
|
||||||
@@ -2593,6 +2604,8 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
|
|||||||
'message': message,
|
'message': message,
|
||||||
'successmessage': successmessage,
|
'successmessage': successmessage,
|
||||||
'interactiveplot':script,
|
'interactiveplot':script,
|
||||||
|
'form':form,
|
||||||
|
'airport':airportcode,
|
||||||
'airportdistance':airportdistance,
|
'airportdistance':airportdistance,
|
||||||
'the_div':div,
|
'the_div':div,
|
||||||
'gmap':gmscript,
|
'gmap':gmscript,
|
||||||
|
|||||||
@@ -2,12 +2,23 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from rowingdata import rowingdata
|
from rowingdata import rowingdata,geo_distance
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from rowers.models import Rower, Workout
|
from rowers.models import Rower, Workout
|
||||||
|
|
||||||
from rowsandall_app.settings import FORECAST_IO_KEY
|
from rowsandall_app.settings import FORECAST_IO_KEY
|
||||||
|
|
||||||
|
# Find closest airport
|
||||||
|
def get_airport_code(lat,lon):
|
||||||
|
metardata = pd.read_csv('rowers/data/metarlatlon.csv')
|
||||||
|
deltasq = (lat-metardata.lat)**2+(lon-metardata.lon)**2
|
||||||
|
a = metardata[deltasq == deltasq.min()]
|
||||||
|
airport_code = a.iloc[0]['icao']
|
||||||
|
newlat = a.iloc[0]['lat']
|
||||||
|
newlon = a.iloc[0]['lon']
|
||||||
|
distance = geo_distance(lat,lon,newlat,newlon)
|
||||||
|
return airport_code,newlat,newlon,distance
|
||||||
|
|
||||||
# Get weather data from the DarkSky API
|
# Get weather data from the DarkSky API
|
||||||
def get_weather_data(long,lat,unixtime):
|
def get_weather_data(long,lat,unixtime):
|
||||||
url = "https://api.darksky.net/forecast/"+FORECAST_IO_KEY+"/"
|
url = "https://api.darksky.net/forecast/"+FORECAST_IO_KEY+"/"
|
||||||
|
|||||||
Reference in New Issue
Block a user