public TrendData GetTrend(WaveData wave, float[] spectrum) { TrendData trendData = new TrendData(); trendData.Time = wave.time; switch (this.option) { case "p2p": trendData.Value = GetPeakToPeak(wave); break; case "upper": trendData.Value = GetUpperPeak(wave); break; case "lower": trendData.Value = GetLowerPeak(wave); break; case "peak": trendData.Value = GetPeak(wave); break; default: throw new Exception("Peak option is unavailable"); } return(trendData); }
internal int PressureTrend() { int trend = 0; TrendData t = new TrendData(); t.time = DateTime.Now; t.pressure = AirObj.obs[0][(int)AirIndex.PRESSURE].GetValueOrDefault(); Trend.Enqueue(t); t = Trend.Peek(); if (t.time.AddHours(3) < DateTime.Now) { t = Trend.Dequeue(); if (t.pressure < (AirObj.obs[0][(int)AirIndex.PRESSURE] + 1)) { trend = 1; } else if (t.pressure > (AirObj.obs[0][(int)AirIndex.PRESSURE] - 1)) { trend = -1; } } return(trend); }
/// <summary> /// Returns an empty list. /// </summary> private IEnumerable <TrendData> GetEmptyTrend() { TrendData[] trends = new TrendData[] { new TrendData { target = "-1", datapoints = null } }; return(trends); }
public TrendData RemoveLatest(TrendData trendData) { if (trendData.Data.Any()) { var min = trendData.Data.Min(d => d.Key); trendData.Data.Remove(min); } trendData.Trend = Trend.STAY; return(trendData); }
public TrendData CalculateTrend(TrendData trendData, DateTime matchDate, int value) { if (trendData.Data.Count >= 5) { var min = trendData.Data.Min(d => d.Key); trendData.Data.Remove(min); } while (trendData.Data.ContainsKey(matchDate)) { matchDate = matchDate.AddMinutes(1); } trendData.Data.Add(matchDate, value); trendData.Trend = this.ReCalculate(trendData.Data); return(trendData); }
//Get Rms with Option public TrendData GetTrend(WaveData wave, float[] spectrum) { double square = 0; float mean, root = 0; for (int i = start; i < end; i++) { square += (wave.Floats[i] * wave.Floats[i]); } mean = (float)square / wave.data.Length; root = (float)Math.Sqrt(mean); var id = title; TrendData trendData = new TrendData(); trendData.Value = root; trendData.Time = wave.time; //trendData.Id = title; return(trendData); }
public IEnumerable <TrendData> GetDataForGrafana([FromBody] GrafanaArg grafanaArg) { if (grafanaArg == null) { return(GetEmptyTrend()); } else { if (grafanaArg.targets == null) { Log.WriteError("It is not possible to receive data"); return(GetEmptyTrend()); } else { SelectArcType(grafanaArg, out bool isHour, out int timeCoef); TrendData[] trends = new TrendData[grafanaArg.targets.Length]; long fromMs = GetUnixTimeMs(grafanaArg.range.from); long toMs = GetUnixTimeMs(grafanaArg.range.to); for (int i = 0; i < grafanaArg.targets.Length; i++) { List <double?[]> points = new List <double?[]>(); if (!int.TryParse(grafanaArg.targets[i].target.Trim(), out int cnlNum)) { Log.WriteError("It is not possible to read the dates for the channel " + cnlNum); trends[i] = new TrendData { target = "-1", datapoints = null }; } else { foreach (DateTime date in EachDay(grafanaArg.range.from, grafanaArg.range.to)) { Trend trend = GetTrend(UtcToLocalTime(date), cnlNum, isHour); for (int i1 = 0; i1 < trend.Points.Count; i1++) { long pointMs = GetUnixTimeMs(LocalToUtcTime(trend.Points[i1].DateTime)); if (pointMs >= fromMs && pointMs <= toMs) { if (i1 > 0) { long prevMs = GetUnixTimeMs(LocalToUtcTime(trend.Points[i1 - 1].DateTime)); if (pointMs - prevMs > timeCoef * 60000) { points.Add(new double?[] { null, prevMs + timeCoef * 60000 }); } else { if (trend.Points[i1].Stat > 0) { points.Add(new double?[] { trend.Points[i1].Val, pointMs }); } else { points.Add(new double?[] { null, pointMs }); } } } else { if (trend.Points[i1].Stat > 0) { points.Add(new double?[] { trend.Points[i1].Val, pointMs }); } else { points.Add(new double?[] { null, pointMs }); } } } } } InCnlProps inCnlProps = dataAccess.GetCnlProps(cnlNum); string cnlName = inCnlProps == null ? "" : inCnlProps.CnlName; trends[i] = new TrendData { target = "[" + cnlNum + "] " + cnlName, datapoints = points }; Log.WriteAction("Channel data received " + cnlNum); } } return(trends); } } }
public IEnumerable <TrendData> GetDataForGrafana([FromBody] GrafanaArg grafanaArg) { if (grafanaArg == null) { return(GetEmptyTrend()); } else { if (grafanaArg.targets == null) { Log.WriteError("It is not possible to receive data"); return(GetEmptyTrend()); } else { List <double?[]> points = new List <double?[]>(); SelectArcType(grafanaArg, out bool isHour, out int timeCoef); TrendData[] trends = new TrendData[grafanaArg.targets.Length]; for (int i = 0; i < grafanaArg.targets.Length; i++) { points = new List <double?[]>(); if (!int.TryParse(grafanaArg.targets[i].target.Trim(), out int cnlNum)) { Log.WriteError("It is not possible to read the dates for the channel " + cnlNum); trends[i] = new TrendData { target = "-1", datapoints = null }; } else { foreach (DateTime date in EachDay(grafanaArg.range.from, grafanaArg.range.to)) { Trend trend = GetTrend(date, cnlNum, isHour); for (int i1 = 0; i1 < trend.Points.Count; i1++) { long ofsVal = GetUnixTimeMs(trend.Points[i1].DateTime); if (i1 > 0) { long ofsValP = GetUnixTimeMs(trend.Points[i1 - 1].DateTime); if ((ofsVal - ofsValP) > timeCoef * 60000) { points.Add(new double?[] { null, ofsValP + timeCoef * 60000 }); } else { points.Add(new double?[] { trend.Points[i1].Val, ofsVal }); } } else { points.Add(new double?[] { trend.Points[i1].Val, ofsVal }); } } } trends[i] = new TrendData { target = cnlNum.ToString(), datapoints = points }; Log.WriteAction("Channel data received " + cnlNum); } } return(trends); } } }
private void FetchTwitterTrends(double latitude, double longitude, long woeId) { var placeTrends = Trends.GetTrendsAt(woeId); var twitterTrendingData = new TwitterTrendingData { Trends = new List<TrendData>() }; foreach (var item in placeTrends.Trends) { twitterTrendingData.TimeId = placeTrends.AsOf; var trendData = new TrendData { Name = item.Name }; var searchParameter = Search.CreateTweetSearchParameter(item.Name); // searchParameter.MaximumNumberOfResults = 500; ICoordinates coord = new Coordinates(longitude, latitude); searchParameter.SetGeoCode(coord, 50000, DistanceMeasure.Miles); var tweets = Search.SearchTweets(searchParameter); trendData.Tweets = new List<MyTweet>(); foreach (var tweet in tweets) { var myTweet = new MyTweet { Latitude = tweet.Coordinates.Latitude, Longitude = tweet.Coordinates.Longitude, Text = tweet.Text }; trendData.Tweets.Add(myTweet); } twitterTrendingData.Trends.Add(trendData); } }
public void waveReceiver_WavesReceived(WaveData[] waves) { /*Time*/ var resolution = Settings.Default.AsyncLine / (double)Settings.Default.AsyncFMax; foreach (var serise in TimeChart.Series) { (serise as FastLine).Clear(); } for (int ch = 0; ch < waves.Length; ch++) { var displayData = EnableIntegrator ? NormalIntegrator.Integration(waves[ch].AsyncData) : waves[ch].AsyncData; TimeChart.Series[ch].BeginUpdate(); for (int i = 0; i < waves[ch].AsyncDataCount; i++) { TimeChart.Series[ch].Add(i * resolution / (double)waves[ch].AsyncDataCount, displayData[i]); } TimeChart.Series[ch].EndUpdate(); } /*FFT*/ foreach (var serise in FFTChart.Series) { (serise as FastLine).Clear(); } for (int ch = 0; ch < waves.Length; ch++) { var displayData = EnableIntegrator ? NormalIntegrator.Integration(waves[ch].AsyncData) : waves[ch].AsyncData; var fft = FFTCalculator.CreateSpectrumData(displayData, waves[ch].DateTime); FFTChart.Series[ch].BeginUpdate(); for (int i = 0; i < fft.XValues.Length; i++) { FFTChart.Series[ch].Add(fft.XValues[i], fft.YValues[i]); } FFTChart.Series[ch].EndUpdate(); } TrendData[] datas = new TrendData[MeasureList.Count]; /*Trend*/ if (MeasureList.Count > 0) { for (int i = 0; i < MeasureList.Count; i++) { var chid = MeasureList[i].GetChannelIdx(); var fftData = FFTCalculator.CreateSpectrumData(waves[chid].AsyncData, waves[chid].DateTime); var series = TrendChart.Series[i]; if (series.Count > TrendXScale) { series.Delete(0); } var measureData = MeasureList[i].CalcMeasureScalar(waves[chid], fftData); series.Add(waves[chid].DateTime, MeasureList[i].CalcMeasureScalar(waves[chid], fftData)); SQLRepository.TrendData.InsertData(new TrendData(waves[chid].DateTime, MeasureList[i].GetIdx(), measureData)); } } foreach (var recoder in RecoderList) { var queue = recoder.GetWavesQueue(); lock (((ICollection)queue).SyncRoot) { if (queue.Count > 100) { WaveQueue.Dequeue(); } queue.Enqueue(waves); } } }