travelling hours between devis location in a journey in thanato statistic
This commit is contained in:
parent
7f2632c175
commit
bc40f97d6a
@ -4,5 +4,5 @@ declare(strict_types=1);
|
|||||||
namespace OCA\Gestion\Constants;
|
namespace OCA\Gestion\Constants;
|
||||||
abstract class GeoConstant
|
abstract class GeoConstant
|
||||||
{
|
{
|
||||||
const DRIVING_MODE = "driving";
|
const DRIVING_MODE = "drive";
|
||||||
}
|
}
|
||||||
@ -2371,39 +2371,13 @@ class Bdd {
|
|||||||
return $devis;
|
return $devis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDistanceTotalByDevisIdList(array $devisIdList){
|
public function getRouteLinesByDevisIdList(array $devisIdList){
|
||||||
$ligneTrajetList = $this->getLigneTrajetsByDevisIdList($devisIdList);
|
|
||||||
$distanceTotal = $this->getLigneTrajetsListDistance($ligneTrajetList);
|
|
||||||
return $distanceTotal;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLigneTrajetsListDistance(array $ligneTrajetList){
|
|
||||||
$distanceCumul = 0;
|
|
||||||
$last_point = NULL;
|
|
||||||
for ($i=0; $i < sizeof($ligneTrajetList); $i++) {
|
|
||||||
$currentDistance = 0;
|
|
||||||
if($ligneTrajetList[$i]['lieu_id'] != NULL){
|
|
||||||
$last_point = $ligneTrajetList[$i];
|
|
||||||
}
|
|
||||||
if($last_point['lieu_id'] != NULL && $ligneTrajetList[$i+1]['lieu_id'] != NULL){
|
|
||||||
$currentDistance = $this->calcul_distance(
|
|
||||||
floatval(value: $last_point['latitude']),
|
|
||||||
floatval($last_point['longitude']),
|
|
||||||
floatval($ligneTrajetList[$i+1]['latitude']),
|
|
||||||
floatval($ligneTrajetList[$i+1]['longitude'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$distanceCumul += $currentDistance;
|
|
||||||
}
|
|
||||||
return $distanceCumul;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getLigneTrajetsByDevisIdList(array $devisIdList){
|
|
||||||
if(empty($devisIdList)){
|
if(empty($devisIdList)){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIdList), '?'));
|
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIdList), '?'));
|
||||||
$sql = "SELECT ligne_trajet.id, ligne_trajet.rang, ligne_trajet.id_nextcloud, ligne_trajet.date, ligne_trajet.user_id, ligne_trajet.commentaire, ligne_trajet.source,
|
$sql = "SELECT ligne_trajet.id, ligne_trajet.rang, ligne_trajet.id_nextcloud, ligne_trajet.date,
|
||||||
|
ligne_trajet.user_id, ligne_trajet.commentaire, ligne_trajet.source,
|
||||||
lieu.id as lieu_id, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude
|
lieu.id as lieu_id, lieu.nom as lieu, lieu.latitude as latitude, lieu.longitude as longitude
|
||||||
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
|
FROM (".$this->tableprefix."ligne_trajet as ligne_trajet
|
||||||
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id)
|
LEFT JOIN ".$this->tableprefix."lieu as lieu on ligne_trajet.id_lieu = lieu.id)
|
||||||
|
|||||||
@ -43,10 +43,14 @@ class ExportThanatoStatisticService {
|
|||||||
/** @var IRootFolder */
|
/** @var IRootFolder */
|
||||||
private $rootFolder;
|
private $rootFolder;
|
||||||
|
|
||||||
|
private $geoService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Bdd $gestionBdd,
|
Bdd $gestionBdd,
|
||||||
LoggerInterface $logger,
|
LoggerInterface $logger,
|
||||||
IRootFolder $rootFolder) {
|
IRootFolder $rootFolder,
|
||||||
|
GeoService $geoService) {
|
||||||
|
$this->geoService = $geoService;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->gestionBdd = $gestionBdd;
|
$this->gestionBdd = $gestionBdd;
|
||||||
@ -109,6 +113,7 @@ class ExportThanatoStatisticService {
|
|||||||
'HEURES TOTAL DE SOIN'.';'.
|
'HEURES TOTAL DE SOIN'.';'.
|
||||||
'HEURES TOTAL DE CONGE'.';'.
|
'HEURES TOTAL DE CONGE'.';'.
|
||||||
'HEURES TOTAL DE TRAVAIL'.';'.
|
'HEURES TOTAL DE TRAVAIL'.';'.
|
||||||
|
'HEURES TOTAL DE PARCOURS ENTRE DEVIS'.';'.
|
||||||
"\n";
|
"\n";
|
||||||
return $fileHeader;
|
return $fileHeader;
|
||||||
}
|
}
|
||||||
@ -138,16 +143,18 @@ class ExportThanatoStatisticService {
|
|||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
|
''.';'.
|
||||||
''.';'."\n";
|
''.';'."\n";
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
public function populateExportDataIntoFileContent(array $exportData,string $fileContent): string{
|
||||||
foreach($exportData as $devisDate => $devisData){
|
foreach($exportData as $devisDate => $devisData){
|
||||||
$distanceTotal = 0;
|
|
||||||
$totalDevisHours = 0;
|
$totalDevisHours = 0;
|
||||||
$totalWorkedHours = 8;
|
$totalWorkedHours = 8;
|
||||||
$totalLeaveHours = 0;
|
$totalLeaveHours = 0;
|
||||||
|
$totalDistance = 0;
|
||||||
|
$totalTravelingHoursBetweenDevisLocation = 0;
|
||||||
$hasDevisInTheCurrentDate = $devisData['hasDevis'];
|
$hasDevisInTheCurrentDate = $devisData['hasDevis'];
|
||||||
if($hasDevisInTheCurrentDate === false){
|
if($hasDevisInTheCurrentDate === false){
|
||||||
$leaves = $devisData["leaves"];
|
$leaves = $devisData["leaves"];
|
||||||
@ -161,7 +168,10 @@ class ExportThanatoStatisticService {
|
|||||||
$totalWorkedHours -= $totalLeaveHours;
|
$totalWorkedHours -= $totalLeaveHours;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$distanceTotal = $this->gestionBdd->getDistanceTotalByDevisIdList($devisData["devisId"]);
|
$routeLines = $this->gestionBdd->getRouteLinesByDevisIdList($devisData["devisId"]);
|
||||||
|
$totalDistanceAndTotalTravelingHoursBetweenDevis = $this->geoService->getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines($routeLines);
|
||||||
|
$totalDistance = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalDistance"];
|
||||||
|
$totalTravelingHoursBetweenDevisLocation = $totalDistanceAndTotalTravelingHoursBetweenDevis["totalTravelingHours"];
|
||||||
$devisList = $devisData["devis"];
|
$devisList = $devisData["devis"];
|
||||||
$leaves = $devisData["leaves"];
|
$leaves = $devisData["leaves"];
|
||||||
if(!empty($devisList)){
|
if(!empty($devisList)){
|
||||||
@ -181,16 +191,17 @@ class ExportThanatoStatisticService {
|
|||||||
}
|
}
|
||||||
$fileContent = $this->populateLastRecapForTheLine(
|
$fileContent = $this->populateLastRecapForTheLine(
|
||||||
$fileContent,
|
$fileContent,
|
||||||
$distanceTotal,
|
$totalDistance,
|
||||||
$totalDevisHours,
|
$totalDevisHours,
|
||||||
$totalWorkedHours,
|
$totalWorkedHours,
|
||||||
$totalLeaveHours
|
$totalLeaveHours,
|
||||||
|
$totalTravelingHoursBetweenDevisLocation
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function populateLastRecapForTheLine(string $fileContent,$distance,$totalDevisHours,$totalWorkedHours,$totalLeaveHours){
|
private function populateLastRecapForTheLine(string $fileContent,$distance,$totalDevisHours,$totalWorkedHours,$totalLeaveHours,$totalTravelingHours){
|
||||||
$fileContent = $fileContent.
|
$fileContent = $fileContent.
|
||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
@ -207,7 +218,8 @@ class ExportThanatoStatisticService {
|
|||||||
"$distance".';'.
|
"$distance".';'.
|
||||||
"$totalDevisHours".';'.
|
"$totalDevisHours".';'.
|
||||||
"$totalLeaveHours".';'.
|
"$totalLeaveHours".';'.
|
||||||
"$totalWorkedHours".';'."\n";
|
"$totalWorkedHours".';'.
|
||||||
|
"$totalTravelingHours"."\n";
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,6 +251,7 @@ class ExportThanatoStatisticService {
|
|||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
''.';'.
|
''.';'.
|
||||||
|
''.';'.
|
||||||
''.';'."\n";
|
''.';'."\n";
|
||||||
|
|
||||||
return $fileContent;
|
return $fileContent;
|
||||||
|
|||||||
@ -27,14 +27,28 @@ declare(strict_types=1);
|
|||||||
namespace OCA\Gestion\Service;
|
namespace OCA\Gestion\Service;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use OCA\Gestion\Constants\GeoConstant;
|
||||||
use OCA\Gestion\Helpers\GeoHelpers;
|
use OCA\Gestion\Helpers\GeoHelpers;
|
||||||
|
|
||||||
class GestionService {
|
class GeoService {
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTravellingHourBetweenTwoPoints(array $origin,array $destination,$mode = "driving"){
|
/**
|
||||||
|
* Calcul la distance entre les deux points à vol d'oiseau
|
||||||
|
*/
|
||||||
|
private function getDistanceInKmBetweenTwoPoints($lat1, $lon1, $lat2, $lon2) {
|
||||||
|
$R = 6371; // Rayon moyen de la Terre en kilomètres
|
||||||
|
$dLat = deg2rad($lat2 - $lat1);
|
||||||
|
$dLon = deg2rad($lon2 - $lon1);
|
||||||
|
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($dLon/2) * sin($dLon/2);
|
||||||
|
$c = 2 * atan2(sqrt($a), sqrt(1-$a));
|
||||||
|
$d = $R * $c;
|
||||||
|
return round($d, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getTravelingHourBetweenTwoPoints(array $origin,array $destination,$mode = "driving"){
|
||||||
$baseUrl = "https://api.geoapify.com/v1/routing";
|
$baseUrl = "https://api.geoapify.com/v1/routing";
|
||||||
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"],$origin["longitude"]);
|
$originPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($origin["latitude"],$origin["longitude"]);
|
||||||
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"],$destination["longitude"]);
|
$destinationPoints = GeoHelpers::getPointsTextFromLatitudeAndLongitude($destination["latitude"],$destination["longitude"]);
|
||||||
@ -70,4 +84,45 @@ class GestionService {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTotalDistanceAndTotalTravelingHoursBetweenDevisLocationByRouteLines(array $routeLines){
|
||||||
|
$distanceCumul = 0;
|
||||||
|
$totalTravelingHoursBetweenTwoDevisLocation = 0;
|
||||||
|
$lastPoint = NULL;
|
||||||
|
for ($i=0; $i < sizeof($routeLines); $i++) {
|
||||||
|
$currentDistance = 0;
|
||||||
|
if($routeLines[$i]['lieu_id'] != NULL){
|
||||||
|
$lastPoint = $routeLines[$i];
|
||||||
|
}
|
||||||
|
if($lastPoint['lieu_id'] != NULL && $routeLines[$i+1]['lieu_id'] != NULL){
|
||||||
|
$currentDistance = $this->getDistanceInKmBetweenTwoPoints(
|
||||||
|
floatval(value: $lastPoint['latitude']),
|
||||||
|
floatval($lastPoint['longitude']),
|
||||||
|
floatval($routeLines[$i+1]['latitude']),
|
||||||
|
floatval($routeLines[$i+1]['longitude'])
|
||||||
|
);
|
||||||
|
$targetIsBetweenTwoDevisLocation = $lastPoint['source'] != "siege" && $routeLines[$i+1]["source"] != "siege";
|
||||||
|
if($targetIsBetweenTwoDevisLocation){
|
||||||
|
$originPoints = [
|
||||||
|
"latitude" => $lastPoint["latitude"],
|
||||||
|
"longitude" => $lastPoint["longitude"]
|
||||||
|
];
|
||||||
|
$destinationPoints = [
|
||||||
|
"latitude" => $routeLines[$i+1]["latitude"],
|
||||||
|
"longitude" => $routeLines[$i+1]["longitude"]
|
||||||
|
];
|
||||||
|
$totalTravelingHoursBetweenTwoDevisLocation+= $this->getTravelingHourBetweenTwoPoints(
|
||||||
|
$originPoints,
|
||||||
|
$destinationPoints,
|
||||||
|
GeoConstant::DRIVING_MODE
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$distanceCumul += $currentDistance;
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
"totalDistance" => $distanceCumul,
|
||||||
|
"totalTravelingHours" => $totalTravelingHoursBetweenTwoDevisLocation
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user