Affichage graph des données

This commit is contained in:
Jérôme Delacotte
2025-05-07 16:45:28 +02:00
parent 7f778867c4
commit 5861697489
5 changed files with 221 additions and 109 deletions

View File

@@ -9,19 +9,22 @@ from io import TextIOWrapper
app = Flask(__name__)
FILES_DIR = '/mnt/external'
FREQTRADE_USERDATA_DIR = '/mnt/external'
@app.route('/')
def home():
# Liste les fichiers dans le répertoire monté
files = os.listdir('/mnt/external')
files = os.listdir(FREQTRADE_USERDATA_DIR + "/backtest_results")
# Filtre pour obtenir uniquement les fichiers (pas les dossiers)
files = [f for f in files if os.path.isfile(os.path.join('/mnt/external', f))]
files = [f for f in files if os.path.isfile(os.path.join(FREQTRADE_USERDATA_DIR + "/backtest_results", f))]
files2 = os.listdir(FREQTRADE_USERDATA_DIR + "/data/binance")
files2 = [f for f in files2 if os.path.isfile(os.path.join(FREQTRADE_USERDATA_DIR + "/data/binance", f))]
# Retourne le template avec la liste des fichiers
return render_template('index.html', files=files)
return render_template('index.html', files=files, files2=files2)
@app.route('/process', methods=['POST'])
@@ -32,7 +35,7 @@ def process():
@app.route('/read_json/<path:filename>')
def read_json(filename):
full_path = os.path.join(FILES_DIR, filename)
full_path = os.path.join(FREQTRADE_USERDATA_DIR + "/backtest_results", filename)
if filename.endswith('.json'):
with open(full_path) as f:
@@ -66,16 +69,28 @@ def read_json(filename):
try:
data = joblib.load(f)
if isinstance(data, pd.DataFrame):
return data.to_json(orient='split'), 200, {'Content-Type': 'application/json'}
if isinstance(data, dict):
df = pd.DataFrame.from_dict(data)
return df.to_json(orient='split'), 200, {'Content-Type': 'application/json'}
if isinstance(data, list):
print("dataframe")
zip_contents[name] = data.to_csv() #orient='split'), 200, {'Content-Type': 'application/json'}
elif isinstance(data, dict):
# On suppose quil y a un seul modèle/clé au premier niveau
outer_key = list(data.keys())[0]
inner_dict = data[outer_key]
if isinstance(inner_dict, dict):
# On suppose quil y a une seule paire (ex: 'BTC/USDT')
inner_key = list(inner_dict.keys())[0]
df = inner_dict[inner_key]
print(df)
if isinstance(df, pd.DataFrame):
zip_contents[name] = df.to_html() #json(orient='split'), 200, {'Content-Type': 'application/json'}
elif isinstance(data, list):
print('list')
df = pd.DataFrame(data)
return df.to_json(orient='split'), 200, {'Content-Type': 'application/json'}
return json.dumps({"error": f"Type {type(data)} non géré."}), 200
zip_contents[name] = df.to_html() #orient='split'), 200, {'Content-Type': 'application/json'}
else:
zip_contents[name] = json.dumps({"error": f"Type {type(data)} non géré."}), 200
except Exception as e:
return json.dumps({"error": str(e)}), 500
zip_contents[name] = json.dumps({"error": str(e)}), 500
return json.dumps(zip_contents)
except Exception as e:
return json.dumps({"error": str(e)}), 500
@@ -83,5 +98,18 @@ def read_json(filename):
return json.dumps({"error": "Fichier non pris en charge"}), 400
@app.route('/read_feather/<path:filename>')
def read_feather(filename):
path = os.path.join(FREQTRADE_USERDATA_DIR + "/data/binance/", filename)
try:
print(path)
df = pd.read_feather(path)
print(df)
return df.to_json(orient="records")
except Exception as e:
print(e)
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)