Repository navigation
Add iter_finding_outcomes with per-denominator outcome rates - #156
Open
HemanthGangula wants to merge 1 commit into
Open
HemanthGangula wants to merge 1 commit into
HemanthGangula wants to merge 1 commit into
Conversation
Read the finding_outcomes export as typed FindingOutcomeGroup rows on the sync and async clients. Each rate divides by the denominator the export docs give it: human outcomes by external_validation_denominator, code_changed by published, post-merge outcomes by post_merge.judged. A zero denominator has no rate (OutcomeRate.value is None), never 0% or 100%. Every row is checked against the documented counts before it is yielded: all six outcomes once, published equals their sum, the human denominator equals the four human outcomes, post-merge outcomes sum to judged, and code_changed and judged stay within published. Counts must be ints (bools and floats are rejected) and timestamps timezone-aware. A bad row raises invalid-response and no group from its page is yielded, matching iter_export_pages. Unknown fields are accepted. Register the helper in the contract check.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
finding_outcomesexport docs (https://proofline.sh/docs/exports, "Read finding outcomes") say each count has to be divided by its own denominator rather than bypublished, and that a zero denominator has no rate. Today the SDK hands back raw dicts, so every caller has to get that right by hand, and dividing a human outcome bypublishedis an easy mistake that produces a plausible but wrong number.This adds
iter_finding_outcomesonProoflineClientandAsyncProoflineClient, which yields one typedFindingOutcomeGroupper row:human_rate(outcome)divides byexternal_validation_denominatorand only acceptsFIXED,CONFIRMED,ACCEPTED_RISKandDISMISSED.code_changed_rate()divides bypublished.post_merge_rate(outcome)divides bypost_merge.judged.OutcomeRatekeeps the count and its denominator together.valueisNonewhen the denominator is 0, and it prints0 of 0, no rate, never 0% or 100%.It is built on
iter_export_pages(NDJSON only, since CSV flattens the nested counts to strings), so pagination,cursor=,max_pagesand the transport retries behave exactly as they do there.group_bydefaults torepository, like the server.Row checks
Each row is checked against the documented counts before anything is yielded. A row that fails raises
ProoflineErrorwithurn:proofline:sdk:invalid-response, and no group from its page is yielded, which matches howiter_export_pagesnever yields a page with a bad cursor.publishedequals the sum of the six outcomesexternal_validation_denominatorequals the four human outcomesjudgedcode_changedandjudgedare at mostpublishedTrueand3.0are rejected, since they would pass the sums), andfrom/tocarry a timezoneUnknown fields are ignored, so new server fields don't break the parser. The
outcomesandpost_mergemappings are read-only.Choices worth a look
1 of 200 (0%). The count always comes first andvalueis exact.validation_sourcesisn't checked against each outcome's count, because the group doesn't expose it.judged" is implied by "one count per post-merge outcome" and by the docs' example rather than stated outright. If the server can ever disagree, I'm happy to drop that check.Tests
python3 scripts/check.pypasses (271 tests, ruff, mypy, contracts, wheel and sdist installs).invalid-responselimitationsare acceptedtests/http_server.py, sync and async, withcursor=forwardedgroup_byis sent, andmax_pagesends inpagination-limitscripts/contracts.pylists the new method as a client helper.