예제 #1
0
    public void InvTimeSpanString()
    {
        var converter = new TimeConverter();
        var result    = converter.Convert("13:14:41.410");

        Assert.AreEqual(new TimeSpan(0, 13, 14, 41, 410), result);
    }
예제 #2
0
    public void FromTimeDateTime()
    {
        var converter = new TimeConverter();
        var result    = converter.Convert(new DateTime(2010, 5, 12, 13, 14, 41, 410));

        Assert.AreEqual(new DateTime(2010, 5, 12, 13, 14, 41, 410).TimeOfDay, result);
    }
예제 #3
0
    public void FromStringWithOneNumberSmaller()
    {
        var converter = new TimeConverter();
        var result    = converter.Convert(" 134  ");

        Assert.AreEqual(new TimeSpan(134, 0, 0, 0), result);
    }
예제 #4
0
    public void FromTimeSpan()
    {
        var converter = new TimeConverter();
        var result    = converter.Convert(new TimeSpan(134578));

        Assert.AreEqual(new TimeSpan(134578), result);
    }
예제 #5
0
        public IEnumerable <Track> GetTracksList(long carID, DateTime start, DateTime end)
        {
            var startDateTimestamp = TimeConverter.Convert(start) * 1000000;
            var endDateTimestamp   = TimeConverter.Convert(end) * 1000000;

            using (PostgresConnectionProvider _provider = new PostgresConnectionProvider(_configuration.GetConnectionString("DataAccessPostgreSqlProviderRO")))
            {
                var res = _provider.Connection.Query <Track>(@"
                    with temp_gaps as (select (unix_timestamp/1000000) as start,
                   (lead(unix_timestamp) over(order by unix_timestamp))/1000000 as stop,
                   (lead(unix_timestamp) over(order by unix_timestamp)/1000000) - (unix_timestamp/1000000) as diff,
                   (min(obd.unix_timestamp) over())/1000000 as interval_start
                   from raw_data.obd_data obd 
                   where obd.car_id = @CarID
                     and obd.unix_timestamp >= @start_period
                     and obd.unix_timestamp < @end_period
                   order by obd.unix_timestamp
), track as (select coalesce(lag(stop) over (order by stop), temp_gaps.interval_start) as start,
                    temp_gaps.start as end
                    from temp_gaps
             where diff >= @StopLength
             order by 1)
select 
       track.start,
       track.end
from track
",
                                                             new { start_period = startDateTimestamp, end_period = endDateTimestamp, CarID = carID, StopLength = _configuration.GetValue <int>("StopLength") });
                return(res);
            }
        }
