Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Relatório Telemetria

Relatório criado pelo core para SUZANO MVI.

Relatório tem como base os dados da tabela marte_report_pos.

Sobre o relatório

Por não utilizar dos mesmos dados que a telemetria do NFS, o relatório pode ter variações nos montantes, pois esse relatório irá considerar dados entre o inicio do primeiro evento do dia, e o termino do último evento do dia.

  • Motor Ligado -> Com a ignição ON, é considerado motor ligado quando a velocidade for maior que 0, ou o deslocamento for maior que 0 ou que o RPM form maior ou igual a 300.
  • Motor Ocioso -> Com a ignição ON, é considerado ocioso quando a velocidade for 0 e o deslocamento também for 0, e o RPM deve estar maior que 300.
  • Motor Desligado -> Quando a ignição estiver OFF, ou nao se enquadrar como motor ligado ou ocioso.
  • Tempo em Deslocamento -> Com a ignição ON, e o deslocamento maior que 0.
  • Velocidade Máxima -> Maior velocidade atingida no dia.
  • Velocidade Média -> É obtida a partir do deslocamento total e o tempo em deslocamento.

Report

FILTERS

{
	"inicio": {
		"type": "Date",
		"options": {
			"label": "De",
			"required": true
		}
	},
	"fim": {
		"type": "Date",
		"options": {
			"label": "Até",
			"required": true
		}
	},
	"eqp": {
		"type": "Table",
		"options": {
			"label": "Equipamento",
			"multiple": true,
			"required": false
		}
	},
	"eqp_classe": {
		"type": "Table",
		"options": {
			"label": "Classe Operacional",
			"multiple": true,
			"required": false
		}
	}
}

QUERIES

{
	"equipamento_list":{
		"dump": "",
		"select":[
			"e.SEQ_DB"
		],
		"from":"eqp e",
		"where":[
			"e.SEQ_DB in (:eqp)"
		],
		"order_by": [
			["e.CODIGO","ASC"],
			["e.DESCRICAO","ASC"]
		]
	},
	"tele_marte":{
		"dump":"",
		"select":[
			"i.VEICULO_EQUIPAMENTO_SEQ_DB",
			"DATE_FORMAT(i.INI_DH,'%d/%m/%Y') DIA",
			"ROUND((SUM(i.VEL_MED_GPS)/COUNT(i.SEQ_DB)/5),2)MEDIA",
			"ROUND((MAX(i.VEL_MAX_GPS)),2)MAXIMA",
			"ROUND(sum(i.DISTANCIA_CALCULADA_PONTOS),2)DISTANCIA"
		],
		"from":"marte_ignicao i",
		"where":[
			"i.INI_DH BETWEEN :inicioIniDb and :fimFimDb",
			"i.VEICULO_EQUIPAMENTO_SEQ_DB in (:eqp)",
			"e.EQP_CLASSE_SEQ_DB in (:eqp_classe)"
		],
		"inner_join":[
			["i","eqp","e","i.VEICULO_EQUIPAMENTO_SEQ_DB = e.SEQ_DB"]
		],
		"group_by": [
			"i.VEICULO_EQUIPAMENTO_SEQ_DB",
			"DATE(i.INI_DH)"
		],
		"order_by": [
			["i.INI_DH","ASC"]
		],
		"group_result_by": "VEICULO_EQUIPAMENTO_SEQ_DB"
	}
}

TEMPLATE

{% extends 'reports/base.twig' %}
{% from 'reports/macros.twig' import img64 %}

