Skip to content

Commit

Permalink
Merge pull request #3 from maximepiton/Alapadu/request_paraglidable
Browse files Browse the repository at this point in the history
Use paraglidable forecast
  • Loading branch information
maximepiton authored Mar 24, 2019
2 parents 9fea216 + b53223f commit 883718d
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
rangs.tgz
raspGM-bin.tgz
raspGM.tgz

paralert/__pycache__/
paralert/paraglidable_forecast/
51 changes: 51 additions & 0 deletions paralert/paraglidable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import json
import requests
import numpy

import paralert_tool

number_of_sites = 0

def get_paraglidable_json():

response = requests.get("https://api.paraglidable.com/?key=4933a9d306367800&format=JSON&version=1")
forecast_pgble = json.loads(response.text)

global number_of_sites
number_of_sites =len(forecast_pgble[paralert_tool.date_N_day_after(1)])

return forecast_pgble


def get_paraglidable_score(json, site):

""" get scores in json file """
tm_fly = json[paralert_tool.date_N_day_after(1)][site]['forecast']['fly']
tm_XC = json[paralert_tool.date_N_day_after(1)][site]['forecast']['XC']
atm_fly = json[paralert_tool.date_N_day_after(2)][site]['forecast']['fly']
atm_XC = json[paralert_tool.date_N_day_after(2)][site]['forecast']['XC']

""" Score : mean of the 'XC' and 'fly' score """
tomorrow_score = numpy.mean([tm_fly,tm_XC])
after_tomorrow_score = numpy.mean([atm_fly,atm_XC])

""" Manage score to print note xx/10 """
tm_score_10 = int(tomorrow_score * 10)
atm_score_10 = int(after_tomorrow_score * 10)

site_name = json[paralert_tool.date_N_day_after(1)][site]['name']

result_table = [site_name, tm_score_10, atm_score_10]
return result_table


def get_paraglidable_all_scores(pgble_json):

table = []

""" range depend of the number of sites in paraglidable json file """
for x in range(0, number_of_sites):
table.append(get_paraglidable_score(pgble_json, x))

return table

38 changes: 33 additions & 5 deletions paralert/paralert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import math
import yaml

import paraglidable


def add_windspeed_winddir_to_forecast(forecast_df):
"""
Expand Down Expand Up @@ -81,27 +83,53 @@ def get_flight_score(forecast_df):


if __name__ == "__main__":

"""
Get input forecast
"""
pgble_json = paraglidable.get_paraglidable_json()


"""
Get Paraglidable score
"""
pgble = paraglidable.get_paraglidable_all_scores(pgble_json)

print ( 'Paraglidable score : ' + '\n' )

for x in range (0, len(pgble)):
print(
"Site : " + pgble[x][0] + '\n' +
"demain : " + ' ' + str(pgble[x][1]) + '/10' + '\n' +
"apres demain : " + str(pgble[x][2]) + '/10' + '\n'
)


"""
Get Paralert score
"""

with open("forecast.json", "r") as f:
json_data = json.load(f)

with open("locations.yaml", "r") as f:
locations = yaml.load(f)

site_parameters = locations["gensac"]
print(site_parameters)
# print(site_parameters)

forecast_df = pd.DataFrame(json_data["data"]).transpose()
add_windspeed_winddir_to_forecast(forecast_df)
print(forecast_df)
# print(forecast_df)

forecast_df = filter_out_low_cloudbase(
forecast_df, site_parameters["min_bl_thickness"]
)
print(forecast_df)
# print(forecast_df)

forecast_df = filter_out_strong_wind(
forecast_df, site_parameters["max_windspeed"]
)
print(forecast_df)
# print(forecast_df)

print(get_flight_score(forecast_df))
print('Paralert : ' + str(get_flight_score(forecast_df)))
16 changes: 16 additions & 0 deletions paralert/paralert_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
from datetime import datetime, timedelta


def date_N_day_after(N):

tomorrow = datetime.now() + timedelta(days=N)

return tomorrow.strftime("%Y-%m-%d")


def write_to_JSON_file(path, fileName, data):

filePathNameWExt = './' + path + '/' + fileName + '.json'
with open(filePathNameWExt, 'w') as fp:
json.dump(data, fp)

0 comments on commit 883718d

Please sign in to comment.