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 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>
|
||||
<p>
|
||||
Download wind speed and bearing from <a href="http://forecast.io/">The Dark Sky</a>
|
||||
@@ -111,4 +113,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -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/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/airport/(?P<airportcode>\w+)$',views.workout_downloadwind_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/(\d+)/crewnerdsummary$',views.workout_crewnerd_summary_view),
|
||||
|
||||
@@ -82,7 +82,7 @@ import mpld3
|
||||
from mpld3 import plugins
|
||||
import stravalib
|
||||
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
|
||||
|
||||
@@ -2435,7 +2435,9 @@ def workout_crewnerd_summary_view(request,id=0,message="",successmessage=""):
|
||||
'id':row.id})
|
||||
|
||||
# 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=""):
|
||||
try:
|
||||
row = Workout.objects.get(id=id)
|
||||
@@ -2536,7 +2538,16 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
|
||||
rowdata.add_bearing()
|
||||
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
|
||||
|
||||
|
||||
if request.method == 'POST':
|
||||
@@ -2593,6 +2604,8 @@ def workout_wind_view(request,id=0,message="",successmessage=""):
|
||||
'message': message,
|
||||
'successmessage': successmessage,
|
||||
'interactiveplot':script,
|
||||
'form':form,
|
||||
'airport':airportcode,
|
||||
'airportdistance':airportdistance,
|
||||
'the_div':div,
|
||||
'gmap':gmscript,
|
||||
|
||||
@@ -2,12 +2,23 @@ import requests
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
from rowingdata import rowingdata
|
||||
from rowingdata import rowingdata,geo_distance
|
||||
import pandas as pd
|
||||
from rowers.models import Rower, Workout
|
||||
|
||||
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
|
||||
def get_weather_data(long,lat,unixtime):
|
||||
url = "https://api.darksky.net/forecast/"+FORECAST_IO_KEY+"/"
|
||||
|
||||
Reference in New Issue
Block a user