Exemplo n.º 1
0
        /// <summary>
        /// requestに従って数え上げる
        /// </summary>
        /// <returns>Expression,結果のペアリスト</returns>
        public Tuple <string, long>[] Run(LibraRequest request)
        {
            try {
                var delegates = request.BuildFilter();
                var signals   = request.SignalList;

                if (!signals.Any())
                {
                    throw new LibraException("Conditions have no signals");
                }

                var db = new ReadOnlyRepository(request.SqliteFile);
                log.Info("----Parameter Info----");
                Console.WriteLine(db.GetParameter());
                log.Info("----------------------");

                using var bar = new ProgressBar(
                          (int)(request.IsSplitWithSeed ? (request.SeedEnd - request.SeedStart + 1) : request.Sweeps.Times),
                          "Ptolemy.Libra", new ProgressBarOptions {
                    ForegroundColor     = ConsoleColor.DarkYellow, BackgroundCharacter = '-',
                    ProgressCharacter   = '>', CollapseWhenFinished = true, BackgroundColor = ConsoleColor.Gray,
                    ForegroundColorDone = ConsoleColor.Green
                });
                db.IntervalEvent += () => bar.Tick();


                var result = request.IsSplitWithSeed switch {
                    true => db.Aggregate(token, signals, delegates,
                                         Range(request.SeedStart, request.SeedEnd).ToList(),
                                         request.Sweeps.Size,
                                         request.Sweeps.Start,
                                         LibraRequest.GetKey),
                    false => db.Aggregate(token, signals,
                                          delegates,
                                          request.SeedStart,
                                          request.Sweeps.Section().ToList(),
                                          LibraRequest.GetKey)
                };

                return(request.ExpressionNameList.Zip(result, Tuple.Create).ToArray());
            }
            catch (LibraException) {
                throw;
            }
            catch (Exception e) {
                throw new LibraException($"Unknown error has occured\n\t-->{e}");
            }
        }
Exemplo n.º 2
0
        public void AddEntityTest()
        {
            var tmp = Path.Combine(Path.GetTempPath(), "Ptolemy.Repository", "Test");

            Directory.CreateDirectory(tmp);

            var root = Path.Combine(tmp, "dbRoot");

            Directory.CreateDirectory(root);

            var pe = GenerateDummyParameters().First();

            try {
                using var hub = new DbHub(CancellationToken.None, root, 1, null);
                var key = hub.AddDb(pe);

                hub.AddEntity(key, new ResultEntity {
                    Sweep  = 1, Seed = 2,
                    Signal = "signal", Time = 0,
                    Value  = 1
                });

                hub.CloseDb(key);

                var repo = new ReadOnlyRepository(Path.Combine(root, $"{key}.sqlite"));
                Func <Map <string, decimal>, bool> f = m => m[$"signal/{0M:E5}"] == 1;
                var res = repo.Aggregate(
                    CancellationToken.None, new[] { "signal" }, new[] { f }, 2, new (long start, long end)[] { (1, 10) },