Skip to content

Commit

Permalink
Merge pull request #323 from crf-devs/add-fixture-slot-comments
Browse files Browse the repository at this point in the history
Add fixtures slot comments
  • Loading branch information
mRoca authored Apr 18, 2020
2 parents 115e6c0 + a2d1bef commit 30f1c64
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
28 changes: 16 additions & 12 deletions src/DataFixtures/ApplicationFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ private function loadResourcesAvailabilities(ObjectManager $manager, array $reso
$resourcePartiallyAvailable = \array_slice($resourcesRandom, $index, (int) ($resourceCount * $percentPartiallyAvailable));

// Creating slots locked
$data = $this->createAvailabilities($resourceLocked, $today, AvailabilityInterface::STATUS_LOCKED);
$data = $this->createAvailabilities($resourceLocked, $today, AvailabilityInterface::STATUS_LOCKED, false, 'Raison médicale');

// Creating slots available
$data = array_merge($data, $this->createAvailabilities($resourceAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE));

// Creating slots partially available
$data = array_merge($data, $this->createAvailabilities($resourcePartiallyAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE, true));
$data = array_merge($data, $this->createAvailabilities($resourcePartiallyAvailable, $today, AvailabilityInterface::STATUS_AVAILABLE, true, 'Alpha '.random_int(1, 8)));

$insert = sprintf(
'INSERT INTO %s (id, %s, start_time, end_time, status, created_at, updated_at, planning_agent_id) VALUES %s',
'INSERT INTO %s (id, %s, start_time, end_time, status, created_at, updated_at, planning_agent_id, comment) VALUES %s',
$manager->getClassMetadata($class)->getTableName(),
UserAvailability::class === $class ? 'user_id' : 'asset_id',
implode(', ', $data)
Expand All @@ -327,7 +327,7 @@ private function loadResourcesAvailabilities(ObjectManager $manager, array $reso
$manager->getConnection()->exec(sprintf('SELECT setval(\''.$sequence.'\', %d, true)', $this->availabilitiesId));
}

private function createAvailabilities(array $objects, \DateTimeInterface $thisWeek, string $globalStatus, bool $partiallyAvailable = false): array
private function createAvailabilities(array $objects, \DateTimeInterface $thisWeek, string $globalStatus, bool $partiallyAvailable = false, string $defaultComment = ''): array
{
$data = [];

Expand Down Expand Up @@ -360,14 +360,18 @@ private function createAvailabilities(array $objects, \DateTimeInterface $thisWe
$organizationId = $this->getRandomOrganization();
}

$data[] = '('.$this->availabilitiesId++.','.
$object->getId().','.
"'".$slot->format('Y-m-d H:i:s')."',".
"'".$this->closeInterval($slot)->format('Y-m-d H:i:s')."',".
"'".$status."',".
"'".date('Y-m-d H:i:s')."',".
"'".date('Y-m-d H:i:s')."',".
($organizationId ?: 'NULL').')';
$data[] = sprintf(
"(%d,%d,'%s','%s','%s','%s','%s',%s, '%s')",
$this->availabilitiesId++,
$object->getId(),
$slot->format('Y-m-d H:i:s'),
$this->closeInterval($slot)->format('Y-m-d H:i:s'),
$status,
date('Y-m-d H:i:s'),
date('Y-m-d H:i:s'),
$organizationId ?: 'NULL',
AvailabilityInterface::STATUS_AVAILABLE !== $status ? $defaultComment : '',
);
}

$slot = $slot->add(new \DateInterval(self::SLOT_INTERVAL));
Expand Down
2 changes: 1 addition & 1 deletion src/DataFixtures/SlotAvailabilityGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class SlotAvailabilityGuesser

public function guessAvailableSlot(\DateTimeImmutable $slot): bool
{
$rand = rand(1, 100);
$rand = random_int(1, 100);
$chance = $this->getSlotChances($slot);

if ($this->availableSlotCount > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/DataFixtures/SlotBookingGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class SlotBookingGuesser

public function guessBookedSlot(\DateTimeImmutable $slot): bool
{
$rand = mt_rand(1, 100);
$rand = random_int(1, 100);

if ($this->isPreviousSlotBooked($slot)) {
if ($this->isPreviousSlotBooked()) {
if ($rand <= $this->bookedSlotPercentageWithPrevious) {
//Decreasing chances of being booked
$this->bookedSlotPercentageWithPrevious -= self::RATE_OF_BOOKED_PERCENTAGE;
Expand Down Expand Up @@ -52,7 +52,7 @@ public function resetGuesser(int $resetLastBookedSlot = 1): void
$this->bookedSlotPercentageWithPrevious = 100;
}

private function isPreviousSlotBooked(\DateTimeImmutable $slot): bool
private function isPreviousSlotBooked(): bool
{
if (0 === $this->bookedSlotCount) {
return false;
Expand Down

0 comments on commit 30f1c64

Please sign in to comment.