public PropertyReference(string col, string path, int line, int charPositionInLine) { Line = line; Character = charPositionInLine; Collection = col; Path = path; IsAggregate = false; if (path.EndsWith("COUNT", StringComparison.Ordinal)) { IsAggregate = true; AggregateType = AggregateTypes.Count; Alias = col + "_count"; } else if (path.EndsWith("SUM", StringComparison.Ordinal)) { IsAggregate = true; AggregateType = AggregateTypes.Sum; Alias = col + "_sum"; } else if (path.EndsWith("AVG", StringComparison.Ordinal)) { IsAggregate = true; AggregateType = AggregateTypes.Average; Alias = col + "_avg"; } }
/// <summary> /// retrieves aggregate relations for a resource /// </summary> /// <param name="levelOfStripping">stripping level</param> private void RetrieveAggreagates(int levelOfStripping) { //No retrievals below stripping level if (levelOfStripping <= 0) { return; } Debug.Assert(ResourceUri != Guid.Empty); using (ZentityContext context = CoreHelper.CreateZentityContext()) { List <Relationship> contains = context.Relationships.Where( relationship => relationship.Subject.Id == ResourceUri && relationship.Predicate.Uri == Properties.Resources.ORE_CONTAINS_PREDICATE ).ToList(); foreach (Relationship relation in contains) { relation.ObjectReference.Load(); ZentityAggregatedResource resource = new ZentityAggregatedResource(relation.Object.Id, --levelOfStripping); AggreagtedResources.Add(resource); Type objectType = context.Resources.Where(res => res.Id == relation.Object.Id).First().GetType(); AggregateTypes.Add(objectType); } } }
/// <summary> /// Creates a new Metric using the current UTC time as the timestamp /// </summary> /// <param name="name">The name of the Metric</param> /// <param name="value">The value of the Metric</param> /// <param name="aggregateType">The aggregation type to use for the metric</param> /// <param name="filter1">The value for filter1</param> /// <param name="filter2">The value for filter2</param> public Metric(string name, double value, AggregateTypes aggregateType, string filter1 = null, string filter2 = null) { this.SetTimestamp(TimeHelper.EpochFromUtc) .SetName(name) .SetValue(value) .SetAggregation(aggregateType) .SetFilter1(filter1) .SetFilter2(filter2); }
/// <summary> /// Creates a new Metric /// </summary> /// <param name="timestamp">Time in milliseconds since Epoch when the Metric was recorded</param> /// <param name="name">The name of the Metric</param> /// <param name="value">The value of the Metric</param> /// <param name="aggregateType">The aggregation type to use for the metric</param> /// <param name="filter1">The value for filter1</param> /// <param name="filter2">The value for filter2</param> public Metric(long timestamp, string name, double value, AggregateTypes aggregateType, string filter1 = null, string filter2 = null) { this.SetTimestamp(timestamp) .SetName(name) .SetValue(value) .SetAggregation(aggregateType) .SetFilter1(filter1) .SetFilter2(filter2); }
private AggregateTypes GetAggregateType(string fieldName) { AggregateTypes returnValue = AggregateTypes.None; foreach (var aggregateTypeName in Enum.GetNames(typeof(AggregateTypes))) { if (fieldName.Length > aggregateTypeName.Length && fieldName.Substring(0, aggregateTypeName.Length + 1) == aggregateTypeName.ToLower() + "(") { returnValue = (AggregateTypes)Enum.Parse(typeof(AggregateTypes), aggregateTypeName); } } return(returnValue); }
public static AbstractAggregate GetAggregateClient(AggregateTypes type) { switch (type) { case AggregateTypes.AskTankTruck: return(new AskTankTruckAggregate <AskItem>()); case AggregateTypes.TankTruckBlog: return(new TankTruckBlogAggregate <BlogItem>()); case AggregateTypes.Resources: return(new ResourcesAggregate <ResourceItem>()); default: throw new AggregateDoesNotExistException(); } }
public virtual void Deserialize(IntermediateFormatReader reader) { reader.RegisterDeclaration(DataAggregateInfo.m_Declaration); while (reader.NextMember()) { switch (reader.CurrentMember.MemberName) { case MemberName.Name: this.m_name = reader.ReadString(); break; case MemberName.AggregateType: this.m_aggregateType = (AggregateTypes)reader.ReadEnum(); break; case MemberName.Expressions: this.m_expressions = reader.ReadArrayOfRIFObjects <ExpressionInfo>(); break; case MemberName.DuplicateNames: this.m_duplicateNames = reader.ReadListOfPrimitives <string>(); break; case MemberName.DataSetIndexInCollection: this.m_dataSetIndexInCollection = reader.ReadInt32(); break; case MemberName.UpdateScopeID: this.m_updateScopeID = reader.ReadInt32(); break; case MemberName.UpdateScopeDepth: this.m_updateScopeDepth = reader.ReadInt32(); break; case MemberName.UpdatesAtRowScope: this.m_updatesAtRowScope = reader.ReadBoolean(); break; default: Global.Tracer.Assert(false); break; } } }
private string GetBareFieldName(string fieldName, AggregateTypes aggregateType) { return(fieldName.Substring(aggregateType.ToString().Length + 1, fieldName.Length - aggregateType.ToString().Length - 2)); }
internal void calculateAggregates(object row) { if (aggregatedValues == null) { aggregatedValues = new Dictionary <string, double>(); } foreach (IReportObject reportObject in ReportObjects) { ReportObjectField reportObjectField = reportObject as ReportObjectField; if (reportObjectField == null) { continue; } string fieldName = reportObjectField.FieldName; AggregateTypes aggregateType = GetAggregateType(fieldName); if (aggregateType == AggregateTypes.None) { continue; } string bareFieldName = GetBareFieldName(fieldName, aggregateType); if (aggregateType == AggregateTypes.Count) { if (!aggregatedValues.ContainsKey(fieldName)) { aggregatedValues.Add(fieldName, 1); } else { aggregatedValues[fieldName] = aggregatedValues[fieldName] + 1; } } else { object valueObject = row.GetType().GetProperty(bareFieldName).GetValue(row); if (valueObject != null) { switch (aggregateType) { case AggregateTypes.Sum: if (!aggregatedValues.ContainsKey(fieldName)) { aggregatedValues.Add(fieldName, Convert.ToDouble(valueObject)); } else { aggregatedValues[fieldName] = aggregatedValues[fieldName] + Convert.ToDouble(valueObject); } break; case AggregateTypes.Average: if (!aggregatedValues.ContainsKey(fieldName)) { aggregatedValues.Add(fieldName, 0); } else { aggregatedValues[fieldName] = aggregatedValues[fieldName] + 0; } break; case AggregateTypes.Min: if (!aggregatedValues.ContainsKey(fieldName)) { aggregatedValues.Add(fieldName, Convert.ToDouble(valueObject)); } else { aggregatedValues[fieldName] = Math.Min(aggregatedValues[fieldName], Convert.ToDouble(valueObject)); } break; case AggregateTypes.Max: if (!aggregatedValues.ContainsKey(fieldName)) { aggregatedValues.Add(fieldName, Convert.ToDouble(valueObject)); } else { aggregatedValues[fieldName] = Math.Max(aggregatedValues[fieldName], Convert.ToDouble(valueObject)); } break; } } } } }
public Metric SetAggregation(AggregateTypes aggregateType) { // convert the enum to it's lowercase string representation Aggregation = aggregateType.ToString().ToLowerInvariant(); return(this); }