示例#1
0
        public static List <PredictDictionary> FromFilters(this PredictorPredictContext ctx, List <Filter> filters, PredictionOptions?options = null)
        {
            var qd = QueryLogic.Queries.QueryDescription(ctx.Predictor.MainQuery.Query.ToQueryName());

            var qr = new QueryRequest
            {
                QueryName = qd.QueryName,

                GroupResults = ctx.Predictor.MainQuery.GroupResults,

                Filters = filters, /*Filters of Main Query not considered*/

                Columns = ctx.Predictor.MainQuery.Columns.Select(c => new Column(c.Token.Token, null)).ToList(),

                Pagination = new Pagination.All(),
                Orders     = Enumerable.Empty <Order>().ToList(),
            };

            var mainQueryKeys = PredictorLogic.GetParentKeys(ctx.Predictor.MainQuery);

            var rt = QueryLogic.Queries.ExecuteQuery(qr);

            var subQueryResults = ctx.Predictor.SubQueries.ToDictionaryEx(sq => sq, sqe =>
            {
                List <QueryToken> parentKeys = sqe.Columns.Where(a => a.Usage == PredictorSubQueryColumnUsage.ParentKey).Select(a => a.Token.Token).ToList();

                QueryDescription sqd = QueryLogic.Queries.QueryDescription(sqe.Query.ToQueryName());

                Dictionary <string, string> tokenReplacements = mainQueryKeys.ZipStrict(parentKeys, (m, p) => KVP.Create(m.FullKey(), p.FullKey())).ToDictionaryEx();

                Filter[] mainFilters = filters.Select(f => Replace(f, tokenReplacements, sqd)).ToArray();

                List <Filter> additionalFilters = sqe.Filters.ToFilterList();

                List <Column> allColumns = sqe.Columns.Select(c => new Column(c.Token.Token, null)).ToList();

                var qgr = new QueryRequest
                {
                    QueryName    = sqe.Query.ToQueryName(),
                    GroupResults = true,
                    Filters      = mainFilters.Concat(additionalFilters).ToList(),
                    Columns      = allColumns,
                    Orders       = new List <Order>(),
                    Pagination   = new Pagination.All(),
                };

                ResultTable resultTable = QueryLogic.Queries.ExecuteQuery(qgr);

                var tuples = sqe.Columns.Zip(resultTable.Columns, (sqc, rc) => (sqc: sqc, rc: rc)).ToList();
                ResultColumn[] entityGroupKey = tuples.Extract(t => t.sqc.Usage == PredictorSubQueryColumnUsage.ParentKey).Select(a => a.rc).ToArray();
                ResultColumn[] remainingKeys  = tuples.Extract(t => t.sqc.Usage == PredictorSubQueryColumnUsage.SplitBy).Select(a => a.rc).ToArray();
                var valuesTuples = tuples;

                return(resultTable.Rows.AgGroupToDictionary(
                           row => row.GetValues(entityGroupKey),
                           gr => gr.ToDictionaryEx(
                               row => row.GetValues(remainingKeys),
                               row => valuesTuples.ToDictionaryEx(t => t.sqc, t => row[t.rc]),
                               ObjectArrayComparer.Instance
                               )
                           ));
            });
        private static double Evaluate(ExecutingProcess ep, PredictorEntity p, Action <decimal?> onProgress)
        {
            PredictorLogic.TrainSync(p, onReportProgres: (str, val) => onProgress(val));

            return(p.ResultValidation !.Loss.Value);
        }