Fix setting of rider's current rating. Fix issues found during testing. Remove debug messages. #764
This commit is contained in:
parent
629829691c
commit
a3c875b907
5 changed files with 17 additions and 17 deletions
|
|
@ -84,7 +84,7 @@ class LoadAggregateRiderRatingsComand extends Command
|
|||
|
||||
protected function createAggregatedRiderRating($agg_rider_ratings)
|
||||
{
|
||||
error_log(print_r($agg_rider_ratings, true));
|
||||
// error_log(print_r($agg_rider_ratings, true));
|
||||
|
||||
foreach ($agg_rider_ratings as $key => $data)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1707,10 +1707,10 @@ class APIController extends Controller implements LoggedController
|
|||
$em->flush();
|
||||
|
||||
// need to update or add aggregated rider rating
|
||||
$this->updateAggregatedRiderRating($em, $rider, $rating_num);
|
||||
$average_rating = $this->updateAggregatedRiderRating($em, $rider, $rating_num);
|
||||
|
||||
// TODO: preliminary rating computation on the entity for now
|
||||
$rider->updateRatingAverage();
|
||||
$rider->updateRatingAverage($average_rating);
|
||||
$em->persist($rider);
|
||||
$em->flush();
|
||||
|
||||
|
|
@ -4837,6 +4837,7 @@ class APIController extends Controller implements LoggedController
|
|||
protected function updateAggregatedRiderRating($em, $rider, $rating_num)
|
||||
{
|
||||
$rider_id = $rider->getID();
|
||||
$agg_rating = 0;
|
||||
|
||||
// check if rider is in the the aggregated rider rating table
|
||||
$agg_rider_rating = $em->getRepository(AggregatedRiderRating::class)->findOneBy(['rider_id' => $rider_id]);
|
||||
|
|
@ -4861,7 +4862,7 @@ class APIController extends Controller implements LoggedController
|
|||
$r_rating = $agg_rider_rating->getAggregateRating();
|
||||
$r_count = $agg_rider_rating->getAggregateCount();
|
||||
|
||||
$new_count = ++$r_count;
|
||||
$new_count = $r_count + 1;
|
||||
|
||||
$agg_rating = $this->computeAggregatedRiderRating($r_rating, $rating_num, $r_count, $new_count);
|
||||
|
||||
|
|
@ -4871,6 +4872,8 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
|
||||
$em->flush();
|
||||
|
||||
return $agg_rating;
|
||||
}
|
||||
|
||||
protected function computeAggregatedRiderRating($old_rating, $new_rating, $r_count, $new_count)
|
||||
|
|
@ -4879,7 +4882,7 @@ class APIController extends Controller implements LoggedController
|
|||
$agg_comp = bcmul($old_rating, $r_count, 2);
|
||||
|
||||
$rating = bcadd($agg_comp, $new_rating, 2);
|
||||
|
||||
|
||||
$agg_rating = bcdiv($rating, $new_count, 2);
|
||||
|
||||
return $agg_rating;
|
||||
|
|
|
|||
|
|
@ -232,10 +232,10 @@ class RiderController extends ApiController
|
|||
$this->em->flush();
|
||||
|
||||
// need to update or add aggregated rider rating
|
||||
$this->updateAggregatedRiderRating($rider, $rating_num);
|
||||
$average_rating = $this->updateAggregatedRiderRating($rider, $rating_num);
|
||||
|
||||
// TODO: preliminary rating computation on the entity for now
|
||||
$rider->updateRatingAverage();
|
||||
$rider->updateRatingAverage($average_rating);
|
||||
$this->em->persist($rider);
|
||||
$this->em->flush();
|
||||
|
||||
|
|
@ -246,6 +246,7 @@ class RiderController extends ApiController
|
|||
protected function updateAggregatedRiderRating($rider, $rating_num)
|
||||
{
|
||||
$rider_id = $rider->getID();
|
||||
$agg_rating = 0;
|
||||
|
||||
// check if rider is in the the aggregated rider rating table
|
||||
$agg_rider_rating = $this->em->getRepository(AggregatedRiderRating::class)->findOneBy(['rider_id' => $rider_id]);
|
||||
|
|
@ -270,7 +271,7 @@ class RiderController extends ApiController
|
|||
$r_rating = $agg_rider_rating->getAggregateRating();
|
||||
$r_count = $agg_rider_rating->getAggregateCount();
|
||||
|
||||
$new_count = ++$r_count;
|
||||
$new_count = $r_count + 1;
|
||||
|
||||
$agg_rating = $this->computeAggregatedRiderRating($r_rating, $rating_num, $r_count, $new_count);
|
||||
|
||||
|
|
@ -280,6 +281,8 @@ class RiderController extends ApiController
|
|||
}
|
||||
|
||||
$this->em->flush();
|
||||
|
||||
return $agg_rating;
|
||||
}
|
||||
|
||||
protected function computeAggregatedRiderRating($old_rating, $new_rating, $r_count, $new_count)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class AggregatedRiderRating
|
|||
|
||||
// average rating of rider
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
* @ORM\Column(type="float")
|
||||
*/
|
||||
protected $aggregate_rating;
|
||||
|
||||
|
|
|
|||
|
|
@ -241,15 +241,9 @@ class Rider
|
|||
return $this->image_file;
|
||||
}
|
||||
|
||||
public function updateRatingAverage()
|
||||
public function updateRatingAverage($rating)
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
foreach ($this->ratings as $rating) {
|
||||
$total += $rating->getRating();
|
||||
}
|
||||
|
||||
$this->setCurrentRating(round($total / $this->ratings->count(), 2));
|
||||
$this->setCurrentRating($rating);
|
||||
}
|
||||
|
||||
public function setCurrentRating($rating)
|
||||
|
|
|
|||
Loading…
Reference in a new issue