コード例 #1
0
ファイル: OccuranceAnalyzer.cs プロジェクト: lanicon/nesper
        private static OccuranceBucket GetBucket(OccuranceIntermediate inter)
        {
            var countTotal = 0;

            foreach (Pair <long, EventBean[]> entry in inter.Items)
            {
                countTotal += entry.Second.Length;
            }

            return(new OccuranceBucket(inter.Low, inter.High, inter.Items.Count, countTotal));
        }
コード例 #2
0
ファイル: OccuranceAnalyzer.cs プロジェクト: lanicon/nesper
        public static IList <OccuranceBucket> RecursiveAnalyze(
            IList <Pair <long, EventBean[]> > occurances,
            long[] granularities,
            int level,
            long start,
            long end)
        {
            // form buckets
            var granularity = granularities[level];
            IDictionary <int, OccuranceIntermediate> intermediates = new LinkedHashMap <int, OccuranceIntermediate>();
            var countBucket = 0;

            for (var offset = start; offset < end; offset += granularity)
            {
                var intermediate = new OccuranceIntermediate(offset, offset + granularity - 1);
                intermediates.Put(countBucket, intermediate);
                countBucket++;
            }

            // sort into bucket
            foreach (var entry in occurances)
            {
                long time         = entry.First;
                var  delta        = time - start;
                var  bucket       = (int)(delta / granularity);
                var  intermediate = intermediates.Get(bucket);
                intermediate.Items.Add(entry);
            }

            // report each bucket
            IList <OccuranceBucket> buckets = new List <OccuranceBucket>();

            foreach (KeyValuePair <int, OccuranceIntermediate> pair in intermediates)
            {
                var inter  = pair.Value;
                var bucket = GetBucket(inter);
                buckets.Add(bucket);

                // for buckets within buckets
                if (level < granularities.Length - 1 && !inter.Items.IsEmpty())
                {
                    bucket.InnerBuckets = RecursiveAnalyze(inter.Items, granularities, level + 1, inter.Low, inter.High);
                }
            }

            return(buckets);
        }