-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# api/rest_api.py | ||
|
||
from flask import Flask, jsonify, request | ||
from flask_cors import CORS | ||
from src.core.climate_models import ClimateModel | ||
from src.iot.sensor_integration import SensorData | ||
|
||
app = Flask(__name__) | ||
CORS(app) # Enable CORS for all routes | ||
|
||
# Initialize climate model and sensor data | ||
climate_model = ClimateModel() | ||
sensor_data = SensorData() | ||
|
||
@app.route('/api/v1/climate-data', methods=['GET']) | ||
def get_climate_data(): | ||
"""Retrieve the latest climate data from IoT sensors.""" | ||
data = sensor_data.get_latest_data() | ||
return jsonify(data), 200 | ||
|
||
@app.route('/api/v1/predict', methods=['POST']) | ||
def predict_climate_outcome(): | ||
"""Predict climate outcomes based on input parameters.""" | ||
input_data = request.json | ||
prediction = climate_model.predict(input_data) | ||
return jsonify(prediction), 200 | ||
|
||
@app.route('/api/v1/geoengineering', methods=['POST']) | ||
def initiate_geoengineering(): | ||
"""Initiate a geoengineering intervention.""" | ||
intervention_data = request.json | ||
result = climate_model.initiate_geoengineering(intervention_data) | ||
return jsonify(result), 200 | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, host='0.0.0.0', port=5000) |