-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
39 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,39 @@ | ||
import pandas as pd | ||
import numpy as np | ||
from flask import Flask, jsonify, request | ||
from flask_cors import CORS | ||
from sqlalchemy import create_engine | ||
|
||
app = Flask(__name__) | ||
CORS(app) | ||
|
||
# Database connection | ||
engine = create_engine('postgresql://user:password@host:port/dbname') | ||
|
||
# Load data from database | ||
def load_data(): | ||
data = pd.read_sql_table('pi_coin_data', engine) | ||
return data | ||
|
||
# API endpoint to retrieve real-time data | ||
@app.route('/api/data', methods=['GET']) | ||
def get_data(): | ||
data = load_data() | ||
return jsonify(data.to_dict(orient='records')) | ||
|
||
# API endpoint to retrieve aggregated data | ||
@app.route('/api/aggregated_data', methods=['GET']) | ||
def get_aggregated_data(): | ||
data = load_data() | ||
aggregated_data = data.groupby('date').agg({'price': 'mean', 'volume': 'sum'}) | ||
return jsonify(aggregated_data.to_dict(orient='records')) | ||
|
||
# API endpoint to retrieve listing progress data | ||
@app.route('/api/listing_progress', methods=['GET']) | ||
def get_listing_progress(): | ||
data = load_data() | ||
listing_progress = data.groupby('listing_status').size().reset_index(name='count') | ||
return jsonify(listing_progress.to_dict(orient='records')) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |