public ActionResult Get(int eventID, int pixels) { using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"])) { Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID); if (evt == null) { return(BadRequest("Must provide a valid EventID")); } Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]); Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >(); DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache); VICycleDataGroup vICycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter); Dictionary <string, List <double[]> > returnList = new Dictionary <string, List <double[]> >(); foreach (CycleDataGroup dg in vICycleDataGroup.CycleDataGroups) { if (dg.RMS.SeriesInfo.Channel.MeasurementType.Name == "Voltage") { string name = "V" + dg.RMS.SeriesInfo.Channel.Phase.Name; returnList.Add(name, GetRapidVoltageChangeSeries(dg.RMS)); } } return(Ok(returnList)); } }
public ActionResult Get(int eventID, string type, int pixels) { using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"])) { DateTime epoch = new DateTime(1970, 1, 1); Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID); if (evt == null) { return(BadRequest("Must provide a valid EventID")); } Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]); Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >(); DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache); DataGroup dataGroup = dataGroupHelper.QueryDataGroup(eventID, meter);; foreach (var series in dataGroup.DataSeries) { List <double[]> data = series.DataPoints.Select(dp => new double[2] { (dp.Time - epoch).TotalMilliseconds, dp.Value }).ToList(); if (series.SeriesInfo.Channel.MeasurementType.Name == type && series.SeriesInfo.Channel.MeasurementCharacteristic.Name == "Instantaneous") { returnData.Add((type == "Voltage" ? "V" : "I") + series.SeriesInfo.Channel.Phase.Name, data); } } VICycleDataGroup viCycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter);; foreach (CycleDataGroup cdg in viCycleDataGroup.CycleDataGroups.Where(ds => ds.RMS.SeriesInfo.Channel.MeasurementType.Name == type)) { List <double[]> rmsPoints = cdg.RMS.DataPoints.Select(dp => new double[2] { (dp.Time - epoch).TotalMilliseconds, dp.Value }).ToList(); returnData.Add((type == "Voltage" ? "V" : "I") + cdg.RMS.SeriesInfo.Channel.Phase.Name + " RMS", rmsPoints); List <double[]> ampPoints = cdg.Peak.DataPoints.Select(dp => new double[2] { (dp.Time - epoch).TotalMilliseconds, dp.Value }).ToList(); returnData.Add((type == "Voltage" ? "V" : "I") + cdg.Peak.SeriesInfo.Channel.Phase.Name + " Amplitude", ampPoints); List <double[]> phPoints = cdg.Phase.DataPoints.Select(dp => new double[2] { (dp.Time - epoch).TotalMilliseconds, dp.Value * 180 / Math.PI }).ToList(); returnData.Add((type == "Voltage" ? "V" : "I") + cdg.Phase.SeriesInfo.Channel.Phase.Name + " Phase", phPoints); } return(Ok(returnData)); } }
public ActionResult Get(int eventID, int pixels) { using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"])) { Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID); if (evt == null) { return(BadRequest("Must provide a valid EventID")); } Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]); Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >(); DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache); VICycleDataGroup vICycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter); Dictionary <string, List <double[]> > returnList = new Dictionary <string, List <double[]> >(); if (vICycleDataGroup.VA != null && vICycleDataGroup.VB != null && vICycleDataGroup.VC != null) { var va = vICycleDataGroup.VA.RMS.DataPoints; var vaPhase = vICycleDataGroup.VA.Phase.DataPoints; var vb = vICycleDataGroup.VB.RMS.DataPoints; var vbPhase = vICycleDataGroup.VB.Phase.DataPoints; var vc = vICycleDataGroup.VC.RMS.DataPoints; var vcPhase = vICycleDataGroup.VC.Phase.DataPoints; IEnumerable <SequenceComponents> sequencComponents = va.Select((point, index) => { DataPoint vaPoint = point; DataPoint vaPhasePoint = vaPhase[index]; Complex vaComplex = Complex.FromPolarCoordinates(vaPoint.Value, vaPhasePoint.Value); DataPoint vbPoint = vb[index]; DataPoint vbPhasePoint = vbPhase[index]; Complex vbComplex = Complex.FromPolarCoordinates(vbPoint.Value, vbPhasePoint.Value); DataPoint vcPoint = vc[index]; DataPoint vcPhasePoint = vcPhase[index]; Complex vcComplex = Complex.FromPolarCoordinates(vcPoint.Value, vcPhasePoint.Value); SequenceComponents sequenceComponents = CalculateSequenceComponents(vaComplex, vbComplex, vcComplex); return(sequenceComponents); }); returnList.Add("S0/S1 Voltage", sequencComponents.Select((point, index) => new double[] { va[index].Time.Subtract(m_epoch).TotalMilliseconds, point.S0.Magnitude / point.S1.Magnitude * 100.0D }).ToList()); returnList.Add("S2/S1 Voltage", sequencComponents.Select((point, index) => new double[] { va[index].Time.Subtract(m_epoch).TotalMilliseconds, point.S2.Magnitude / point.S1.Magnitude * 100.0D }).ToList()); } if (vICycleDataGroup.IA != null && vICycleDataGroup.IB != null && vICycleDataGroup.IC != null) { var ia = vICycleDataGroup.IA.RMS.DataPoints; var iaPhase = vICycleDataGroup.IA.Phase.DataPoints; var ib = vICycleDataGroup.IB.RMS.DataPoints; var ibPhase = vICycleDataGroup.IB.Phase.DataPoints; var ic = vICycleDataGroup.IC.RMS.DataPoints; var icPhase = vICycleDataGroup.IC.Phase.DataPoints; IEnumerable <SequenceComponents> sequencComponents = ia.Select((point, index) => { DataPoint iaPoint = point; DataPoint iaPhasePoint = iaPhase[index]; Complex iaComplex = Complex.FromPolarCoordinates(iaPoint.Value, iaPhasePoint.Value); DataPoint ibPoint = ib[index]; DataPoint ibPhasePoint = ibPhase[index]; Complex ibComplex = Complex.FromPolarCoordinates(ibPoint.Value, ibPhasePoint.Value); DataPoint icPoint = ic[index]; DataPoint icPhasePoint = icPhase[index]; Complex icComplex = Complex.FromPolarCoordinates(icPoint.Value, icPhasePoint.Value); SequenceComponents sequenceComponents = CalculateSequenceComponents(iaComplex, ibComplex, icComplex); return(sequenceComponents); }); returnList.Add("S0/S1 Current", sequencComponents.Select((point, index) => new double[] { ia[index].Time.Subtract(m_epoch).TotalMilliseconds, point.S0.Magnitude / point.S1.Magnitude * 100.0D }).ToList()); returnList.Add("S2/S1 Current", sequencComponents.Select((point, index) => new double[] { ia[index].Time.Subtract(m_epoch).TotalMilliseconds, point.S2.Magnitude / point.S1.Magnitude * 100.0D }).ToList()); } return(Ok(returnList)); } }
public FileStreamResult Get(int eventID) { using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"])) { DateTime epoch = new DateTime(1970, 1, 1); Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID); string fileName = $"Event_{eventID}.csv"; if (evt == null) { throw new Exception("Needs valid EventID"); } Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]); Dictionary <string, List <string> > returnData = new Dictionary <string, List <string> >(); DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache); DataGroup dataGroup = dataGroupHelper.QueryDataGroup(eventID, meter);; foreach (var series in dataGroup.DataSeries) { if (!returnData.ContainsKey("Timestamps")) { returnData.Add("Timestamps", series.DataPoints.Select(x => x.Time.ToString("MM/dd/yyyyTHH:mm:ss.fffffffK")).ToList()); } List <string> data = series.DataPoints.Select(dp => dp.Value.ToString()).ToList(); if (series.SeriesInfo.Channel.MeasurementType.Name == "Voltage" && series.SeriesInfo.Channel.MeasurementCharacteristic.Name == "Instantaneous") { returnData.Add("V" + series.SeriesInfo.Channel.Phase.Name, data); } else if (series.SeriesInfo.Channel.MeasurementType.Name == "Current" && series.SeriesInfo.Channel.MeasurementCharacteristic.Name == "Instantaneous") { returnData.Add("I" + series.SeriesInfo.Channel.Phase.Name, data); } } VICycleDataGroup viCycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter);; foreach (CycleDataGroup cdg in viCycleDataGroup.CycleDataGroups) { List <string> rmsPoints = cdg.RMS.DataPoints.Select(dp => dp.Value.ToString()).ToList(); returnData.Add((cdg.RMS.SeriesInfo.Channel.MeasurementType.Name == "Voltage" ? "V" : "I") + cdg.RMS.SeriesInfo.Channel.Phase.Name + " RMS", rmsPoints); List <string> ampPoints = cdg.Peak.DataPoints.Select(dp => dp.Value.ToString()).ToList(); returnData.Add((cdg.RMS.SeriesInfo.Channel.MeasurementType.Name == "Voltage" ? "V" : "I") + cdg.Peak.SeriesInfo.Channel.Phase.Name + " Amplitude", ampPoints); List <string> phPoints = cdg.Phase.DataPoints.Select(dp => (dp.Value * 180 / Math.PI).ToString()).ToList(); returnData.Add((cdg.RMS.SeriesInfo.Channel.MeasurementType.Name == "Voltage" ? "V" : "I") + cdg.Phase.SeriesInfo.Channel.Phase.Name + " Phase", phPoints); } string file = string.Join(",", returnData.Keys) + "\n"; for (int i = 0; i < returnData.First().Value.Count(); ++i) { file += string.Join(",", returnData.Keys.Select(key => { if (i < returnData[key].Count()) { return(returnData[key][i]); } else { return(""); } })) + '\n'; } byte[] fileBytes = Encoding.ASCII.GetBytes(file); Response.Headers.Add("fileName", fileName); return(new FileStreamResult(new MemoryStream(fileBytes), "text/csv") { FileDownloadName = fileName, }); } }
public ActionResult Get(int eventID, int pixels) { using (AdoDataConnection connection = new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"])) { Event evt = new TableOperations <Event>(connection).QueryRecordWhere("ID = {0}", eventID); if (evt == null) { return(BadRequest("Must provide a valid EventID")); } Meter meter = new TableOperations <Meter>(connection).QueryRecordWhere("ID = {0}", evt.MeterID); meter.ConnectionFactory = () => new AdoDataConnection(m_configuration["OpenXDA:ConnectionString"], m_configuration["OpenXDA:DataProviderString"]); Dictionary <string, IEnumerable <double[]> > returnData = new Dictionary <string, IEnumerable <double[]> >(); DataGroupHelper dataGroupHelper = new DataGroupHelper(m_configuration, m_memoryCache); VICycleDataGroup vICycleDataGroup = dataGroupHelper.QueryVICycleDataGroup(eventID, meter); double systemFrequency = connection.ExecuteScalar <double?>("SELECT Value FROM Setting WHERE Name = 'SystemFrequency'") ?? 60.0; Dictionary <string, List <double[]> > returnList = new Dictionary <string, List <double[]> >(); List <Complex> powerPointsAN = null; List <Complex> powerPointsBN = null; List <Complex> powerPointsCN = null; if (vICycleDataGroup.IA != null && vICycleDataGroup.VA != null) { List <DataPoint> voltagePointsMag = vICycleDataGroup.VA.RMS.DataPoints; List <DataPoint> voltagePointsAng = vICycleDataGroup.VA.Phase.DataPoints; List <Complex> voltagePoints = voltagePointsMag.Select((vMagPoint, index) => Complex.FromPolarCoordinates(vMagPoint.Value, voltagePointsAng[index].Value)).ToList(); List <DataPoint> currentPointsMag = vICycleDataGroup.IA.RMS.DataPoints; List <DataPoint> currentPointsAng = vICycleDataGroup.IA.Phase.DataPoints; List <Complex> currentPoints = currentPointsMag.Select((iMagPoint, index) => Complex.Conjugate(Complex.FromPolarCoordinates(iMagPoint.Value, currentPointsAng[index].Value))).ToList(); powerPointsAN = voltagePoints.Select((vPoint, index) => currentPoints[index] * vPoint).ToList(); returnList.Add("AN Reactive Power", powerPointsAN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Imaginary / 1000 }).ToList()); returnList.Add("AN Active Power", powerPointsAN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / 1000 }).ToList()); returnList.Add("AN Apparent Power", powerPointsAN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Magnitude / 1000 }).ToList()); returnList.Add("AN Power Factor", powerPointsAN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / iPoint.Magnitude }).ToList()); } if (vICycleDataGroup.IB != null && vICycleDataGroup.VB != null) { List <DataPoint> voltagePointsMag = vICycleDataGroup.VB.RMS.DataPoints; List <DataPoint> voltagePointsAng = vICycleDataGroup.VB.Phase.DataPoints; List <Complex> voltagePoints = voltagePointsMag.Select((vMagPoint, index) => Complex.FromPolarCoordinates(vMagPoint.Value, voltagePointsAng[index].Value)).ToList(); List <DataPoint> currentPointsMag = vICycleDataGroup.IB.RMS.DataPoints; List <DataPoint> currentPointsAng = vICycleDataGroup.IB.Phase.DataPoints; List <Complex> currentPoints = currentPointsMag.Select((iMagPoint, index) => Complex.Conjugate(Complex.FromPolarCoordinates(iMagPoint.Value, currentPointsAng[index].Value))).ToList(); powerPointsBN = voltagePoints.Select((vPoint, index) => currentPoints[index] * vPoint).ToList(); returnList.Add("BN Reactive Power", powerPointsBN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Imaginary / 1000 }).ToList()); returnList.Add("BN Active Power", powerPointsBN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / 1000 }).ToList()); returnList.Add("BN Apparent Power", powerPointsBN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Magnitude / 1000 }).ToList()); returnList.Add("BN Power Factor", powerPointsBN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / iPoint.Magnitude }).ToList()); } if (vICycleDataGroup.IC != null && vICycleDataGroup.VC != null) { List <DataPoint> voltagePointsMag = vICycleDataGroup.VC.RMS.DataPoints; List <DataPoint> voltagePointsAng = vICycleDataGroup.VC.Phase.DataPoints; List <Complex> voltagePoints = voltagePointsMag.Select((vMagPoint, index) => Complex.FromPolarCoordinates(vMagPoint.Value, voltagePointsAng[index].Value)).ToList(); List <DataPoint> currentPointsMag = vICycleDataGroup.IC.RMS.DataPoints; List <DataPoint> currentPointsAng = vICycleDataGroup.IC.Phase.DataPoints; List <Complex> currentPoints = currentPointsMag.Select((iMagPoint, index) => Complex.Conjugate(Complex.FromPolarCoordinates(iMagPoint.Value, currentPointsAng[index].Value))).ToList(); powerPointsCN = voltagePoints.Select((vPoint, index) => currentPoints[index] * vPoint).ToList(); returnList.Add("CN Reactive Power", powerPointsCN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Imaginary / 1000 }).ToList()); returnList.Add("CN Active Power", powerPointsCN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / 1000 }).ToList()); returnList.Add("CN Apparent Power", powerPointsCN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Magnitude / 1000 }).ToList()); returnList.Add("CN Power Factor", powerPointsCN.Select((iPoint, index) => new double[] { voltagePointsMag[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / iPoint.Magnitude }).ToList()); } if (powerPointsAN != null && powerPointsAN.Any() && powerPointsBN != null && powerPointsBN.Any() && powerPointsCN != null && powerPointsCN.Any()) { IEnumerable <Complex> powerPoints = powerPointsAN.Select((pPoint, index) => pPoint + powerPointsBN[index] + powerPointsCN[index]).ToList(); returnList.Add("Total Reactive Power", powerPointsAN.Select((iPoint, index) => new double[] { vICycleDataGroup.VC.RMS.DataPoints[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Imaginary / 1000 }).ToList()); returnList.Add("Total Active Power", powerPointsAN.Select((iPoint, index) => new double[] { vICycleDataGroup.VC.RMS.DataPoints[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / 1000 }).ToList()); returnList.Add("Total Apparent Power", powerPointsAN.Select((iPoint, index) => new double[] { vICycleDataGroup.VC.RMS.DataPoints[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Magnitude / 1000 }).ToList()); returnList.Add("Total Power Factor", powerPointsAN.Select((iPoint, index) => new double[] { vICycleDataGroup.VC.RMS.DataPoints[index].Time.Subtract(m_epoch).TotalMilliseconds, iPoint.Real / iPoint.Magnitude }).ToList()); } return(Ok(returnList)); } }