Skip to content

Commit

Permalink
Deleted parameters.py to remove complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-florentin-charles committed Nov 8, 2023
1 parent 2c04127 commit 043bf99
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
16 changes: 0 additions & 16 deletions src/api/parameters.py

This file was deleted.

58 changes: 43 additions & 15 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from flasgger import Swagger, swag_from
from flask import Flask, jsonify, request, Response

from api.parameters import Parameter
import src.api.schemas as model
from src.api.swagger.rainfall import (average_specs, normal_specs,
relative_distance_to_normal_specs,
standard_deviation_specs)
from src.api.swagger.year import below_normal_specs, above_normal_specs
import src.api.swagger.parameters_specs as param
from src.core.models.all_rainfall import AllRainfall
from config import Config

Expand All @@ -31,8 +31,12 @@
@app.route(f"{swagger.template['basePath']}/rainfall/average")
@swag_from(average_specs.route_specs)
def average_rainfall() -> Response:
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
end_year: int = request.args.get(*Parameter.END_YEAR.value)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
end_year: int = request.args.get(param.end_year['name'],
default=param.end_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_average_yearly_rainfall(begin_year, end_year)

return jsonify(model.AverageYearlyRainfall().load({
Expand All @@ -45,7 +49,9 @@ def average_rainfall() -> Response:
@app.route(f"{swagger.template['basePath']}/rainfall/normal")
@swag_from(normal_specs.route_specs)
def normal_rainfall() -> Response:
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_normal(begin_year)

return jsonify(model.NormalYearlyRainfall().load({
Expand All @@ -58,9 +64,15 @@ def normal_rainfall() -> Response:
@app.route(f"{swagger.template['basePath']}/rainfall/relative_distance_to_normal")
@swag_from(relative_distance_to_normal_specs.route_specs)
def rainfall_relative_distance_to_normal() -> Response:
normal_year: int = request.args.get(*Parameter.NORMAL_YEAR.value)
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
end_year: int = request.args.get(*Parameter.END_YEAR.value)
normal_year: int = request.args.get(param.normal_year['name'],
default=param.normal_year['default'],
type=int)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
end_year: int = request.args.get(param.end_year['name'],
default=param.end_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_relative_distance_from_normal(
normal_year,
begin_year,
Expand All @@ -77,8 +89,12 @@ def rainfall_relative_distance_to_normal() -> Response:
@app.route(f"{swagger.template['basePath']}/rainfall/standard_deviation")
@swag_from(standard_deviation_specs.route_specs)
def standard_deviation() -> Response:
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
end_year: int = request.args.get(*Parameter.END_YEAR.value)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
end_year: int = request.args.get(param.end_year['name'],
default=param.end_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_standard_deviation(begin_year, end_year)

return jsonify(model.StandardDeviationYearlyRainfall().load({
Expand All @@ -91,9 +107,15 @@ def standard_deviation() -> Response:
@app.route(f"{swagger.template['basePath']}/year/below_normal")
@swag_from(below_normal_specs.route_specs)
def years_below_normal() -> Response:
normal_year: int = request.args.get(*Parameter.NORMAL_YEAR.value)
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
end_year: int = request.args.get(*Parameter.END_YEAR.value)
normal_year: int = request.args.get(param.normal_year['name'],
default=param.normal_year['default'],
type=int)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
end_year: int = request.args.get(param.end_year['name'],
default=param.end_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_years_below_normal(
normal_year,
begin_year,
Expand All @@ -110,9 +132,15 @@ def years_below_normal() -> Response:
@app.route(f"{swagger.template['basePath']}/year/above_normal")
@swag_from(above_normal_specs.route_specs)
def years_above_normal() -> Response:
normal_year: int = request.args.get(*Parameter.NORMAL_YEAR.value)
begin_year: int = request.args.get(*Parameter.BEGIN_YEAR.value)
end_year: int = request.args.get(*Parameter.END_YEAR.value)
normal_year: int = request.args.get(param.normal_year['name'],
default=param.normal_year['default'],
type=int)
begin_year: int = request.args.get(param.begin_year['name'],
default=param.begin_year['default'],
type=int)
end_year: int = request.args.get(param.end_year['name'],
default=param.end_year['default'],
type=int)
value: float = all_rainfall.yearly_rainfall.get_years_above_normal(
normal_year,
begin_year,
Expand Down

0 comments on commit 043bf99

Please sign in to comment.