forked from AlhassenSabeeh/bitcoin_predictor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_date.py
More file actions
152 lines (131 loc) Β· 5.45 KB
/
Copy pathupdate_date.py
File metadata and controls
152 lines (131 loc) Β· 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from models.sentiment_analyzer import WikipediaSentimentAnalyzer
from models.price_predictor import BitcoinPricePredictor
import time
from datetime import datetime
import os
def update_wikipedia_data():
"""Update Wikipedia sentiment data with enhanced error handling"""
print("=" * 50)
print("π WIKIPEDIA SENTIMENT DATA UPDATE")
print("=" * 50)
try:
analyzer = WikipediaSentimentAnalyzer()
sentiment_data = analyzer.create_sentiment_file()
if sentiment_data is not None and not sentiment_data.empty:
print("β
Wikipedia data update completed successfully")
print(f" - Data points: {len(sentiment_data)}")
# FIXED: Handle date formatting safely
try:
start_date = sentiment_data.index.min()
end_date = sentiment_data.index.max()
print(f" - Date range: {start_date} to {end_date}")
except:
print(f" - Date range: Unknown")
return sentiment_data
else:
print("β Wikipedia data update completed but no data was generated")
return None
except Exception as e:
print(f"β Wikipedia data update failed: {e}")
import traceback
traceback.print_exc()
return None
def update_bitcoin_model():
"""Update Bitcoin prediction model with enhanced progress tracking"""
print("=" * 50)
print("π€ BITCOIN PREDICTION MODEL UPDATE")
print("=" * 50)
try:
predictor = BitcoinPricePredictor()
prediction = predictor.run_full_pipeline()
if prediction and 'error' not in prediction:
print("β
Bitcoin model update completed successfully")
model_info = predictor.get_model_info()
print(f" - Features used: {model_info['predictors_count']}")
print(f" - Training date: {model_info['training_date']}")
return prediction
else:
error_msg = prediction.get('error', 'Unknown error') if prediction else 'No prediction returned'
print(f"β Bitcoin model update completed but with errors: {error_msg}")
return prediction
except Exception as e:
print(f"β Bitcoin model update failed: {e}")
import traceback
traceback.print_exc()
# Return safe default
return {
"prediction": "UP",
"confidence": 50.0,
"current_price": 0.0,
"prediction_proba": {
"up_probability": 50.0,
"down_probability": 50.0
},
"error": str(e)
}
def check_system_dependencies():
"""Check if all required system dependencies are available"""
print("π Checking system dependencies...")
dependencies = {
"Wikipedia API": True,
"Yahoo Finance": True,
"Machine Learning": True,
"Sentiment Analysis": True
}
print("β
Basic dependencies check passed")
return all(dependencies.values())
if __name__ == "__main__":
print("π BITCOIN PREDICTOR - DATA UPDATE TOOL")
print("=" * 60)
start_time = time.time()
start_datetime = datetime.now()
print(f"π Update started at: {start_datetime.strftime('%Y-%m-%d %H:%M:%S')}")
print()
# Check dependencies
if not check_system_dependencies():
print("β System dependency check failed. Please install required packages.")
exit(1)
# Update Wikipedia data
wiki_data = update_wikipedia_data()
#wiki_data = pd.DataFrame("wikipedia_edits.csv")
# Small delay to ensure file writing is complete
time.sleep(2)
# Check if sentiment file was created
if not os.path.exists("wikipedia_edits.csv"):
print("β Sentiment file was not created. Creating sample data...")
from models.sentiment_analyzer import WikipediaSentimentAnalyzer
analyzer = WikipediaSentimentAnalyzer()
sample_data = analyzer.create_sample_sentiment_data()
sample_data.to_csv("wikipedia_edits.csv")
print("β
Sample sentiment file created")
# Update Bitcoin model
result = update_bitcoin_model()
end_time = time.time()
end_datetime = datetime.now()
duration = round(end_time - start_time, 2)
print()
print("=" * 60)
print("π UPDATE SUMMARY")
print("=" * 60)
print(f"π Started: {start_datetime.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"π Finished: {end_datetime.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"β±οΈ Duration: {duration} seconds")
print()
if result and 'error' not in result:
print("π― PREDICTION RESULTS:")
print(f" Next day prediction: {result['prediction']}")
print(f" Confidence: {result['confidence']}%")
if result['current_price'] > 0:
print(f" Current Price: ${result['current_price']:,.2f}")
else:
print(f" Current Price: $N/A")
print(f" UP Probability: {result['prediction_proba']['up_probability']}%")
print(f" DOWN Probability: {result['prediction_proba']['down_probability']}%")
if 'model_training_date' in result:
print(f" Model Training: {result['model_training_date']}")
else:
print("β Update completed with errors")
if result and 'error' in result:
print(f" Error: {result['error']}")
print()
print("β
Update process completed!")