diff --git a/.gitignore b/.gitignore index f1111ba..fd4fe2e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ rangs.tgz raspGM-bin.tgz raspGM.tgz + +paralert/__pycache__/ +paralert/paraglidable_forecast/ diff --git a/paralert/paraglidable.py b/paralert/paraglidable.py new file mode 100644 index 0000000..2a48f48 --- /dev/null +++ b/paralert/paraglidable.py @@ -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 + diff --git a/paralert/paralert.py b/paralert/paralert.py index e66ab21..12df2c4 100644 --- a/paralert/paralert.py +++ b/paralert/paralert.py @@ -3,6 +3,8 @@ import math import yaml +import paraglidable + def add_windspeed_winddir_to_forecast(forecast_df): """ @@ -81,6 +83,32 @@ 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) @@ -88,20 +116,20 @@ def get_flight_score(forecast_df): 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))) diff --git a/paralert/paralert_tool.py b/paralert/paralert_tool.py new file mode 100644 index 0000000..0a01b4e --- /dev/null +++ b/paralert/paralert_tool.py @@ -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) \ No newline at end of file