Пример #1
0
        public static bool ValidateSelection(PCAxis.Paxiom.IPXModelBuilder builder, List <PCAxis.Paxiom.Selection> selections)
        {
            //Check that all mandatory variables has at least one value selected

            var mandatoryVariables = builder.Model.Meta.Variables.Where(v => !v.Elimination);

            foreach (var v in mandatoryVariables)
            {
                var selection = selections.FirstOrDefault(s => s.VariableCode == v.Code);
                if (selection == null)
                {
                    return(false);
                }
                if (selection.ValueCodes.Count == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public static PCAxis.Paxiom.Selection SelectAggregation(Variable variable, Query query, PCAxis.Paxiom.IPXModelBuilder builder)
        {
            GroupingIncludesType aggType;
            string agg;

            if (!PCAxis.Query.QueryHelper.TryParseAggregationAndType(query.Selection.Filter, out agg, out aggType))
            {
                throw new Exception(); //TODO could not parse aggregation
            }

            var aggInfo = variable.GetGroupingInfoById(agg);

            if (aggInfo == null)
            {
                throw new Exception(); //TODO no such aggregation
            }

            builder.ApplyGrouping(variable.Code, aggInfo, aggType);

            var v = builder.Model.Meta.Variables.First(x => x.Code == variable.Code);

            return(SelectItem(v, query));
        }
Пример #3
0
        public static PCAxis.Paxiom.Selection SelectValueSet(Variable variable, Query query, PCAxis.Paxiom.IPXModelBuilder builder)
        {
            if (!query.Selection.Filter.StartsWith("vs:"))
            {
                throw new Exception(); //TODO it must be an aggregation
            }

            string vs     = query.Selection.Filter.Substring(3);
            var    vsInfo = variable.GetValuesetById(vs);

            if (vsInfo == null)
            {
                throw new Exception(); //TODO no such aggregation
            }

            builder.ApplyValueSet(variable.Code, vsInfo);

            var v = builder.Model.Meta.Variables.First(x => x.Code == variable.Code);

            return(SelectItem(v, query));
        }
Пример #4
0
        public static List <PCAxis.Paxiom.Selection> BuildSelections(this PCAxis.Paxiom.IPXModelBuilder builder, TableQuery tableQuery)
        {
            //Check to see that the variable exists
            int c = builder.Model.Meta.Variables.Where(var => tableQuery.Query.Select(q => q.Code).Contains(var.Code)).ToArray().Length;

            if (tableQuery.Query.Length > c)
            {
                throw new ArgumentException("Variable is not defined");
            }

            var selections = new List <PCAxis.Paxiom.Selection>();

            foreach (var variable in builder.Model.Meta.Variables)
            {
                PCAxis.Paxiom.Selection selection = new PCAxis.Paxiom.Selection(variable.Code);
                var query = tableQuery.Query.SingleOrDefault(q => q.Code == variable.Code);
                if (query != null)
                {
                    // Process filters
                    if (query.Selection.Filter.ToLower() == "all") // All
                    {
                        selection = QueryHelper.SelectAll(variable, query);
                    }
                    else if (query.Selection.Filter.ToLower() == "top") // Top
                    {
                        selection = QueryHelper.SelectTop(variable, query);
                    }
                    else if (PCAxis.Query.QueryHelper.IsAggregation(query.Selection.Filter))
                    {
                        selection = QueryHelper.SelectAggregation(variable, query, builder);
                    }
                    else if (query.Selection.Filter.StartsWith("vs:", StringComparison.InvariantCultureIgnoreCase))
                    {
                        selection = QueryHelper.SelectValueSet(variable, query, builder);
                    }
                    else
                    {
                        // Assume item
                        selection = QueryHelper.SelectItem(variable, query);
                    }
                }
                else
                {
                    // Variable not specified in query
                    if (!variable.Elimination)
                    {
                        selection = PCAxis.Paxiom.Selection.SelectAll(variable);
                    }
                }

                if (selection != null)
                {
                    selections.Add(selection);
                }
                else
                {
                    //The user as requested an non vaild selection
                    return(null);
                }
            }

            if (!ValidateSelection(builder, selections))
            {
                return(null);
            }

            return(selections);
        }