public static void CalculateSpeed(RouteStart routeStart, VibrationData data) { var distance = CalculateDistance(routeStart.StartLocationLongitude, routeStart.StartLocationLatitude, data.LocationLongitude, data.LocationLatitude); var timeDiff = routeStart.BeginTime - data.TimeStamp; var speed = distance / Math.Abs(timeDiff.TotalHours); data.Speed = speed; }
public static void CalculateSpeed(VibrationData previousData, VibrationData data) { var distance = CalculateDistance(previousData.LocationLongitude, previousData.LocationLatitude, data.LocationLongitude, data.LocationLatitude); var timeDiff = previousData.TimeStamp - data.TimeStamp; var speed = distance / Math.Abs(timeDiff.TotalHours); data.Speed = speed; }
public void Post([FromBody] VibrationData data) { var previousData = _dbContext.VibrationDatas.Where(vb => vb.RouteId == data.RouteId).OrderByDescending(vb => vb.TimeStamp).FirstOrDefault(); if (previousData == null) { //First mesurement in route var route = _dbContext.Routes.Where(r => r.RouteId == data.RouteId).FirstOrDefault(); var routeStart = new RouteStart { BeginTime = route.BeginTime, StartLocationLatitude = route.StartLocationLatitude, StartLocationLongitude = route.StartLocationLongitude }; SpeedCalculator.CalculateSpeed(routeStart, data); } else { SpeedCalculator.CalculateSpeed(previousData, data); } _dbContext.Add(data); _dbContext.SaveChanges(); }
private async Task AMSTrackChanged(IEnumerable <BaseWaveChannelToken> tokens) { try { if (tokens == null) { return; } var unValidTokens = tokens.Where(o => o.CurrentIndex == -1); foreach (var token in unValidTokens) { token.VData = null; } var validTokens = tokens.Where(o => o.CurrentIndex != -1).ToArray(); if (validTokens.Length == 0) { return; } //var globalIndexes = validTokens.Select(o => o.DataContracts[o.CurrentIndex].ChannelGlobalIndex).ToArray(); //var ids = validTokens.Select(o => o.DataContracts[o.CurrentIndex].id).ToArray(); //var date = validTokens.Select(o => o.DataContracts[o.CurrentIndex].ACQDatetime).First(); List <IWaveformData> result = new List <IWaveformData>(); foreach (var token in validTokens) { if (token is BaseDivfreChannelToken) { var divtoken = token as BaseDivfreChannelToken; List <D_WirelessVibrationSlot_Waveform> data = null; if (divtoken.CurrentIndex != -1 && (divtoken.DataContracts[divtoken.CurrentIndex] as IBaseDivfreSlot).IsValidWave.Value == true)//修正拖动太快,CurrentIndex一直在变 { data = await _databaseComponent.GetHistoryData <D_WirelessVibrationSlot_Waveform>(divtoken.IP, divtoken.Guid, new string[] { "WaveData", "SampleFre", "SamplePoint", "WaveUnit" }, divtoken.DataContracts[divtoken.CurrentIndex].ACQDatetime.AddSeconds(-1), divtoken.DataContracts[divtoken.CurrentIndex].ACQDatetime.AddSeconds(20), "(RecordLab = @0)", new object[] { divtoken.DataContracts[divtoken.CurrentIndex].RecordLab }); } else { token.VData = null; } if (data != null && data.Count > 0) { result.Add(ClassCopyHelper.AutoCopy <D_WirelessVibrationSlot_Waveform, WirelessVibrationSlotData_Waveform>(data[0])); } else { token.VData = null; } } } await Task.Run(() => Parallel.For(0, result.Count, i => { VibrationData vdata = new VibrationData(); vdata.Waveform = Algorithm.ByteToSingle(result[i].WaveData); vdata.SampleFre = result[i].SampleFre ?? 0; vdata.SamplePoint = result[i].SamplePoint ?? 0; vdata.Unit = result[i].WaveUnit; var paras = Algorithm.CalculatePara(vdata.Waveform); if (paras != null) { vdata.RMSValue = paras[0]; vdata.PeakValue = paras[1]; vdata.PeakPeakValue = paras[2]; vdata.Slope = paras[3]; vdata.Kurtosis = paras[4]; vdata.KurtosisValue = paras[5]; vdata.WaveIndex = paras[6]; vdata.PeakIndex = paras[7]; vdata.ImpulsionIndex = paras[8]; vdata.RootAmplitude = paras[9]; vdata.ToleranceIndex = paras[10]; } double sampleFre = vdata.SampleFre; if (vdata.Trigger == TriggerType.Angle) { if (vdata.RPM > 0 && vdata.TeethNumber > 0) { sampleFre = vdata.RPM *vdata.TeethNumber / 60; } } int length = (int)(vdata.SamplePoint / 2.56) + 1; if (vdata.Frequency == null || vdata.Frequency.Length != length) { vdata.Frequency = new double[length]; } double frequencyInterval = sampleFre / vdata.SamplePoint; for (int j = 0; j < length; j++) { vdata.Frequency[j] = frequencyInterval *j; } var output = Algorithm.Instance.FFT2AndPhaseAction(vdata.Waveform, vdata.SamplePoint); if (output != null) { vdata.Amplitude = output[0].Take(length).ToArray(); vdata.Phase = output[1].Take(length).ToArray(); } validTokens[i].VData = vdata; })); timeDomainVM.ChangeChannelData(tokens); frequencyDomainVM.ChangeChannelData(tokens); } catch (Exception ex) { _eventAggregator.GetEvent <ThrowExceptionEvent>().Publish(Tuple.Create <string, Exception>("数据回放-TrackChanged", ex)); } }