Skip to content

Commit bba3b72

Browse files
author
Test User
committed
Day 73 (12:00): auto-format backend
1 parent 33a0e72 commit bba3b72

40 files changed

Lines changed: 167 additions & 195 deletions

src/backend/api/chat.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,9 +2406,7 @@ def _detect_interaction_request(
24062406
)
24072407

24082408
_GOAL_SEEK_NUMBER_RE = re.compile(
2409-
r"(?:^|[\s=:to])"
2410-
r"(?:[$€£¥]?\s*)?"
2411-
r"(\d[\d,]*(?:\.\d+)?)\s*([kmb])?\b",
2409+
r"(?:^|[\s=:to])" r"(?:[$€£¥]?\s*)?" r"(\d[\d,]*(?:\.\d+)?)\s*([kmb])?\b",
24122410
re.IGNORECASE,
24132411
)
24142412

@@ -11968,9 +11966,7 @@ def _fmt_metric(metrics_json: str | None) -> str | None:
1196811966
_wu_trend = (
1196911967
"up"
1197011968
if (_wu_change_pct or 0) > 5
11971-
else "down"
11972-
if (_wu_change_pct or 0) < -5
11973-
else "flat"
11969+
else "down" if (_wu_change_pct or 0) < -5 else "flat"
1197411970
)
1197511971

1197611972
# Per-day breakdown for the current week (7 entries)
@@ -11989,7 +11985,9 @@ def _fmt_metric(metrics_json: str | None) -> str | None:
1198911985
_wu_feature_tally: dict[str, dict[str, int]] = {}
1199011986
_wu_recent_logs = [
1199111987
lg for lg in _wu_logs if lg.created_at >= _wu_week_start
11992-
][:100] # cap to last 100 for performance
11988+
][
11989+
:100
11990+
] # cap to last 100 for performance
1199311991
for _wl in _wu_recent_logs:
1199411992
try:
1199511993
_feat_dict: dict = json.loads(_wl.input_features or "{}")
@@ -14627,9 +14625,7 @@ def _fmt_metric(metrics_json: str | None) -> str | None:
1462714625
else (
1462814626
"healthy"
1462914627
if _n_failed == 0
14630-
else "warning"
14631-
if _n_failed / _n_total < 0.1
14632-
else "critical"
14628+
else "warning" if _n_failed / _n_total < 0.1 else "critical"
1463314629
)
1463414630
)
1463514631
_wh_total_events += _n_total
@@ -14688,9 +14684,7 @@ def _fmt_metric(metrics_json: str | None) -> str | None:
1468814684
else (
1468914685
"warning"
1469014686
if any(d["status"] == "warning" for d in _wh_dep_summaries)
14691-
else "no_events"
14692-
if _wh_total_events == 0
14693-
else "healthy"
14687+
else "no_events" if _wh_total_events == 0 else "healthy"
1469414688
)
1469514689
)
1469614690
)

