Skip to content

Refactor recommender scoring weights and add test#173

Merged
komalharshita merged 1 commit into
komalharshita:mainfrom
EHEGUY:refactor/scoring-weights
May 17, 2026
Merged

Refactor recommender scoring weights and add test#173
komalharshita merged 1 commit into
komalharshita:mainfrom
EHEGUY:refactor/scoring-weights

Conversation

@EHEGUY
Copy link
Copy Markdown
Contributor

@EHEGUY EHEGUY commented May 16, 2026

Description

This PR refactors the recommendation engine's scoring logic by consolidating the module-level weight constants (WEIGHT_SKILL, WEIGHT_LEVEL, WEIGHT_INTEREST, WEIGHT_TIME) into a single SCORING_WEIGHTS dictionary. It also updates score_single_project() to reference this new structure, improving overall code organization and maintainability.

Additionally, a unit test has been added to verify the integrity of the new dictionary.

Changes Made

  • utils/recommender.py: Replaced individual weight constants with the SCORING_WEIGHTS dictionary and updated downstream variable references.
  • tests/test_basic.py: Added test_scoring_weights_has_all_keys to ensure all four required keys (skill, level, interest, time) remain present.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@EHEGUY is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting your first pull request to DevPath.

Before review:

  • Complete the PR template fully
  • Ensure all tests pass
  • Link your PR to an issue
  • Keep changes scoped to the issue

A maintainer will review your contribution soon.

@EHEGUY
Copy link
Copy Markdown
Contributor Author

EHEGUY commented May 16, 2026

Summary [required]

This PR centralizes the recommendation scoring weights into a single SCORING_WEIGHTS dictionary in utils/recommender.py. This refactor improves the maintainability of the codebase by consolidating the separate weight constants into one organized structure, making future configuration changes easier to manage. It also introduces a unit test to verify that the scoring configuration contains all expected fields.

Related Issue [required]

Closes #173

Type of Change [required]

  • Bug fix — resolves a broken behaviour
  • Feature — adds new functionality
  • Data — adds new projects to data/projects.json
  • Documentation — updates docs, README, or code comments only
  • Style — CSS or visual changes only, no logic change
  • Refactor — restructures code without changing behaviour
  • Test — adds or updates tests

What Was Changed [required]

File Change made
utils/recommender.py Consolidated individual WEIGHT_* constants into a single SCORING_WEIGHTS dictionary and updated scoring logic to reference it.
tests/test_basic.py Added test_scoring_weights_has_all_keys unit test to verify that the SCORING_WEIGHTS dictionary contains exactly the expected keys (skill, level, interest, time).

How to Test This PR [required]

  1. Clone this branch: git checkout refactor/scoring-weights
  2. Install dependencies: pip install -r requirements.txt
  3. Run the app: python app.py
  4. Open http://127.0.0.1:5000 and verify that project recommendations are still functioning.
  5. Run the tests: python tests/test_basic.py

Expected test output:

28 passed, 0 failed out of 28 tests

Test Results [required]

  PASS  test_projects_json_loads
  PASS  test_each_project_has_required_fields
  PASS  test_find_project_by_id_found
  PASS  test_find_project_by_id_missing
  PASS  test_parse_skills_basic
  PASS  test_parse_skills_empty_string
  PASS  test_parse_skills_single_entry
  PASS  test_score_single_project_full_match
  PASS  test_score_single_project_no_match
  PASS  test_get_recommendations_returns_results
  PASS  test_get_recommendations_max_three
  PASS  test_get_recommendations_no_match_returns_empty
  PASS  test_get_recommendations_result_format
  PASS  test_validate_all_valid
  PASS  test_validate_missing_skills
  PASS  test_validate_missing_level
  PASS  test_validate_missing_interest
  PASS  test_validate_missing_time
  PASS  test_validate_all_missing
  PASS  test_home_route
  PASS  test_recommend_api_valid
  PASS  test_recommend_api_missing_field
  PASS  test_recommend_api_empty_body
  PASS  test_project_detail_found
  PASS  test_project_detail_not_found
  PASS  test_view_code_found
  PASS  test_download_code_found
  PASS  test_scoring_weights_has_all_keys

28 passed, 0 failed out of 28 tests

Self-Review Checklist [required]

  • I have read CONTRIBUTING.md and followed all guidelines
  • My branch name follows the convention: feat/, fix/, docs/, data/, style/, test/
  • I have run python tests/test_basic.py and all 28 tests pass
  • I have run flake8 . locally and there are no errors
  • I have not introduced any print() or console.log() debug statements
  • Every new function I wrote has a docstring
  • I have not modified files outside the scope of the linked issue

Notes for Reviewer

None

Copy link
Copy Markdown
Owner

@komalharshita komalharshita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution — this is a clean and meaningful refactor.

Centralizing the recommendation scoring weights into a single SCORING_WEIGHTS dictionary improves maintainability and makes future configuration changes easier to manage. The added unit test is also a good addition and fits the scope of the PR well.

Before this can be merged, please make the following updates:

  1. Link the PR to a related issue using:
Closes #issue_number
  1. Please update the PR description to properly follow the repository PR template, including:
  • issue reference,
  • testing details,
  • completed checklist sections.

Once these contribution-process updates are completed, the PR should be good to merge.

@EHEGUY
Copy link
Copy Markdown
Contributor Author

EHEGUY commented May 16, 2026

Thank you for the contribution — this is a clean and meaningful refactor.

Centralizing the recommendation scoring weights into a single SCORING_WEIGHTS dictionary improves maintainability and makes future configuration changes easier to manage. The added unit test is also a good addition and fits the scope of the PR well.

Before this can be merged, please make the following updates:

1. Link the PR to a related issue using:
Closes #issue_number
2. Please update the PR description to properly follow the repository PR template, including:


* issue reference,

* testing details,

* completed checklist sections.

Once these contribution-process updates are completed, the PR should be good to merge.

Thank you @komalharshita for the review and the positive feedback on the refactor!

I have updated the PR description to fully follow the repository's template. The description now includes:

The issue reference (Closes #173)
The testing details and exact test output (all 28 tests passing)
The completed self-review checklist
Please let me know if there's anything else needed before this can be merged!

@komalharshita
Copy link
Copy Markdown
Owner

Approved for merge!

@komalharshita komalharshita merged commit 85bafc0 into komalharshita:main May 17, 2026
8 of 9 checks passed
@EHEGUY EHEGUY deleted the refactor/scoring-weights branch May 17, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants