bmitch / churn-php

Discover files in need of refactoring.
MIT License
1.36k stars 56 forks source link

Negative Scores? #366

Open MGatner opened 2 years ago

MGatner commented 2 years ago
I was confused why I was not getting the full filesToShow when minScoreToShow was 0. It turns out some scores are coming back negative: Times Changed Complexity Score
45 1068 1
40 792 0.719
26 786 0.502
38 418 0.372
25 591 0.37
30 378 0.273
33 290 0.224
18 457 0.171
21 387 0.169
11 697 0.168
21 354 0.145
14 406 0.073
15 323 0.035
17 281 0.036
19 245 0.037
18 229 0.011
20 191 0.009
10 377 -0.012
15 250 -0.015
16 145 -0.078

I know score is a somewhat-contrived calculation based on the actual value columns... but how does a negative make sense?

villfa commented 2 years ago

Interesting.

The reason we have negative scores come from this line.

For instance, by changing the code like below we won't have negative values anymore, but the maximum score will be 1.414 (square root of 2) instead of 1.

- return \round(1 - $distanceFromTopRightCorner, 3);
+ return \round(\sqrt(2) - $distanceFromTopRightCorner, 3);

If we want to have a score between 0 and 1, a better solution would probably be to apply this formula.

MGatner commented 2 years ago

How about your alternative equation divided by 1.414?

villfa commented 2 years ago

It sounds more simple indeed 😅