Skip to content

Implement Aggregate Rating Calculation for Product Reviews - #18

Open
HermanL0201 wants to merge 5 commits into
199358a8-4bbc-457d-bb74-b89ae5096bb7from
feature-product-rating-aggregate-1749188548
Open

Implement Aggregate Rating Calculation for Product Reviews#18
HermanL0201 wants to merge 5 commits into
199358a8-4bbc-457d-bb74-b89ae5096bb7from
feature-product-rating-aggregate-1749188548

Conversation

@HermanL0201

@HermanL0201 HermanL0201 commented Jun 6, 2025

Copy link
Copy Markdown
Owner

Implement Aggregate Rating Calculation for Product Reviews

Description

Task

Create a method to calculate and return average product rating

Acceptance Criteria

  • 1

  • .

  • F

  • u

  • n

  • c

  • t

  • i

  • o

  • n

  • c

  • o

  • r

  • r

  • e

  • c

  • t

  • l

  • y

  • c

  • a

  • l

  • c

  • u

  • l

  • a

  • t

  • e

  • s

  • a

  • v

  • e

  • r

  • a

  • g

  • e

  • r

  • a

  • t

  • i

  • n

  • g

  • f

  • r

  • o

  • m

  • r

  • e

  • v

  • i

  • e

  • w

  • a

  • r

  • r

  • a

  • y

  • 2

  • .

  • R

  • e

  • t

  • u

  • r

  • n

  • s

  • 0

  • f

  • o

  • r

  • e

  • m

  • p

  • t

  • y

  • r

  • e

  • v

  • i

  • e

  • w

  • a

  • r

  • r

  • a

  • y

  • s

  • 3

  • .

  • V

  • a

  • l

  • i

  • d

  • a

  • t

  • e

  • s

  • r

  • a

  • t

  • i

  • n

  • g

  • i

  • n

  • p

  • u

  • t

  • t

  • y

  • p

  • e

  • (

  • m

  • u

  • s

  • t

  • b

  • e

  • n

  • u

  • m

  • b

  • e

  • r

  • )

  • 4

  • .

  • V

  • a

  • l

  • i

  • d

  • a

  • t

  • e

  • s

  • r

  • a

  • t

  • i

  • n

  • g

  • r

  • a

  • n

  • g

  • e

  • (

  • 1

  • 5

  • )

  • 5

  • .

  • R

  • o

  • u

  • n

  • d

  • s

  • r

  • e

  • s

  • u

  • l

  • t

  • t

  • o

  • 2

  • d

  • e

  • c

  • i

  • m

  • a

  • l

  • p

  • l

  • a

  • c

  • e

  • s

  • 6

  • .

  • H

  • a

  • n

  • d

  • l

  • e

  • s

  • e

  • d

  • g

  • e

  • c

  • a

  • s

  • e

  • s

  • w

  • i

  • t

  • h

  • r

  • o

  • b

  • u

  • s

  • t

  • e

  • r

  • r

  • o

  • r

  • c

  • h

  • e

  • c

  • k

  • i

  • n

  • g

Summary of Work

This pull request implements a robust method for calculating aggregate product ratings based on user reviews.

Changes Made

  • Created calculateAggregateRating function in src/rating-utils.ts
  • Implemented comprehensive rating calculation logic
  • Added input validation for review ratings
  • Ensured edge cases are handled gracefully

Implementation Details

  • Function calculates average rating from an array of review objects
  • Validates each review rating for type and range (1-5)
  • Returns 0 for empty review arrays
  • Rounds result to 2 decimal places for precision

Validation Checks

  • Handles empty review arrays
  • Validates rating type (must be number)
  • Validates rating range (1-5)
  • Throws errors for invalid inputs
  • Prevents potential division by zero

Example Scenarios

// Valid case
calculateAggregateRating([{rating: 4}, {rating: 5}, {rating: 3}]) // Returns 4.00

// Empty array
calculateAggregateRating([]) // Returns 0

// Invalid ratings will throw errors
calculateAggregateRating([{rating: 0}]) // Throws Error
calculateAggregateRating([{rating: 'invalid'}]) // Throws Error

Notes

  • Assumes reviews are an array of objects with a rating property
  • Provides robust error handling and input validation

Changes Made

  • Created calculateAggregateRating function
  • Added input validation for ratings
  • Implemented rounding to 2 decimal places
  • Handled empty review array scenario

Tests

  • Verify average rating calculation
  • Check handling of empty review array
  • Validate rating input type
  • Validate rating range
  • Test rounding to 2 decimal places

Signatures

Staking Key

DZwmqbbKALnQYMhTLYdYeBBKVNptDMSAKQjaASJ9btgo: FUGpUH7UmF3KWafiHspSHWt5GmD9n3XLLMUNdBWyPkJmhXxzoKnvftx7SuzcHBj5iCo2DKGyFKdn64zT6d7xCyMcLbCHV44TWeVLZvRyqbLxjxPWY6RoHZhMGNMbxss93xkPahvmpKNE3GvvAJ2GKbtn5xhJv41rTVDydgE2vkVmKoJJrnaCmdCZGddP8Tnoc8UC2fSxJUECaqyVei8c76eTmNtKTs5w7toojV459fhgnRgpucBwS7X9fN6aARtbVf4JKi7snr8SK8h1BqiZn7DLkcmePNsx139fxNeRo5xcyDM7ewmetrqXyqPt8pvXPggSWPTNVjSHwukT1wzvjajbMmCTEVRXsJF4xc9PRk3bhXgknzxhw6Gcjcz9cMwd7N7PKu1wCPp5Y17bE6C1nw3Uc4GXuKyceYC

Public Key

4E3nQUGBiknkTFLJE6Htj3KKNnHzpxhNv2Jw5cvW4s7J: 2iyFWe4Y8TfAxEbtUswQTGmnDjbHVGMHPhneZR3QrKmRiU3AAJ9CnbHrKuBqkzngQ1P68hYknvtNVUuCwhxhv4MBtVPzNorhgNDnyCxLLQ8mTRr7ao7eRcmwNFjfZAA6LxSmspo7Tct84mK9PSZ6S7WsG4nqGxWhuybQDFkRSHnFR1BEnjaPNBM9mVx7P7BUY53Jcyjw34v6jiKQRAaEovFV3wzAomEmEumTt1YgF6rjeK1pyfMvxQGqpkEtRXywnAuoxgzPVdPnpSrUSHupn3Bm47C9NtKSUb9U98We4UNPh8cWYF44EoPMmkTf2db14sJ7XBd7RTq7KiQaf4j65tWWRR85YxWCC1oRvWwwkRhuuLazqLXLmQuT7JNw8FDjBLst7Y5dSvLzFAHjruYe79nufzrZNUatjoLQ

@HermanL0201 HermanL0201 changed the title [WIP] Implement Aggregate Product Rating Calculation Implement Aggregate Rating Calculation for Product Reviews Jun 6, 2025
@HermanL0201
HermanL0201 marked this pull request as ready for review June 6, 2025 05:44
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.

1 participant