Skip to content

Commit

Permalink
Merge pull request #31 from ETCE-LAB/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
MattesKnigge authored Jul 12, 2024
2 parents 5cc6930 + 622e1f7 commit ffba24b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
25 changes: 24 additions & 1 deletion Controllers/GreenHouseController.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

greenhouse_ns = Namespace('greenhouse', description='Endpoints for Greenhouse management')


"""
@greenhouse_ns.route('/temperature')
class Temperature(Resource):
@greenhouse_ns.marshal_list_with(greenhouse_model)
Expand All @@ -31,6 +31,7 @@ def get(self):
return data, 200
except Exception as e:
greenhouse_ns.abort(500, f"Internal server error: {str(e)}")
"""


@greenhouse_ns.route('/temperature/<date>')
Expand All @@ -47,6 +48,17 @@ def get(self, date):
greenhouse_ns.abort(500, f"Internal server error: {str(e)}")


@greenhouse_ns.route('temperature/<start_date>/<end_date>')
class HumidityRange(Resource):
@greenhouse_ns.marshal_list_with(greenhouse_model)
def get(self, start_date, end_date):
try:
data = GreenHouseService.get_temperature_range(start_date, end_date)
return data, 200
except Exception as e:
greenhouse_ns.abort(500, f"Internal server error: {str(e)}")


@greenhouse_ns.route('/humidity/<date>')
class Humidity(Resource):
@greenhouse_ns.marshal_list_with(greenhouse_model)
Expand All @@ -61,6 +73,17 @@ def get(self, date):
greenhouse_ns.abort(500, f"Internal server error: {str(e)}")


@greenhouse_ns.route('humidity/<start_date>/<end_date>')
class HumidityRange(Resource):
@greenhouse_ns.marshal_list_with(greenhouse_model)
def get(self, start_date, end_date):
try:
data = GreenHouseService.get_humidity_range(start_date, end_date)
return data, 200
except Exception as e:
greenhouse_ns.abort(500, f"Internal server error: {str(e)}")


@greenhouse_ns.route('/measure')
class All(Resource):
def post(self):
Expand Down
8 changes: 8 additions & 0 deletions DataLayer/GreenHouseRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ def get_all_data():
def get_data_by_date(date):
data = GreenHouseData.query.with_entities(GreenHouseData.temperature, GreenHouseData.humidity).filter_by(date=date).all()
return data


def get_humidity_by_date_range(start_date, end_date):
return GreenHouseData.query.with_entities(GreenHouseData.humidity).filter(GreenHouseData.date.between(start_date, end_date)).all()


def get_temperature_by_date_range(start_date, end_date):
return GreenHouseData.query.with_entities(GreenHouseData.temperature).filter(GreenHouseData.date.between(start_date, end_date)).all()
8 changes: 8 additions & 0 deletions Services/GreenHouseService.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ def get_all_data():

def get_data_by_date(date):
return GreenHouseRepository.get_data_by_date(date)


def get_humidity_range(start_date, end_date):
return GreenHouseRepository.get_humidity_by_date_range(start_date, end_date)


def get_temperature_range(start_date, end_date):
return GreenHouseRepository.get_temperature_by_date_range(start_date, end_date)
2 changes: 1 addition & 1 deletion Services/Interfaces/IWeatherPredictionService.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ def get_weather_forecast_by_date(self, date):

@abstractmethod
def get_weather_forecast_by_date_range(self, start_date, end_date):
pass
pass

0 comments on commit ffba24b

Please sign in to comment.