Skip to content

Implement analytics outcomes, admin APIs, export fields, and analysis tools#9

Open
Spbd1 wants to merge 1 commit into
codex/add-research-data-export-servicefrom
codex/implement-analytics-calculations-and-api
Open

Implement analytics outcomes, admin APIs, export fields, and analysis tools#9
Spbd1 wants to merge 1 commit into
codex/add-research-data-export-servicefrom
codex/implement-analytics-calculations-and-api

Conversation

@Spbd1

@Spbd1 Spbd1 commented May 10, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide engine-level calculations for primary and secondary experimental outcomes so analytics are consistent across exports and admin views.
  • Expose per-server and cross-server analytics to the admin UI and API to support monitoring and research diagnostics.
  • Add a lightweight analysis script and documentation to produce quick treatment-effect estimates from exported CSVs.

Description

  • Added engine outcome computations in packages/engine/src/outcomes.ts and exported them from the engine index to compute per-round and per-server metrics (informalCooperationRate, contractReliability, productiveInvestmentShare, publicContributionShare, exitRate, safeAssetShare, lobbyingShare, totalOutput, treasuryBalance, activePlayers, finalWealthGini, initialParcelQualityGini, formalContractShare, averageWealth, medianWealth, and contract counts).
  • Implemented an admin analytics service apps/web/lib/services/adminAnalytics.ts that loads Prisma rows, maps to engine inputs, and returns rounds, latest, players, and parcels payloads; added GET /api/admin/servers/:serverId/analytics at apps/web/app/api/admin/servers/[serverId]/analytics/route.ts and expanded GET /api/admin/analytics/overview at apps/web/app/api/admin/analytics/overview/route.ts to include analytics summaries.
  • Reworked the admin server analytics page at apps/web/app/admin/servers/[serverId]/analytics/page.tsx to show treatment condition badges, current round stats, line charts (productive investment share, public contribution share, informal cooperation rate, contract reliability, exit rate), a bar chart (formal vs informal contracts), a histogram of final wealth, a parcel quality map, and a round outcomes table.
  • Updated research export logic in apps/web/lib/services/researchExport.ts to reuse engine outcome calculations and include the new outcome fields in round_outcomes.csv and server_summary.csv.
  • Added a simple analysis script packages/analysis/scripts/estimate_effects.py that reads exported CSVs (or ZIP) and runs quick OLS regressions of the form outcome ~ high_inequality + uncertainty + interaction, writing a Markdown report, and added docs/analysis-plan.md documenting outcomes, treatment design, regression model, clustering warning, and limitations.

Testing

  • Ran git diff --check with no problems reported.
  • Successfully syntax-checked the Python helper with python3 -m py_compile packages/analysis/scripts/estimate_effects.py and executed python3 packages/analysis/scripts/estimate_effects.py <temp-csv-dir> -o <temp-csv-dir>/report.md to produce a sample Markdown report (succeeded).
  • Attempted TypeScript typechecks (pnpm --filter @parcel-society/engine typecheck and pnpm --filter @parcel-society/web typecheck) but they could not complete in this environment because workspace Node dependencies were unavailable and pnpm install failed due to external registry access restrictions (npm 403), so full TS checks were not run here.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant