public IQueryable<MetricValue> GetByMetricId( int metricId, MetricValueType? metricValueType = null ) { // include MetricValuePartitions and each MetricValuePartition's MetricPartition so that MetricValuePartitionEntityIds doesn't have to lazy load var result = Get().Include( a => a.MetricValuePartitions.Select( b => b.MetricPartition ) ).Where( a => a.MetricId == metricId ); if ( metricValueType.HasValue ) { result = result.Where( a => a.MetricValueType == metricValueType ); } return result.OrderBy( a => a.MetricValueDateTime ); }
public IQueryable<MetricValue> GetByMetricId( int metricId, MetricValueType? metricValueType = null ) { var metric = new MetricService( new RockContext() ).Get( metricId ); var result = Get().Where( a => a.MetricId == metricId ); if ( metricValueType.HasValue ) { result = result.Where( a => a.MetricValueType == metricValueType ); } return result.OrderBy( a => a.MetricValueDateTime ); }
public IEnumerable<MetricSummary> GetSummary( string metricIdList, DateTime? startDate = null, DateTime? endDate = null, MetricValueType? metricValueType = null, int? entityTypeId = null, int? entityId = null ) { List<int> metricIds = metricIdList.SplitDelimitedValues().AsIntegerList(); var qry = Get().Where( a => metricIds.Contains( a.MetricId ) ); if ( metricValueType.HasValue ) { qry = qry.Where( a => a.MetricValueType == metricValueType ); } if ( startDate.HasValue ) { qry = qry.Where( a => a.MetricValueDateTime >= startDate.Value ); } if ( endDate.HasValue ) { qry = qry.Where( a => a.MetricValueDateTime < endDate.Value ); } //// if an entityTypeId/EntityId filter was specified, and the entityTypeId is the same as the metrics.EntityTypeId, filter the values to the specified entityId //// Note: If a Metric or it's Metric Value doesn't have a context, include it regardless of Context setting if ( entityTypeId.HasValue ) { if ( entityId.HasValue ) { qry = qry.Where( a => ( a.Metric.EntityTypeId == entityTypeId && a.EntityId == entityId ) || ( a.Metric.EntityTypeId == null) || ( a.EntityId == null ) ); } } var groupBySum = qry .GroupBy( a => a.Metric ) .Select( g => new { MetricId = g.Key.Id, MetricTitle = g.Key.Title, YValueTotal = g.Sum( s => s.YValue ) } ).ToList(); return groupBySum.Select( s => new MetricSummary { MetricId = s.MetricId, MetricTitle = s.MetricTitle, YValueTotal = s.YValueTotal, StartDateTimeStamp = startDate.HasValue ? startDate.Value.ToJavascriptMilliseconds() : 0, EndDateTimeStamp = endDate.HasValue ? endDate.Value.ToJavascriptMilliseconds() : 0 } ); }
public MetricValue(MetricValueType type) : this() { Type = type; }
public IEnumerable<MetricSummary> GetSummary( string metricIdList, DateTime? startDate = null, DateTime? endDate = null, MetricValueType? metricValueType = null ) { List<int> metricIds = metricIdList.SplitDelimitedValues().Select(a=> a.AsInteger()).ToList(); var qry = Get().Where( a => metricIds.Contains( a.MetricId ) ); if ( metricValueType.HasValue ) { qry = qry.Where( a => a.MetricValueType == metricValueType ); } if ( startDate.HasValue ) { qry = qry.Where( a => a.MetricValueDateTime >= startDate.Value ); } if ( endDate.HasValue ) { qry = qry.Where( a => a.MetricValueDateTime < endDate.Value ); } var groupBySum = qry .GroupBy( a => a.Metric ) .Select( g => new { MetricId = g.Key.Id, MetricTitle = g.Key.Title, YValueTotal = g.Sum( s => s.YValue ) } ).ToList(); return groupBySum.Select( s => new MetricSummary { MetricId = s.MetricId, MetricTitle = s.MetricTitle, YValueTotal = s.YValueTotal, StartDateTimeStamp = startDate.HasValue ? startDate.Value.ToJavascriptMilliseconds() : 0, EndDateTimeStamp = endDate.HasValue ? endDate.Value.ToJavascriptMilliseconds() : 0 } ); }