Skip to content

Refactor redundant SDG score rounding in aurora_api.py#42

Open
Tech-Psycho95 wants to merge 1 commit into
chaoss:mainfrom
Tech-Psycho95:main
Open

Refactor redundant SDG score rounding in aurora_api.py#42
Tech-Psycho95 wants to merge 1 commit into
chaoss:mainfrom
Tech-Psycho95:main

Conversation

@Tech-Psycho95
Copy link
Copy Markdown

Description

This PR addresses the issue of inefficient SDG score rounding in backend/aurora_api.py. The current implementation uses a verbose and redundant method to round scores to three decimal places, which has been refactored to use Python's built-in round() function for improved code quality.

Changes Made

  • File Modified: backend/aurora_api.py (around line 75)
  • Before: sdg_predictions[sdg_name] = float(f"{float(score):.3f}")
  • After: sdg_predictions[sdg_name] = round(score, 3)

Why This Change?

The original code was unnecessarily complex and inefficient. By switching to round(score, 3), it achieved:

  • Better Readability: The intent is immediately clear without string formatting gymnastics.
  • Improved Efficiency: Built-in functions are optimized and faster than converting floats to strings and back.
  • Enhanced Maintainability: Simpler, more idiomatic Python code that's easier to understand and modify.

Testing

  • Verified that the rounding behavior remains identical (e.g., round(0.123456, 3) produces 0.123).
  • No functional changes to the API output; scores are still rounded to 3 decimal places.
  • Ran existing tests (if any) to ensure no regressions.

Closes #41

Checklist

  • Code follows project style guidelines
  • No breaking changes
  • Tested locally
  • Documentation updated (if needed)

@Tech-Psycho95 Tech-Psycho95 marked this pull request as draft May 3, 2026 08:57
@Tech-Psycho95 Tech-Psycho95 marked this pull request as ready for review May 3, 2026 09:10
Replaced redundant float-to-string conversion with Python's built-in round() function for better readability, efficiency, and maintainability. No functional changes to output.

Co-authored-by: Copilot <copilot@github.com>
Signed-off-by: Tech-Psycho95 <shivamsingh.smn@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Refactoring redundant SDG score rounding in `aurora_api.py'

1 participant