public void CanAddFromXy() { var series = new FlotSeries(null); series.Add(2, 3); Assert.AreEqual(1, series.Data.Count); }
public JsonReturn GetBreakerData() { Dictionary <string, string> query = Request.QueryParameters(); int eventId = int.Parse(query["eventId"]); Event evt = m_dataContext.Table <Event>().QueryRecordWhere("ID = {0}", eventId); Meter meter = m_dataContext.Table <Meter>().QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_dataContext.Connection.Connection, typeof(SqlDataAdapter), false); DateTime epoch = new DateTime(1970, 1, 1); DateTime startTime = (query.ContainsKey("startDate") ? DateTime.Parse(query["startDate"]) : evt.StartTime); DateTime endTime = (query.ContainsKey("endDate") ? DateTime.Parse(query["endDate"]) : evt.EndTime); int pixels = int.Parse(query["pixels"]); DataTable table; int calcCycle = m_dataContext.Connection.ExecuteScalar <int?>("SELECT CalculationCycle FROM FaultSummary WHERE EventID = {0} AND IsSelectedAlgorithm = 1", evt.ID) ?? -1; Dictionary <string, FlotSeries> dict = new Dictionary <string, FlotSeries>(); table = m_dataContext.Connection.RetrieveData("select ID from Event WHERE StartTime <= {0} AND EndTime >= {1} and MeterID = {2} AND LineID = {3}", ToDateTime2(m_dataContext.Connection, endTime), ToDateTime2(m_dataContext.Connection, startTime), evt.MeterID, evt.LineID); foreach (DataRow row in table.Rows) { Dictionary <string, FlotSeries> temp = QueryBreakerData(int.Parse(row["ID"].ToString()), meter); foreach (string key in temp.Keys) { if (dict.ContainsKey(key)) { dict[key].DataPoints = dict[key].DataPoints.Concat(temp[key].DataPoints).ToList(); } else { dict.Add(key, temp[key]); } } } if (dict.Count == 0) { return(null); } double calcTime = (calcCycle >= 0 ? dict.First().Value.DataPoints[calcCycle][0] : 0); List <FlotSeries> returnList = new List <FlotSeries>(); foreach (string key in dict.Keys) { FlotSeries series = new FlotSeries(); series = dict[key]; series.DataPoints = Downsample(dict[key].DataPoints.Where(x => !double.IsNaN(x[1])).OrderBy(x => x[0]).ToList(), pixels, new Range <DateTime>(startTime, endTime)); returnList.Add(series); } JsonReturn returnDict = new JsonReturn(); returnDict.StartDate = evt.StartTime; returnDict.EndDate = evt.EndTime; returnDict.Data = returnList; returnDict.CalculationTime = calcTime; return(returnDict); }
public void CheckSeriesDotChart() { var chart = new FlotChart("test"); var series = new FlotSeries(chart); Assert.AreEqual(chart, series.Chart); }
public FlotSeries Clone() { FlotSeries clone = (FlotSeries)MemberwiseClone(); clone.DataPoints = new List <double[]>(); return(clone); }
public void CanGetJsonWhenNotFieldsOrPoints() { var series = new FlotSeries(null); string json = series.ToJson(); Assert.AreEqual("null", json); }
public void CanAddSinglePoint() { var series = new FlotSeries(null); series.Add(new FlotPoint(2, 3)); Assert.AreEqual(1, series.Data.Count); }
public void CanAddEnumerableFuncPoints() { var indexes = new [] {1,2,3,4,5}; var series = new FlotSeries(null); series.Add(indexes, x=> new FlotPoint(x,x)); Assert.AreEqual(5, series.Data.Count); }
public void CanAddEnumerableFuncPoints() { var indexes = new [] { 1, 2, 3, 4, 5 }; var series = new FlotSeries(null); series.Add(indexes, x => new FlotPoint(x, x)); Assert.AreEqual(5, series.Data.Count); }
public void CanAddEnumerablePoints() { var points = new[] { new FlotPoint(1,1), new FlotPoint(2,2), new FlotPoint(3,3) }; var series = new FlotSeries(null); series.Add(points); Assert.AreEqual(3, series.Data.Count); }
private Dictionary <string, FlotSeries> GetFrequencyDataLookup(VICycleDataGroup vICycleDataGroup, string type) { IEnumerable <string> names = vICycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type).Select(ds => ds.RMS.SeriesInfo.Channel.Phase.Name); Dictionary <string, FlotSeries> dataLookup = new Dictionary <string, FlotSeries>(); foreach (CycleDataGroup cdg in vICycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type)) { FlotSeries flotSeriesRMS = new FlotSeries { ChannelID = cdg.RMS.SeriesInfo.Channel.ID, ChannelName = cdg.RMS.SeriesInfo.Channel.Name, ChannelDescription = cdg.RMS.SeriesInfo.Channel.Description, MeasurementCharacteristic = cdg.RMS.SeriesInfo.Channel.MeasurementCharacteristic.Name, MeasurementType = cdg.RMS.SeriesInfo.Channel.MeasurementType.Name, Phase = cdg.RMS.SeriesInfo.Channel.Phase.Name, SeriesType = cdg.RMS.SeriesInfo.Channel.MeasurementType.Name, DataPoints = cdg.RMS.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(), ChartLabel = GetChartLabel(cdg.RMS.SeriesInfo.Channel, "RMS") }; dataLookup.Add(flotSeriesRMS.ChartLabel, flotSeriesRMS); FlotSeries flotSeriesWaveAmp = new FlotSeries { ChannelID = cdg.Peak.SeriesInfo.Channel.ID, ChannelName = cdg.Peak.SeriesInfo.Channel.Name, ChannelDescription = cdg.Peak.SeriesInfo.Channel.Description, MeasurementCharacteristic = cdg.Peak.SeriesInfo.Channel.MeasurementCharacteristic.Name, MeasurementType = cdg.Peak.SeriesInfo.Channel.MeasurementType.Name, Phase = cdg.Peak.SeriesInfo.Channel.Phase.Name, SeriesType = cdg.Peak.SeriesInfo.Channel.MeasurementType.Name, DataPoints = cdg.Peak.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(), ChartLabel = GetChartLabel(cdg.Peak.SeriesInfo.Channel, "Amplitude") }; dataLookup.Add(flotSeriesWaveAmp.ChartLabel, flotSeriesWaveAmp); FlotSeries flotSeriesPolarAngle = new FlotSeries { ChannelID = cdg.Phase.SeriesInfo.Channel.ID, ChannelName = cdg.Phase.SeriesInfo.Channel.Name, ChannelDescription = cdg.Phase.SeriesInfo.Channel.Description, MeasurementCharacteristic = cdg.Phase.SeriesInfo.Channel.MeasurementCharacteristic.Name, MeasurementType = cdg.Phase.SeriesInfo.Channel.MeasurementType.Name, Phase = cdg.Phase.SeriesInfo.Channel.Phase.Name, SeriesType = cdg.Phase.SeriesInfo.Channel.MeasurementType.Name, DataPoints = cdg.Phase.DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(), ChartLabel = GetChartLabel(cdg.Phase.SeriesInfo.Channel, "Phase") }; dataLookup.Add(flotSeriesPolarAngle.ChartLabel, flotSeriesPolarAngle); } return(dataLookup); }
public void CanAddEnumerablePoints() { var points = new[] { new FlotPoint(1, 1), new FlotPoint(2, 2), new FlotPoint(3, 3) }; var series = new FlotSeries(null); series.Add(points); Assert.AreEqual(3, series.Data.Count); }
private KeyValuePair <string, FlotSeries> QueryFaultDistanceData(int faultCurveID, Meter meter) { FaultCurve faultCurve = m_dataContext.Table <FaultCurve>().QueryRecordWhere("ID = {0}", faultCurveID); DataGroup dataGroup = ToDataGroup(meter, faultCurve.Data); FlotSeries flotSeries = new FlotSeries() { ChannelID = 0, ChannelName = faultCurve.Algorithm, ChannelDescription = faultCurve.Algorithm, MeasurementCharacteristic = "FaultCurve", MeasurementType = "FaultCurve", Phase = "None", SeriesType = "None", DataPoints = dataGroup.DataSeries[0].DataPoints.Select(dataPoint => new double[] { dataPoint.Time.Subtract(m_epoch).TotalMilliseconds, dataPoint.Value }).ToList(), ChartLabel = faultCurve.Algorithm }; return(new KeyValuePair <string, FlotSeries> (faultCurve.Algorithm, flotSeries)); }
public JsonReturn GetData() { Dictionary <string, FlotSeries> temp; using (AdoDataConnection connection = new AdoDataConnection("dbOpenXDA")) { Dictionary <string, string> query = Request.QueryParameters(); int breakerID; int channelID; try { channelID = int.Parse(query["channelid"]); } catch { channelID = -1; } try { breakerID = int.Parse(query["breakerid"]); } catch { breakerID = -1; } Breaker breaker = new TableOperations <Breaker>(connection).QueryRecordWhere("ID = {0}", breakerID); temp = GetStatisticsLookup(breaker.ID, channelID); } Dictionary <string, FlotSeries> dict = new Dictionary <string, FlotSeries>(); foreach (string key in temp.Keys) { if (temp[key].DataPoints.Count() > 0) { if (dict.ContainsKey(key)) { dict[key].DataPoints = dict[key].DataPoints.Concat(temp[key].DataPoints).ToList(); } else { dict.Add(key, temp[key]); } } } if (dict.Count == 0) { return(null); } JsonReturn returnDict = new JsonReturn(); List <FlotSeries> returnList = new List <FlotSeries>(); foreach (string key in dict.Keys) { FlotSeries series = new FlotSeries(); series = dict[key]; series.DataPoints = dict[key].DataPoints.OrderBy(x => x[0]).ToList(); returnList.Add(series); } //returnDict.StartDate = evt.StartTime; //returnDict.EndDate = evt.EndTime; returnDict.Data = null; returnDict.CalculationTime = 0; returnDict.CalculationEnd = 0; return(returnDict); }
public List<FlotSeries> GetFlotData(int eventID, List<int> seriesIndexes) { List<FlotSeries> flotSeriesList = new List<FlotSeries>(); using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter<EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter<EventDataTableAdapter>(); FaultCurveTableAdapter faultCurveAdapter = dbAdapterContainer.GetAdapter<FaultCurveTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter<MeterInfoDataContext>(); FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter<FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID); List<Series> waveformInfo = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID); List<string> faultCurveInfo = GetFaultCurveInfo(connection, eventID); DateTime epoch = new DateTime(1970, 1, 1); Lazy<Dictionary<int, DataSeries>> waveformData = new Lazy<Dictionary<int, DataSeries>>(() => { return ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID); }); Lazy<DataGroup> cycleData = new Lazy<DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID))); Lazy<Dictionary<string, DataSeries>> faultCurveData = new Lazy<Dictionary<string, DataSeries>>(() => { return faultCurveAdapter .GetDataBy(eventRow.ID) .Select(faultCurve => new { Algorithm = faultCurve.Algorithm, DataGroup = ToDataGroup(meter, faultCurve.Data) }) .Where(obj => obj.DataGroup.DataSeries.Count > 0) .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0]); }); foreach (int index in seriesIndexes) { DataSeries dataSeries = null; FlotSeries flotSeries = null; int waveformIndex = index; int cycleIndex = waveformIndex - waveformInfo.Count; int faultCurveIndex = cycleIndex - CycleDataInfo.Count; if (waveformIndex < waveformInfo.Count) { if (!waveformData.Value.TryGetValue(waveformInfo[index].ID, out dataSeries)) continue; flotSeries = ToFlotSeries(waveformInfo[index]); } else if (cycleIndex < CycleDataInfo.Count) { if (cycleIndex >= cycleData.Value.DataSeries.Count) continue; dataSeries = cycleData.Value[cycleIndex]; flotSeries = new FlotSeries() { MeasurementType = CycleDataInfo[cycleIndex].MeasurementType, MeasurementCharacteristic = CycleDataInfo[cycleIndex].MeasurementCharacteristic, Phase = CycleDataInfo[cycleIndex].Phase, SeriesType = CycleDataInfo[cycleIndex].SeriesType }; } else if (faultCurveIndex < faultCurveInfo.Count) { string algorithm = faultCurveInfo[faultCurveIndex]; if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries)) continue; flotSeries = ToFlotSeries(faultCurveInfo[faultCurveIndex]); } else { continue; } foreach (DataPoint dataPoint in dataSeries.DataPoints) { if (!double.IsNaN(dataPoint.Value)) flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value }); } flotSeriesList.Add(flotSeries); } } return flotSeriesList; }
public List <FlotSeries> GetFlotData(int eventID, List <int> seriesIndexes) { List <FlotSeries> flotSeriesList = new List <FlotSeries>(); using (DbAdapterContainer dbAdapterContainer = new DbAdapterContainer(ConnectionString)) using (AdoDataConnection connection = new AdoDataConnection(dbAdapterContainer.Connection, typeof(SqlDataAdapter), false)) { EventTableAdapter eventAdapter = dbAdapterContainer.GetAdapter <EventTableAdapter>(); EventDataTableAdapter eventDataAdapter = dbAdapterContainer.GetAdapter <EventDataTableAdapter>(); FaultCurveTableAdapter faultCurveAdapter = dbAdapterContainer.GetAdapter <FaultCurveTableAdapter>(); MeterInfoDataContext meterInfo = dbAdapterContainer.GetAdapter <MeterInfoDataContext>(); FaultLocationInfoDataContext faultLocationInfo = dbAdapterContainer.GetAdapter <FaultLocationInfoDataContext>(); MeterData.EventRow eventRow = eventAdapter.GetDataByID(eventID).FirstOrDefault(); Meter meter = meterInfo.Meters.First(m => m.ID == eventRow.MeterID); List <Series> waveformInfo = GetWaveformInfo(meterInfo.Series, eventRow.MeterID, eventRow.LineID); List <string> faultCurveInfo = GetFaultCurveInfo(connection, eventID); DateTime epoch = new DateTime(1970, 1, 1); Lazy <Dictionary <int, DataSeries> > waveformData = new Lazy <Dictionary <int, DataSeries> >(() => { return(ToDataGroup(meter, eventDataAdapter.GetTimeDomainData(eventRow.EventDataID)).DataSeries .ToDictionary(dataSeries => dataSeries.SeriesInfo.ID)); }); Lazy <DataGroup> cycleData = new Lazy <DataGroup>(() => ToDataGroup(meter, eventDataAdapter.GetFrequencyDomainData(eventRow.EventDataID))); Lazy <Dictionary <string, DataSeries> > faultCurveData = new Lazy <Dictionary <string, DataSeries> >(() => { return(faultCurveAdapter .GetDataBy(eventRow.ID) .Select(faultCurve => new { Algorithm = faultCurve.Algorithm, DataGroup = ToDataGroup(meter, faultCurve.Data) }) .Where(obj => obj.DataGroup.DataSeries.Count > 0) .ToDictionary(obj => obj.Algorithm, obj => obj.DataGroup[0])); }); foreach (int index in seriesIndexes) { DataSeries dataSeries = null; FlotSeries flotSeries = null; int waveformIndex = index; int cycleIndex = waveformIndex - waveformInfo.Count; int faultCurveIndex = cycleIndex - CycleDataInfo.Count; if (waveformIndex < waveformInfo.Count) { if (!waveformData.Value.TryGetValue(waveformInfo[index].ID, out dataSeries)) { continue; } flotSeries = ToFlotSeries(waveformInfo[index]); } else if (cycleIndex < CycleDataInfo.Count) { if (cycleIndex >= cycleData.Value.DataSeries.Count) { continue; } dataSeries = cycleData.Value[cycleIndex]; flotSeries = new FlotSeries() { MeasurementType = CycleDataInfo[cycleIndex].MeasurementType, MeasurementCharacteristic = CycleDataInfo[cycleIndex].MeasurementCharacteristic, Phase = CycleDataInfo[cycleIndex].Phase, SeriesType = CycleDataInfo[cycleIndex].SeriesType }; } else if (faultCurveIndex < faultCurveInfo.Count) { string algorithm = faultCurveInfo[faultCurveIndex]; if (!faultCurveData.Value.TryGetValue(algorithm, out dataSeries)) { continue; } flotSeries = ToFlotSeries(faultCurveInfo[faultCurveIndex]); } else { continue; } foreach (DataPoint dataPoint in dataSeries.DataPoints) { if (!double.IsNaN(dataPoint.Value)) { flotSeries.DataPoints.Add(new double[] { dataPoint.Time.Subtract(epoch).TotalMilliseconds, dataPoint.Value }); } } flotSeriesList.Add(flotSeries); } } return(flotSeriesList); }
public void CanCreateSeries() { var series = new FlotSeries(null); }
/// <summary> /// Get canned/dummy flot chart /// </summary> /// <param name="mode">Mode for which to get the chart</param> /// <returns>Flot chart</returns> public FlotChart GetFlotChart(int mode) { FlotOptions options = new FlotOptions { xaxis = new JQFlot.SubOptions.AxisOptions { axisLabel = "X axis label", axisLabelColor = "#222222" }, yaxis = new JQFlot.SubOptions.AxisOptions { axisLabel = "Y axis label", axisLabelColor = "#222222" }, grid = new JQFlot.SubOptions.GridOptions { borderWidth = 1 } }; List <FlotSeries> series = new List <FlotSeries>(); FlotSeries serie = null; switch (mode) { case 6: serie = new FlotSeries { label = "Sample Line Graph", data = GraphSampleData, lines = new LineGraph { show = true } }; series.Add(serie); options = new FlotOptions { grid = new JQFlot.SubOptions.GridOptions { borderWidth = 1 }, xaxis = new JQFlot.SubOptions.AxisOptions { tickDecimals = 2, tickFormatter = new JsFunc { ParameterNames = new string[] { "val", "axis" }, Body = "return val.toFixed(axis.tickDecimals);" }, axisLabel = "X Axis - Ticks to two decimals", axisLabelColor = "#222222" }, yaxis = new JQFlot.SubOptions.AxisOptions { axisLabel = "Y Axis Label", axisLabelColor = "#222222" } }; break; case 5: goto default; case 4: series = Enumerable.Range(1, 5).Select(f => new FlotSeries { label = "Serie" + f.ToString(CultureInfo.InvariantCulture), data = m_rand.NextDouble() * 100 }).ToList(); options = new FlotOptions { series = new JQFlot.SubOptions.SeriesOptions { pie = new PieGraph { show = true } } }; break; case 3: serie = new FlotSeries { label = "Sample Bar Graph", data = GraphSampleData, bars = new BarGraph { show = true } }; series.Add(serie); break; case 2: serie = new FlotSeries { label = "Sample Curved Line Graph", data = GraphSampleData, curvedLines = new CurvedLineGraph { show = true } }; options = new FlotOptions { xaxis = new JQFlot.SubOptions.AxisOptions { axisLabel = "X axis label", axisLabelColor = "#222222" }, yaxis = new AxisOptions { axisLabel = "Y axis label", axisLabelColor = "#222222" }, grid = new GridOptions { borderWidth = 1 }, series = new SeriesOptions { curvedLines = new CurvedLineOptions { active = true } } }; series.Add(serie); break; case 1: serie = new FlotSeries { label = "Sample Dashed Line Graph", data = GraphSampleData, dashes = new DashedLineGraph { show = true } }; series.Add(serie); break; case 0: default: serie = new FlotSeries { label = "Sample Line Graph", data = GraphSampleData, lines = new LineGraph { show = true } }; series.Add(serie); break; } FlotChart chart = new FlotChart { chartOptions = options, chartSeries = series.ToArray() }; return(chart); }
public ActionResult GetData() { int eventId = int.Parse(Request.QueryString["eventId"]); Event evt = m_dataContext.Table <Event>().QueryRecordWhere("ID = {0}", eventId); Meter meter = m_dataContext.Table <Meter>().QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_dataContext.Connection.Connection, typeof(SqlDataAdapter), false); int calcCycle = m_dataContext.Connection.ExecuteScalar <int?>("SELECT CalculationCycle FROM FaultSummary WHERE EventID = {0} AND IsSelectedAlgorithm = 1", evt.ID) ?? -1; double systemFrequency = m_dataContext.Connection.ExecuteScalar <double?>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? 60.0; string type = Request.QueryString["type"]; string dataType = Request.QueryString["dataType"]; DateTime startTime = (Request.QueryString["startDate"] != null ? DateTime.Parse(Request.QueryString["startDate"]) : evt.StartTime); DateTime endTime = (Request.QueryString["endDate"] != null ? DateTime.Parse(Request.QueryString["endDate"]) : evt.EndTime); int pixels = int.Parse(Request.QueryString["pixels"]); DataTable table; Dictionary <string, FlotSeries> dict = new Dictionary <string, FlotSeries>(); table = m_dataContext.Connection.RetrieveData("select ID from Event WHERE StartTime <= {0} AND EndTime >= {1} and MeterID = {2} AND LineID = {3}", ToDateTime2(m_dataContext.Connection, endTime), ToDateTime2(m_dataContext.Connection, startTime), evt.MeterID, evt.LineID); foreach (DataRow row in table.Rows) { Dictionary <string, FlotSeries> temp; if (dataType == "Time") { temp = QueryEventData(int.Parse(row["ID"].ToString()), meter, type); } else { temp = QueryFrequencyData(int.Parse(row["ID"].ToString()), meter, type); } foreach (string key in temp.Keys) { if (temp[key].MeasurementType == type) { if (dict.ContainsKey(key)) { dict[key].DataPoints = dict[key].DataPoints.Concat(temp[key].DataPoints).ToList(); } else { dict.Add(key, temp[key]); } } } } double calcTime = (calcCycle >= 0 ? dict.First().Value.DataPoints[calcCycle][0] : 0); List <FlotSeries> returnList = new List <FlotSeries>(); foreach (string key in dict.Keys) { FlotSeries series = new FlotSeries(); series = dict[key]; series.DataPoints = Downsample(dict[key].DataPoints.OrderBy(x => x[0]).ToList(), pixels, new Range <DateTime>(startTime, endTime)); returnList.Add(series); } JsonReturn returnDict = new JsonReturn(); returnDict.StartDate = evt.StartTime; returnDict.EndDate = evt.EndTime; returnDict.Data = returnList; returnDict.CalculationTime = calcTime; returnDict.CalculationEnd = calcTime + 1000 / systemFrequency; return(Json(returnDict, JsonRequestBehavior.AllowGet)); }