Ejemplo n.º 1
0
        /**
         * {@inheritDoc}
         */
        public override Tuple Decode(int[] encoded, string parentFieldName)
        {
            // Get the scalar values from the underlying scalar encoder
            DecodeResult result = (DecodeResult)scalarEncoder.Decode(encoded, parentFieldName);

            if (result.GetFields().Count == 0)
            {
                return(result);
            }

            // Expect only 1 field
            if (result.GetFields().Count != 1)
            {
                throw new InvalidOperationException("Expecting only one field");
            }

            //Get the list of categories the scalar values correspond to and
            //  generate the description from the category name(s).
            Map <string, RangeList> fieldRanges = result.GetFields();
            List <MinMax>           outRanges   = new List <MinMax>();
            StringBuilder           desc        = new StringBuilder();

            foreach (string descripStr in fieldRanges.Keys)
            {
                MinMax minMax = fieldRanges[descripStr].GetRange(0);
                int    minV   = (int)Math.Round(minMax.Min());
                int    maxV   = (int)Math.Round(minMax.Max());
                outRanges.Add(new MinMax(minV, maxV));
                while (minV <= maxV)
                {
                    if (desc.Length > 0)
                    {
                        desc.Append(", ");
                    }
                    desc.Append(indexToCategory[minV]);
                    minV += 1;
                }
            }

            //Return result
            string fieldName;

            if (parentFieldName.Any())
            {
                fieldName = string.Format("{0}.{1}", parentFieldName, name);
            }
            else
            {
                fieldName = name;
            }

            Map <string, RangeList> retVal = new Map <string, RangeList>();

            retVal.Add(fieldName, new RangeList(outRanges, desc.ToString()));

            return(new DecodeResult(retVal, new[] { fieldName }.ToList()));
        }
Ejemplo n.º 2
0
        /**
         * {@inheritDoc}
         */
        public override Tuple Decode(int[] encoded, string parentFieldName)
        {
            // Get the scalar values from the underlying scalar encoder
            DecodeResult decodeResult = (DecodeResult)_encoder.Decode(encoded, parentFieldName);

            Map <string, RangeList> fields = decodeResult.GetFields();

            if (fields.Keys.Count == 0)
            {
                return(decodeResult);
            }

            // Convert each range into normal space
            RangeList inRanges  = fields.Values.ToArray()[0];
            RangeList outRanges = new RangeList(new List <MinMax>(), "");

            foreach (MinMax minMax in inRanges.GetRanges())
            {
                MinMax scaledMinMax = new MinMax(Math.Pow(10, minMax.Min()),
                                                 Math.Pow(10, minMax.Max()));
                outRanges.Add(scaledMinMax);
            }

            // Generate a text description of the ranges
            string desc      = "";
            int    numRanges = outRanges.Count;

            for (int i = 0; i < numRanges; i++)
            {
                MinMax minMax = outRanges.GetRange(i);
                if (minMax.Min() != minMax.Max())
                {
                    desc += string.Format("{0:#.00}-{1:#.00}", minMax.Min(), minMax.Max());
                }
                else
                {
                    desc += string.Format("{0:#.00}", minMax.Min());
                }
                if (i < numRanges - 1)
                {
                    desc += ", ";
                }
            }
            outRanges.SetDescription(desc);

            string fieldName;

            if (!parentFieldName.Equals(""))
            {
                fieldName = string.Format("{0}.{1}", parentFieldName, GetName());
            }
            else
            {
                fieldName = GetName();
            }

            Map <string, RangeList> outFields = new Map <string, RangeList>();

            outFields.Add(fieldName, outRanges);

            List <string> fieldNames = new List <string>();

            fieldNames.Add(fieldName);

            return(new DecodeResult(outFields, fieldNames));
        }