{% block content %}
	<table class="table table-condensed" id="telemetriacore">
		<thead>
			<tr style="background-color:#BDBDBD;">
				<th colspan = "3" style="vertical-align: middle; text-align: left;">{{img64(images['suzano64'].image_base64,'50px')}}</th>
				<th colspan = "4" style="vertical-align: middle; text-align: left;font-size:30px"><strong>RELATÓRIO DE TELEMETRIA</strong></th>
				<th colspan = "2" style="vertical-align: middle; text-align: right;">
					Data/Hora Emissão: <strong>{{ 'now'|date('d/m/Y H:i:s') }}</strong><br>
					Período: <strong>{{ parameters.inicio }} à {{ parameters.fim }}</strong><br>
				</th>
			</tr>
			<tr style="background-color:#305496;">
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Eqp/Veic</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Data</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Tempo Motor Desligado</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Tempo Motor Ligado</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Tempo Em Deslocamento</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Tempo Motor Ocioso</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Velocidade Média (km/h)</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Velocidade Máxima (km/h)</th>
				<th style="vertical-align: middle; text-align: center; border:1px solid #000000; color:white;">Distância (km)</th>
			</tr>
		</thead>
		<tbody>
			{%for e in equipamento_list%}
				{%set media = 0.0%}
				{%set maxima = 0.0%}
				{%set distancia = 0.0%}
				{%set total_desligado = 0.0%}
				{%set total_ocioso = 0.0%}
				{%set total_motor_ligado = 0.0%}
				{%set total_deslocamento = 0.0%}
				{%set total_geral = 0.0%}
				{%set total_media = 0.0%}
				{%set total_maxima = 0.0%}
				{%set total_distancia = 0.0%}
				{%set registros = 0%}
				{%set possuiApontamento = false%}

				{% for m in marte_pos %}
					{% if e.SEQ_DB == m.VEICULO_EQUIPAMENTO_SEQ_DB %}
						{%set possuiApontamento = true%}
						{%set total_geral = total_geral + m.TEMPO_TOTAL%}
						{%set total_desligado = total_desligado + m.MOTOR_DESLIGADO%}
						{%set total_ocioso = total_ocioso + m.OCIOSO%}
						{%set total_motor_ligado = total_motor_ligado + m.MOTOR_LIGADO%}
						{%set total_deslocamento = total_deslocamento + m.DESLOCAMENTO%}
						{%set total_media = total_media + m.AVGSPEED%}
						{%set total_maxima = total_maxima + m.MAXSPEED%}
						{%set total_distancia = total_distancia + m.TOTDESLOCAMENTO%}
						{%set registros = registros + 1%}

						<tr>
							<td style="vertical-align: middle; text-align: center; font-size:15px">{{m.EQUIPAMENTO}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.DATA}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.MOTOR_DESLIGADO|seconds_to_time}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.MOTOR_LIGADO|seconds_to_time}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.DESLOCAMENTO|seconds_to_time}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.OCIOSO|seconds_to_time}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.AVGSPEED}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.MAXSPEED}}</td>
							<td style="vertical-align: middle; text-align: center;font-size:15px">{{m.TOTDESLOCAMENTO}}</td>
						</tr>
					{% endif %}
				{% endfor %}

				{% if possuiApontamento %}
					<tr style="background-color:#F2F2F2;">
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>Total Geral - h</strong></td>
						<td></td>
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{total_desligado|seconds_to_time}}</strong></td>
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{total_motor_ligado|seconds_to_time}}</strong></td>
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{total_deslocamento|seconds_to_time}}</strong></td>
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{total_ocioso|seconds_to_time}}</strong></td>
						{%if registros == 0 %}
							<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{(0)|round(2)}}</strong></td>
							<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{(0)|round(2)}}</strong></td>
						{%else%}
							<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{(total_media / registros)|round(2)}}</strong></td>
							<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{(total_maxima / registros)|round(2)}}</strong></td>
						{%endif%}
						<td style="vertical-align: middle; text-align: center;font-size:15px"><strong>{{total_distancia}}</strong></td>
					</tr>
				{% endif %}
			{%endfor%}
		</tbody>
	</table>
{% endblock %}

EXPORT_OPTIONS

{
	"pdf": {
		"orientation": "Landscape",
		"footer-right": "[title] - [page]/[topage]"
	},
	"data_table": {
		"output": "telemetriacore",
		"buttons": [
			{
				"extend": "excel",
				"text": "<i class='fa fa-file-excel-o'></i> Exportar para Excel",
				"className": "btn-sm btn-primary"
			},{
				"extend": "pdf",
				"text": "<i class='fa fa-file-pdf-o'></i> Exportar para PDF",
				"className": "btn-sm btn-primary"
			},{
				"extend": "copy",
				"text": "<i class='fa fa-clipboard'></i> Copiar para Clipboard",
				"className": "btn-sm btn-primary"
			},{
				"extend": "print",
				"text": "<i class='fa fa-print'></i> Imprimir",
				"className": "btn-sm btn-primary"
			}
		]
	},
	"images": ["suzano64"]
}