src/backend/api/deploy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,9 +2714,7 @@ def set_accuracy_alert(
27142714
+ (
27152715
f"drops below {thr:.0%}."
27162716
if problem_type == "classification" and thr is not None
2717-
else f"exceeds {thr:.1f}%."
2718-
if thr is not None
2719-
else ""
2717+
else f"exceeds {thr:.1f}%." if thr is not None else ""
27202718
)
27212719
if threshold_set
27222720
else "Accuracy alert disabled."

src/backend/api/projects.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ def get_portfolio(session: Session = Depends(get_session)):
158158
metric_name = (
159159
"r2"
160160
if "r2" in metrics
161-
else "accuracy"
162-
if "accuracy" in metrics
163-
else None
161+
else "accuracy" if "accuracy" in metrics else None
164162
)
165163
if metric_val is not None and (
166164
best_metric_value is None or metric_val > best_metric_value
@@ -241,9 +239,7 @@ def get_cross_project_comparison(session: Session = Depends(get_session)):
241239
metric_name = (
242240
"r2"
243241
if "r2" in metrics
244-
else "accuracy"
245-
if "accuracy" in metrics
246-
else None
242+
else "accuracy" if "accuracy" in metrics else None
247243
)
248244
if metric_val is not None and (
249245
best_metric_value is None or metric_val > best_metric_value
@@ -591,9 +587,7 @@ def _static_narrative(ctx: dict) -> str:
591587
quality = (
592588
"clean"
593589
if d["missing_pct"] < 5
594-
else "mostly complete"
595-
if d["missing_pct"] < 20
596-
else "with some gaps"
590+
else "mostly complete" if d["missing_pct"] < 20 else "with some gaps"
597591
)
598592
parts.append(
599593
f"The analysis is based on **{d['filename']}** — "

src/backend/core/advisor.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,15 @@ def _build_summary(
364364
quality = (
365365
"excellent"
366366
if pct >= 85
367-
else "good"
368-
if pct >= 70
369-
else "moderate"
370-
if pct >= 55
371-
else "limited"
367+
else "good" if pct >= 70 else "moderate" if pct >= 55 else "limited"
372368
)
373369
base = f"Your model explains {pct}% of variation in the target — {quality} predictive power."
374370
else:
375371
pct = round(primary_metric * 100)
376372
quality = (
377373
"excellent"
378374
if pct >= 90
379-
else "good"
380-
if pct >= 80
381-
else "moderate"
382-
if pct >= 70
383-
else "limited"
375+
else "good" if pct >= 80 else "moderate" if pct >= 70 else "limited"
384376
)
385377
base = f"Your model achieves {pct}% accuracy — {quality} performance."
386378

src/backend/core/deployer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,7 @@ def compute_prediction_cohort(
10431043
direction_label = (
10441044
"higher"
10451045
if top_mean > overall_mean
1046-
else "lower"
1047-
if top_mean < overall_mean
1048-
else "similar"
1046+
else "lower" if top_mean < overall_mean else "similar"
10491047
)
10501048
numeric_profile.append(
10511049
{

src/backend/core/query_engine.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ def _execute_spec(spec: dict, df: pd.DataFrame) -> tuple[pd.DataFrame | None, st
285285
strength = (
286286
"strong"
287287
if abs(corr_val) >= 0.7
288-
else "moderate"
289-
if abs(corr_val) >= 0.4
290-
else "weak"
288+
else "moderate" if abs(corr_val) >= 0.4 else "weak"
291289
)
292290
direction = "positive" if corr_val >= 0 else "negative"
293291
text = (

src/backend/core/report_generator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,7 @@ def generate_model_card_html(
403403
score_color = (
404404
"#059669"
405405
if brier_score < 0.1
406-
else "#d97706"
407-
if brier_score < 0.2
408-
else "#dc2626"
406+
else "#d97706" if brier_score < 0.2 else "#dc2626"
409407
)
410408
cal_html = f"""<h2 style="font-size:1rem;font-weight:600;color:#1e40af;margin:1.5rem 0 0.5rem">
411409
Calibration

src/backend/tests/test_accuracy_alert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def test_accuracy_alert_patterns_no_false_positives():
162162
"what is the drift score",
163163
]
164164
for phrase in non_matches:
165-
assert not _ACCURACY_ALERT_PATTERNS.search(phrase), (
166-
f"False positive: {phrase!r}"
167-
)
165+
assert not _ACCURACY_ALERT_PATTERNS.search(
166+
phrase
167+
), f"False positive: {phrase!r}"
168168

169169

170170
def test_accuracy_alert_threshold_re_extracts_percent():

src/backend/tests/test_anomaly.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,6 @@ def test_irrelevant_message_does_not_match(self):
246246
"deploy the model",
247247
]
248248
for phrase in phrases:
249-
assert not _ANOMALY_PATTERNS.search(phrase), (
250-
f"Unexpected match for: {phrase!r}"
251-
)
249+
assert not _ANOMALY_PATTERNS.search(
250+
phrase
251+
), f"Unexpected match for: {phrase!r}"

src/backend/tests/test_balance_train_chat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ def test_class_weight_emits_training_started(self, sync_client, tmp_path):
219219
pid = _setup_classification(sync_client, tmp_path)
220220
events = _chat_events(sync_client, pid, "train with class weighting")
221221
started = [e for e in events if e.get("type") == "training_started"]
222-
assert len(started) == 1, (
223-
f"Expected training_started, got: {[e.get('type') for e in events]}"
224-
)
222+
assert (
223+
len(started) == 1
224+
), f"Expected training_started, got: {[e.get('type') for e in events]}"
225225
payload = started[0]["training"]
226226
assert payload["imbalance_strategy"] == "class_weight"
227227
assert payload["problem_type"] == "classification"
@@ -256,9 +256,9 @@ def test_regression_target_no_training_started(self, sync_client, tmp_path):
256256
pid = _setup_regression(sync_client, tmp_path)
257257
events = _chat_events(sync_client, pid, "train with class weighting")
258258
started = [e for e in events if e.get("type") == "training_started"]
259-
assert len(started) == 0, (
260-
"Should not start training for regression with imbalance correction"
261-
)
259+
assert (
260+
len(started) == 0
261+
), "Should not start training for regression with imbalance correction"
262262

263263
def test_fix_imbalance_variant_works(self, sync_client, tmp_path):
264264
"""'fix the imbalance and train' phrase triggers balanced training."""

0 commit comments

Comments
 (0)