/** * @param Request $request * @param Created $payload */ public function created(Request $request, Created $payload) { $serializer = Routine::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $document = new Document($resource); return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]); }
private function analyzeRoutine(Routine $routine, PerformanceStatistic $statistic, $target) { $sum = 0; $min = 30; $max = 0; $scores = $routine->getPerformanceScores()->count(); $values = []; foreach ($routine->getPerformanceScores() as $score) { $method = 'get' . $target; $val = $score->{$method}(); $min = min($min, $val); $max = max($max, $val); $sum += $val; $values[] = $val; } $avg = $sum / $scores; $statistic->setAverage($avg); $statistic->setMin($min); $statistic->setMax($max); $statistic->setRange(abs($max - $min)); // median sort($values); if ($scores % 2 == 0) { $lower = floor($scores / 2); $upper = ceil($scores / 2); $md = ($values[$lower] + $values[$upper]) / 2; } else { $md = $values[ceil($scores / 2)]; } $statistic->setMedian($md); // sd + variance $sum = 0; foreach ($routine->getPerformanceScores() as $score) { $method = 'get' . $target; $sum += pow($val - $avg, 2); } $v = 1 / ($scores - 1) * $sum; $sd = sqrt($v); $statistic->setVariance($v); $statistic->setStandardDeviation($sd); $statistic->setVariabilityCoefficient($sd / $avg * 100); $statistic->save(); return $statistic; }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = PerformanceScore::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['routine', 'judge'])); $resource = $resource->fields($params->getFields(['performance-score' => PerformanceScore::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = PerformanceStatistic::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['events', 'startgroups', 'routine'])); $resource = $resource->fields($params->getFields(['performance-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'event' => Event::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = Routine::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['startgroup', 'performance-total-statistic', 'performance-execution-statistic', 'performance-choreography-statistic', 'performance-music-and-timing-statistic', 'performance-scores'])); $resource = $resource->fields($params->getFields(['routine' => Routine::getSerializer()->getFields(), 'startgroup' => Startgroup::getSerializer()->getFields(), 'performance-total-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-execution-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-choreography-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-music-and-timing-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-score' => PerformanceScore::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = Startgroup::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['competition', 'event', 'performance-total-statistic', 'performance-execution-statistic', 'performance-choreography-statistic', 'performance-music-and-timing-statistic', 'routines', 'judges', 'routines.performance-total-statistic', 'routines.performance-execution-statistic', 'routines.performance-choreography-statistic', 'routines.performance-music-and-timing-statistic', 'routines.performance-scores', 'routines.performance-scores.judge'])); $resource = $resource->fields($params->getFields(['startgroup' => Startgroup::getSerializer()->getFields(), 'competition' => Competition::getSerializer()->getFields(), 'event' => Event::getSerializer()->getFields(), 'performance-total-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-execution-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-choreography-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-music-and-timing-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = PerformanceScore::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['routine', 'judge'])); $resource = $resource->fields($params->getFields(['performance-score' => PerformanceScore::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()])); $document = new Document($resource); // meta $document->setMeta(['total' => $data->getNbResults(), 'first' => $data->getFirstPage(), 'next' => $data->getNextPage(), 'previous' => $data->getPreviousPage(), 'last' => $data->getLastPage()]); // return response return new JsonResponse($document->toArray()); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = Startgroup::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['competition', 'event', 'performance-total-statistic', 'performance-execution-statistic', 'performance-choreography-statistic', 'performance-music-and-timing-statistic', 'routines', 'judges', 'routines.performance-total-statistic', 'routines.performance-execution-statistic', 'routines.performance-choreography-statistic', 'routines.performance-music-and-timing-statistic', 'routines.performance-scores', 'routines.performance-scores.judge'])); $resource = $resource->fields($params->getFields(['startgroup' => Startgroup::getSerializer()->getFields(), 'competition' => Competition::getSerializer()->getFields(), 'event' => Event::getSerializer()->getFields(), 'performance-total-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-execution-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-choreography-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'performance-music-and-timing-statistic' => PerformanceStatistic::getSerializer()->getFields(), 'routine' => Routine::getSerializer()->getFields(), 'judge' => Judge::getSerializer()->getFields()])); $document = new Document($resource); // meta $document->setMeta(['total' => $data->getNbResults(), 'first' => $data->getFirstPage(), 'next' => $data->getNextPage(), 'previous' => $data->getPreviousPage(), 'last' => $data->getLastPage()]); // return response return new JsonResponse($document->toArray()); }
/** * @param mixed $model * @return Relationship */ public function routine($model) { $serializer = Routine::getSerializer(); $id = $serializer->getId($model->getRoutine()); if ($id !== null) { $relationship = new Relationship(new Resource($model->getRoutine(), $serializer)); $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]); return $this->addRelationshipSelfLink($relationship, $model, 'routine'); } return null; }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aRoutine) { $this->aRoutine->removeScore($this); } if (null !== $this->aJudge) { $this->aJudge->removeScore($this); } $this->id = null; $this->routine_id = null; $this->judge_id = null; $this->total = null; $this->descendant_class = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * @param Request $request * @param Found $payload */ public function read(Request $request, Found $payload) { $serializer = Routine::getSerializer(); $relationship = $serializer->performanceMusicAndTimingStatistic($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * @param ChildRoutine $routineRelatedByPerformanceMusicAndTimingStatisticId The ChildRoutine object to add. */ protected function doAddRoutineRelatedByPerformanceMusicAndTimingStatisticId(ChildRoutine $routineRelatedByPerformanceMusicAndTimingStatisticId) { $this->collRoutinesRelatedByPerformanceMusicAndTimingStatisticId[] = $routineRelatedByPerformanceMusicAndTimingStatisticId; $routineRelatedByPerformanceMusicAndTimingStatisticId->setPerformanceMusicAndTimingStatistic($this); }
/** * Exclude object from result * * @param ChildRoutine $routine Object to remove from the list of results * * @return $this|ChildRoutineQuery The current query, for fluid interface */ public function prune($routine = null) { if ($routine) { $this->addUsingAlias(RoutineTableMap::COL_ID, $routine->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Filter the query by a related \iuf\junia\model\Routine object * * @param \iuf\junia\model\Routine|ObjectCollection $routine the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildPerformanceStatisticQuery The current query, for fluid interface */ public function filterByRoutineRelatedByPerformanceMusicAndTimingStatisticId($routine, $comparison = null) { if ($routine instanceof \iuf\junia\model\Routine) { return $this->addUsingAlias(PerformanceStatisticTableMap::COL_ID, $routine->getPerformanceMusicAndTimingStatisticId(), $comparison); } elseif ($routine instanceof ObjectCollection) { return $this->useRoutineRelatedByPerformanceMusicAndTimingStatisticIdQuery()->filterByPrimaryKeys($routine->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByRoutineRelatedByPerformanceMusicAndTimingStatisticId() only accepts arguments of type \\iuf\\junia\\model\\Routine or Collection'); } }
/** * Filter the query by a related \iuf\junia\model\Routine object * * @param \iuf\junia\model\Routine|ObjectCollection $routine The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @throws \Propel\Runtime\Exception\PropelException * * @return ChildPerformanceScoreQuery The current query, for fluid interface */ public function filterByRoutine($routine, $comparison = null) { if ($routine instanceof \iuf\junia\model\Routine) { return $this->addUsingAlias(PerformanceScoreTableMap::COL_ROUTINE_ID, $routine->getId(), $comparison); } elseif ($routine instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(PerformanceScoreTableMap::COL_ROUTINE_ID, $routine->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByRoutine() only accepts arguments of type \\iuf\\junia\\model\\Routine or Collection'); } }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $serializer = Routine::getSerializer(); $relationship = $serializer->performanceScores($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * @param mixed $model * @return Relationship */ public function routines($model) { $relationship = new Relationship(new Collection($model->getRoutines(), Routine::getSerializer())); return $this->addRelationshipSelfLink($relationship, $model, 'routine'); }
/** * Updates a Routine with the given idand the provided data * * @param mixed $id * @param mixed $data * @return PayloadInterface */ public function update($id, $data) { // find $model = $this->get($id); if ($model === null) { return new NotFound(['message' => 'Routine not found.']); } // hydrate $serializer = Routine::getSerializer(); $model = $serializer->hydrate($model, $data); // validate $validator = $this->getValidator(); if ($validator !== null && !$validator->validate($model)) { return new NotValid(['errors' => $validator->getValidationFailures()]); } // dispatch $event = new RoutineEvent($model); $dispatcher = $this->getServiceContainer()->getDispatcher(); $dispatcher->dispatch(RoutineEvent::PRE_UPDATE, $event); $dispatcher->dispatch(RoutineEvent::PRE_SAVE, $event); $rows = $model->save(); $dispatcher->dispatch(RoutineEvent::POST_UPDATE, $event); $dispatcher->dispatch(RoutineEvent::POST_SAVE, $event); $payload = ['model' => $model]; if ($rows === 0) { return new NotUpdated($payload); } return new Updated($payload); }
/** * Filter the query by a related \iuf\junia\model\Routine object * * @param \iuf\junia\model\Routine|ObjectCollection $routine the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildStartgroupQuery The current query, for fluid interface */ public function filterByRoutine($routine, $comparison = null) { if ($routine instanceof \iuf\junia\model\Routine) { return $this->addUsingAlias(StartgroupTableMap::COL_ID, $routine->getStartgroupId(), $comparison); } elseif ($routine instanceof ObjectCollection) { return $this->useRoutineQuery()->filterByPrimaryKeys($routine->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByRoutine() only accepts arguments of type \\iuf\\junia\\model\\Routine or Collection'); } }
/** * @param ChildRoutine $routine The ChildRoutine object to add. */ protected function doAddRoutine(ChildRoutine $routine) { $this->collRoutines[] = $routine; $routine->setStartgroup($this); }
/** * Clears the current object, sets all attributes to their default values and removes * outgoing references as well as back-references (from other objects to this one. Results probably in a database * change of those foreign objects when you call `save` there). */ public function clear() { if (null !== $this->aScore) { $this->aScore->removePerformanceScore($this); } if (null !== $this->aRoutine) { $this->aRoutine->removePerformanceScore($this); } if (null !== $this->aJudge) { $this->aJudge->removePerformanceScore($this); } $this->execution = null; $this->choreography = null; $this->music_and_timing = null; $this->id = null; $this->routine_id = null; $this->judge_id = null; $this->total = null; $this->alreadyInSave = false; $this->clearAllReferences(); $this->resetModified(); $this->setNew(true); $this->setDeleted(false); }
/** * * @param string $id * @return Routine */ private function getRoutine($id) { if (!$this->routines->has($id)) { $routine = new Routine(); $routine->setName('Routine #' . $id); $this->routines->set($id, $routine); } return $this->routines->get($id); }
/** * @param Request $request * @param Found $payload */ public function read(Request $request, Found $payload) { $serializer = Routine::getSerializer(); $relationship = $serializer->startgroup($payload->getModel()); return new JsonResponse($relationship->toArray()); }