ENTRYPOINT

FILE_OR_DOMAIN

REPORTS

CODE

$parametros = $this->parameters;

$eqpSeqDb = $parametros['eqp'];
$ini = $parametros['inicioIniDb'];
$fim = $parametros['fimFimDb'];
$eqpClasseSeqDb = $parametros['eqp_classe'];

$qb = NFSQueryBuilder::select([
	"a.SEQ_DB",
	"a.EVT_DH INI_DH", 
	"a.IGN_ON", 
	"a.GPS_SPEED", 
	"a.VEICULO_EQUIPAMENTO_SEQ_DB", 
	"a.EVT_DH FIM_DH",
	"a.POSICAO_PLAT",
	"a.POSICAO_PLON",
	"a.RPM"
])
	->from('MARTE_REPORT_POS', 'a')
	->orderBy('a.VEICULO_EQUIPAMENTO_SEQ_DB', 'ASC')
	->addOrderBy('a.EVT_DH', 'ASC');

if (!empty($eqpSeqDb)) {
	$qb->andWhere("a.VEICULO_EQUIPAMENTO_SEQ_DB in (:seqDb)");
	$qb->setParameter('seqDb', $eqpSeqDb);
}

if (!empty($ini)) {
	$qb->andWhere("a.EVT_DH >= (:ini)");
	$qb->setParameter('ini', $ini);
}

if (!empty($fim)) {
	$qb->andWhere("a.EVT_DH <= (:fim)");
	$qb->setParameter('fim', $fim);
}

$rowsAll = $qb->get();
$results = [];

foreach ($rowsAll as $r) {
	
	$v_eqp = $r["VEICULO_EQUIPAMENTO_SEQ_DB"];
	$ini_dh = $r["INI_DH"];
	$seq = $r["SEQ_DB"];
	
    if (!isset($results[$v_eqp][$ini_dh])) {
        $results[$v_eqp][$ini_dh] = $r;
    } else {
        $current = $results[$v_eqp][$ini_dh];
        if ($current["SEQ_DB"] < $seq) {
            $results[$v_eqp][$ini_dh] = $r;
        }
    }
}

// Remover registros com mesmo evt_dh duplicados (por veículo_equip)
$rows = [];

foreach ($results as $group) {
    foreach ($group as $r) {
        $rows[] = $r;
    }
}

// transforma em um array não associativo
$rows = array_values($rows);

$equipamento = NFSQueryBuilder::select([
	"e.SEQ_DB", 
	"CONCAT(e.CODIGO, ' :: ', e.DESCRICAO) EQUIPAMENTO",
])
	->from('eqp', 'e')
	->orderBy('e.SEQ_DB', 'ASC');

if (!empty($eqpSeqDb)) {
	$equipamento->andWhere("e.SEQ_DB in (:seqDb)");
	$equipamento->setParameter('seqDb', $eqpSeqDb);
}

if (!empty($eqpClasseSeqDb)) {
	$equipamento->andWhere("e.EQP_CLASSE_SEQ_DB in (:classeSeqDb)");
	$equipamento->setParameter('classeSeqDb', $eqpClasseSeqDb);
}

$rowsEqp = $equipamento->get();

$valores = [];
$horaInicio = 0;
$horaFim = 0;
$data = "";
$eqp = 0;
$eqpDescricao = '';
$contador = 0;
$contadorSaida = 0;
$duracao = 0;
$tempoTotal = 0;
$tempoMotorDesligado = 0;
$tempoMotorLigado = 0;
$tempoEmDeslocamento = 0;
$tempoMotorOcioso = 0;
$numRegistros = count($rows);
$deslocamentoMetros = 0;
$totalDeslocamento = 0;
$maxSpeed = 0;
$latitudeFrom = '';
$longitudeFrom = '';
$latitudeTo = '';
$longitudeTo = '';
$newDate = true;
	
