Score a cost advisor on savings that actually landed
Your task
Engineers rightsizing cloud resources by hand never keep up, so an advisor agent proposes cost optimizations that a person approves. You score the agent on savings that actually landed, not on what it claims.
Write realized_savings_report(statuses, projected_savings, realized_savings, days_to_incident, incident_window_days): the report that scores the agent.
statuses(list of str): for each proposal,"applied"(approved and shipped),"proposed"or"rejected".projected_savings(list of int): the savings the agent projected for each proposal.realized_savings(list of int): how much the bill actually dropped. It may be negative.days_to_incident(list of int): days from applying the change to the next incident on that resource, or -1 if none followed.incident_window_days(int): an incident within this many days takes away a change's credit.- Index
iin each list is one proposal. Return[identified, realized, credited, acceptance_pct].
Rules:
identifiedis the sum ofprojected_savingsover every proposal.realizedis the sum ofrealized_savingsover applied proposals only. A status other than exactlyappliedadds only toidentified.creditedis likerealized, but leaves out any applied proposal whosedays_to_incidentis from 0 toincident_window_days, both ends included.acceptance_pctis the number of applied proposals times 100, divided by the number of proposals and rounded down. With no proposals it is 0.
Examples
realized_savings_report(statuses: list[str], projected_savings: list[int], realized_savings: list[int], days_to_incident: list[int], incident_window_days: int) -> list[int]Example 1
Input
realized_savings_report(["applied", "proposed", "rejected"], [1200, 800, 500], [900, 0, 0], [-1, -1, -1], 14)Output
[2500, 900, 900, 33]Example 2
Input
realized_savings_report(["applied", "applied"], [1000, 1000], [1000, 950], [3, -1], 14)Output
[2000, 1950, 950, 100]Example 3
Input
realized_savings_report(["applied", "rejected", "applied", "proposed"], [300, 900, 700, 250], [250, 0, 800, 0], [-1, -1, -1, -1], 14)Output
[2150, 1050, 1050, 50]