2021-05-18 21:37:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Lib;
|
|
|
|
|
|
2021-08-01 13:44:08 +02:00
|
|
|
use App\Enums\LoadLevel;
|
|
|
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
|
|
2021-05-18 21:37:42 +02:00
|
|
|
class Utils
|
|
|
|
|
{
|
|
|
|
|
public static function plainToHtml(string $text)
|
|
|
|
|
{
|
|
|
|
|
$text = e($text);
|
|
|
|
|
// url replace and email replace
|
|
|
|
|
$text = preg_replace_callback(
|
2021-07-23 12:06:08 +02:00
|
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
2021-05-18 22:07:49 +02:00
|
|
|
'/(?P<email>[^\s@]+@([^\s@.,]+\.)+[^\s@.,]{2,})|(?P<user>@\w*)|(?P<url>(?:http[s]?:\/\/.)?(?:www\.)?[-a-zA-Z0-9@%._\+~#=]{2,256}\.[a-z]{2,6}\b(?:[-a-zA-Z0-9@:%_\+.~#?&\/\/=]*))/',
|
2021-05-18 21:37:42 +02:00
|
|
|
function ($matches) {
|
|
|
|
|
$match = collect($matches)->first() ?? '';
|
|
|
|
|
if (filter_var($match, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
|
return strlen($match) ? "<a href=\"mailto:$match\">$match</a>" : $match;
|
2021-05-18 22:07:49 +02:00
|
|
|
} elseif (isset($matches['user']) and strlen($matches['user'])) {
|
|
|
|
|
return sprintf(
|
|
|
|
|
'<span class="text-primary fw-bold font-weight-bold">%s</span>',
|
|
|
|
|
$matches['user']
|
|
|
|
|
);
|
2021-05-18 21:37:42 +02:00
|
|
|
} else {
|
|
|
|
|
$url = $match;
|
|
|
|
|
if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {
|
|
|
|
|
$url = sprintf('http://%s', $url);
|
|
|
|
|
}
|
2021-06-18 16:52:57 +02:00
|
|
|
$fsligthbox = self::isImageFile($url) ? 'data-fslightbox="gallery"' : '';
|
2021-06-18 15:39:19 +02:00
|
|
|
return strlen($match) ? "<a $fsligthbox href=\"$url\" target=\"_blank\">$match</a>" : $match;
|
2021-05-18 21:37:42 +02:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
$text
|
|
|
|
|
);
|
|
|
|
|
return nl2br($text);
|
|
|
|
|
}
|
2021-06-18 15:39:19 +02:00
|
|
|
|
|
|
|
|
public static function isImageFile(string $url): bool
|
|
|
|
|
{
|
|
|
|
|
$m = [];
|
2021-06-18 16:52:57 +02:00
|
|
|
return \preg_match('/(\.png|\.jpg|\.jpeg|\.gif)$/', $url, $m) === 1;
|
2021-06-18 15:39:19 +02:00
|
|
|
}
|
2021-08-01 13:44:08 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* delais 7 jours 168h
|
|
|
|
|
* travaillé 5 jours 37h
|
|
|
|
|
* temps tickets 1 jours 7.4h
|
|
|
|
|
*
|
|
|
|
|
* personnes 4 (TpP) 3.7h / semaine * prs
|
|
|
|
|
*
|
|
|
|
|
* délais moyen ticket (Dmt) 0.75h
|
|
|
|
|
*
|
|
|
|
|
* délais max attente pour 1 ticket (Dam) 7jours
|
|
|
|
|
*
|
|
|
|
|
* niveaux de charge 4: - faible
|
|
|
|
|
* - stable
|
|
|
|
|
* - élevée
|
|
|
|
|
* - saturation
|
|
|
|
|
*
|
|
|
|
|
* états tickets(Et) : - nouveaux (non traités)
|
|
|
|
|
* - en attente (charge pendante)
|
|
|
|
|
* - traités
|
|
|
|
|
*
|
|
|
|
|
* Algo : linéaire
|
|
|
|
|
*
|
|
|
|
|
* TpP : 3.7h
|
|
|
|
|
* P : 4
|
|
|
|
|
*
|
|
|
|
|
* Et(nvx) * Dam
|
|
|
|
|
*
|
|
|
|
|
* Nv Charge = (P * TpP) / (Et(nvx) * Dam) - (P * TpP) / (Et(nvx) * DmT) - (Et(att) * DmT)
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Si nv Charge < 0 => saturation
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function computeWorkload(): LoadLevel
|
|
|
|
|
{
|
|
|
|
|
$Tnew = View::shared('ticketsNew');
|
|
|
|
|
$Tprogress = View::shared('ticketsInProgress');
|
|
|
|
|
$Twaiting = View::shared('ticketsWaiting');
|
|
|
|
|
|
|
|
|
|
$worked = config('tickets.workedHoursInAWeek');
|
|
|
|
|
$workedDays = config('tickets.workedDaysInAWeek');
|
|
|
|
|
$morningWorkTime = ($worked / $workedDays / 2); // in hours
|
|
|
|
|
$workingDevsPerWeek = config('tickets.workingDevsPerWeek'); // Devs handlings tickets per week
|
|
|
|
|
$timePerWeekDev = $workingDevsPerWeek * $morningWorkTime; // Worktime per week to handle tickets
|
|
|
|
|
|
|
|
|
|
$avgTimeForTicket = config('tickets.avgTimeForTicket'); // 45min for a ticket
|
|
|
|
|
|
|
|
|
|
$todoListDelay = $Tnew * $avgTimeForTicket; // The time needed to handle new ticket (average)
|
|
|
|
|
$waitingListDelay = $Twaiting * $avgTimeForTicket; // The time needed to handle new ticket (average)
|
|
|
|
|
$progressListDelay = $Tprogress * $avgTimeForTicket; // The time needed to handle new ticket (average)
|
|
|
|
|
|
|
|
|
|
$totalTicketsDelay = $todoListDelay + $progressListDelay + $waitingListDelay;
|
|
|
|
|
$ETAForAnewTicket = $totalTicketsDelay / $timePerWeekDev; // in weeks
|
|
|
|
|
|
|
|
|
|
switch ((int)round($ETAForAnewTicket)) {
|
|
|
|
|
case LoadLevel::weak()->value:
|
|
|
|
|
case LoadLevel::stable()->value:
|
|
|
|
|
case LoadLevel::high()->value:
|
|
|
|
|
return LoadLevel::make((int)round($ETAForAnewTicket));
|
|
|
|
|
default:
|
|
|
|
|
return LoadLevel::overload();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-18 21:37:42 +02:00
|
|
|
}
|