foreach ($rows as $key => $r) {
	$horaInicio = strtotime($r["INI_DH"]);
	$currentEqp = $r['VEICULO_EQUIPAMENTO_SEQ_DB'];
	
	if (isset($rows[($contador + 1)])) {
		$horaInicioNextEqp = strtotime($rows[($contador + 1)]['INI_DH']);
		$nextEqp = $rows[($contador + 1)]['VEICULO_EQUIPAMENTO_SEQ_DB'];
	}
		
	
	if (isset($nextEqp)) {
		if ($eqp == 0 || $eqp == $nextEqp) {
			if ($eqp == 0) {
				$eqp = $currentEqp; // recebeu seqdb do equipamento first
				foreach ($rowsEqp as $re) {
					if ($nextEqp == $re['SEQ_DB']) {
						$eqpDescricao = $re['EQUIPAMENTO']; // apenas pega a descrição da tabela equipamento
						break;
					}
				}
			}
			
			if ($data == "" || $data == date("d/m/Y", $horaInicioNextEqp)) {
				if ($data == "" || $newDate == true) { // primeiro do relatório
					$data = date("d/m/Y", $horaInicio);
					$hora = date("H:i:s", $horaInicio);
					
					list($horas, $minutos, $segundos) = explode(':', $hora);
					$timeBefore = $horas * 3600 + $minutos * 60 + $segundos;
					$tempoMotorDesligado = $timeBefore;
					$newDate = false;
				}
			} else if (date("d/m/Y", $horaFim) != date("d/m/Y", $horaInicio)) {
				// só zerar pois se trata da transição	
				$tempoTotal = 0;
				$tempoMotorDesligado = 0;
				$tempoMotorLigado = 0;
				$tempoEmDeslocamento = 0;
				$tempoMotorOcioso = 0;
				$maxSpeed = 0;
				$data = date("d/m/Y", $horaInicioNextEqp);
				
			} else {			
				$today = date("Y-m-d");
				$day = date("Y-m-d", $horaFim);
				
				if ($today > $day) {
					list($horas, $minutos, $segundos) = explode(':', date("H:i:s", $horaFim));
					$timeAfter = $horas * 3600 + $minutos * 60 + $segundos;

					$fimDoDia = 23 * 3600 + 59 * 60 + 59;
					$tempoRestante = $fimDoDia - $timeAfter;				
					$tempoMotorDesligado = $tempoMotorDesligado + $tempoRestante;
				}				
				
				$valores[$contadorSaida]["VEICULO_EQUIPAMENTO_SEQ_DB"] = $eqp;
				$valores[$contadorSaida]["EQUIPAMENTO"] = $eqpDescricao;
				$valores[$contadorSaida]["DATA"] = $data;
				$valores[$contadorSaida]["TEMPO_TOTAL"] = $tempoTotal;
				$valores[$contadorSaida]["MOTOR_DESLIGADO"] = $tempoMotorDesligado;
				$valores[$contadorSaida]["MOTOR_LIGADO"] = $tempoMotorLigado;
				$valores[$contadorSaida]["DESLOCAMENTO"] = $tempoEmDeslocamento;
				$valores[$contadorSaida]["OCIOSO"] = $tempoMotorOcioso;
				$valores[$contadorSaida]["MAXSPEED"] = $maxSpeed;
				$valores[$contadorSaida]["TOTDESLOCAMENTO"] = round(($totalDeslocamento / 1000),2);
				
				if ($totalDeslocamento > 0 && $tempoEmDeslocamento > 0) {
					$avgSpeed = round(($totalDeslocamento / 1000) / ($tempoEmDeslocamento / 3600), 2);
				} else {
					$avgSpeed = 0;
				}

				$valores[$contadorSaida]["AVGSPEED"] = $avgSpeed;
				
				$contadorSaida++;

				$tempoTotal = 0;
				$tempoMotorDesligado = 0;
				$tempoMotorLigado = 0;
				$tempoEmDeslocamento = 0;
				$tempoMotorOcioso = 0;
				$maxSpeed = 0;
				$totalDeslocamento = 0;
				$newDate = true;
				$data = date("d/m/Y", $horaInicioNextEqp);
			} 
			
		} else {			
			$today = date("Y-m-d");
			$day = date("Y-m-d", $horaFim);

			if ($today > $day) {
				list($horas, $minutos, $segundos) = explode(':', date("H:i:s", $horaFim));
				$timeAfter = $horas * 3600 + $minutos * 60 + $segundos;

				$fimDoDia = 23 * 3600 + 59 * 60 + 59;
				$tempoRestante = $fimDoDia - $timeAfter;				
				$tempoMotorDesligado = $tempoMotorDesligado + $tempoRestante;
			}
			
			$valores[$contadorSaida]["VEICULO_EQUIPAMENTO_SEQ_DB"] = $eqp;
			$valores[$contadorSaida]["EQUIPAMENTO"] = $eqpDescricao;
			$valores[$contadorSaida]["DATA"] = $data;
			$valores[$contadorSaida]["TEMPO_TOTAL"] = $tempoTotal;
			$valores[$contadorSaida]["MOTOR_DESLIGADO"] = $tempoMotorDesligado;
			$valores[$contadorSaida]["MOTOR_LIGADO"] = $tempoMotorLigado;
			$valores[$contadorSaida]["DESLOCAMENTO"] = $tempoEmDeslocamento;
			$valores[$contadorSaida]["OCIOSO"] = $tempoMotorOcioso;
			$valores[$contadorSaida]["MAXSPEED"] = $maxSpeed;
			$valores[$contadorSaida]["TOTDESLOCAMENTO"] = round(($totalDeslocamento / 1000),2);
			
			if ($totalDeslocamento > 0 && $tempoEmDeslocamento > 0) {
				$avgSpeed = round(($totalDeslocamento / 1000) / ($tempoEmDeslocamento / 3600), 2);
			} else {
				$avgSpeed = 0;
			}
		
			$valores[$contadorSaida]["AVGSPEED"] = $avgSpeed;
			
			$contadorSaida++;

			$tempoTotal = 0;
			$tempoMotorDesligado = 0;
			$tempoMotorLigado = 0;
			$tempoEmDeslocamento = 0;
			$tempoMotorOcioso = 0;
			$maxSpeed = 0;
			$totalDeslocamento = 0;
			$newDate = true;
			$data = date("d/m/Y", $horaInicio);	
			foreach ($rowsEqp as $re) {
				if ($nextEqp == $re['SEQ_DB']) {
					$eqpDescricao = $re['EQUIPAMENTO'];
					break;
				}
			}
		}
	} else {
		if ($eqp == 0 || $eqp == $curEqp) {
			
		
			if ($eqp == 0) {
				$eqp = $currentEqp; // recebeu seqdb do equipamento first
				foreach ($rowsEqp as $re) {
					if ($currentEqp == $re['SEQ_DB']) {
						$eqpDescricao = $re['EQUIPAMENTO']; // apenas pega a descrição da tabela equipamento
						break;
					}
				}
			}
			if ($data == "" || $data == date("d/m/Y", $horaInicio)) {
				if ($data == "") {
					$data = date("d/m/Y", $horaInicio);
				}
			} else {
				$valores[$contadorSaida]["VEICULO_EQUIPAMENTO_SEQ_DB"] = $eqp;
				$valores[$contadorSaida]["EQUIPAMENTO"] = $eqpDescricao;
				$valores[$contadorSaida]["DATA"] = $data;
				$valores[$contadorSaida]["TEMPO_TOTAL"] = $tempoTotal;
				$valores[$contadorSaida]["MOTOR_DESLIGADO"] = $tempoMotorDesligado;
				$valores[$contadorSaida]["MOTOR_LIGADO"] = $tempoMotorLigado;
				$valores[$contadorSaida]["DESLOCAMENTO"] = $tempoEmDeslocamento;
				$valores[$contadorSaida]["OCIOSO"] = $tempoMotorOcioso;
				$valores[$contadorSaida]["MAXSPEED"] = $maxSpeed;
				$valores[$contadorSaida]["TOTDESLOCAMENTO"] = round(($totalDeslocamento / 1000),2);
				
				if ($totalDeslocamento > 0 && $tempoEmDeslocamento > 0) {
					$avgSpeed = round(($totalDeslocamento / 1000) / ($tempoEmDeslocamento / 3600), 2);
				} else {
					$avgSpeed = 0;
				}

				$valores[$contadorSaida]["AVGSPEED"] = $avgSpeed;
				
				$contadorSaida++;

				$tempoTotal = 0;
				$tempoMotorDesligado = 0;
				$tempoMotorLigado = 0;
				$tempoEmDeslocamento = 0;
				$tempoMotorOcioso = 0;
				$maxSpeed = 0;
				$totalDeslocamento = 0;
				$data = date("d/m/Y", $horaInicio);
			} 
			
		} else {
			$valores[$contadorSaida]["VEICULO_EQUIPAMENTO_SEQ_DB"] = $eqp;
			$valores[$contadorSaida]["EQUIPAMENTO"] = $eqpDescricao;
			$valores[$contadorSaida]["DATA"] = $data;
			$valores[$contadorSaida]["TEMPO_TOTAL"] = $tempoTotal;
			$valores[$contadorSaida]["MOTOR_DESLIGADO"] = $tempoMotorDesligado;
			$valores[$contadorSaida]["MOTOR_LIGADO"] = $tempoMotorLigado;
			$valores[$contadorSaida]["DESLOCAMENTO"] = $tempoEmDeslocamento;
			$valores[$contadorSaida]["OCIOSO"] = $tempoMotorOcioso;
			$valores[$contadorSaida]["MAXSPEED"] = $maxSpeed;
			$valores[$contadorSaida]["TOTDESLOCAMENTO"] = round(($totalDeslocamento / 1000),2);

			if ($totalDeslocamento > 0 && $tempoEmDeslocamento > 0) {
				$avgSpeed = round(($totalDeslocamento / 1000) / ($tempoEmDeslocamento / 3600), 2);
			} else {
				$avgSpeed = 0;
			}
		
			$valores[$contadorSaida]["AVGSPEED"] = $avgSpeed;
			
			$contadorSaida++;

			$tempoTotal = 0;
			$tempoMotorDesligado = 0;
			$tempoMotorLigado = 0;
			$tempoEmDeslocamento = 0;
			$tempoMotorOcioso = 0;
			$maxSpeed = 0;
			$totalDeslocamento = 0;
			$data = date("d/m/Y", $horaInicio);	
			foreach ($rowsEqp as $re) {
				if ($currentEqp == $re['SEQ_DB']) {
					$eqpDescricao = $re['EQUIPAMENTO'];
					break;
				}
			}
		}
	}
	
	if ($contador < ($numRegistros - 1) && $eqp == $rows[($contador + 1)]["VEICULO_EQUIPAMENTO_SEQ_DB"]) {
		$horaFim = strtotime($rows[($contador + 1)]["INI_DH"]);
		$horaFim_ = $rows[($contador + 1)]["INI_DH"];
	} else {
		
		$horaFim = strtotime($r["INI_DH"]);
		$horaFim_ = $r["INI_DH"];
	}
	
	if (date("d/m/Y", $horaInicio) == date("d/m/Y", $horaFim)) {
		$duracao = floatval($horaFim - $horaInicio);
	} else {
		$duracao = 0;
	}
	
	if ($horaInicio == $horaFim) {
		$r["GPS_SPEED"] = 0;
	}

	//ver se houve deslocamento (new)
	if ($contador < ($numRegistros - 1)) {
		if ($r['VEICULO_EQUIPAMENTO_SEQ_DB'] == $rows[($contador + 1)]['VEICULO_EQUIPAMENTO_SEQ_DB']) {
			$latitudeFrom = $r["POSICAO_PLAT"];
			$longitudeFrom = $r["POSICAO_PLON"];

			$latitudeTo = $rows[$contador + 1]["POSICAO_PLAT"];
			$longitudeTo = $rows[$contador + 1]["POSICAO_PLON"];

			$rad = M_PI / 180;
			// Calculate distance from latitude and longitude
			$theta = $longitudeFrom - $longitudeTo;
			$dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);

			//transformando km em metro
			$kms = acos($dist) / $rad * 60 * 1.853;
			$deslocamentoMetros = (int)($kms * 1000);
		} else {
			$latitudeFrom = $r["POSICAO_PLAT"];
			$longitudeFrom = $r["POSICAO_PLON"];

			$latitudeTo = $r["POSICAO_PLAT"];
			$longitudeTo = $r["POSICAO_PLON"];

			$rad = M_PI / 180;
			// Calculate distance from latitude and longitude
			$theta = $longitudeFrom - $longitudeTo;
			$dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);

			//transformando km em metro
			$kms = acos($dist) / $rad * 60 * 1.853;
			$deslocamentoMetros = (int)($kms * 1000);
		}	
			
	} else {
		$latitudeFrom = $r["POSICAO_PLAT"];
		$longitudeFrom = $r["POSICAO_PLON"];

		$latitudeTo = $r["POSICAO_PLAT"];
		$longitudeTo = $r["POSICAO_PLON"];

		$rad = M_PI / 180;
		// Calculate distance from latitude and longitude
		$theta = $longitudeFrom - $longitudeTo;
		$dist = sin($latitudeFrom * $rad) * sin($latitudeTo * $rad) + cos($latitudeFrom * $rad) * cos($latitudeTo * $rad) * cos($theta * $rad);

		//transformando km em metro
		$kms = acos($dist) / $rad * 60 * 1.853;
		$deslocamentoMetros = (int)($kms * 1000);
	}
	
	if (date("d/m/Y", $horaInicio) != date("d/m/Y", $horaFim)) {
		$deslocamentoMetros = 0;
	}
	
	if ($r["IGN_ON"] == "0") {
		$tempoMotorDesligado += $duracao;
	} else {		
		if ($r["GPS_SPEED"] <= "0" && $deslocamentoMetros <= "0" && $r["RPM"] >= 300) {		
			$tempoMotorOcioso += $duracao;
			$tempoMotorLigado += $duracao;
			
		} else if ($r["GPS_SPEED"] > "0" || $deslocamentoMetros > "0") {
			$tempoEmDeslocamento += $duracao;
			$tempoMotorLigado += $duracao;
			
			if ($r["GPS_SPEED"] > 0) {
				if ($maxSpeed < $r["GPS_SPEED"])
				$maxSpeed = $r["GPS_SPEED"];
			}
			
			if ($deslocamentoMetros > 0) {	
				$totalDeslocamento += $deslocamentoMetros;
			} 
		} else {
			$tempoMotorDesligado += $duracao;
		}
	}
	
	$tempoTotal += $duracao;
	
	if ($contador == ($numRegistros - 1)) {
		
		$today = date("Y-m-d");
		$day = date("Y-m-d", $horaFim);

		if ($today > $day) {
			list($horas, $minutos, $segundos) = explode(':', date("H:i:s", $horaFim));
			$timeAfter = $horas * 3600 + $minutos * 60 + $segundos;

			$fimDoDia = 23 * 3600 + 59 * 60 + 59;
			$tempoRestante = $fimDoDia - $timeAfter;				
			$tempoMotorDesligado = $tempoMotorDesligado + $tempoRestante;
		}
		
		$valores[$contadorSaida]["VEICULO_EQUIPAMENTO_SEQ_DB"] = $eqp;
		$valores[$contadorSaida]["EQUIPAMENTO"] = $eqpDescricao;
		$valores[$contadorSaida]["DATA"] = $data;
		$valores[$contadorSaida]["TEMPO_TOTAL"] = $tempoTotal;
		$valores[$contadorSaida]["MOTOR_DESLIGADO"] = $tempoMotorDesligado;
		$valores[$contadorSaida]["MOTOR_LIGADO"] = $tempoMotorLigado;
		$valores[$contadorSaida]["DESLOCAMENTO"] = $tempoEmDeslocamento;
		$valores[$contadorSaida]["OCIOSO"] = $tempoMotorOcioso;
		$valores[$contadorSaida]["MAXSPEED"] = $maxSpeed;
		$valores[$contadorSaida]["TOTDESLOCAMENTO"] = round(($totalDeslocamento / 1000),2);		
		
		if ($totalDeslocamento > 0 && $tempoEmDeslocamento > 0) {
			$avgSpeed = round(($totalDeslocamento / 1000) / ($tempoEmDeslocamento / 3600), 2);
		} else {
			$avgSpeed = 0;
		}
		
		$valores[$contadorSaida]["AVGSPEED"] = $avgSpeed;

	}
	
	if (isset($rows[($contador + 1)]['VEICULO_EQUIPAMENTO_SEQ_DB'])) {
		$eqp = $rows[($contador + 1)]['VEICULO_EQUIPAMENTO_SEQ_DB'];
	} else {
		$eqp = $r['VEICULO_EQUIPAMENTO_SEQ_DB'];
	}	
	$contador++;
}

$this->queryData['marte_pos'] = $valores;

Last Updated

  • Jira: https://simova.atlassian.net/browse/NFSCORE-1165