bulltrackers-module 1.0.607 → 1.0.608

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1413,21 +1413,33 @@ const fetchAllReviewsForPI = async (db, piId, limit = 100) => {
1413
1413
 
1414
1414
  // 2. Calculate Stats
1415
1415
  let total = 0;
1416
- const distribution = { 1:0, 2:0, 3:0, 4:0, 5:0 };
1416
+ const counts = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 };
1417
1417
 
1418
1418
  reviews.forEach(r => {
1419
1419
  const rating = r.rating || 0;
1420
1420
  total += rating;
1421
- if(distribution[rating] !== undefined) distribution[rating]++;
1421
+ if(counts[rating] !== undefined) counts[rating]++;
1422
1422
  });
1423
1423
 
1424
1424
  const count = reviews.length;
1425
- const avg = count > 0 ? (total / count).toFixed(2) : 0;
1425
+ const avg = count > 0 ? Number((total / count).toFixed(2)) : 0;
1426
+
1427
+ // Calculate percentages
1428
+ const percentages = {
1429
+ 1: count > 0 ? Number((counts[1] / count * 100).toFixed(1)) : 0,
1430
+ 2: count > 0 ? Number((counts[2] / count * 100).toFixed(1)) : 0,
1431
+ 3: count > 0 ? Number((counts[3] / count * 100).toFixed(1)) : 0,
1432
+ 4: count > 0 ? Number((counts[4] / count * 100).toFixed(1)) : 0,
1433
+ 5: count > 0 ? Number((counts[5] / count * 100).toFixed(1)) : 0
1434
+ };
1426
1435
 
1427
1436
  return {
1428
1437
  count,
1429
1438
  averageRating: avg,
1430
- distribution,
1439
+ ratingDistribution: {
1440
+ counts,
1441
+ percentages
1442
+ },
1431
1443
  reviews
1432
1444
  };
1433
1445
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.607",
3
+ "version": "1.0.608",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [