mobhub
Decentralized model and agent weights distribution network
Brought by drakestapleton
| 1 | //! Ultra-low-latency Axum HTTP service and embedded dashboard UI. |
| 2 | |
| 3 | use crate::gym::{self, SessionParams}; |
| 4 | use crate::payout::{self, PayoutOptions, PayoutPolicy, PayoutResult, MemberInput}; |
| 5 | use crate::reconcile::{self, GiveForMatch, ParsedDisbursement, ReconcileSummary, RegisterRowForMatch}; |
| 6 | use crate::storage::{Database, StoredDisbursement, StoredWar}; |
| 7 | use crate::torn::TornClient; |
| 8 | use crate::valuation::{self, ValuationBreakdown}; |
| 9 | use crate::vault; |
| 10 | |
| 11 | use axum::extract::{Path, Query, State}; |
| 12 | use axum::http::{header, StatusCode}; |
| 13 | use axum::response::{Html, IntoResponse, Json}; |
| 14 | use axum::routing::{get, post}; |
| 15 | use axum::Router; |
| 16 | use serde::Deserialize; |
| 17 | use serde_json::json; |
| 18 | use std::net::SocketAddr; |
| 19 | use std::sync::Arc; |
| 20 | use tower_http::cors::CorsLayer; |
| 21 | use tower_http::trace::TraceLayer; |
| 22 | |
| 23 | #[derive(Clone)] |
| 24 | pub struct AppState { |
| 25 | pub storage: Database, |
| 26 | pub torn: TornClient, |
| 27 | pub faction_id: i64, |
| 28 | } |
| 29 | |
| 30 | #[derive(Debug, Deserialize)] |
| 31 | pub struct PayoutComputeRequest { |
| 32 | pub cache_value: i64, |
| 33 | pub policy: PayoutPolicy, |
| 34 | pub members: Vec<MemberInput>, |
| 35 | #[serde(default)] |
| 36 | pub options: PayoutOptions, |
| 37 | } |
| 38 | |
| 39 | #[derive(Debug, Deserialize)] |
| 40 | pub struct ValuationRequest { |
| 41 | pub respect: f64, |
| 42 | pub respect_rate: f64, |
| 43 | pub armory_value: f64, |
| 44 | pub faction_cash: f64, |
| 45 | } |
| 46 | |
| 47 | #[derive(Debug, Deserialize)] |
| 48 | pub struct CsvExportRequest { |
| 49 | pub result: PayoutResult, |
| 50 | pub faction_id: Option<i64>, |
| 51 | } |
| 52 | |
| 53 | #[derive(Debug, Deserialize)] |
| 54 | pub struct ReconcileMatchRequest { |
| 55 | pub gives: Vec<GiveForMatch>, |
| 56 | pub register: Vec<RegisterRowForMatch>, |
| 57 | #[serde(default)] |
| 58 | pub tolerance_pct: Option<f64>, |
| 59 | } |
| 60 | |
| 61 | #[derive(Debug, Deserialize)] |
| 62 | pub struct DisbursementsQuery { |
| 63 | pub war_id: Option<i64>, |
| 64 | } |
| 65 | |
| 66 | pub fn create_router(state: AppState) -> Router { |
| 67 | Router::new() |
| 68 | .route("/", get(dashboard_handler)) |
| 69 | .route("/health", get(health_handler)) |
| 70 | .route("/status", get(status_handler)) |
| 71 | .route("/api/payout/compute", post(payout_compute_handler)) |
| 72 | .route("/api/payout/export-csv", post(payout_csv_handler)) |
| 73 | .route("/api/valuation/compute", post(valuation_compute_handler)) |
| 74 | .route("/api/gym/simulate", post(gym_simulate_handler)) |
| 75 | .route("/api/reconcile/parse", post(reconcile_parse_handler)) |
| 76 | .route("/api/reconcile/match", post(reconcile_match_handler)) |
| 77 | .route("/api/disbursements", get(list_disbursements_handler).post(save_disbursements_handler)) |
| 78 | .route("/api/wars", get(list_wars_handler).post(create_war_handler)) |
| 79 | .route("/api/wars/:id", get(get_war_handler)) |
| 80 | .route("/api/balances", get(list_balances_handler)) |
| 81 | .layer(CorsLayer::permissive()) |
| 82 | .layer(TraceLayer::new_for_http()) |
| 83 | .with_state(Arc::new(state)) |
| 84 | } |
| 85 | |
| 86 | pub async fn run_server(port: u16, state: AppState) -> Result<(), Box<dyn std::error::Error>> { |
| 87 | let app = create_router(state); |
| 88 | let addr = SocketAddr::from(([0, 0, 0, 0], port)); |
| 89 | tracing::info!("MobHub native server listening on http://{}", addr); |
| 90 | |
| 91 | let listener = tokio::net::TcpListener::bind(addr).await?; |
| 92 | axum::serve(listener, app).await?; |
| 93 | Ok(()) |
| 94 | } |
| 95 | |
| 96 | async fn health_handler() -> impl IntoResponse { |
| 97 | Json(json!({ |
| 98 | "status": "ok", |
| 99 | "service": "mobhub", |
| 100 | "engine": "native-rust-axum", |
| 101 | "version": env!("CARGO_PKG_VERSION") |
| 102 | })) |
| 103 | } |
| 104 | |
| 105 | async fn status_handler() -> impl IntoResponse { |
| 106 | let tpm_active = vault::is_torn_key_present(); |
| 107 | Json(json!({ |
| 108 | "status": "ok", |
| 109 | "service": "mobhub", |
| 110 | "tpm_vault_active": tpm_active, |
| 111 | "runtime": "native-arm64-rust", |
| 112 | "version": env!("CARGO_PKG_VERSION") |
| 113 | })) |
| 114 | } |
| 115 | |
| 116 | async fn payout_compute_handler( |
| 117 | Json(req): Json<PayoutComputeRequest>, |
| 118 | ) -> Result<Json<PayoutResult>, (StatusCode, Json<serde_json::Value>)> { |
| 119 | let res = payout::compute_payout(req.cache_value, &req.policy, &req.members, &req.options); |
| 120 | Ok(Json(res)) |
| 121 | } |
| 122 | |
| 123 | async fn payout_csv_handler( |
| 124 | State(state): State<Arc<AppState>>, |
| 125 | Json(req): Json<CsvExportRequest>, |
| 126 | ) -> impl IntoResponse { |
| 127 | let fid = req.faction_id.unwrap_or(state.faction_id); |
| 128 | let csv_content = payout::export_payout_csv(&req.result, fid); |
| 129 | |
| 130 | ( |
| 131 | [ |
| 132 | (header::CONTENT_TYPE, "text/csv; charset=utf-8"), |
| 133 | ( |
| 134 | header::CONTENT_DISPOSITION, |
| 135 | "attachment; filename=\"payout.csv\"", |
| 136 | ), |
| 137 | ], |
| 138 | csv_content, |
| 139 | ) |
| 140 | } |
| 141 | |
| 142 | async fn valuation_compute_handler( |
| 143 | Json(req): Json<ValuationRequest>, |
| 144 | ) -> Json<ValuationBreakdown> { |
| 145 | let res = valuation::compute_valuation( |
| 146 | req.respect, |
| 147 | req.respect_rate, |
| 148 | req.armory_value, |
| 149 | req.faction_cash, |
| 150 | ); |
| 151 | Json(res) |
| 152 | } |
| 153 | |
| 154 | async fn gym_simulate_handler( |
| 155 | Json(req): Json<SessionParams>, |
| 156 | ) -> Json<gym::SessionResult> { |
| 157 | let res = gym::run_mojo_optimizer(&req); |
| 158 | Json(res) |
| 159 | } |
| 160 | |
| 161 | async fn reconcile_parse_handler( |
| 162 | Json(news_payload): Json<serde_json::Value>, |
| 163 | ) -> Json<Vec<ParsedDisbursement>> { |
| 164 | let disbursements = reconcile::parse_disbursements(&news_payload); |
| 165 | Json(disbursements) |
| 166 | } |
| 167 | |
| 168 | async fn reconcile_match_handler( |
| 169 | Json(req): Json<ReconcileMatchRequest>, |
| 170 | ) -> Json<ReconcileSummary> { |
| 171 | let tol = req.tolerance_pct.unwrap_or(0.005); |
| 172 | let summary = reconcile::match_disbursements(&req.gives, &req.register, tol); |
| 173 | Json(summary) |
| 174 | } |
| 175 | |
| 176 | async fn list_disbursements_handler( |
| 177 | State(state): State<Arc<AppState>>, |
| 178 | Query(query): Query<DisbursementsQuery>, |
| 179 | ) -> Result<Json<Vec<StoredDisbursement>>, (StatusCode, String)> { |
| 180 | state |
| 181 | .storage |
| 182 | .list_disbursements(query.war_id) |
| 183 | .map(Json) |
| 184 | .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) |
| 185 | } |
| 186 | |
| 187 | #[derive(Debug, Deserialize)] |
| 188 | pub struct SaveDisbursementPayload { |
| 189 | pub news_id: String, |
| 190 | pub war_id: Option<i64>, |
| 191 | pub recipient_torn_id: i64, |
| 192 | pub recipient_name: Option<String>, |
| 193 | pub amount: i64, |
| 194 | pub occurred_at: Option<String>, |
| 195 | pub matched_register_id: Option<i64>, |
| 196 | pub raw_text: String, |
| 197 | } |
| 198 | |
| 199 | async fn save_disbursements_handler( |
| 200 | State(state): State<Arc<AppState>>, |
| 201 | Json(payload): Json<SaveDisbursementPayload>, |
| 202 | ) -> Result<(StatusCode, Json<serde_json::Value>), (StatusCode, String)> { |
| 203 | state |
| 204 | .storage |
| 205 | .save_disbursement( |
| 206 | &payload.news_id, |
| 207 | payload.war_id, |
| 208 | payload.recipient_torn_id, |
| 209 | payload.recipient_name.as_deref(), |
| 210 | payload.amount, |
| 211 | payload.occurred_at.as_deref(), |
| 212 | payload.matched_register_id, |
| 213 | &payload.raw_text, |
| 214 | ) |
| 215 | .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; |
| 216 | |
| 217 | Ok((StatusCode::CREATED, Json(json!({ "saved": true, "news_id": payload.news_id })))) |
| 218 | } |
| 219 | |
| 220 | async fn list_wars_handler( |
| 221 | State(state): State<Arc<AppState>>, |
| 222 | ) -> Result<Json<Vec<StoredWar>>, (StatusCode, String)> { |
| 223 | state |
| 224 | .storage |
| 225 | .list_wars() |
| 226 | .map(Json) |
| 227 | .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) |
| 228 | } |
| 229 | |
| 230 | #[derive(Debug, Deserialize)] |
| 231 | struct CreateWarPayload { |
| 232 | id: i64, |
| 233 | name: String, |
| 234 | cache_value: i64, |
| 235 | status: String, |
| 236 | data: serde_json::Value, |
| 237 | } |
| 238 | |
| 239 | async fn create_war_handler( |
| 240 | State(state): State<Arc<AppState>>, |
| 241 | Json(payload): Json<CreateWarPayload>, |
| 242 | ) -> Result<(StatusCode, Json<serde_json::Value>), (StatusCode, String)> { |
| 243 | let data_str = payload.data.to_string(); |
| 244 | state |
| 245 | .storage |
| 246 | .save_war( |
| 247 | payload.id, |
| 248 | &payload.name, |
| 249 | payload.cache_value, |
| 250 | &payload.status, |
| 251 | &data_str, |
| 252 | ) |
| 253 | .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; |
| 254 | |
| 255 | Ok(( |
| 256 | StatusCode::CREATED, |
| 257 | Json(json!({ "recorded": true, "war_id": payload.id })), |
| 258 | )) |
| 259 | } |
| 260 | |
| 261 | async fn get_war_handler( |
| 262 | State(state): State<Arc<AppState>>, |
| 263 | Path(id): Path<i64>, |
| 264 | ) -> Result<Json<StoredWar>, (StatusCode, String)> { |
| 265 | match state.storage.get_war(id) { |
| 266 | Ok(Some(w)) => Ok(Json(w)), |
| 267 | Ok(None) => Err((StatusCode::NOT_FOUND, "War not found".to_string())), |
| 268 | Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())), |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | async fn list_balances_handler( |
| 273 | State(state): State<Arc<AppState>>, |
| 274 | ) -> Result<Json<Vec<crate::storage::StoredBalance>>, (StatusCode, String)> { |
| 275 | state |
| 276 | .storage |
| 277 | .list_balances() |
| 278 | .map(Json) |
| 279 | .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string())) |
| 280 | } |
| 281 | |
| 282 | async fn dashboard_handler(State(state): State<Arc<AppState>>) -> Html<String> { |
| 283 | let tpm_active = vault::is_torn_key_present(); |
| 284 | let status_badge = if tpm_active { |
| 285 | r#"<span class="badge active">TPM Vault Active</span>"# |
| 286 | } else { |
| 287 | r#"<span class="badge warn">Vault Unbound</span>"# |
| 288 | }; |
| 289 | |
| 290 | let html = format!(r#"<!DOCTYPE html> |
| 291 | <html lang="en"> |
| 292 | <head> |
| 293 | <meta charset="UTF-8"> |
| 294 | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 295 | <title>MobHub: Sovereign Faction Ops</title> |
| 296 | <style> |
| 297 | :root {{ |
| 298 | --bg: #0d1117; |
| 299 | --surface: #161b22; |
| 300 | --border: #30363d; |
| 301 | --text: #c9d1d9; |
| 302 | --text-dim: #8b949e; |
| 303 | --accent: #238636; |
| 304 | --accent-glow: rgba(35, 134, 54, 0.4); |
| 305 | --gold: #d29922; |
| 306 | }} |
| 307 | * {{ box-sizing: border-box; margin: 0; padding: 0; }} |
| 308 | body {{ |
| 309 | background: var(--bg); |
| 310 | color: var(--text); |
| 311 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace; |
| 312 | line-height: 1.5; |
| 313 | padding: 2rem; |
| 314 | }} |
| 315 | .header {{ |
| 316 | display: flex; |
| 317 | justify-content: space-between; |
| 318 | align-items: center; |
| 319 | border-bottom: 1px solid var(--border); |
| 320 | padding-bottom: 1rem; |
| 321 | margin-bottom: 2rem; |
| 322 | }} |
| 323 | h1 {{ |
| 324 | font-size: 1.5rem; |
| 325 | color: #fff; |
| 326 | letter-spacing: -0.5px; |
| 327 | }} |
| 328 | .badge {{ |
| 329 | padding: 0.25rem 0.6rem; |
| 330 | border-radius: 9999px; |
| 331 | font-size: 0.75rem; |
| 332 | font-weight: 600; |
| 333 | text-transform: uppercase; |
| 334 | }} |
| 335 | .badge.active {{ |
| 336 | background: var(--accent-glow); |
| 337 | color: #3fb950; |
| 338 | border: 1px solid #2ea043; |
| 339 | }} |
| 340 | .badge.warn {{ |
| 341 | background: rgba(210, 153, 34, 0.2); |
| 342 | color: #d29922; |
| 343 | border: 1px solid #bb8009; |
| 344 | }} |
| 345 | .container {{ |
| 346 | display: grid; |
| 347 | grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); |
| 348 | gap: 1.5rem; |
| 349 | }} |
| 350 | .card {{ |
| 351 | background: var(--surface); |
| 352 | border: 1px solid var(--border); |
| 353 | border-radius: 6px; |
| 354 | padding: 1.25rem; |
| 355 | }} |
| 356 | h2 {{ |
| 357 | font-size: 1.1rem; |
| 358 | margin-bottom: 1rem; |
| 359 | color: #fff; |
| 360 | border-bottom: 1px solid var(--border); |
| 361 | padding-bottom: 0.5rem; |
| 362 | }} |
| 363 | label {{ |
| 364 | display: block; |
| 365 | font-size: 0.8rem; |
| 366 | color: var(--text-dim); |
| 367 | margin-top: 0.8rem; |
| 368 | margin-bottom: 0.2rem; |
| 369 | }} |
| 370 | input, select {{ |
| 371 | width: 100%; |
| 372 | background: var(--bg); |
| 373 | border: 1px solid var(--border); |
| 374 | color: #fff; |
| 375 | padding: 0.5rem; |
| 376 | border-radius: 4px; |
| 377 | font-family: inherit; |
| 378 | }} |
| 379 | button {{ |
| 380 | margin-top: 1rem; |
| 381 | padding: 0.6rem 1.2rem; |
| 382 | background: var(--accent); |
| 383 | color: white; |
| 384 | border: none; |
| 385 | border-radius: 4px; |
| 386 | cursor: pointer; |
| 387 | font-weight: 600; |
| 388 | width: 100%; |
| 389 | }} |
| 390 | button:hover {{ |
| 391 | filter: brightness(1.1); |
| 392 | }} |
| 393 | .result {{ |
| 394 | margin-top: 1rem; |
| 395 | background: var(--bg); |
| 396 | border: 1px solid var(--border); |
| 397 | padding: 0.75rem; |
| 398 | border-radius: 4px; |
| 399 | font-family: monospace; |
| 400 | font-size: 0.85rem; |
| 401 | white-space: pre-wrap; |
| 402 | max-height: 250px; |
| 403 | overflow-y: auto; |
| 404 | }} |
| 405 | </style> |
| 406 | </head> |
| 407 | <body> |
| 408 | <div class="header"> |
| 409 | <h1>MobHub Sovereign Faction Suite</h1> |
| 410 | <div> |
| 411 | {status_badge} |
| 412 | <span style="margin-left: 0.8rem; font-size: 0.85rem; color: var(--text-dim);">Faction: #{faction_id}</span> |
| 413 | </div> |
| 414 | </div> |
| 415 | <div class="container"> |
| 416 | <!-- MobPay Calculator --> |
| 417 | <div class="card"> |
| 418 | <h2>MobPay Payout Engine</h2> |
| 419 | <label>War Cache Value ($)</label> |
| 420 | <input type="number" id="payoutCache" value="349499999"> |
| 421 | <label>Model</label> |
| 422 | <select id="payoutModel"> |
| 423 | <option value="flat_rate">Flat Rate (Respect Based)</option> |
| 424 | <option value="pool_share">Pool Share (Hit Based)</option> |
| 425 | </select> |
| 426 | <label>Members Split (0.0 - 1.0)</label> |
| 427 | <input type="number" step="0.01" id="splitMembers" value="0.8"> |
| 428 | <label>Faction Split (0.0 - 1.0)</label> |
| 429 | <input type="number" step="0.01" id="splitFaction" value="0.2"> |
| 430 | <button onclick="runPayout()">Compute Payout</button> |
| 431 | <div class="result" id="payoutResult">Ready.</div> |
| 432 | </div> |
| 433 | |
| 434 | <!-- MobWorth Valuation --> |
| 435 | <div class="card"> |
| 436 | <h2>MobWorth Faction Valuation</h2> |
| 437 | <label>Faction Respect</label> |
| 438 | <input type="number" id="valRespect" value="100000"> |
| 439 | <label>Respect Rate ($/respect)</label> |
| 440 | <input type="number" id="valRate" value="180284"> |
| 441 | <label>Armory Value ($)</label> |
| 442 | <input type="number" id="valArmory" value="50000000"> |
| 443 | <label>Spendable Faction Cash ($)</label> |
| 444 | <input type="number" id="valCash" value="25000000"> |
| 445 | <button onclick="runValuation()">Calculate Worth</button> |
| 446 | <div class="result" id="valResult">Ready.</div> |
| 447 | </div> |
| 448 | |
| 449 | <!-- MobGym Projections --> |
| 450 | <div class="card"> |
| 451 | <h2>MobGym Mojo Accelerator</h2> |
| 452 | <label>Stat Type</label> |
| 453 | <select id="gymStat"> |
| 454 | <option value="strength">Strength</option> |
| 455 | <option value="speed">Speed</option> |
| 456 | <option value="dexterity">Dexterity</option> |
| 457 | <option value="defense">Defense</option> |
| 458 | </select> |
| 459 | <label>Current Stat</label> |
| 460 | <input type="number" id="gymStartStat" value="1000000"> |
| 461 | <label>Current Happy</label> |
| 462 | <input type="number" id="gymHappy" value="5000"> |
| 463 | <label>Energy to Spend</label> |
| 464 | <input type="number" id="gymEnergy" value="1000"> |
| 465 | <label>Gym Dots (/10)</label> |
| 466 | <input type="number" step="0.1" id="gymDots" value="7.3"> |
| 467 | <button onclick="runGym()">Simulate Session</button> |
| 468 | <div class="result" id="gymResult">Ready.</div> |
| 469 | </div> |
| 470 | </div> |
| 471 | |
| 472 | <script> |
| 473 | async function runPayout() {{ |
| 474 | const cache = parseInt(document.getElementById('payoutCache').value); |
| 475 | const model = document.getElementById('payoutModel').value; |
| 476 | const splitM = parseFloat(document.getElementById('splitMembers').value); |
| 477 | const splitF = parseFloat(document.getElementById('splitFaction').value); |
| 478 | |
| 479 | const payload = {{ |
| 480 | cache_value: cache, |
| 481 | policy: {{ |
| 482 | model: model, |
| 483 | rate_per_respect: 180284, |
| 484 | rate_per_outside_hit: 500000, |
| 485 | rate_per_assist: 250000, |
| 486 | weight_war_hit: 1.0, |
| 487 | weight_assist: 0.5, |
| 488 | weight_outside_hit: 0.5, |
| 489 | split_members_pct: splitM, |
| 490 | split_faction_pct: splitF, |
| 491 | split_leadership_pct: 0.0, |
| 492 | leadership_recipient_torn_id: null |
| 493 | }}, |
| 494 | members: [ |
| 495 | {{ torn_id: 2532285, name: "MrRazorlove", flat_respect: 413.12, war_hits: 55, assists: 0, outside_hits: 1 }}, |
| 496 | {{ torn_id: 4187899, name: "BabyBubbles", flat_respect: 180.5, war_hits: 26, assists: 0, outside_hits: 0 }}, |
| 497 | {{ torn_id: 3455459, name: "MrLoki", flat_respect: 168.01, war_hits: 33, assists: 0, outside_hits: 0 }} |
| 498 | ] |
| 499 | }}; |
| 500 | |
| 501 | try {{ |
| 502 | const res = await fetch('/api/payout/compute', {{ |
| 503 | method: 'POST', |
| 504 | headers: {{ 'Content-Type': 'application/json' }}, |
| 505 | body: JSON.stringify(payload) |
| 506 | }}); |
| 507 | const data = await res.json(); |
| 508 | document.getElementById('payoutResult').innerText = JSON.stringify(data, null, 2); |
| 509 | }} catch (e) {{ |
| 510 | document.getElementById('payoutResult').innerText = 'Error: ' + e; |
| 511 | }} |
| 512 | }} |
| 513 | |
| 514 | async function runValuation() {{ |
| 515 | const r = parseFloat(document.getElementById('valRespect').value); |
| 516 | const rate = parseFloat(document.getElementById('valRate').value); |
| 517 | const a = parseFloat(document.getElementById('valArmory').value); |
| 518 | const c = parseFloat(document.getElementById('valCash').value); |
| 519 | |
| 520 | try {{ |
| 521 | const res = await fetch('/api/valuation/compute', {{ |
| 522 | method: 'POST', |
| 523 | headers: {{ 'Content-Type': 'application/json' }}, |
| 524 | body: JSON.stringify({{ respect: r, respect_rate: rate, armory_value: a, faction_cash: c }}) |
| 525 | }}); |
| 526 | const data = await res.json(); |
| 527 | document.getElementById('valResult').innerText = JSON.stringify(data, null, 2); |
| 528 | }} catch (e) {{ |
| 529 | document.getElementById('valResult').innerText = 'Error: ' + e; |
| 530 | }} |
| 531 | }} |
| 532 | |
| 533 | async function runGym() {{ |
| 534 | const stat = document.getElementById('gymStat').value; |
| 535 | const s = parseFloat(document.getElementById('gymStartStat').value); |
| 536 | const h = parseFloat(document.getElementById('gymHappy').value); |
| 537 | const e = parseFloat(document.getElementById('gymEnergy').value); |
| 538 | const d = parseFloat(document.getElementById('gymDots').value); |
| 539 | |
| 540 | try {{ |
| 541 | const res = await fetch('/api/gym/simulate', {{ |
| 542 | method: 'POST', |
| 543 | headers: {{ 'Content-Type': 'application/json' }}, |
| 544 | body: JSON.stringify({{ |
| 545 | stat: stat, |
| 546 | start_stat: s, |
| 547 | start_happy: h, |
| 548 | energy_available: e, |
| 549 | energy_per_train: 5.0, |
| 550 | gym_dots: d, |
| 551 | perk_bonuses: [] |
| 552 | }}) |
| 553 | }}); |
| 554 | const data = await res.json(); |
| 555 | document.getElementById('gymResult').innerText = JSON.stringify(data, null, 2); |
| 556 | }} catch (err) {{ |
| 557 | document.getElementById('gymResult').innerText = 'Error: ' + err; |
| 558 | }} |
| 559 | }} |
| 560 | </script> |
| 561 | </body> |
| 562 | </html>"#, status_badge = status_badge, faction_id = state.faction_id); |
| 563 | |
| 564 | Html(html) |
| 565 | } |