Exemplo n.º 1
0
        public void TestDtoToBo()
        {
            ReportSettingsDto dto = new ReportSettingsDto();

            dto.TerminalId    = "test";
            dto.StartDateTime = new DateTime(1990, 1, 2, 3, 4, 5);
            dto.EndDateTime   = new DateTime(1990, 5, 4, 3, 2, 1);
            dto.Properties.Add(DynamicPropertyManagers.Reports.AvgSpeed.Name);
            dto.Properties.Add(DynamicPropertyManagers.Reports.MaxSpeed.Name);

            var bo = ReportSettingsDto.Unwrap(dto);

            Assert.AreEqual(dto.TerminalId, bo.TerminalId);
            Assert.AreEqual(dto.StartDateTime, bo.StartDateTime);
            Assert.AreEqual(dto.EndDateTime, bo.EndDateTime);
            Assert.IsTrue(dto.Properties.Contains(DynamicPropertyManagers.Reports.AvgSpeed.Name));
            Assert.IsTrue(dto.Properties.Contains(DynamicPropertyManagers.Reports.MaxSpeed.Name));
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task <ReportDto> BuildReport(ReportSettingsDto settings)
        {
            var rep         = new Report();
            var repSettings = ReportSettingsDto.Unwrap(settings);

            rep.ReportSettings = repSettings;

            if (repSettings.Properties.Contains(DynamicPropertyManagers.Reports.MaxSpeed))
            {
                var maxSpeed = await _meteringRepository.GetMaxPropertyValue(
                    repSettings.TerminalId,
                    DynamicPropertyManagers.Sensors.SpeedKmh,
                    repSettings.StartDateTime,
                    repSettings.EndDateTime);

                rep.Values.SetValue(
                    DynamicPropertyManagers.Reports.MaxSpeed,
                    maxSpeed);
            }
            if (repSettings.Properties.Contains(DynamicPropertyManagers.Reports.AvgSpeed))
            {
                var avgSpeed = await _meteringRepository.GetAvgPropertyValue(
                    repSettings.TerminalId,
                    DynamicPropertyManagers.Sensors.SpeedKmh,
                    repSettings.StartDateTime,
                    repSettings.EndDateTime);

                rep.Values.SetValue(
                    DynamicPropertyManagers.Reports.AvgSpeed,
                    (float)avgSpeed);
            }
            if (repSettings.Properties.Contains(DynamicPropertyManagers.Reports.MileageKm))
            {
                var differencePropertyValue = await _meteringRepository.GetLastFirstDifferencePropertyValue(
                    repSettings.TerminalId,
                    DynamicPropertyManagers.Sensors.MileageKm,
                    repSettings.StartDateTime,
                    repSettings.EndDateTime);

                rep.Values.SetValue(
                    DynamicPropertyManagers.Reports.MileageKm,
                    (float)differencePropertyValue);
            }
            if (repSettings.Properties.Contains(DynamicPropertyManagers.Reports.EngineWorkTime))
            {
                var meterings = await _meteringRepository.GetMeterings(
                    repSettings.TerminalId,
                    repSettings.StartDateTime,
                    repSettings.EndDateTime,
                    DynamicPropertyManagers.Sensors.IsEngineRunning);

                TimeSpan engineWorkTime = new TimeSpan(0);
                for (int i = 1; i < meterings.Count; i++)
                {
                    if (
                        (bool)meterings[i - 1].SensorValues.GetValue(DynamicPropertyManagers.Sensors.IsEngineRunning) &&
                        (bool)meterings[i].SensorValues.GetValue(DynamicPropertyManagers.Sensors.IsEngineRunning))
                    {
                        engineWorkTime = engineWorkTime.Add(meterings[i].Time - meterings[i - 1].Time);
                    }
                }
                rep.Values.SetValue(
                    DynamicPropertyManagers.Reports.EngineWorkTime,
                    engineWorkTime);
            }

            return(ReportDto.Wrap(rep));
        }