Bug 319 - Sorting by performance do not sort the data in the correct order
Summary: Sorting by performance do not sort the data in the correct order
Status: RESOLVED FIXED
Alias: None
Product: Laptop Recommendation System
Classification: Unclassified
Component: Laptop Recommendation System (show other bugs)
Version: unspecified
Hardware: All All
: High critical
Deadline: 2019-11-17
Assignee: Matthew
URL:
Depends on:
Blocks:
 
Reported: 2019-11-28 00:16 HKT by Matthew
Modified: 2019-11-28 17:12 HKT (History)
1 user (show)

See Also:


Attachments
The 8th laptop has better spec than the 2nd laptop (167.01 KB, image/png)
2019-11-28 00:16 HKT, Matthew
Details
bad code lines (165.28 KB, image/png)
2019-11-28 00:40 HKT, Matthew
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew 2019-11-28 00:16:23 HKT
Created attachment 31 [details]
The 8th laptop has better spec than the 2nd laptop

Overview:
Sorting by performance do not sort the data in the correct order

Steps to Reproduce:
1) Input value(s) to any textfield in the recommendation panel (I inputted "Acer" in the Brand textfield)

2)Choose the Sort By Performance option

3)Press Submit button

Actual Results:
The data is sorted in incorrect order, some laptops with weaker CPU and GPU have been arranged ahead of those with stronger CPU and GPU

Expected Results:
The array list displayed should be arranged according to their hardware spec

Build Date & Hardware:
Build 2019-11-15 on Mac OS 10.14.5 & Windows 10
Comment 1 Matthew 2019-11-28 00:37:44 HKT
Debug steps:
1) reproduced the bug as mentioned

2) print out the rating index of each data (which affects the order of the data)

Observations:
Most data get the 1.0 rating from the formula we designed, so that the rating cannot separate the data far enough to obtain a result with correct order.

The following formula should generate different result but it did not
double rating1 = i5 + 1080Ti = (5*1080)/5350 = 1.0
double rating2 = i5 + 1070Ti = (5*1070)/5350 = 1.0

Suggested solution:
We should be careful of the base in the formula, the hardcoded base rating denominator 5350 is declared in integer type, so the result is always in integer. We can change the code to  

  double rating = (cpuRating * gpuRating) / 5350.0;

So that the type of variables in this formula is unified as double. It should gives out slight difference in each data for correct sorting.
Comment 2 Matthew 2019-11-28 00:40:04 HKT
Created attachment 32 [details]
bad code lines