Spaces:
Sleeping
Sleeping
Fix: Force overwrite of V2 Advisor code
Browse files- static/script.js +48 -31
static/script.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
async function runAnalysis() {
|
| 2 |
const query = document.getElementById('query').value;
|
|
|
|
| 3 |
const loader = document.getElementById('loader');
|
| 4 |
const dashboard = document.getElementById('dashboard');
|
| 5 |
|
|
@@ -10,6 +11,10 @@ async function runAnalysis() {
|
|
| 10 |
// Prepare form data
|
| 11 |
const formData = new FormData();
|
| 12 |
formData.append('query', query);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
try {
|
| 15 |
const response = await fetch('/analyze', {
|
|
@@ -17,6 +22,12 @@ async function runAnalysis() {
|
|
| 17 |
body: formData
|
| 18 |
});
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
const data = await response.json();
|
| 21 |
|
| 22 |
if (data.error) {
|
|
@@ -32,30 +43,30 @@ async function runAnalysis() {
|
|
| 32 |
|
| 33 |
} catch (e) {
|
| 34 |
console.error(e);
|
| 35 |
-
alert("System Error: Could not reach quantitative engine.");
|
| 36 |
loader.style.display = 'none';
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
function updateDashboard(data) {
|
| 41 |
-
// 1. Executive
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
|
| 60 |
// 3. Chart
|
| 61 |
const layout = {
|
|
@@ -77,16 +88,22 @@ function updateDashboard(data) {
|
|
| 77 |
const tbody = document.querySelector('#comps-table tbody');
|
| 78 |
tbody.innerHTML = '';
|
| 79 |
|
| 80 |
-
data.comparables
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
<
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
|
|
|
| 1 |
async function runAnalysis() {
|
| 2 |
const query = document.getElementById('query').value;
|
| 3 |
+
const lastPrivate = document.getElementById('last-private').value;
|
| 4 |
const loader = document.getElementById('loader');
|
| 5 |
const dashboard = document.getElementById('dashboard');
|
| 6 |
|
|
|
|
| 11 |
// Prepare form data
|
| 12 |
const formData = new FormData();
|
| 13 |
formData.append('query', query);
|
| 14 |
+
// Only append if value exists
|
| 15 |
+
if (lastPrivate) {
|
| 16 |
+
formData.append('last_private', lastPrivate);
|
| 17 |
+
}
|
| 18 |
|
| 19 |
try {
|
| 20 |
const response = await fetch('/analyze', {
|
|
|
|
| 22 |
body: formData
|
| 23 |
});
|
| 24 |
|
| 25 |
+
// Check for HTTP errors (like 500)
|
| 26 |
+
if (!response.ok) {
|
| 27 |
+
const errorText = await response.text();
|
| 28 |
+
throw new Error(`Server Error (${response.status}): ${errorText}`);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
const data = await response.json();
|
| 32 |
|
| 33 |
if (data.error) {
|
|
|
|
| 43 |
|
| 44 |
} catch (e) {
|
| 45 |
console.error(e);
|
| 46 |
+
alert("System Error: Could not reach quantitative engine. \nDetail: " + e.message);
|
| 47 |
loader.style.display = 'none';
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
| 51 |
function updateDashboard(data) {
|
| 52 |
+
// 1. Executive Commentary (The "Advisor")
|
| 53 |
+
// Safe check if advisory exists
|
| 54 |
+
if (data.advisory && data.advisory.commentary) {
|
| 55 |
+
document.getElementById('exec-summary-content').innerHTML = data.advisory.commentary;
|
| 56 |
+
document.getElementById('m-price').textContent = `$${data.advisory.low} - $${data.advisory.high}`;
|
| 57 |
+
|
| 58 |
+
const statusEl = document.getElementById('m-status');
|
| 59 |
+
statusEl.textContent = data.advisory.sentiment;
|
| 60 |
+
statusEl.style.color = data.advisory.color;
|
| 61 |
+
|
| 62 |
+
// Helper
|
| 63 |
+
const formatNum = (num) => (num ? num.toFixed(1) + "x" : "--");
|
| 64 |
+
|
| 65 |
+
document.getElementById('m-ev-rev').textContent = formatNum(data.metrics.avg_ev_rev);
|
| 66 |
+
document.getElementById('m-rule-40').textContent = data.metrics.avg_rule_40 ? data.metrics.avg_rule_40.toFixed(0) : "--";
|
| 67 |
+
document.getElementById('m-vix').textContent = data.macro ? data.macro.vix.toFixed(2) : "--";
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
|
| 71 |
// 3. Chart
|
| 72 |
const layout = {
|
|
|
|
| 88 |
const tbody = document.querySelector('#comps-table tbody');
|
| 89 |
tbody.innerHTML = '';
|
| 90 |
|
| 91 |
+
if (data.comparables) {
|
| 92 |
+
data.comparables.forEach(c => {
|
| 93 |
+
// Colors for Rule of 40
|
| 94 |
+
const r40Color = c.rule_40 < 40 ? '#fa5c5c' : '#5cfa85';
|
| 95 |
+
|
| 96 |
+
const row = `
|
| 97 |
+
<tr>
|
| 98 |
+
<td style="font-weight:bold; color:var(--primary-gold)">${c.ticker}</td>
|
| 99 |
+
<td>$${(c.market_cap / 1e9).toFixed(2)}B</td>
|
| 100 |
+
<td>${c.ev_rev ? c.ev_rev.toFixed(1) + 'x' : 'N/A'}</td>
|
| 101 |
+
<td style="color:${r40Color}">${c.rule_40 ? c.rule_40.toFixed(0) : '--'}</td>
|
| 102 |
+
<td>${c.growth ? (c.growth * 100).toFixed(0) + '%' : 'N/A'}</td>
|
| 103 |
+
<td>${c.beta ? c.beta.toFixed(2) : '1.00'}</td>
|
| 104 |
+
</tr>
|
| 105 |
+
`;
|
| 106 |
+
tbody.innerHTML += row;
|
| 107 |
+
});
|
| 108 |
+
}
|
| 109 |
}
|