示例#1
0
 private async Task<string> GetFormattedResultAsync(ResultSetPrinter printer)
 {
     var task = new Task<string>(printer.GetFormattedResults);
     task.Start();
     return await task;
 }
示例#2
0
 private async void CountQuery(string city)
 {
     var query =
         new ResultSetPrinter(
             new RecordParser(
                 new CountRecordProvider("city", "id",
                     new PracticeDatabaseReader("practices.dat", indexManager,
                         new List<IWhereQueryConstraint>
                         {
                             new EqualityConstraint("city", "LONDON", byteConverter)
                         }))));
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     var results = await GetFormattedResultAsync(query);
     stopwatch.Stop();
     Output += $"{results}Time: {stopwatch.ElapsedMilliseconds} ms\n";
 }
示例#3
0
 private async void PostcodeQuery()
 {
     var query =
         new ResultSetPrinter(
             new RecordParser(
                 new LimitRecordProvider(5,
                     new SortingRecordProvider("cost",
                         new SumRecordProvider("postal_code", "cost",
                             new SelectionRecordProvider(new[] {"cost", "postal_code"},
                                 new JoinRecordProvider(
                                     new SelectionRecordProvider(new List<string> {"cost", "practice"},
                                         new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                                             new List<IWhereQueryConstraint>())),
                                     new SelectionRecordProvider(new List<string> {"id", "postal_code"},
                                         new PracticeDatabaseReader("practices.dat", indexManager,
                                             new List<IWhereQueryConstraint>())),
                                     "practice",
                                     "id"))),
                         SortingRecordProvider.Order.DESCENDING
                         ))));
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     var results = await GetFormattedResultAsync(query);
     stopwatch.Stop();
     Output += $"{results}Time: {stopwatch.ElapsedMilliseconds} ms\n";
 }
示例#4
0
 private async void AverageQuery(string product)
 {
     var query =
         new ResultSetPrinter(
             new RecordParser(
                 new WhereRecordProvider(
                     new AverageRecordProvider("bnf_name", "cost",
                         new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                             new List<IWhereQueryConstraint>())),
                     new[] {new EqualityConstraint("bnf_name", "Peppermint Oil", byteConverter)})));
     Stopwatch stopwatch = new Stopwatch();
     stopwatch.Start();
     var results = await GetFormattedResultAsync(query);
     stopwatch.Stop();
     Output += $"{results}Time: {stopwatch.ElapsedMilliseconds} ms\n";
 }
示例#5
0
        private async void RegionQuery()
        {
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            var averageQuery = new RecordParser(
                new UngroupedAverageProvider("cost",
                    new SelectionRecordProvider(new[] {"cost", "bnf_name"},
                        new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                            new List<IWhereQueryConstraint>
                            {
                                new ContainsQueryConstraint("bnf_name", "Flucloxacillin"),
                                new Not(new ContainsQueryConstraint("bnf_name", "Co-Fluampicil")),
                                new Not(new EqualityConstraint("bnf_name", "", byteConverter))
                            }))));
            float avg =  (float) (await GetUnformattedResultAsync(averageQuery)).First()["avg_of_cost"];
            Func<RecordMetaData, byte[], dynamic> differ = (recordMetaData, row) =>
            {
                float value = BitConverter.ToSingle(row, recordMetaData.ColumnDescriptors["avg_of_cost"].Offset);
                return value - avg;
            };
            var query =
                new ResultSetPrinter(
                    new RecordParser(
                        new ComputedFieldProvider("diff", ColumnType.Float, differ,
                            new AverageRecordProvider("region", "cost",
                                new WhereRecordProvider(
                                    new JoinRecordProvider(
                                        new SelectionRecordProvider(new List<string> {"cost", "practice", "bnf_name"},
                                            new OrderDatabaseReader("orders.dat", indexManager, QueryMode.Auto,
                                                new List<IWhereQueryConstraint>())),
                                        new SelectionRecordProvider(new List<string> {"id", "region"},
                                            new PracticeDatabaseReader("practices.dat", indexManager,
                                                new List<IWhereQueryConstraint>())),
                                        "practice",
                                        "id"),
                                    new List<IWhereQueryConstraint>
                                    {
                                        new ContainsQueryConstraint("bnf_name", "Flucloxacillin"),
                                        new Not(new ContainsQueryConstraint("bnf_name", "Co-Fluampicil")),
                                        new Not(new EqualityConstraint("bnf_name", "", byteConverter))
                                    })))));
            var results = await GetFormattedResultAsync(query);
            stopwatch.Stop();
            Output += $"{results}Time: {stopwatch.ElapsedMilliseconds} ms\n";
        }