MCPcopy Create free account
hub / github.com/idank/explainshell / OptionCountSummary

Class OptionCountSummary

explainshell/extraction/report.py:59–123  ·  view source on GitHub ↗

Distribution of per-page option counts across successful extractions.

Source from the content-addressed store, hash-verified

57
58
59class OptionCountSummary(BaseModel):
60 """Distribution of per-page option counts across successful extractions."""
61
62 n: int
63 total: int
64 mean: float
65 median: float
66 p90: float
67 max: int
68 # Stable bucket order. Values are file counts.
69 buckets: dict[str, int]
70
71 @classmethod
72 def empty(cls) -> OptionCountSummary:
73 """Zero-everything summary, used when the histogram is unavailable.
74
75 Old reports written before option-count tracking existed migrate
76 to this shape rather than ``null`` so analysis tools can rely on
77 the field always being a populated struct.
78 """
79 return cls(
80 n=0,
81 total=0,
82 mean=0.0,
83 median=0.0,
84 p90=0.0,
85 max=0,
86 buckets={"0": 0, "1-5": 0, "6-15": 0, "16-50": 0, "50+": 0},
87 )
88
89 @classmethod
90 def from_counts(cls, counts: list[int]) -> OptionCountSummary:
91 """Build a summary from a list of per-file option counts.
92
93 Empty input yields :meth:`empty` rather than ``None`` — the field
94 is always present in the report.
95 """
96 if not counts:
97 return cls.empty()
98 buckets = {"0": 0, "1-5": 0, "6-15": 0, "16-50": 0, "50+": 0}
99 for c in counts:
100 if c == 0:
101 buckets["0"] += 1
102 elif c <= 5:
103 buckets["1-5"] += 1
104 elif c <= 15:
105 buckets["6-15"] += 1
106 elif c <= 50:
107 buckets["16-50"] += 1
108 else:
109 buckets["50+"] += 1
110 # statistics.quantiles requires n >= 2 data points.
111 if len(counts) >= 2:
112 p90 = statistics.quantiles(counts, n=10)[8]
113 else:
114 p90 = float(counts[0])
115 return cls(
116 n=len(counts),

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected