forked from Jon-Becker/prediction-market-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
162 lines (130 loc) · 4.57 KB
/
Copy pathmain.py
File metadata and controls
162 lines (130 loc) · 4.57 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
153
154
155
156
157
158
159
160
161
162
from __future__ import annotations
import sys
from pathlib import Path
from simple_term_menu import TerminalMenu
from src.common.analysis import Analysis
from src.common.indexer import Indexer
from src.common.util import package_data
from src.common.util.strings import snake_to_title
def analyze(name: str | None = None):
"""Run analysis by name or show interactive menu."""
analyses = Analysis.load()
if not analyses:
print("No analyses found in src/analysis/")
return
output_dir = Path("output")
# If name provided, run that specific analysis
if name:
if name == "all":
print("\nRunning all analyses...\n")
for analysis_cls in analyses:
instance = analysis_cls()
print(f"Running: {instance.name}")
saved = instance.save(output_dir, formats=["png", "pdf", "csv", "json", "gif"])
for fmt, path in saved.items():
print(f" {fmt}: {path}")
print("\nAll analyses complete.")
return
# Find matching analysis
for analysis_cls in analyses:
instance = analysis_cls()
if instance.name == name:
print(f"\nRunning: {instance.name}\n")
saved = instance.save(output_dir, formats=["png", "pdf", "csv", "json", "gif"])
print("Saved files:")
for fmt, path in saved.items():
print(f" {fmt}: {path}")
return
# No match found
print(f"Analysis '{name}' not found. Available analyses:")
for analysis_cls in analyses:
instance = analysis_cls()
print(f" - {instance.name}")
sys.exit(1)
# Interactive menu mode
options = ["[All] Run all analyses"]
for analysis_cls in analyses:
instance = analysis_cls()
options.append(f"{snake_to_title(instance.name)}: {instance.description}")
options.append("[Exit]")
menu = TerminalMenu(
options,
title="Select an analysis to run (use arrow keys):",
cycle_cursor=True,
clear_screen=False,
)
choice = menu.show()
if choice is None or choice == len(options) - 1:
print("Exiting.")
return
if choice == 0:
# Run all analyses
print("\nRunning all analyses...\n")
for analysis_cls in analyses:
instance = analysis_cls()
print(f"Running: {instance.name}")
saved = instance.save(output_dir, formats=["png", "pdf", "csv", "json", "gif"])
for fmt, path in saved.items():
print(f" {fmt}: {path}")
print("\nAll analyses complete.")
else:
# Run selected analysis
analysis_cls = analyses[choice - 1]
instance = analysis_cls()
print(f"\nRunning: {instance.name}\n")
saved = instance.save(output_dir, formats=["png", "pdf", "csv", "json", "gif"])
print("Saved files:")
for fmt, path in saved.items():
print(f" {fmt}: {path}")
def index():
"""Interactive indexer selection menu."""
indexers = Indexer.load()
if not indexers:
print("No indexers found in src/indexers/")
return
# Build menu options
options = []
for indexer_cls in indexers:
instance = indexer_cls()
options.append(f"{snake_to_title(instance.name)}: {instance.description}")
options.append("[Exit]")
menu = TerminalMenu(
options,
title="Select an indexer to run (use arrow keys):",
cycle_cursor=True,
clear_screen=False,
)
choice = menu.show()
if choice is None or choice == len(options) - 1:
print("Exiting.")
return
indexer_cls = indexers[choice]
instance = indexer_cls()
print(f"\nRunning: {instance.name}\n")
instance.run()
print("\nIndexer complete.")
def package():
"""Package the data directory into a zstd-compressed tar archive."""
success = package_data()
sys.exit(0 if success else 1)
def main():
if len(sys.argv) < 2:
print("\nUsage: uv run main.py <command>")
print("Commands: analyze, index, package")
sys.exit(0)
command = sys.argv[1]
if command == "analyze":
name = sys.argv[2] if len(sys.argv) > 2 else None
analyze(name)
sys.exit(0)
if command == "index":
index()
sys.exit(0)
if command == "package":
package()
sys.exit(0)
print(f"Unknown command: {command}")
print("Commands: analyze, index, package")
sys.exit(1)
if __name__ == "__main__":
main()