diff --git a/app/Helpers/vectors.php b/app/Helpers/vectors.php index 8c5e7e0c..8ffae6c5 100644 --- a/app/Helpers/vectors.php +++ b/app/Helpers/vectors.php @@ -31,9 +31,11 @@ function percentageMatch(array $a, array $b) if ($va->length() == 0) { return 0; } - // normalize vectors - $va = $va->normalize(); - $vb = $vb->normalize(); - // compute scalar projection of a on b (dot(a, b)/len(b)) - return $va->dotProduct($vb) / $vb->length() * 100; + + // compute scalar projection of a on b (dot(a, b)/len(b)), divided by len(b) again to get percentage + try { + return min(max($va->dotProduct($vb) / $vb->length() ** 2 * 100, 10), 100); + } catch (DivisionByZeroError $e) { + return null; + } } diff --git a/resources/views/actiewijzer/result.blade.php b/resources/views/actiewijzer/result.blade.php index c3794b93..d96e1521 100755 --- a/resources/views/actiewijzer/result.blade.php +++ b/resources/views/actiewijzer/result.blade.php @@ -45,7 +45,8 @@ class="mt-10" @foreach($referentie_types as $rt)
{{$rt->title}} -  {{$rt->match_perc}}% +   + @if($rt->match_perc){{$rt->match_perc}}%@endif
@endforeach @@ -56,7 +57,7 @@ class="mt-10"

Thema's

-
+
@foreach ($themes as $t)
-

{{$rt->title}} {{$rt->match_perc}}%

+

{{$rt->title}}  + @if($rt->match_perc){{$rt->match_perc}}%@endif +

{!! filterScripts($rt->description) !!}

@if ($rt->title == config('app.actiewijzer.demonstrations_section_name'))

Demonstraties voor