* Get total spend across all campaigns. * Uses real cost when available, falls back to estimated. * @returns {{ total: number, by_campaign: Object, session_count: number, has_real_data: boolean }}
()
| 192 | * @returns {{ total: number, by_campaign: Object, session_count: number, has_real_data: boolean }} |
| 193 | */ |
| 194 | function readTotalCost() { |
| 195 | const byCampaign = readCostByCampaign(); |
| 196 | let total = 0; |
| 197 | let sessionCount = 0; |
| 198 | let hasRealData = false; |
| 199 | |
| 200 | for (const slug of Object.keys(byCampaign)) { |
| 201 | total += byCampaign[slug].total_cost; |
| 202 | sessionCount += byCampaign[slug].sessions; |
| 203 | if (byCampaign[slug].has_real_data) hasRealData = true; |
| 204 | } |
| 205 | |
| 206 | return { |
| 207 | total: Math.round(total * 100) / 100, |
| 208 | by_campaign: byCampaign, |
| 209 | session_count: sessionCount, |
| 210 | has_real_data: hasRealData, |
| 211 | }; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Compute estimated cost for a single session based on agent activity. |
no test coverage detected