Files
adaptive-pricing/projects/coulomb-pricing/observatory/allocation.py
tegwick 0a38def5a5 Complete Economic Observatory MVP (ADAPTIVE-WP-0002)
Add file-based Bubble, Stripe, and OpenRouter importers; usage attribution,
cost allocation, pricing simulator, credit wallets, and recommendations in the
dashboard API. Document whynot-design UI workflow and archive the finished
workplan with all ten tasks marked done.
2026-06-22 23:23:31 +02:00

32 lines
1.1 KiB
Python

from __future__ import annotations
from decimal import Decimal
from .models import EconomicsSnapshot
from .usage import build_usage_summary
def build_cost_allocation(
snapshot: EconomicsSnapshot,
usage_records: list[dict],
) -> dict:
usage = build_usage_summary(usage_records, snapshot.period)
variable_ai = usage["total_ai_spend_eur"]
fixed = snapshot.monthly_infrastructure_cost
variable_processing = snapshot.monthly_payment_processing_cost
total = fixed + variable_processing + variable_ai
contribution = snapshot.monthly_revenue - total
return {
"period": snapshot.period,
"currency": snapshot.currency,
"fixed_costs_eur": fixed,
"variable_processing_eur": variable_processing,
"variable_ai_eur": variable_ai,
"total_platform_cost_eur": total,
"cost_floor_eur": snapshot.cost_per_member,
"contribution_margin_eur": contribution,
"contribution_margin_pct": snapshot.gross_margin_pct,
"cost_per_member_eur": snapshot.cost_per_member,
"active_members": snapshot.active_members,
}