/// <summary> /// Records the trending information. /// </summary> /// <param name="tEntity">Entity type - what is trending</param> /// <param name="gShard">Sharding area key</param> /// <param name="gEntity">GDID of the trending entity</param> /// <param name="count">Trending count</param> /// <param name="dimensions">Dimensions vector in plain or laconic format</param> public static void Emit(string tEntity, GDID gShard, GDID gEntity, long count, string dimensions) { if (!TryValidateEntityName(tEntity)) { throw new SocialException(StringConsts.ARGUMENT_ERROR + "Emit(tEntity!Valid:'{0}')".Args(tEntity)); } if (dimensions != null && dimensions.Length > MAX_DIMENSION_LENGTH) { throw new SocialException(StringConsts.ARGUMENT_ERROR + "Emit(dims to long)"); } var inst = App.Instrumentation; if (!inst.Enabled) { return; } var datum = new SocialTrendingGauge(count) { m_Entity = tEntity, m_G_Shard = gShard, m_G_Entity = gEntity, m_Dimensions = dimensions }; inst.Record(datum); }
private bool highPassFilter(SocialTrendingGauge sample) { if (!m_HighPassFilterEnabled) { return(true); } var entityName = sample.Entity; if (entityName.IsNullOrWhiteSpace()) { entityName = "*"; } var key = sample.G_Entity.Counter & HIGH_PASS_FILTER_COUNTER_MASK; DateTime lastDate; var now = App.TimeSource.UTCNow; //If the sample happened more than threshold then bypass filtering by time altogether var pass = sample.Value >= m_HighPassFilterBypassThresholdCount; var filter = m_HighPassFilter.GetOrRegister(entityName, n => new entityFilter(n), entityName); //only include those GDIDS that had some traffic in the past m_HighPassFilterTimeWindowMinutes if (!pass && filter.TryGetValue(key, out lastDate)) { pass = (now - lastDate).TotalMinutes <= m_HighPassFilterTimeWindowMinutes; } filter[key] = now; return(pass); }
protected override Datum MakeAggregateInstance() { var aggregated = new SocialTrendingGauge(this.Value) { m_Entity = this.m_Entity, m_G_Shard = this.m_G_Shard, m_G_Entity = this.m_G_Entity, m_Dimensions = this.m_Dimensions }; return(aggregated); }
/// <param name="tEntity">If null, then trending across all types is queried</param> /// <param name="startDate">The start timespan of sampling</param> /// <param name="endDate">The end timespan of sampling</param> /// <param name="sampleCount">How many samples we want to get in a date range</param> /// <param name="fetchStart">The starting ranking position of trending</param> /// <param name="fetchCount"></param> /// <param name="filter">The count of trending records</param> public TrendingQuery(string tEntity, DateTime startDate, DateTime endDate, int sampleCount, int fetchStart, int fetchCount, string filter) { if (!SocialTrendingGauge.TryValidateEntityName(tEntity)) { throw new SocialException(StringConsts.ARGUMENT_ERROR + "TrendingQuery.ctor(tEntity!Valid:'{0}')".Args(tEntity)); } EntityType = tEntity; StartDate = startDate; EndDate = endDate; SampleCount = sampleCount <0 ? 1 : sampleCount> MAX_SAMPLE_COUNT ? MAX_SAMPLE_COUNT : sampleCount; FetchStart = fetchStart < 0 ? 0 : fetchStart; FetchCount = fetchCount <0 ? 1 : fetchCount> MAX_FETCH_COUNT ? MAX_FETCH_COUNT : fetchCount; DimensionFilter = filter; }