Ejemplo n.º 1
0
        //TODO make private
        public bool Parse(out string embedWarning)
        {
            //As we read in all of our command tokens,
            //there are a couple of things to keep in mind:
            //Walter suggests that commands types have a specific order:
            //    columns then rows.
            //If for any reason we can't discern the IteratorType,
            //the default will be decided based on whether or not we've
            //parsed any 'row' types yet.
            bool foundRows = false;

            string rowsAndCols;

            if (!HasMatch(this.EmbedInstruction, out embedWarning, out this.Role, out rowsAndCols))
            {
                return(false);
            }

            MatchCollection matches = COMMAND_PARSER.Matches(rowsAndCols);

            foreach (Match m in matches)
            {
                string type         = m.Groups[GROUP_TYPE].Value;
                string cmdSelection = m.Groups[GROUP_SELECTION].Value;
                string style        = m.Groups[GROUP_STYLE].Value;
                string cmdFilter    = m.Groups[GROUP_FILTER].Value;

                CommandIterator.IteratorType cmdType  = CommandIterator.ParseIteratorType(type, ref foundRows);
                CommandIterator.StyleType    cmdStyle = CommandIterator.ParseStyleType(style);

                CommandIterator iterator = new CommandIterator(cmdType, cmdSelection, cmdStyle, cmdFilter);
                this.LoadIterator(iterator);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generate bar chart data based on data within the embed report.
        /// </summary>
        /// <returns>A <see cref="SortedDictionary{TKey,TValue}"/> with the
        /// keys being years and values containing data.</returns>
        public SortedDictionary <int, double> GenerateBarChartData()
        {
            SortedDictionary <int, double> barChartData = new SortedDictionary <int, double>();

            if (!IsBarChartReport())
            {
                return(barChartData);
            }

            CommandIterator.IteratorType elPos = this.InstanceReport.GetElementLocation();

            List <InstanceReportItem> items = null;

            if (elPos == CommandIterator.IteratorType.Column)
            {
                items = this.InstanceReport.Columns.ConvertAll(col => (InstanceReportItem)col);
            }
            else
            {
                items = this.InstanceReport.Rows.ConvertAll(row => (InstanceReportItem)row);
            }

            foreach (InstanceReportItem item in items)
            {
                if (item.EmbedRequirements == null)
                {
                    continue;
                }

                InstanceReportRow irr = item.EmbedRequirements.ElementRow;
                if (irr.ElementName.IndexOf("AnnualReturn", StringComparison.CurrentCultureIgnoreCase) == -1)
                {
                    continue;
                }

                string yearString = irr.ElementName.Substring(irr.ElementName.Length - 4, 4);
                int    yearValue  = 0;
                if (!int.TryParse(yearString, out yearValue))
                {
                    continue;
                }

                Cell[] cells = item.GetCellArray(this.InstanceReport);
                if (cells == null || cells.Length == 0)
                {
                    continue;
                }

                foreach (Cell c in cells)
                {
                    if (c.HasData)
                    {
                        barChartData[yearValue] = (double)c.NumericAmount;
                        break;
                    }
                }
            }

            return(barChartData);
        }
Ejemplo n.º 3
0
        private bool SortByCommands(CommandIterator[] commands)
        {
            if (commands == null || commands.Length == 0)
            {
                return(false);
            }

            CommandIterator.IteratorType type = commands[0].Type;

            //sorting may only be performed on rows or columsn.  'Unknown' is not allowed.
            if (type == CommandIterator.IteratorType.Unknown)
            {
                return(false);
            }

            //sorting may only be performed on items of a consistent type (rows or columns)
            if (!Array.TrueForAll(commands, c => c.Type == type))
            {
                return(false);
            }

            //collect all of the possible values in command order
            List <string>[] commandValueKeys = new List <string> [commands.Length];

            CommandIterator[] emptySet = new CommandIterator[0];
            for (int i = 0; i < commands.Length; i++)
            {
                //we can't compare a separator
                if (commands[i].Selection == CommandIterator.SelectionType.Separator)
                {
                    commandValueKeys[i] = null;
                }
                else
                {
                    bool hasDefaultMember;
                    Dictionary <string, object> tmp = this.GetSelectionMembers(emptySet, commands[i], out hasDefaultMember);
                    List <string> sortedKeys        = new List <string>(tmp.Keys);
                    commandValueKeys[i] = sortedKeys;
                }
            }

            ItemSorter sorter = (left, right) =>
            {
                for (int i = 0; i < commands.Length; i++)
                {
                    //we can't compare a separator
                    if (commands[i].Selection == CommandIterator.SelectionType.Separator)
                    {
                        continue;
                    }

                    List <string> valueKeys = commandValueKeys[i];

                    int leftIdx  = 0;
                    int rightIdx = 0;

                    switch (commands[i].Selection)
                    {
                    case CommandIterator.SelectionType.Axis:
                        string leftSegment  = ((Segment)left.EmbedRequirements.GetMemberKeyValue(commands[i]).Value).DimensionInfo.Id;
                        string rightSegment = ((Segment)right.EmbedRequirements.GetMemberKeyValue(commands[i]).Value).DimensionInfo.Id;

                        leftIdx  = valueKeys.IndexOf(leftSegment);
                        rightIdx = valueKeys.IndexOf(rightSegment);
                        break;

                    case CommandIterator.SelectionType.Element:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.ElementKey);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.ElementKey);
                        break;

                    case CommandIterator.SelectionType.Period:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.PeriodLabel);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.PeriodLabel);
                        break;

                    case CommandIterator.SelectionType.Unit:
                        leftIdx  = valueKeys.IndexOf(left.EmbedRequirements.UnitCode);
                        rightIdx = valueKeys.IndexOf(right.EmbedRequirements.UnitCode);
                        break;
                    }

                    if (leftIdx < rightIdx)
                    {
                        return(-1);
                    }

                    if (leftIdx > rightIdx)
                    {
                        return(1);
                    }
                }

                return(0);
            };

            if (type == CommandIterator.IteratorType.Column)
            {
                this.InstanceReport.Columns.Sort((left, right) => sorter(left, right));
            }
            else
            {
                this.InstanceReport.Rows.Sort((left, right) => sorter(left, right));
            }

            return(true);
        }