Exemplo n.º 1
0
 public override Tuple <string, long>[] Count(Func <Record, bool> whereFunc, Filter filter)
 {
     using (var context = new Context(name))
         return(filter.Aggregate(
                    context
                    .Records
                    .Where(whereFunc)
                    .GroupBy(r => new { r.Sweep, r.Seed })
                    .Select(g => g.ToMap(r => r.Key, r => r.Value)).ToList()
                    ));
 }
Exemplo n.º 2
0
        public void Aggregate()
        {
            var map = new Dictionary <string, string>
            {
                ["A"] = "s[1n]<=t[2G]",
                ["B"] = "s[4n]>=10"
            };
            var exp = new[] { "A&&B", "!(B)" };

            var filter = new Filter(map, exp);
            var expect = new[] { 0L, 0L };

            var rnd    = new Random(DateTime.Now.Millisecond);
            var inputs = Enumerable.Range(0, 100).Select(_ => {
                var s1 = rnd.Next();
                var s2 = rnd.Next();
                var t  = rnd.Next();
                var d  = new Map <string, decimal> {
                    [$"s/{1E-9M:E10}"] = s1,
                    [$"t/{2E9M:E10}"]  = t,
                    [$"s/{4E-9M:E10}"] = s2
                };

                if (s1 <= t && s2 >= 10)
                {
                    expect[0]++;
                }
                if (!(s2 >= 10))
                {
                    expect[1]++;
                }

                return(d);
            }).ToList();

            var res = filter.Aggregate(inputs);

            Assert.True(exp.SequenceEqual(res.Select(t => t.Item1)));
            Assert.True(expect.SequenceEqual(res.Select(t => t.Item2)));
        }
 public Entry[] Query(params Predicate <Entry>[] Filter)
 {
     return((from Entry e in entries.Values
             where Filter.Aggregate <Predicate <Entry>, bool>(true, (bool current, Predicate <Entry> f) => current && f.Invoke(e))
             select e).ToArray());
 }