protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["eventId"] != null) { postedEventId = Request["eventId"]; using (MeterDataQualitySummaryTableAdapter meterdataqualityAdapter = new DbAdapterContainer(connectionstring).GetAdapter <MeterDataQualitySummaryTableAdapter>()) using (MeterInfoDataContext meterInfo = new MeterInfoDataContext(connectionstring)) { try { DataQuality.MeterDataQualitySummaryRow theevent = meterdataqualityAdapter.GetDataByID(Convert.ToInt32(postedEventId)).First(); Meter themeter = meterInfo.Meters.Single(m => m.ID == theevent.MeterID); postedDate = theevent.Date.ToShortDateString(); postedMeterId = theevent.MeterID.ToString(); postedMeterName = themeter.Name; } catch (Exception ex) { postedDate = ""; postedEventId = ""; postedMeterId = ""; postedMeterName = ""; } finally { } } } } }
public void Upsert(DataQuality.MeterDataQualitySummaryRow dataRow) { UpsertQuery(dataRow.MeterID, dataRow.Date, dataRow.ExpectedPoints, dataRow.GoodPoints, dataRow.LatchedPoints, dataRow.UnreasonablePoints, dataRow.NoncongruentPoints, dataRow.DuplicatePoints); }
public override void Execute(MeterDataSet meterDataSet) { List <ChannelSummary> channelSummaries; ChannelDataQualitySummaryTableAdapter channelSummaryAdapter = m_dbAdapterContainer.GetAdapter <ChannelDataQualitySummaryTableAdapter>(); MeterDataQualitySummaryTableAdapter meterSummaryAdapter = m_dbAdapterContainer.GetAdapter <MeterDataQualitySummaryTableAdapter>(); DataQuality.MeterDataQualitySummaryDataTable meterSummaryTable = new DataQuality.MeterDataQualitySummaryDataTable(); DataQuality.ChannelDataQualitySummaryDataTable channelSummaryTable = new DataQuality.ChannelDataQualitySummaryDataTable(); DataQuality.ChannelDataQualitySummaryRow channelSummaryRow = null; DataQuality.MeterDataQualitySummaryRow meterSummaryRow = null; double meterSamplesPerHour; // Process the data quality range limits to identify unreasonable values ProcessDataQualityRangeLimits(meterDataSet); // Get the total cumulative samples per hour // of each of the enabled channels in the meter meterSamplesPerHour = meterDataSet.Meter.Channels .Where(channel => channel.Enabled != 0) .Where(channel => channel.SamplesPerHour <= 60.0D) .Select(channel => channel.SamplesPerHour) .DefaultIfEmpty(0.0D) .Sum(); // Convert trending data summaries to channel summaries // so that we can order by date to make processing easier channelSummaries = meterDataSet.GetResource <TrendingDataSummaryResource>().TrendingDataSummaries .SelectMany(kvp => kvp.Value.Select(summary => new ChannelSummary(kvp.Key, summary))) .Where(channelSummary => channelSummary.Channel.Enabled != 0) .OrderBy(channelSummary => channelSummary.Date) .ThenBy(channelSummary => channelSummary.Channel.ID) .ToList(); foreach (ChannelSummary channelSummary in channelSummaries) { // If the current channel summary's data does not belong in the same aggregate as the previous channel summary, // update the meter summary record, submit the current channel summary record, and create a new channel summary record if ((object)channelSummaryRow != null && (channelSummary.Channel.ID != channelSummaryRow.ChannelID || channelSummary.Date != channelSummaryRow.Date)) { meterSummaryRow.GoodPoints += channelSummaryRow.GoodPoints; meterSummaryRow.LatchedPoints += channelSummaryRow.LatchedPoints; meterSummaryRow.UnreasonablePoints += channelSummaryRow.UnreasonablePoints; meterSummaryRow.NoncongruentPoints += channelSummaryRow.NoncongruentPoints; meterSummaryRow.DuplicatePoints += channelSummaryRow.DuplicatePoints; channelSummaryRow.EndEdit(); channelSummaryAdapter.Upsert(channelSummaryRow); channelSummaryRow = null; } // If the current channel summary's data does not fall on the same date as the previous // channel summary's data, submit the current meter summary record and create a new one if ((object)meterSummaryRow != null && channelSummary.Date != meterSummaryRow.Date) { meterSummaryRow.EndEdit(); meterSummaryAdapter.Upsert(meterSummaryRow); meterSummaryRow = null; } // If there is no existing record to aggregate // channel summary data, create a new one if ((object)channelSummaryRow == null) { channelSummaryRow = channelSummaryTable.NewChannelDataQualitySummaryRow(); channelSummaryRow.BeginEdit(); channelSummaryRow.ChannelID = channelSummary.Channel.ID; channelSummaryRow.Date = channelSummary.Date; channelSummaryRow.ExpectedPoints = (int)Math.Round(24.0D * channelSummary.Channel.SamplesPerHour); channelSummaryRow.GoodPoints = 0; channelSummaryRow.LatchedPoints = 0; channelSummaryRow.UnreasonablePoints = 0; channelSummaryRow.NoncongruentPoints = 0; channelSummaryRow.DuplicatePoints = 0; } // If there is no existing record to aggregate // meter summary data, create a new one if ((object)meterSummaryRow == null) { meterSummaryRow = meterSummaryTable.NewMeterDataQualitySummaryRow(); meterSummaryRow.BeginEdit(); meterSummaryRow.MeterID = meterDataSet.Meter.ID; meterSummaryRow.Date = channelSummary.Date; meterSummaryRow.ExpectedPoints = (int)Math.Round(24.0D * meterSamplesPerHour); meterSummaryRow.GoodPoints = 0; meterSummaryRow.LatchedPoints = 0; meterSummaryRow.UnreasonablePoints = 0; meterSummaryRow.NoncongruentPoints = 0; meterSummaryRow.DuplicatePoints = 0; } // Update the channel summary aggregates // based on the current channel summary if (channelSummary.TrendingSummary.IsDuplicate) { channelSummaryRow.DuplicatePoints++; } else if (channelSummary.TrendingSummary.Latched) { channelSummaryRow.LatchedPoints++; } else if (channelSummary.TrendingSummary.Unreasonable) { channelSummaryRow.UnreasonablePoints++; } else if (channelSummary.TrendingSummary.NonCongruent) { channelSummaryRow.NoncongruentPoints++; } else { channelSummaryRow.GoodPoints++; } } // Make sure the last channel and meter summary // records get submitted to the database if ((object)channelSummaryRow != null) { meterSummaryRow.GoodPoints += channelSummaryRow.GoodPoints; meterSummaryRow.LatchedPoints += channelSummaryRow.LatchedPoints; meterSummaryRow.UnreasonablePoints += channelSummaryRow.UnreasonablePoints; meterSummaryRow.NoncongruentPoints += channelSummaryRow.NoncongruentPoints; meterSummaryRow.DuplicatePoints += channelSummaryRow.DuplicatePoints; channelSummaryRow.EndEdit(); channelSummaryAdapter.Upsert(channelSummaryRow); meterSummaryRow.EndEdit(); meterSummaryAdapter.Upsert(meterSummaryRow); } }