diff --git a/testy/tablesizes.py b/testy/tablesizes.py new file mode 100644 index 0000000..41b759c --- /dev/null +++ b/testy/tablesizes.py @@ -0,0 +1,74 @@ +import queue +import sqlite3 +import threading +from appdirs import user_data_dir + +DATA_DIR = user_data_dir("v2realbot") +sqlite_db_file = DATA_DIR + "/v2trading.db" + +class ConnectionPool: + def __init__(self, max_connections): + self.max_connections = max_connections + self.connections = queue.Queue(max_connections) + self.lock = threading.Lock() + + def get_connection(self): + with self.lock: + if self.connections.empty(): + return self.create_connection() + else: + return self.connections.get() + + def release_connection(self, connection): + with self.lock: + self.connections.put(connection) + + def create_connection(self): + connection = sqlite3.connect(sqlite_db_file, check_same_thread=False) + return connection + + +pool = ConnectionPool(10) + +def get_table_sizes_in_mb(): + # Connect to the SQLite database + conn = pool.get_connection() + cursor = conn.cursor() + + # Get the list of tables + cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") + tables = cursor.fetchall() + + # Dictionary to store table sizes + table_sizes = {} + + for table in tables: + table_name = table[0] + + # Get total number of rows in the table + cursor.execute(f"SELECT COUNT(*) FROM {table_name};") + row_count = cursor.fetchone()[0] + + if row_count > 0: + # Sample a few rows (e.g., 10 rows) and calculate average row size + cursor.execute(f"SELECT * FROM {table_name} LIMIT 10;") + sample_rows = cursor.fetchall() + total_sample_size = sum(sum(len(str(cell)) for cell in row) for row in sample_rows) + avg_row_size = total_sample_size / len(sample_rows) + + # Estimate table size in megabytes + size_in_mb = (avg_row_size * row_count) / (1024 * 1024) + else: + size_in_mb = 0 + + table_sizes[table_name] = {'size_mb': size_in_mb, 'rows': row_count} + + conn.close() + return table_sizes + +# Usage example +db_path = 'path_to_your_database.db' +table_sizes = get_table_sizes_in_mb() +for table, info in table_sizes.items(): + print(f"Table: {table}, Size: {info['size_mb']} MB, Rows: {info['rows']}") + diff --git a/v2realbot/main.py b/v2realbot/main.py index f7e03a7..70c8f8a 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -653,7 +653,7 @@ def _generate_report_image(runner_ids: list[UUID]): res, stream = generate_trading_report_image(runner_ids=runner_ids,stream=True) if res == 0: return StreamingResponse(stream, media_type="image/png",headers={"Content-Disposition": "attachment; filename=report.png"}) elif res < 0: - raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error: {res}:{id}") + raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error: {res}:{stream}") except Exception as e: raise HTTPException(status_code=status.HTTP_406_NOT_ACCEPTABLE, detail=f"Error: {str(e)}" + format_exc()) diff --git a/v2realbot/scheduler/ap_scheduler.py b/v2realbot/scheduler/ap_scheduler.py index 4be757f..ef5cd28 100644 --- a/v2realbot/scheduler/ap_scheduler.py +++ b/v2realbot/scheduler/ap_scheduler.py @@ -213,7 +213,7 @@ def _start_runman_record(id: UUID, market = "US", debug_date = None): market_time_now, market_open_datetime, market_close_datetime = sada print(f"OPEN:{market_open_datetime} CLOSE:{market_close_datetime}") else: - sada = "Error getting market times (CLOSED): " + str(sada) + sada = f"Market {market} Error getting market times (CLOSED): " + str(sada) return res, record, sada if cs.is_stratin_running(record.strat_id): diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index e82991c..3521db6 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -1164,7 +1164,7 @@ - + diff --git a/v2realbot/static/js/tables/runmanager/init.js b/v2realbot/static/js/tables/runmanager/init.js index bd60e48..abd5e7b 100644 --- a/v2realbot/static/js/tables/runmanager/init.js +++ b/v2realbot/static/js/tables/runmanager/init.js @@ -176,16 +176,16 @@ function initialize_runmanagerRecords() { tit = date.toLocaleString('cs-CZ', { timeZone: 'America/New_York', }) - - if (isToday(now)) { - //return local time only - return '