Skip to content

Commit

Permalink
Merge pull request #108 from ADORSYS-GIS/31-setup-backend-to-serve-an…
Browse files Browse the repository at this point in the history
…alysis-results

Setting up API Endpoint for Analysis Results From Database
  • Loading branch information
forkimenjeckayang committed Dec 2, 2023
2 parents 74676b0 + b5f1fef commit 7108327
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import csv
import json
import os
from apiendpoint import fetch_data_from_database

app = Flask(__name__)

Expand Down Expand Up @@ -96,5 +97,20 @@ def save_to_json(data):
def analysis():
return render_template('test.html')

#API endpoint to fetch analysis result from databse
@app.route('/api/fetch-data', methods=['GET'])
def get_data():
# Get specified columns from the query parameters
columns = request.args.getlist('columns')

# Fetch data based on criteria
df = fetch_data_from_database(columns=columns)

# Convert the DataFrame to an HTML table
html_table = df.to_html(index=False, classes='table-striped table-bordered')

# rendering the table
return render_template('table_template.html', table_content=html_table)

if __name__ == '__main__':
app.run(debug=True)
34 changes: 34 additions & 0 deletions templates/table_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fetched Analysis Results</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<style>
th {
text-align: center;
}

td {
text-align: center;
word-wrap: break-word;
}

th, td {
border: 1px solid black;
}

</style>
</head>
<body>
<div class="container mt-4">
<h1 class="mb-4"><b>Fetched Data</b></h1>
<div class="table-responsive">
<table class="table-striped table-bordered">
{{ table_content | safe }}
</table>
</div>
</div>
</body>
</html>

0 comments on commit 7108327

Please sign in to comment.