Skip to content

Same-Day Resolution Fix - Implementation Summary

Problem Statement

Previously, issues created and resolved on the same business day would return 0 business days in lead time and cycle time calculations. This caused them to be filtered out by the if lead_time > 0 condition in the KPI calculators, resulting in:

  • Velocity count mismatch: Velocity counted all completed issues, but lead/cycle time metrics excluded same-day issues
  • Incomplete metrics: Fast resolutions (which are positive!) were being ignored
  • Example: O2C team had 65 velocity but only 60 issues in lead time calculation (5 same-day issues excluded)

Solution Implemented

Changed same-day resolutions to return 0.5 business days instead of 0, with the following logic:

  1. Weekday same-day: Returns 0.5 days (e.g., Monday 9am → Monday 3pm)
  2. Weekend same-day: Returns 0.0 days (e.g., Saturday 9am → Saturday 3pm)
  3. Multi-day spans: Count actual business days between dates

Code Changes

File: src/calculators/utilities/business_days.py

Key changes: 1. Check if start and end are on same calendar day using .date() comparison 2. Return 0.5 for weekday same-day resolutions 3. Fixed weekend edge case bug where Sunday → Tuesday was incorrectly returning 0 instead of 1

# Before: Used (end_date - start_date).days which could miss business days
total_days = (end_date - start_date).days

# After: Count actual business days in range
if start_date.date() == end_date.date():
    return 0.5 if start_date.weekday() < 5 else 0.0

business_days = 0
current = start_date.date()
while current < end_date.date():
    if current.weekday() < 5:
        business_days += 1
    current += timedelta(days=1)

Additional Bug Fix

Weekend Edge Case: Found and fixed issue where issues created on weekends and resolved on weekdays were incorrectly calculated.

Example: LGMT-2834 - Created: Sunday, Nov 9, 3:06 PM - Resolved: Tuesday, Nov 11, 2:11 AM - Before: 0 business days (incorrect - Monday was missed) - After: 1 business day (correct - Monday counted)

Root cause: The old logic used (end_date - start_date).days which truncates to whole days, then subtracted weekend days from that. This caused issues when the day difference was small but spanned a weekend.

Fix: Changed to iterate through the date range and count only weekdays (Mon-Fri).

Impact Analysis

All Teams Now Match! ✅

Team Velocity Lead Time Issues Same-Day Issues Match
O2C 65 65 2
SSH 54 54 5
UAS 27 27 1
ACQREG 47 47 3
LGMT 21 21 1

Same-Day Issues by Team

O2C (2 same-day issues now included): - O2C-941, O2C-945

SSH (5 same-day issues now included): - SSH-309, SSH-308, SSH-288, SSH-287, SSH-324

UAS (1 same-day issue now included): - UAS-1047

ACQREG (3 same-day issues now included): - ACQREG-184, ACQREG-180, ACQREG-213

LGMT (1 same-day issue now included): - LGMT-2846

Impact on Metrics

Before: Same-day issues excluded (counted as 0 days, filtered out) - Lead time median/P85/average: Excluded fast resolutions - Cycle time median/P85/average: Excluded fast resolutions - Result: Metrics slightly inflated (missing the fastest issues)

After: Same-day issues included (counted as 0.5 days) - Lead time median/P85/average: Includes all resolutions - Cycle time median/P85/average: Includes all resolutions - Result: More accurate metrics that reflect true performance including fast turnarounds

Note: The impact on aggregate metrics (median, P85, average) is minimal for most teams because: 1. Same-day issues are relatively rare (1-5 per team per month) 2. The 0.5 day value is at the low end, affecting median only if you had many same-day issues 3. This fix primarily solves the counting mismatch problem, not dramatically changing metric values

Testing

Unit Tests

Added two new tests in tests/test_time_metrics.py:

  1. test_lead_time_same_day_resolution: Verifies same-day lead time returns 0.5
  2. test_cycle_time_same_day_resolution: Verifies same-day cycle time returns 0.5

All 10 tests pass ✓

Edge Case Testing

Verified the fix handles: - ✓ Weekday same-day (returns 0.5) - ✓ Weekend same-day (returns 0.0) - ✓ Sunday → Tuesday (returns 1.0, counts Monday) - ✓ Friday → Monday (returns 1.0, skips weekend) - ✓ Multi-day spans (correct business day count)

Benefits

  1. Velocity matches lead/cycle time counts: No more confusion about mismatched numbers
  2. Complete metrics: Fast resolutions are now properly included
  3. Better accuracy: Metrics reflect all completed work, not just multi-day work
  4. Fixed edge case: Weekend-spanning issues now calculated correctly
  5. Maintains days as unit: Keeps metrics easy to understand (no need for working hours)

Trade-offs

Why 0.5 days instead of 0 or 1? - 0 days: Gets filtered out (the original problem) - 1 day: Over-represents same-day work - 0.5 days: Reasonable middle ground that: - Passes the > 0 filter - Distinguishes same-day from multi-day work - Represents "partial day" work - Keeps calculation simple (no working hours complexity)

Files Modified

  1. src/calculators/utilities/business_days.py - Core calculation logic
  2. tests/test_time_metrics.py - Added same-day resolution tests

Backwards Compatibility

Fully backwards compatible

  • Existing data: No migration needed
  • Existing tests: All pass with updated logic
  • KPI calculations: Automatically recalculated with new logic
  • No API changes: Same function signatures

Recommendations

  1. Recalculate KPIs: Run python kpi_cli.py calculate to regenerate all metrics with the new logic
  2. Monitor trends: Next period's metrics will now include same-day issues
  3. Document in reports: Note that same-day resolutions count as 0.5 days in metric definitions

Future Enhancements

If more granularity is needed in the future, consider: 1. Working hours: Calculate time in hours for sub-day precision 2. Smart display: Show hours for <1 day, days for ≥1 day 3. Configurable same-day value: Allow teams to set their own same-day value (0.25, 0.5, 1.0)

For now, the 0.5 days solution provides a good balance of simplicity and accuracy.


Implementation Date: 2025-11-21 Author: Claude Code Status: ✅ Implemented and Tested