/// <summary> /// Gets the active measurement asynchronous when the BeginMeasurementAsync event is raised. /// </summary> /// <param name="sender">The sender.</param> /// <param name="m">The m.</param> /// <returns></returns> private async Task GetActiveMeasurementAsync(object sender, ActiveMeasurement m) { _comm.BeginMeasurementAsync -= GetActiveMeasurementAsync; ActiveMeasurement = m; if (ActiveMeasurement is ImpedimetricMeasurement eis) { _activeSimpleMeasurement.NewSimpleCurve(PalmSens.Data.DataArrayType.ZRe, PalmSens.Data.DataArrayType.ZIm, "Nyquist", true); //Create a nyquist curve by default } _taskCompletionSource.SetResult(_activeSimpleMeasurement); }
/// <summary> /// Sets the ActiveMeasurement at the start of a measurement and casts BeginMeasurement events coming from a different thread to the UI thread when necessary. /// </summary> /// <param name="sender">The sender.</param> /// <param name="newMeasurement">The new measurement.</param> /// <exception cref="System.NullReferenceException">Platform not set.</exception> private void _comm_BeginMeasurement(object sender, ActiveMeasurement newMeasurement) { if (_platform == null) { throw new NullReferenceException("Platform not set."); } if (_platform.InvokeIfRequired(new CommManager.BeginMeasurementEventHandler(_comm_BeginMeasurement), sender, newMeasurement)) //Recast event to UI thread when necessary { return; } MeasurementStarted?.Invoke(this, EventArgs.Empty); }
private string GetDescription(MeasurementKey key, TableOperations <ActiveMeasurement> table) { ActiveMeasurement measurement = table.QueryRecordWhere("SignalID = {0}", key.SignalID.ToString()); string text = measurement.Description; string stopAt = measurement.PhasorType == 'I' ? "-I" : "-V"; if (!string.IsNullOrWhiteSpace(text)) { int charLocation = text.IndexOf(stopAt, StringComparison.Ordinal); if (charLocation > 0) { return(text.Substring(0, charLocation)); } } return(string.Empty); }
private SignalType GetSignalType(MeasurementKey key, TableOperations <ActiveMeasurement> table) { ActiveMeasurement measurement = table.QueryRecordWhere("SignalID = {0}", key.SignalID.ToString()); if (measurement.SignalType == "IPHM") { return(SignalType.IPHM); } if (measurement.SignalType == "IPHA") { return(SignalType.IPHA); } if (measurement.SignalType == "VPHM") { return(SignalType.VPHM); } if (measurement.SignalType == "VPHA") { return(SignalType.VPHA); } return(SignalType.NONE); }
//Notifies when a measurement begins on the potentiostat protected virtual void Comm_BeginMeasurement(object sender, ActiveMeasurement newMeasurement) { }
/// <summary> /// Gets the reporting Measurment List from Aggregate Channels if available. /// </summary> /// <returns> List of ReportMeasurements to be added to Report.</returns> /// <param name="start">Start date of the Report.</param> /// <param name="end">End date of the Report.</param> /// <param name="type"> Type of Report <see cref="ReportType"/>.</param> /// <param name="criteria"> Criteria for sorting this Report <see cref="ReportCriteria"/></param> /// <param name="numberRecords"> Number of Records that are being obtained. </param> /// <param name="cancelationToken"> Cancleation Token for the historian read operation.</param> /// <param name="dataContext">DataContext from which the available reportingParameters are pulled <see cref="DataContext"/>.</param> private List <ReportMeasurements> GetFromStats(DataContext dataContext, DateTime start, DateTime end, ReportType type, ReportCriteria criteria, int numberRecords, CancellationToken cancelationToken) { List <ReportMeasurements> result = new List <ReportMeasurements>(); // For now lump I and V together since we have to change all of this logic anyway to get away from SignalID back to Point Tags eventually // and get away from SQLLite files - waiting for ritchies comments before implementing that // Also using SignalID for everything this will be adjusted once I figured out how to combine the 2 SQL DB string idCollumn = (type == ReportType.SNR? "SignalID" : "PositivePhaseSignalID"); string sortCollumn = "Max"; string typerestriction = $" AND SignalType = '{(type == ReportType.Unbalance_I? "I" : "V")}'"; switch (criteria) { case (ReportCriteria.Maximum): sortCollumn = "Max"; break; case (ReportCriteria.Mean): sortCollumn = "Mean"; break; case (ReportCriteria.StandardDev): sortCollumn = "StandardDeviation"; break; case (ReportCriteria.TimeInAlarm): sortCollumn = "PercentAlarms"; break; } string sqlQuery = $@"SELECT TOP {numberRecords} {idCollumn} AS ID, {idCollumn} AS SignalID, {idCollumn} AS PointTag, {idCollumn} AS SignalReference, (SUM(SUM)/SUM(Count)) AS Mean, MAX(Maximum) AS Max, Min(Minimum) AS Min, SQRT((1/CAST(SUM(COUNT) AS Float))*(SUM(SquaredSum)-2*SUM(Sum)*Sum(Sum)/CAST(SUM(Count) AS Float)+SUM(Sum)*Sum(Sum)/SUM(Count))) AS StandardDeviation, SUM(AlarmCount) AS NumberOfAlarms, (CAST(SUM(AlarmActiveCount)AS float)/CAST(SUM(Count) AS Float)) as PercentAlarms FROM {(type == ReportType.SNR? "SNRSummary" : "UnbalanceSummary")} WHERE Date >= '{start.ToString("yyyy-MM-dd")}' AND Date <= '{end.ToString("yyyy-MM-dd")}'{(type == ReportType.SNR? "" : typerestriction)} GROUP BY {idCollumn} ORDER BY {sortCollumn}"; DataTable reportTbl; using (AdoDataConnection connection = new AdoDataConnection(ReportSettingsCategory)) reportTbl = connection.RetrieveData(sqlQuery); using (AdoDataConnection connection = new AdoDataConnection("Systemsettings")) { TableOperations <ActiveMeasurement> activeMeasurementTbl = new TableOperations <ActiveMeasurement>(connection); TableOperations <Phasor> phasorTbl = new TableOperations <Phasor>(connection); int i = 0; foreach (DataRow row in reportTbl.Rows) { UpdatePercentage(i, numberRecords); i++; Guid signalID = row.Field <Guid>("SignalID"); ActiveMeasurement sourceMeasurement = activeMeasurementTbl.QueryRecordWhere("SignalID = {0}", signalID); if (sourceMeasurement == null) { continue; } Phasor phasor = phasorTbl.QueryRecordWhere("ID = {0}", sourceMeasurement.PhasorID); result.Add(new ReportMeasurements() { SignalID = signalID, PointTag = (((phasor != null) && (type != ReportType.SNR))? phasor.Label : sourceMeasurement.PointTag), SignalReference = sourceMeasurement.SignalReference, SignalType = sourceMeasurement.SignalType, DeviceName = sourceMeasurement.Device, Mean = row.Field <double>("Mean"), Max = row.Field <double>("Max"), Min = row.Field <double>("Min"), StandardDeviation = row.Field <double>("StandardDeviation"), AlarmCount = row.Field <int>("NumberOfAlarms"), PercentInAlarm = row.Field <double>("PercentAlarms") * 100.0D, }); } } return(result); }
/// <summary> /// Sets the ActiveMeasurement at the start of a measurement and casts BeginMeasurement events coming from a different thread to the UI thread when necessary. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The new measurement.</param> /// <exception cref="System.NullReferenceException">Platform not set.</exception> private async Task _comm_BeginMeasurementAsync(object sender, ActiveMeasurement e) { _comm_BeginMeasurement(sender, e); }
public void Comm_BeginMeasurement(object sender, ActiveMeasurement newMeasurement) { measurement = newMeasurement; }
private Guid?GetSignalID(string pointTag, TableOperations <ActiveMeasurement> table) { ActiveMeasurement measurement = table.QueryRecordWhere("PointTag = {0}", pointTag); return(measurement?.SignalID); }
private bool SearchZero(MeasurementKey key, TableOperations <ActiveMeasurement> table) { ActiveMeasurement measurement = table.QueryRecordWhere("SignalID = {0}", key.SignalID.ToString()); return(measurement.Phase == '0'); }
/// <summary> /// Gets the reporting Measurment List from Aggregate Channels if available. /// </summary> /// <returns> List of ReportMeasurements to be added to Report.</returns> /// <param name="start">Start date of the Report.</param> /// <param name="end">End date of the Report.</param> /// <param name="type"> Type of Report <see cref="ReportType"/>.</param> /// <param name="cancelationToken"> Cancleation Token for the historian read operation.</param> /// <param name="dataContext">DataContext from which the available reportingParameters are pulled <see cref="DataContext"/>.</param> private List <ReportMeasurements> GetFromStats(DataContext dataContext, DateTime start, DateTime end, ReportType type, CancellationToken cancelationToken) { List <ReportMeasurements> result = new List <ReportMeasurements>(); string filterString = ""; if (type == ReportType.SNR) { filterString = "%-SNR"; } else if (type == ReportType.Unbalance_I) { filterString = "%-IUBAL"; } else if (type == ReportType.Unbalance_V) { filterString = "%-VUBAL"; } TableOperations <ActiveMeasurement> tableOperations = new TableOperations <ActiveMeasurement>(dataContext.Connection); tableOperations.RootQueryRestriction[0] = $"{GetSelectedInstanceName()}:%"; if (tableOperations.QueryRecordCountWhere("PointTag LIKE {0}", filterString + ":SUM") > 0) { List <ActiveMeasurement> sumMeasurements = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":SUM").ToList(); List <ActiveMeasurement> squaredSumMeasurments = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":SQR").ToList(); List <ActiveMeasurement> minimumMeasurements = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":MIN").ToList(); List <ActiveMeasurement> maximumMeasurements = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":MAX").ToList(); List <ActiveMeasurement> countMeasurements = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":NUM").ToList(); List <ActiveMeasurement> alertMeasurements = tableOperations.QueryRecordsWhere("PointTag LIKE {0}", filterString + ":ALT").ToList(); result = sumMeasurements.Select(point => new ReportMeasurements(point)).ToList(); // Pull Data From the Open Historian List <ActiveMeasurement> all = sumMeasurements.Concat(squaredSumMeasurments).Concat(minimumMeasurements).Concat(maximumMeasurements).Concat(countMeasurements).Concat(alertMeasurements).ToList(); List <CondensedDataPoint> historiandata; if (cancelationToken.IsCancellationRequested) { return(new List <ReportMeasurements>()); } try { Progress <ulong> progress = new Progress <ulong>(UpdatePercentage); historiandata = m_historianOperations.ReadCondensed(start, end, all, double.MaxValue, cancelationToken, progress).ToList(); } catch { return(new List <ReportMeasurements>()); } if (cancelationToken.IsCancellationRequested) { return(new List <ReportMeasurements>()); } result = result.Where((item, index) => { ReportMeasurements sum = item; string tag = item.PointTag.Remove(item.PointTag.Length - 4); ActiveMeasurement squaredSumChannel = squaredSumMeasurments.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement minimumChannel = minimumMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement maximumChannel = maximumMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement countChannel = countMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement countAlertChannel = alertMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); if (squaredSumChannel is null || minimumChannel is null || maximumChannel is null || countChannel is null || countAlertChannel is null) { return(false); } return(historiandata.Select(point => point.PointID).Contains(sum.PointID) && historiandata.Select(point => point.PointID).Contains(squaredSumChannel.PointID) && historiandata.Select(point => point.PointID).Contains(minimumChannel.PointID) && historiandata.Select(point => point.PointID).Contains(maximumChannel.PointID) && historiandata.Select(point => point.PointID).Contains(countAlertChannel.PointID) && historiandata.Select(point => point.PointID).Contains(countChannel.PointID)); }).ToList(); result = result.Select(item => { string tag = item.PointTag.Remove(item.PointTag.Length - 4); ActiveMeasurement squaredSumChannel = squaredSumMeasurments.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement minimumChannel = minimumMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement maximumChannel = maximumMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement countChannel = countMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement countAlertChannel = alertMeasurements.Find(channel => channel.PointTag.Remove(channel.PointTag.Length - 4) == tag); ActiveMeasurement sumChannel = sumMeasurements.Find(meas => meas.PointTag.Remove(meas.PointTag.Length - 4) == tag); double minimum = historiandata.Find(point => point.PointID == minimumChannel.PointID).Min; double maximum = historiandata.Find(point => point.PointID == maximumChannel.PointID).Max; double count = historiandata.Find(point => point.PointID == countChannel.PointID).Sum; double alarmCount = historiandata.Find(point => point.PointID == countAlertChannel.PointID).Sum; double summation = historiandata.Find(point => point.PointID == sumChannel.PointID).Sum; double squaredsum = historiandata.Find(point => point.PointID == squaredSumChannel.PointID).Sum; item.Max = maximum; item.Min = minimum; item.Mean = summation / count; item.NumberOfAlarms = alarmCount; item.PercentAlarms = alarmCount * 100.0D / count; item.StandardDeviation = Math.Sqrt((squaredsum - 2 * summation * item.Mean + count * item.Mean * item.Mean) / count); item.TimeInAlarm = item.PercentAlarms * (end - start).TotalSeconds / 100.0D; if (type == ReportType.SNR) { item.NumberOfAlarms = count - item.NumberOfAlarms; item.PercentAlarms = 100 - item.PercentAlarms; item.TimeInAlarm = item.PercentAlarms * (end - start).TotalSeconds / 100.0D; } item.PointTag = item.PointTag.Remove(item.PointTag.Length - 4); return(item); }).ToList(); } return(result); }