Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -74,8 +74,9 @@ def find_similar_pattern(df, prediction, future_hours=24):
|
|
| 74 |
def generate_dynamic_prediction(df, initial_prediction, future_hours=24):
|
| 75 |
green_prediction = initial_prediction # Commencer avec la prédiction initiale
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
|
|
|
|
| 79 |
|
| 80 |
# Boucle pour ajuster la prédiction à chaque étape
|
| 81 |
for i in range(future_hours // 5): # Prédiction par segments de 5 heures
|
|
@@ -106,20 +107,16 @@ coins = {
|
|
| 106 |
"Stellar": "stellar"
|
| 107 |
}
|
| 108 |
|
| 109 |
-
#
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
# Récupération des prix pour la crypto sélectionnée
|
| 113 |
-
coin_id = coins[selected_coin]
|
| 114 |
-
crypto_prices = get_crypto_prices({selected_coin: coin_id}, start_time, end_time)
|
| 115 |
|
| 116 |
# Affichage des graphiques
|
| 117 |
-
st.title(
|
| 118 |
-
|
| 119 |
-
price_data = crypto_prices[selected_coin]
|
| 120 |
if price_data:
|
| 121 |
df = pd.DataFrame(price_data, columns=["timestamp", "price"])
|
| 122 |
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
|
|
|
|
| 123 |
|
| 124 |
# Générer les prédictions initiales (jaune)
|
| 125 |
predictions, future_timestamps = predict_patterns(price_data, future_hours=24)
|
|
@@ -131,9 +128,9 @@ if selected_coin in crypto_prices:
|
|
| 131 |
green_prediction = generate_dynamic_prediction(df, initial_prediction, future_hours=24)
|
| 132 |
|
| 133 |
# Affichage des résultats
|
| 134 |
-
st.write(f"#### {
|
| 135 |
fig, ax = plt.subplots(figsize=(12, 6))
|
| 136 |
-
ax.plot(df
|
| 137 |
|
| 138 |
# Courbe de prédiction initiale (jaune)
|
| 139 |
ax.plot(future_timestamps, initial_prediction, label="Prédiction initiale (jaune)", linestyle="--", color="yellow")
|
|
@@ -141,7 +138,7 @@ if selected_coin in crypto_prices:
|
|
| 141 |
# Courbe de prédiction dynamique (verte)
|
| 142 |
ax.plot(future_timestamps, green_prediction, label="Prédiction dynamique (verte)", linestyle="--", color="green")
|
| 143 |
|
| 144 |
-
ax.set_title(f"{
|
| 145 |
ax.set_xlabel("Date")
|
| 146 |
ax.set_ylabel("Prix (USD)")
|
| 147 |
ax.legend()
|
|
|
|
| 74 |
def generate_dynamic_prediction(df, initial_prediction, future_hours=24):
|
| 75 |
green_prediction = initial_prediction # Commencer avec la prédiction initiale
|
| 76 |
|
| 77 |
+
# S'assurer que l'index est bien de type datetime
|
| 78 |
+
last_timestamp = pd.to_datetime(df.index[-1]) # Convertir explicitement l'index en datetime
|
| 79 |
+
future_timestamps = [last_timestamp + timedelta(hours=i) for i in range(1, future_hours + 1)]
|
| 80 |
|
| 81 |
# Boucle pour ajuster la prédiction à chaque étape
|
| 82 |
for i in range(future_hours // 5): # Prédiction par segments de 5 heures
|
|
|
|
| 107 |
"Stellar": "stellar"
|
| 108 |
}
|
| 109 |
|
| 110 |
+
# Récupération des prix
|
| 111 |
+
crypto_prices = get_crypto_prices(coins, start_time, end_time)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# Affichage des graphiques
|
| 114 |
+
st.title("Analyse et Prédictions des Cryptos avec Patterns")
|
| 115 |
+
for coin, price_data in crypto_prices.items():
|
|
|
|
| 116 |
if price_data:
|
| 117 |
df = pd.DataFrame(price_data, columns=["timestamp", "price"])
|
| 118 |
df["timestamp"] = pd.to_datetime(df["timestamp"], unit="ms")
|
| 119 |
+
df.set_index("timestamp", inplace=True)
|
| 120 |
|
| 121 |
# Générer les prédictions initiales (jaune)
|
| 122 |
predictions, future_timestamps = predict_patterns(price_data, future_hours=24)
|
|
|
|
| 128 |
green_prediction = generate_dynamic_prediction(df, initial_prediction, future_hours=24)
|
| 129 |
|
| 130 |
# Affichage des résultats
|
| 131 |
+
st.write(f"#### {coin} - Prix et Prédictions")
|
| 132 |
fig, ax = plt.subplots(figsize=(12, 6))
|
| 133 |
+
ax.plot(df.index, df["price"], label="Prix réel", color="blue")
|
| 134 |
|
| 135 |
# Courbe de prédiction initiale (jaune)
|
| 136 |
ax.plot(future_timestamps, initial_prediction, label="Prédiction initiale (jaune)", linestyle="--", color="yellow")
|
|
|
|
| 138 |
# Courbe de prédiction dynamique (verte)
|
| 139 |
ax.plot(future_timestamps, green_prediction, label="Prédiction dynamique (verte)", linestyle="--", color="green")
|
| 140 |
|
| 141 |
+
ax.set_title(f"{coin} - Prix (7 derniers jours + 24h prévus)")
|
| 142 |
ax.set_xlabel("Date")
|
| 143 |
ax.set_ylabel("Prix (USD)")
|
| 144 |
ax.legend()
|