ldc-supportweb/app/Lib/Utils.php
2022-03-29 18:18:56 +02:00

118 lines
4.3 KiB
PHP

<?php
namespace App\Lib;
use App\Enums\LoadLevel;
use Illuminate\Support\Facades\View;
class Utils
{
public static function plainToHtml(string $text)
{
$text = e($text);
// url replace and email replace
$text = preg_replace_callback(
// phpcs:ignore Generic.Files.LineLength.TooLong
'/(?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@:%_\+.~#?&\/\/=]*))/',
function ($matches) {
$match = collect($matches)->first() ?? '';
if (filter_var($match, FILTER_VALIDATE_EMAIL)) {
return strlen($match) ? "<a href=\"mailto:$match\">$match</a>" : $match;
} elseif (isset($matches['user']) and strlen($matches['user'])) {
return sprintf(
'<span class="text-primary fw-bold font-weight-bold">%s</span>',
$matches['user']
);
} else {
$url = $match;
if (\strpos($url, 'http') === false and \strpos($url, 'https') === false) {
$url = sprintf(
'%s://%s',
config('app.env') !== 'local' ? 'https' : 'http',
$url
);
}
$fsligthbox = self::isImageFile($url) ? 'data-fslightbox="gallery"' : '';
return strlen($match) ? "<a $fsligthbox href=\"$url\" target=\"_blank\">$match</a>" : $match;
}
},
$text
);
return nl2br($text);
}
public static function isImageFile(string $url): bool
{
$m = [];
return \preg_match('/(\.png|\.jpg|\.jpeg|\.gif)$/', $url, $m) === 1;
}
/**
* 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();
}
}
}