bugfixing

This commit is contained in:
MuslemRahimi 2024-10-04 20:14:54 +02:00
parent 144a79f00a
commit a7374541dc
2 changed files with 22 additions and 6 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ app/crypto.*
app/*.sh app/*.sh
app/.env* app/.env*
app/ml_models/weights app/ml_models/weights
app/ml_models/training_data
app/json/* app/json/*
app/logs/* app/logs/*
fastify/node_modules fastify/node_modules

View File

@ -41,9 +41,22 @@ def get_summary(res_list):
latest_pt_current = defaultdict(int) latest_pt_current = defaultdict(int)
# Iterate through the data to update the latest pt_current for each analyst # Iterate through the data to update the latest pt_current for each analyst
for item in filtered_data: for item in filtered_data:
if 'adjusted_pt_current' in item and item['adjusted_pt_current']: if 'adjusted_pt_current' in item and item['adjusted_pt_current']:
analyst_name = item['analyst_name'] analyst_name = item['analyst_name']
latest_pt_current[analyst_name] = max(latest_pt_current[analyst_name], float(item['pt_current'])) # Convert pt_current to float and check if it's a valid number
try:
pt_current_value = float(item['pt_current'])
# Check if the value is float or int
if isinstance(pt_current_value, (float, int)):
# Initialize the analyst entry if it doesn't exist
if analyst_name not in latest_pt_current:
latest_pt_current[analyst_name] = pt_current_value
else:
# Update with the maximum value
latest_pt_current[analyst_name] = max(latest_pt_current[analyst_name], pt_current_value)
except (ValueError, TypeError):
print(f"Invalid pt_current value for analyst '{analyst_name}': {item['pt_current']}")
# Compute the average pt_current based on the latest values # Compute the average pt_current based on the latest values
pt_current_values = list(latest_pt_current.values()) pt_current_values = list(latest_pt_current.values())
@ -124,6 +137,7 @@ def run(chunk,analyst_list):
res_list = [item for item in res_list if item.get('analyst_name')] res_list = [item for item in res_list if item.get('analyst_name')]
#print(res_list[-15]) #print(res_list[-15])
for ticker in chunk: for ticker in chunk:
try: try:
ticker_filtered_data = [item for item in res_list if item['ticker'] == ticker] ticker_filtered_data = [item for item in res_list if item['ticker'] == ticker]
@ -212,7 +226,7 @@ def run(chunk,analyst_list):
#time.sleep(10000) #time.sleep(10000)
with open(f"json/analyst/history/{ticker}.json", 'w') as file: with open(f"json/analyst/history/{ticker}.json", 'w') as file:
ujson.dump(ticker_filtered_data, file) ujson.dump(ticker_filtered_data, file)
print(ticker_filtered_data)
except Exception as e: except Exception as e:
print(e) print(e)
@ -223,7 +237,7 @@ try:
con = sqlite3.connect('stocks.db') con = sqlite3.connect('stocks.db')
stock_cursor = con.cursor() stock_cursor = con.cursor()
stock_cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%'") stock_cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol NOT LIKE '%.%'")
stock_symbols = [row[0] for row in stock_cursor.fetchall()] stock_symbols =[row[0] for row in stock_cursor.fetchall()]
con.close() con.close()
@ -232,8 +246,9 @@ try:
analyst_stats_list = ujson.load(file) analyst_stats_list = ujson.load(file)
chunk_size = len(stock_symbols) // 40 # Divide the list into N chunks chunk_size = len(stock_symbols) // 40 # Divide the list into N chunks
chunks = [stock_symbols[i:i + chunk_size] for i in range(0, len(stock_symbols), chunk_size)] chunks = [stock_symbols[i:i + chunk_size] for i in range(0, len(stock_symbols), chunk_size)]
#chunks = [['AMD','NVDA','MSFT']] #chunks = [['NVDA']]
for chunk in chunks: for chunk in chunks:
run(chunk, analyst_stats_list) run(chunk, analyst_stats_list)