Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use paraglidable forecast #3

Merged
merged 11 commits into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 """
maximepiton marked this conversation as resolved.
Show resolved Hide resolved
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' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, nous fait pas une clément à aligner les symboles. @maximepiton va te faire passer son linter sur tout ça !

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vas'y max, je t'en pris :)

"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)