Code Quality Improvements: Logging, Constants, Docs & Cleanup - #20
Merged
Merged
Conversation
#12, #14, #16, #18) This commit implements four code quality improvements to enhance maintainability, readability, and professionalism of the codebase. ## Changes Made ### Issue #12: Remove Duplicate Utility Functions (HIGH PRIORITY) - **Removed** 69 lines of duplicate code from `analysis_dataset.py`: - `calculate_limits()` - already exists in `objects.py` - `c4()`, `b3()`, `b4()` - statistical helper functions - `detect_beyond_limits()` - limit detection logic - **Result**: Single source of truth for all utility functions in `objects.py` - **Impact**: Eliminates maintenance burden and potential divergence ### Issue #14: Replace print() with Proper Logging (MEDIUM PRIORITY) - **Added** module-level logger: `logger = logging.getLogger(__name__)` - **Replaced** 33+ print() statements with appropriate logging levels: - `logger.debug()` - 25 instances (data inspection, flow tracing) - `logger.info()` - 5 instances (important operations like zero-centering) - `logger.warning()` - 3 instances (limitations, edge cases) - **Benefits**: - Professional logging output - Configurable verbosity levels - Better debugging in production - No performance impact when logging disabled ### Issue #16: Replace Magic Numbers with Named Constants (MEDIUM PRIORITY) - **Added** well-documented statistical constants in `objects.py`: ```python SIGMA_MULTIPLIER = 3 # Standard 3-sigma control limits IMR_LIMIT_MULTIPLIER = 2.66 # E2 constant (n=2 moving range) R_UPPER_LIMIT_MULTIPLIER = 3.268 # D4 constant (n=2 range) ``` - **Updated** 8 occurrences of magic numbers: - `calculate_limits()`: Xbar, IMR, and R calculations - `b3()` and `b4()`: S chart limit calculations - **Benefits**: - Self-documenting code - Easy to verify correctness - Centralized modification point - References to statistical theory included ### Issue #18: Document Sampling Design State Logic (MEDIUM PRIORITY) - **Enhanced** `__calculate_sampling_design_state()` docstring with: - Clear explanation of SDS 0, 1, 2 (currently implemented) - Explicit list of SDS 3-6 (not yet implemented) - Return value documentation - Usage notes and statistical references - **Benefits**: - Users understand current capabilities - Clear roadmap for future enhancements - No misleading documentation ## Impact Summary ### Code Quality Metrics - **Lines removed**: 123 (duplicates + print statements) - **Lines added**: 293 (logging, constants, documentation) - **Net change**: +170 lines (more documentation, better structure) ### Benefits - ✅ **Better maintainability**: Single source of truth for utilities - ✅ **Professional logging**: Configurable debug output - ✅ **Self-documenting code**: Named constants with references - ✅ **Accurate documentation**: Clear about what's implemented - ✅ **All tests passing**: 27/27 tests pass ✓ ## Testing ```bash pytest tests/ -v # ============================== 27 passed in 0.75s ============================== ``` All existing tests pass without modification, confirming backward compatibility. ## Files Modified - `analysis_dataset.py`: Logging, removed duplicates, enhanced docs - `objects.py`: Added statistical constants, removed magic numbers Closes #12 Closes #14 Closes #16 Closes #18 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
21 tasks
cnicholas
added a commit
that referenced
this pull request
Sep 1, 2026
#12, #14, #16, #18) (#20) This commit implements four code quality improvements to enhance maintainability, readability, and professionalism of the codebase. ## Changes Made ### Issue #12: Remove Duplicate Utility Functions (HIGH PRIORITY) - **Removed** 69 lines of duplicate code from `analysis_dataset.py`: - `calculate_limits()` - already exists in `objects.py` - `c4()`, `b3()`, `b4()` - statistical helper functions - `detect_beyond_limits()` - limit detection logic - **Result**: Single source of truth for all utility functions in `objects.py` - **Impact**: Eliminates maintenance burden and potential divergence ### Issue #14: Replace print() with Proper Logging (MEDIUM PRIORITY) - **Added** module-level logger: `logger = logging.getLogger(__name__)` - **Replaced** 33+ print() statements with appropriate logging levels: - `logger.debug()` - 25 instances (data inspection, flow tracing) - `logger.info()` - 5 instances (important operations like zero-centering) - `logger.warning()` - 3 instances (limitations, edge cases) - **Benefits**: - Professional logging output - Configurable verbosity levels - Better debugging in production - No performance impact when logging disabled ### Issue #16: Replace Magic Numbers with Named Constants (MEDIUM PRIORITY) - **Added** well-documented statistical constants in `objects.py`: ```python SIGMA_MULTIPLIER = 3 # Standard 3-sigma control limits IMR_LIMIT_MULTIPLIER = 2.66 # E2 constant (n=2 moving range) R_UPPER_LIMIT_MULTIPLIER = 3.268 # D4 constant (n=2 range) ``` - **Updated** 8 occurrences of magic numbers: - `calculate_limits()`: Xbar, IMR, and R calculations - `b3()` and `b4()`: S chart limit calculations - **Benefits**: - Self-documenting code - Easy to verify correctness - Centralized modification point - References to statistical theory included ### Issue #18: Document Sampling Design State Logic (MEDIUM PRIORITY) - **Enhanced** `__calculate_sampling_design_state()` docstring with: - Clear explanation of SDS 0, 1, 2 (currently implemented) - Explicit list of SDS 3-6 (not yet implemented) - Return value documentation - Usage notes and statistical references - **Benefits**: - Users understand current capabilities - Clear roadmap for future enhancements - No misleading documentation ## Impact Summary ### Code Quality Metrics - **Lines removed**: 123 (duplicates + print statements) - **Lines added**: 293 (logging, constants, documentation) - **Net change**: +170 lines (more documentation, better structure) ### Benefits - ✅ **Better maintainability**: Single source of truth for utilities - ✅ **Professional logging**: Configurable debug output - ✅ **Self-documenting code**: Named constants with references - ✅ **Accurate documentation**: Clear about what's implemented - ✅ **All tests passing**: 27/27 tests pass ✓ ## Testing ```bash pytest tests/ -v # ============================== 27 passed in 0.75s ============================== ``` All existing tests pass without modification, confirming backward compatibility. ## Files Modified - `analysis_dataset.py`: Logging, removed duplicates, enhanced docs - `objects.py`: Added statistical constants, removed magic numbers Closes #12 Closes #14 Closes #16 Closes #18 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
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.
Summary
This PR addresses Issues #12, #14, #16, and #18, implementing four targeted code quality improvements that enhance maintainability, professionalism, and developer experience.
Changes
🧹 Issue #12: Remove Duplicate Utility Functions (HIGH PRIORITY)
Problem: Five utility functions were duplicated between
analysis_dataset.pyandobjects.py, creating a maintenance burden and risk of divergence.Solution:
analysis_dataset.pycalculate_limits()- Control limit calculationsc4()- Bias constant for Xbar/S chartsb3(),b4()- S chart limit multipliersdetect_beyond_limits()- Point detection logicobjects.pyobj.calculate_limits()patternImpact: Eliminates risk of bugs being fixed in one place but not the other
📝 Issue #14: Replace print() with Proper Logging (MEDIUM PRIORITY)
Problem: 33+
print()statements scattered throughout production code made debugging unprofessional and uncontrollable.Solution:
logger = logging.getLogger(__name__)Examples:
Benefits:
🔢 Issue #16: Replace Magic Numbers with Named Constants (MEDIUM PRIORITY)
Problem: Statistical constants (2.66, 3.268, 3) appeared throughout code with no explanation of their origin or purpose.
Solution:
objects.py:calculate_limits()- Xbar, IMR, R calculationsb3(),b4()- S chart calculationsBefore:
After:
Benefits:
📚 Issue #18: Document Sampling Design State Logic (MEDIUM PRIORITY)
Problem: Docstring claimed to handle SDS 1-6 but only SDS 1-2 were implemented, misleading users.
Solution:
__calculate_sampling_design_state()docstring with:Before: Misleading - claimed SDS 1-6 support
After: Accurate - clearly states SDS 0-2 only, with roadmap for 3-6
Benefits:
Impact Summary
Metrics
analysis_dataset.py,objects.py)Quality Improvements
Testing
pytest tests/ -v # ============================== 27 passed in 0.75s ==============================All existing tests pass without modification, confirming zero breaking changes.
Checklist
Related Issues
Closes #12
Closes #14
Closes #16
Closes #18
🤖 Generated with Claude Code