예제 #6
0
        public IEnumerable <IMURecordViewModel> GetIMUByID(long ID, DateTime startDate, DateTime endDate)
        {
            var startDateTimestamp = TimeConverter.Convert(startDate) * 1000000;
            var endDateTimestamp   = TimeConverter.Convert(endDate) * 1000000;

            try
            {
                var rawResult = Context.imu_data
                                .Where(s => s.unix_timestamp > startDateTimestamp && s.unix_timestamp < endDateTimestamp && s.car_id == ID).Select(imu => new IMURecordViewModel {
                    Date        = imu.unix_timestamp,
                    acc_x       = imu.acc_x,
                    acc_y       = imu.acc_y,
                    acc_z       = imu.acc_z,
                    mag_x       = imu.mag_x,
                    mag_y       = imu.mag_y,
                    mag_z       = imu.mag_z,
                    gyro_xangle = imu.gyro_xangle,
                    gyro_yangle = imu.gyro_yangle,
                    gyro_zangle = imu.gyro_zangle
                });
                var sombre = rawResult.ToList();
                return(rawResult);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #7
0
        public IEnumerable <ChartItem> GetOBDByID(long ID, DateTime startDate, DateTime endDate)
        {
            var startDateTimestamp = TimeConverter.Convert(startDate) * 1000000;
            var endDateTimestamp   = TimeConverter.Convert(endDate) * 1000000;

            try {
                var rawResult = Context.obd_data
                                .Where(s => s.unix_timestamp > startDateTimestamp && s.unix_timestamp < endDateTimestamp && s.car_id == ID).Select(obd => new OBDChart
                {
                    Pid   = obd.pid,
                    Value = obd.value,
                    Date  = obd.unix_timestamp
                })
                                .GroupBy(a => a.Pid)
                                .Select(e => new { Key = e.Key, Values = e.OrderBy(a => a.Date).ToList() })
                                .ToList();
                var chartData = rawResult.Select(e => new ChartItem {
                    Label = PidsDictionaryHolder.pids[e.Key], Data = e.Values.Select(s => new DataItem {
                        Date = s.Date, Value = s.Value
                    }).ToList()
                });
                return(chartData);
            }
            catch (Exception ex) {
                return(null);
            }
        }
예제 #8
0
    public void TimeConverter_Convert()
    {
        decimal result = TimeConverter.Convert(TimeUnit.Hour, TimeUnit.Day, 24);

        Assert.AreEqual(1, result);

        result = TimeConverter.Convert(TimeUnit.Minute, TimeUnit.Hour, 60);
        Assert.AreEqual(1, result);

        result = TimeConverter.Convert(TimeUnit.Day, TimeUnit.Week, 7);
        Assert.AreEqual(1, result);
    }
예제 #9
0
        /// <summary>Convert the numbers to the new unit.</summary>
        /// <param name="numbers">The numbers used in the convertion.</param>
        /// <returns>The result of the convertion execution.</returns>
        /// <exception cref="ArgumentNullException">When numbers is null.</exception>
        /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception>
        public double Convert(double[] numbers)
        {
            base.Validate(numbers);
            double fromValue = numbers[0];

            switch (current.UnitType)
            {
            case UnitType.Length:
                return(LengthConverter.Convert(
                           (LengthUnit)current.FromUnit,
                           (LengthUnit)current.ToUnit,
                           fromValue));

            case UnitType.Mass:
                return(MassConverter.Convert(
                           (MassUnit)current.FromUnit,
                           (MassUnit)current.ToUnit,
                           fromValue));

            case UnitType.Speed:
                return(SpeedConverter.Convert(
                           (SpeedUnit)current.FromUnit,
                           (SpeedUnit)current.ToUnit,
                           fromValue));

            case UnitType.Temperature:
                return(TemperatureConverter.Convert(
                           (TemperatureUnit)current.FromUnit,
                           (TemperatureUnit)current.ToUnit,
                           fromValue));

            case UnitType.Time:
                return(TimeConverter.Convert(
                           (TimeUnit)current.FromUnit,
                           (TimeUnit)current.ToUnit,
                           fromValue));

            case UnitType.Volume:
                return(VolumeConverter.Convert(
                           (VolumeUnit)current.FromUnit,
                           (VolumeUnit)current.ToUnit,
                           fromValue));

            default:
                throw new ArgumentOutOfRangeException("numbers");
            }
        }
예제 #10
0
    /// <summary>Convert the numbers to the new unit.</summary>
    /// <param name="numbers">The numbers used in the conversion.</param>
    /// <returns>The result of the conversion execution.</returns>
    /// <exception cref="ArgumentNullException">When numbers is null.</exception>
    /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception>
    public PreciseNumber Evaluate(PreciseNumber[] operands)
    {
        ((IExpression)this).Validate(operands);

        PreciseNumber fromValue = operands[0];

        if (!fromValue.HasValue)
        {
            return(fromValue);
        }

        return(_current.UnitType switch
        {
            UnitType.Length => new PreciseNumber(LengthConverter.Convert((LengthUnit)_current.FromUnit, (LengthUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Mass => new PreciseNumber(MassConverter.Convert((MassUnit)_current.FromUnit, (MassUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Speed => new PreciseNumber(SpeedConverter.Convert((SpeedUnit)_current.FromUnit, (SpeedUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Temperature => new PreciseNumber(TemperatureConverter.Convert((TemperatureUnit)_current.FromUnit, (TemperatureUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Time => new PreciseNumber(TimeConverter.Convert((TimeUnit)_current.FromUnit, (TimeUnit)_current.ToUnit, fromValue.Value)),
            UnitType.Volume => new PreciseNumber(VolumeConverter.Convert((VolumeUnit)_current.FromUnit, (VolumeUnit)_current.ToUnit, fromValue.Value)),
            _ => throw new ArgumentOutOfRangeException(nameof(operands)),
        });
예제 #11
0
        public string GetStatistics(int currentTime, List <Skill> skills, Skill loadStatisticsFromSkill = null, bool showBrief = false, bool showOperStat = false)
        {
            StringBuilder statistics    = new StringBuilder();
            TimeConverter timeConverter = new TimeConverter();

            foreach (var skill in skills)
            {
                if (loadStatisticsFromSkill != null && loadStatisticsFromSkill.SkillName != skill.SkillName)
                {
                    continue;
                }

                statistics.Append($"Statistics in skill {skill.SkillName}\n");
                statistics.Append($"Offered calls \t{skill.statistic.CallsOffered}\n");
                statistics.Append($"Queue in skill \t{ skill.CallsInQueue.Count() }\n");

                if (!showBrief)
                {
                    statistics.Append($"Abandoned calls \t{skill.statistic.AbandonedCalls}\n");
                    statistics.Append($"Calls answered \t{skill.statistic.CallAnswered}\n");
                    statistics.Append($"SLCalls \t\t{skill.statistic.SLCalls}\n");
                }

                if (skill.statistic.CallsOffered > 0)
                {
                    statistics.Append($"SL \t\t{Math.Round(((1.0 * skill.statistic.SLCalls / skill.statistic.CallsOffered) * 100), 2)}%\n");
                }

                statistics.Append($"--------------------------------------\n");

                if (!showBrief)
                {
                    statistics.Append($"Available operators \t{skill.Operators.Where(o => o.CurrentStatus == "Ready").Count()}\n");
                    statistics.Append($"Operator talking in skill \t{skill.ActiveCalls.Count()}\n");
                    statistics.Append($"Longest call in queue \t {timeConverter.Convert(skill.CallsInQueue.Select(c => c.Duration).OrderByDescending(c => c).FirstOrDefault(), null, null, null)}\n");
                    statistics.Append($"--------------------------------------\n");
                }

                if (showOperStat)
                {
                    foreach (var oper in skill.Operators)
                    {
                        if (oper.CurrentStatus == "Talking" && oper.call != null)
                        {
                            statistics.Append($"{oper.Name} in status {oper.CurrentStatus} in skill {skill.SkillName} time = {timeConverter.Convert(oper.TimeInCurrentStatus, null, null, null)} \n");
                        }
                        else
                        if (oper.CurrentStatus == "Talking" && oper.call == null)
                        {
                            foreach (var skillSearch in skills)
                            {
                                if (skillSearch.SkillName != skill.SkillName)
                                {
                                    foreach (var operSearch in skillSearch.Operators)
                                    {
                                        if (operSearch.call != null && operSearch.Name == oper.Name)
                                        {
                                            statistics.Append($"{oper.Name} in status {oper.CurrentStatus} in skill {skillSearch.SkillName} time = {timeConverter.Convert(oper.TimeInCurrentStatus, null, null, null)} \n");
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            statistics.Append($"{oper.Name} in status {oper.CurrentStatus} time = {timeConverter.Convert(oper.TimeInCurrentStatus, null, null, null)}\n");
                        }
                    }
                    statistics.Append($"--------------------------------------\n");
                }
            }

            if (!showBrief)
            {
                foreach (var skill in skills)
                {
                    if (loadStatisticsFromSkill != null && loadStatisticsFromSkill.SkillName != skill.SkillName)
                    {
                        continue;
                    }

                    statistics.Append($"-----HISTORICAL DATA {skill.SkillName}-----\n");

                    foreach (var call in skill.HistoricalCalls.OrderBy(c => c.CallOfferedTime))
                    {
                        if (call.CallAnsweredTime == 0)
                        {
                            //statistics.Append($"Call {call.CallID} in skill {skill.SkillName} was offered at {timeConverter.Convert(call.CallOfferedTime, null, null, null)} and was abandoned at {timeConverter.Convert(call.CallOfferedTime + call.TalkFullDuration, null, null, null)} with duration {timeConverter.Convert(call.TalkFullDuration, null, null, null)} and priority {call.CallPriority}\n");
                            statistics.Append($"Call {call.CallID} offered at {timeConverter.Convert(call.CallOfferedTime, null, null, null)} abandoned at {timeConverter.Convert(call.CallOfferedTime + call.TalkFullDuration, null, null, null)} with duration {timeConverter.Convert(call.TalkFullDuration, null, null, null)} and priority {call.CallPriority}\n");
                        }
                        else
                        {
                            //statistics.Append($"Call {call.CallID} in skill {skill.SkillName} was offered at {timeConverter.Convert(call.CallOfferedTime, null, null, null)} and was answered at {timeConverter.Convert(call.CallAnsweredTime, null, null, null)} with duration {timeConverter.Convert(call.TalkFullDuration, null, null, null)} and priority {call.CallPriority}\n");
                            statistics.Append($"Call {call.CallID} offered at {timeConverter.Convert(call.CallOfferedTime, null, null, null)} answered at {timeConverter.Convert(call.CallAnsweredTime, null, null, null)} wait time {timeConverter.Convert(call.CallAnsweredTime - call.CallOfferedTime, null, null, null)} with duration {timeConverter.Convert(call.TalkFullDuration, null, null, null)} and priority {call.CallPriority}\n");
                        }
                    }

                    if (skill.statistic.Calls.Count > 0)
                    {
                        statistics.Append($"Average Talk Time = { timeConverter.Convert(skill.statistic.Calls.Sum(c => c.Duration) / skill.statistic.Calls.Count, null, null, null) }\n");
                    }

                    statistics.Append($"--------------------------------------\n");
                }
            }

            return(statistics.ToString());
        }
예제 #12
0
        public void Convert_InvalidInput_ThrowsArgumentException(object invalidInput)
        {
            Action act = () => m_timeConverter.Convert <string>(invalidInput);

            act.Should().Throw <ArgumentException>();
        }
        public void Convert_InvalidInput_XamlParseExceptionThrown(object invalidInput)
        {
            Action act = () => m_timeConverter.Convert <string>(invalidInput);

            act.Should().Throw <XamlParseException>();
        }
 public void InvalidCurrentUnit()
 {
     converter.Convert("h", 5, "years");
 }
예제 #15
0
        public void ConvertToSame()
        {
            var value = conv.Convert(43, TimeUnits.Seconds, TimeUnits.Seconds);

            Assert.Equal(43, value);
        }