예제 #1
0
        public override void RenderDataUpdate(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight,
            string path
            )
        {
            if (this.XmlNode.NodeType == XmlNodeType.Text)
            {
                base.RenderDataUpdate(result, context, filter, weight, path);
                return;
            }

            path += this.XmlNode.Name + string.Format(
                ":nth-child({0}) ",
                this.XmlNode.ParentNode.ChildNodes.IndexOf(this.XmlNode)
                );

            foreach (DashboardNode node in this.Children)
            {
                node.RenderDataUpdate(
                    result,
                    context,
                    filter,
                    weight,
                    path
                    );
            }
        }
예제 #2
0
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            DateTime value;

            if (this.XmlNode.Attributes["Value"].Value == "Now")
            {
                value = DateTime.Now;
            }
            else
            {
                value = DateTime.Parse(this.XmlNode.Attributes["Value"].Value);
            }

            if (this.XmlNode.Attributes["Format"] != null)
            {
                result.Append(value.ToString(this.XmlNode.Attributes["Format"].Value));
            }
            else
            {
                result.Append(value.ToString());
            }
        }
예제 #3
0
        public string[] Calculate(
            Data basefilter,
            Data filter,
            StorageMethods.Database storageMethod,
            WeightingFilterCollection weights
            )
        {
            if (this.Assembly == null)
            {
                return new string[] { "0", "0" }
            }
            ;

            try
            {
                //return (decimal)new System.Data.DataTable().Compute(equation, null);
                //EquationEvaluator evaluator = new EquationEvaluator(this);

                List <object> argumentsWeighted = new List <object>();

                List <object> argumentsUnweighted = new List <object>();

                foreach (string key in this.Values.Keys)
                {
                    if (this.Values[key].Type == EquationPlaceHolderType.Value)
                    {
                        Data data = this.Values[key].GetValue(basefilter, filter, storageMethod, weights);

                        argumentsWeighted.Add(data.Value);
                        argumentsUnweighted.Add(data.UnweightedValue);
                    }
                    else
                    {
                        Data data = this.Values[key].GetValue(basefilter, filter, storageMethod, weights);

                        argumentsWeighted.Add(data.Responses);
                        argumentsUnweighted.Add(data.Responses);

                        //argumentsWeighted.Add(data.Responses.Select(x => x.Value[0]).ToArray());
                        //argumentsUnweighted.Add(data.Responses.Select(x => 1.0).ToArray());
                    }
                }

                return(new string[] {
                    this.Assembly.Evaluate(argumentsWeighted.ToArray()),
                    this.Assembly.Evaluate(argumentsUnweighted.ToArray())
                });
            }
            catch (Exception ex)
            {
                Log(string.Format(
                        "<Error><![CDATA[{0}]]></Error><Equation><![CDATA[{1}]]></Equation>",
                        ex.ToString(),
                        this.EquationString
                        ));

                return(new string[] { "0", "0" });
            }
        }
예제 #4
0
        public FilterCategoryOperator(WeightingFilterCollection owner, XmlNode xmlNode, int level, string fileName)
        {
            this.Owner    = owner;
            this.XmlNode  = xmlNode;
            this.Level    = level;
            this.FileName = fileName.Replace("\\", "/");
            this.Load    += FilterCategoryOperator_Load;

            base.EnableViewState = false;

            Parse();
        }
예제 #5
0
        private string GetValue(
            Data filter,
            WeightingFilterCollection weight
            )
        {
            Data data = filter;

            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            if (this.IdVariable.HasValue)
            {
                data = storageMethod.GetRespondentsNumeric(
                    this.IdVariable.Value,
                    true,
                    this.Dashboard.Core.CaseDataLocation,
                    data,
                    weight
                    );
            }

            if (this.XmlNode.Attributes["Decimals"] != null)
            {
                data.Value = Math.Round(data.Value, int.Parse(
                                            this.XmlNode.Attributes["Decimals"].Value
                                            ));
            }

            switch (this.Type)
            {
            case DashboardMeasureType.Sum:
                break;

            case DashboardMeasureType.Average:
                data.Value = data.Value / data.Responses.Count;
                break;
            }

            if (this.XmlNode.Attributes["Format"] != null)
            {
                return(string.Format(
                           this.XmlNode.Attributes["Format"].Value,
                           data.Value
                           ));
            }
            else
            {
                return(data.Value.ToString());
            }
        }
예제 #6
0
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            if (this.XmlNode.NodeType == XmlNodeType.Comment)
            {
                //result.Append(this.XmlNode.OuterXml);
                return;
            }

            if (this.XmlNode.NodeType == XmlNodeType.Text)
            {
                string text = ReplacePlaceholder(this.XmlNode.InnerText, context);

                result.Append(text);
                return;
            }

            // Render the opening tag of the html node.
            result.Append("<");
            result.Append(this.XmlNode.Name);

            // Run through all attributes of the html node.
            foreach (XmlAttribute xmlAttribute in this.XmlNode.Attributes)
            {
                // Render the html attribute.
                result.Append(string.Format(
                                  " {0}=\"{1}\"",
                                  xmlAttribute.Name,
                                  ReplacePlaceholder(xmlAttribute.Value, context)
                                  ));
            }

            result.Append(">");

            // Run through all child dashboard nodes.
            foreach (DashboardNode children in base.Children)
            {
                children.Render(result, context, filter, weight);
            }

            // Render the closing tag of the html node.
            result.Append(string.Format(
                              "</{0}>",
                              this.XmlNode.Name
                              ));
        }
예제 #7
0
        public override void RenderDataUpdate(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight,
            string path
            )
        {
            result.Append("{ \"Path\": \"");
            //result.Append(path);
            result.Append(this.Dashboard.IdCounter++);
            result.Append("\", \"Value\": \"");

            result.Append(this.GetValue(filter, weight));

            result.Append("\" },");
        }
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            string label = "";

            if (context.Categories.ContainsKey(this.Variable))
            {
                label = (string)this.Dashboard.Cache.CategoryLabels[context.Categories[this.Variable]][0][1];
            }

            if (this.Repeat == false && context.LastRenderedLabel.ContainsKey(this.Identity))
            {
                if (context.LastRenderedLabel[this.Identity] == label)
                {
                    return;
                }
            }

            if (!context.LastRenderedLabel.ContainsKey(this.Identity))
            {
                context.LastRenderedLabel.Add(this.Identity, "");
            }

            context.LastRenderedLabel[this.Identity] = label;

            if (this.RenderContainer)
            {
                result.Append(string.Format(
                                  "<span id=\"r_{0}\">",
                                  this.Dashboard.IdCounter++
                                  ));
            }

            result.Append(label);

            if (this.RenderContainer)
            {
                result.Append("</span>");
            }
        }
예제 #9
0
 public virtual void RenderDataUpdate(
     StringBuilder result,
     DashboardRenderContext context,
     Data filter,
     WeightingFilterCollection weight,
     string path
     )
 {
     foreach (DashboardNode node in this.Children)
     {
         node.RenderDataUpdate(
             result,
             context,
             filter,
             weight,
             path
             );
     }
 }
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            Data data = filter;

            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            double highestValue = double.MinValue;
            Guid   idCategory   = new Guid();

            foreach (string category in this.Dashboard.Cache.Categories[this.IdVariable.Value].Keys)
            {
                Data value = storageMethod.GetRespondents(
                    (Guid)this.Dashboard.Cache.Categories[this.IdVariable.Value][category][0][2],
                    this.IdVariable.Value,
                    true,
                    this.Dashboard.Core.CaseDataLocation,
                    data,
                    weight
                    );

                if (value.Value > highestValue)
                {
                    highestValue = value.Value;
                    idCategory   = (Guid)this.Dashboard.Cache.
                                   Categories[this.IdVariable.Value][category][0][2];
                }
            }

            if (this.Dashboard.Cache.CategoryLabels.ContainsKey(idCategory))
            {
                result.Append((string)this.Dashboard.Cache.CategoryLabels[idCategory][0][1]);
            }
        }
예제 #11
0
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            StringBuilder value = new StringBuilder();

            // Run through all child dashboard nodes.
            foreach (DashboardNode children in base.Children)
            {
                children.Render(
                    value,
                    context,
                    filter,
                    weight
                    );
            }

            this.Dashboard.Properties[this.Type] = value.ToString().Trim();
        }
예제 #12
0
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            if (this.RenderContainer)
            {
                result.Append(string.Format(
                                  "<span id=\"r_{0}\">",
                                  this.Dashboard.IdCounter++
                                  ));
            }

            result.Append(this.GetValue(filter, weight));

            if (this.RenderContainer)
            {
                result.Append("</span>");
            }
        }
        public override void RenderDataUpdate(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight,
            string path
            )
        {
            result.Append("{ \"Path\": \"");
            //result.Append(path);
            result.Append(this.Dashboard.IdCounter++);
            result.Append("\", \"Value\": \"");

            string label = "";

            if (context.Categories.ContainsKey(this.Variable))
            {
                label = (string)this.Dashboard.Cache.CategoryLabels[context.Categories[this.Variable]][0][1];
            }

            result.Append(label);

            result.Append("\" },");
        }
        public override void RenderDataUpdate(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight,
            string path
            )
        {
            if (!context.Categories.ContainsKey(this.Variable))
            {
                context.Categories.Add(this.Variable, new Guid());
            }

            DataCore.Classes.Data data = null;
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            if (this.XmlNode.Attributes["DefaultWeighting"] != null)
            {
                if (this.Dashboard.Cache.Variables.ContainsKey(this.XmlNode.Attributes["DefaultWeighting"].Value))
                {
                    XmlNode xmlNode = this.XmlNode.Clone();
                    xmlNode.InnerXml = "";

                    xmlNode.Attributes["DefaultWeighting"].Value =
                        ((Guid)this.Dashboard.Cache.Variables
                         [this.XmlNode.Attributes["DefaultWeighting"].Value][0][1]).ToString();

                    weight = new WeightingFilterCollection(
                        null,
                        this.Dashboard.Core,
                        xmlNode
                        );
                    weight.LoadRespondents(filter);
                }
            }

            foreach (Guid idCategory in this.Categories.Keys)
            {
                data = storageMethod.GetRespondents(
                    idCategory,
                    this.IdVariable,
                    true,
                    this.Dashboard.Core.CaseDataLocation,
                    filter,
                    weight
                    );

                context.Categories[this.Variable] = idCategory;

                foreach (DashboardNode node in this.Children)
                {
                    node.RenderDataUpdate(
                        result,
                        context,
                        data,
                        weight,
                        path
                        );
                }
            }
        }
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            if (!context.Categories.ContainsKey(this.Variable))
            {
                context.Categories.Add(this.Variable, new Guid());
            }

            DataCore.Classes.Data data       = null;
            DataCore.Classes.Data datafilter = null;
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            if (this.XmlNode.Attributes["DefaultWeighting"] != null)
            {
                if (this.Dashboard.Cache.Variables.ContainsKey(this.XmlNode.Attributes["DefaultWeighting"].Value))
                {
                    XmlNode xmlNode = this.XmlNode.Clone();
                    xmlNode.InnerXml = "";

                    xmlNode.Attributes["DefaultWeighting"].Value =
                        ((Guid)this.Dashboard.Cache.Variables
                         [this.XmlNode.Attributes["DefaultWeighting"].Value][0][1]).ToString();

                    weight = new WeightingFilterCollection(
                        null,
                        this.Dashboard.Core,
                        xmlNode
                        );
                    weight.LoadRespondents(filter);
                }
            }

            int count = 0;

            foreach (Guid idCategory in this.Categories.Keys)
            {
                //if (this.Aggregate)
                {
                    data = storageMethod.GetRespondents(
                        idCategory,
                        this.IdVariable,
                        true,
                        this.Dashboard.Core.CaseDataLocation,
                        filter,
                        weight
                        );
                }

                if (this.HideEmpty)
                {
                    /*bool exists = true;
                     * Data hasValueFilter = null;
                     * DashboardCacheHasValue hasValue = null;
                     *
                     * if (!this.Dashboard.Cache.HasValue.ContainsKey(idCategory))
                     * {
                     *  this.Dashboard.Cache.HasValue.Add(idCategory, new DashboardCacheHasValue());
                     *
                     *  if(this.Aggregate)
                     *      this.Dashboard.Cache.HasValue[idCategory].Filter = data;
                     *  else
                     *  {
                     *      this.Dashboard.Cache.HasValue[idCategory].Filter = storageMethod.GetRespondents(
                     *          idCategory,
                     *          this.IdVariable,
                     *          true,
                     *          this.Dashboard.Core.CaseDataLocation,
                     *          filter,
                     *          weight
                     *      );
                     *  }
                     *  hasValueFilter = filter;
                     *  exists = false;
                     * }
                     *
                     * hasValue = this.Dashboard.Cache.HasValue[idCategory];
                     *
                     * foreach (string variable in context.Categories.Keys)
                     * {
                     *  if (variable == this.Variable)
                     *      continue;
                     *
                     *  if (!hasValue.Values.ContainsKey(context.Categories[variable]))
                     *  {
                     *      hasValue.Values.Add(context.Categories[variable], new DashboardCore.DashboardCacheHasValue());
                     *
                     *      exists = false;
                     *      break;
                     *  }
                     *  else
                     *  {
                     *      hasValueFilter = hasValue.Filter;
                     *  }
                     *
                     *  hasValue = hasValue.Values[context.Categories[variable]];
                     *  hasValue.Filter = hasValueFilter;
                     * }
                     *
                     * if (!exists)
                     * {
                     *  if (!this.Aggregate)
                     *  {
                     *      data = storageMethod.GetRespondents(
                     *          idCategory,
                     *          this.IdVariable,
                     *          true,
                     *          this.Dashboard.Core.CaseDataLocation,
                     *          hasValueFilter,
                     *          weight
                     *      );
                     *
                     *      hasValue.Filter = data;
                     *  }
                     *
                     *  hasValue.HasValue = data.Base != 0;
                     * }
                     *
                     * //if(data.Responses.Count == 0)
                     * if (!hasValue.HasValue)
                     *  continue;*/
                    /*if (data.Base == 0)
                     *  continue;*/
                    if (data.Base == 0)
                    {
                        continue;
                    }
                }

                context.Categories[this.Variable] = idCategory;

                // Run through all child dashboard nodes.
                foreach (DashboardNode children in base.Children)
                {
                    children.Render(
                        result,
                        context,
                        data,
                        weight
                        );
                }

                count++;

                if (this.Count != -1 && count == this.Count)
                {
                    break;
                }
            }

            context.Categories.Remove(this.Variable);
        }
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            result.Append("<select");

            if (this.XmlNode.Attributes["class"] != null)
            {
                this.XmlNode.Attributes["class"].Value += " DimensionSelector";
            }
            else
            {
                this.XmlNode.AddAttribute("class", "DimensionSelector");
            }

            DataCore.Classes.Data data = null;
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            if (this.XmlNode.Attributes["DefaultWeighting"] != null)
            {
                if (this.Dashboard.Cache.Variables.ContainsKey(this.XmlNode.Attributes["DefaultWeighting"].Value))
                {
                    XmlNode xmlNode = this.XmlNode.Clone();
                    xmlNode.InnerXml = "";

                    xmlNode.Attributes["DefaultWeighting"].Value =
                        ((Guid)this.Dashboard.Cache.Variables
                         [this.XmlNode.Attributes["DefaultWeighting"].Value][0][1]).ToString();

                    weight = new WeightingFilterCollection(
                        null,
                        this.Dashboard.Core,
                        xmlNode
                        );
                    weight.LoadRespondents(filter);
                }
            }

            if (this.XmlNode.Attributes["selected"] == null)
            {
                // Render the html attribute.
                result.Append(string.Format(
                                  " {0}=\"{1}\"",
                                  "selected",
                                  string.Join(",", this.Selected)
                                  ));
            }

            // Run through all attributes of the html node.
            foreach (XmlAttribute xmlAttribute in this.XmlNode.Attributes)
            {
                // Render the html attribute.
                result.Append(string.Format(
                                  " {0}=\"{1}\"",
                                  xmlAttribute.Name,
                                  ReplacePlaceholder(xmlAttribute.Value, context)
                                  ));
            }

            result.Append(">");

            foreach (Guid idCategory in this.Categories.Keys)
            {
                if (this.HideEmpty)
                {
                    data = storageMethod.GetRespondents(
                        idCategory,
                        this.IdVariable,
                        true,
                        this.Dashboard.Core.CaseDataLocation,
                        null,//filter,
                        weight
                        );

                    //if(data.Responses.Count == 0)
                    if (data.Base == 0)
                    {
                        continue;
                    }
                }
                result.Append(string.Format(
                                  "<option value=\"{0}\">{1}</option>",
                                  this.Dashboard.Cache.Categories2[idCategory][0][1],
                                  this.Dashboard.Cache.CategoryLabels[idCategory][0][1]
                                  ));
            }

            result.Append("</select>");
        }
예제 #17
0
        public Data GetValue(
            Data basefilter,
            Data filter,
            StorageMethods.Database storageMethod,
            WeightingFilterCollection weights
            )
        {
            if (!this.Valid)
            {
                return(new Data());
            }

            Data result;

            if (this.IdWeightingVariable.HasValue)
            {
                XmlDocument document = new XmlDocument();

                XmlNode xmlNode = document.CreateElement("WeightingVariables");
                xmlNode.AddAttribute("DefaultWeighting", this.IdWeightingVariable.Value.ToString());
                xmlNode.AddAttribute("IsTaxonomy", this.IsTaxonomy);

                weights = new WeightingFilterCollection(null, this.Equation.Core, xmlNode);

                weights.LoadRespondents(filter);
            }
            else if (this.WeightingVariable == "NONE")
            {
                weights = null;
            }

            if (this.Unfiltered)
            {
                filter = null;
            }

            if (this.Unfiltered2)
            {
                filter = basefilter;
            }

            if (this.Filter != null)
            {
                filter = this.Filter.Evalute(filter, filter);
            }

            /*if (this.IdFilterVariable.HasValue)
             * {
             *  if (this.IdFilterCategory.HasValue)
             *  {
             *      filter = storageMethod.GetRespondents(
             *          this.IdFilterCategory.Value,
             *          this.IdFilterVariable.Value,
             *          this.IsTaxonomy,
             *          this.Equation.CaseDataLocation,
             *          filter,
             *          null,
             *          null
             *      );
             *  }
             *  else
             *  {
             *      filter = storageMethod.GetRespondents(
             *          this.IdFilterVariable.Value,
             *          this.IsTaxonomy,
             *          this.Equation.CaseDataLocation,
             *          filter,
             *          null
             *      );
             *  }
             * }*/

            if (this.IdCategory.HasValue)
            {
                result = storageMethod.GetRespondents(
                    this.IdCategory.Value,
                    this.IdVariable,
                    this.IsTaxonomy,
                    this.Equation.Core.CaseDataLocation,
                    filter,
                    weights
                    );
            }
            else
            {
                if (this.VariableType != VariableType.Numeric)
                {
                    result = storageMethod.GetRespondents(
                        this.IdVariable,
                        this.IsTaxonomy,
                        this.Equation.Core.CaseDataLocation,
                        filter,
                        weights
                        );
                }
                else
                {
                    result = storageMethod.GetRespondentsNumeric(
                        this.IdVariable,
                        this.IsTaxonomy,
                        this.Equation.CaseDataLocation,
                        filter,
                        weights
                        );

                    if (this.Category == "Mean")
                    {
                        result.Value = result.Value / result.Base;
                    }
                }
            }

            return(result);
        }
예제 #18
0
        public List <EquationValidationError> SyntaxCheck(Data filter, Database storageMethod, WeightingFilterCollection weights)
        {
            try
            {
                EquationEvaluator evaluator = new EquationEvaluator(this);

                evaluator.Compile();

                /*string value = evaluator.Compile(
                 *  filter,
                 *  storageMethod,
                 *  weights
                 * );*/

                return(new List <EquationValidationError>());
            }
            catch (Exception ex)
            {
                List <EquationValidationError> result = new List <EquationValidationError>();

                result.Add(new EquationValidationError(EquationValidationErrorType.Syntax, ex.Message));

                return(result);
            }
        }
예제 #19
0
 /// <summary>
 /// Renders the dashboard node to the result html string.
 /// </summary>
 /// <param name="result">
 /// The string builder that holds the result html string.
 /// </param>
 public abstract void Render(
     StringBuilder result,
     DashboardRenderContext context,
     Data filter,
     WeightingFilterCollection weight
     );
예제 #20
0
 public FilterCategoryOperator(WeightingFilterCollection owner, XmlNode xmlNode, int level, string fileName, FilterCategoryOperator parent)
     : this(owner, xmlNode, level, fileName)
 {
     this.Parent = parent;
 }
예제 #21
0
        private void HighestValue(HttpContext context)
        {
            LogRequest(context);

            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                Global.Core,
                null
                );

            Guid?idVariable = FindVariable(context.Request.Params["Variable"]);

            if (!idVariable.HasValue)
            {
                context.Response.Write(Global.LanguageManager.GetText("Error_VariableNotExists"));
                return;
            }

            Dictionary <Guid, List <object[]> > categories = Global.Core.TaxonomyCategories.ExecuteReaderDict <Guid>(
                "SELECT IdTaxonomyVariable, Id FROM TaxonomyCategories",
                new object[] { }
                );

            Data filter = null;

            if (context.Request.Params["Filter"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter
                        );
                }
            }

            if (context.Request.Params["Filter2"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter2"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter
                        );
                }
            }

            if (context.Request.Params["Filter3"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter3"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter
                        );
                }
            }

            WeightingFilterCollection weighting = null;

            Guid?idWeightingVariable = null;

            if (context.Request.Params["WeightingVariable"] != null)
            {
                idWeightingVariable = FindVariable(context.Request.Params["WeightingVariable"]);

                if (!idWeightingVariable.HasValue)
                {
                    context.Response.Write(
                        Global.LanguageManager.GetText("Error_VariableNotExists"));
                    return;
                }

                weighting = new WeightingFilterCollection(null, Global.Core, null);
                weighting.DefaultWeighting = idWeightingVariable;
                weighting.LoadRespondents(null);
            }

            string highestIdentifier = "highest";

            if (context.Request.Params["HighestIdentifier"] != null)
            {
                highestIdentifier = context.Request.Params["HighestIdentifier"];

                if (highestIdentifier == "undefined")
                {
                    highestIdentifier = "most";
                }
            }

            if (categories.ContainsKey(idVariable.Value))
            {
                double highestShare           = 0;
                Guid?  idCategoryHighestShare = null;

                Data data = storageMethod.GetRespondents(
                    idVariable.Value,
                    true,
                    Global.Core.CaseDataLocation,
                    filter,
                    weighting
                    );

                double baseValue = data.Value;

                foreach (object[] category in categories[idVariable.Value])
                {
                    data = storageMethod.GetRespondents(
                        (Guid)category[1],
                        idVariable.Value,
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );

                    data.Value = data.Value * 100 / baseValue;

                    if (data.Value > highestShare)
                    {
                        highestShare           = data.Value;
                        idCategoryHighestShare = (Guid)category[1];
                    }
                }

                Dictionary <Guid, List <object[]> > categoryLabels = Global.Core.TaxonomyCategoryLabels.ExecuteReaderDict <Guid>(
                    "SELECT IdTaxonomyCategory, Label FROM TaxonomyCategoryLabels",
                    new object[] { }
                    );

                if (idCategoryHighestShare.HasValue)
                {
                    context.Response.Write(string.Format(
                                               Global.LanguageManager.GetText("Output_HighestValue"),
                                               context.Request.Params["Variable"],
                                               categoryLabels[idCategoryHighestShare.Value][0][1],
                                               Math.Round(highestShare, 0),
                                               highestIdentifier,
                                               context.Request.Params["WeightingVariable"] == null ? "value" :
                                               context.Request.Params["WeightingVariable"]
                                               ));
                }
                else
                {
                    context.Response.Write(string.Format(
                                               Global.LanguageManager.GetText("Error_ValueNotFound")
                                               ));
                }
            }
            else
            {
                Data data = storageMethod.GetRespondents(
                    idVariable.Value,
                    true,
                    Global.Core.CaseDataLocation,
                    filter,
                    weighting
                    );

                context.Response.Write(string.Format(
                                           Global.LanguageManager.GetText("Output_Value"),
                                           context.Request.Params["Variable"],
                                           data.Value
                                           ));
            }
        }
예제 #22
0
        /// <summary>
        /// Gets the respondents of a category.
        /// </summary>
        /// <param name="idCategory">The id of the category to get the respondents for.</param>
        public Dictionary <Guid, double[]> GetRespondents(Guid idCategory, Dictionary <Guid, double[]> filter = null, WeightingFilterCollection weightingFilters = null)
        {
            throw new NotImplementedException();

            /*
             * // Load the report file.
             * XmlDocument xmlDocument = LoadReportFile(idCategory);
             *
             * // Build the xPath selection.
             * string path = "Response";
             *
             * // Create a new collection containing the result respondent ids.
             * Dictionary<Guid, double[]> result = new Dictionary<Guid, double[]>();
             *
             * // Select the response xml nodes.
             * XmlNodeList xmlNodes = xmlDocument.DocumentElement.SelectNodes(path);
             *
             * // Run through all response xml nodes.
             * foreach (XmlNode xmlNode in xmlNodes)
             * {
             *  // Get the response's respondent id.
             *  Guid idRespondent = Guid.Parse(
             *      xmlNode.Attributes["IdRespondent"].Value
             *  );
             *
             *  if (filter != null && filter.ContainsKey(idRespondent) == false)
             *      continue;
             *
             *  string weightingVariable = null;
             *
             *  if (weightingFilters != null)
             *  {
             *      // Run through all weighting filters.
             *      foreach (WeightingFilter weightingFilter in weightingFilters.ToArray())
             *      {
             *          // Check if the weighting filter applies to the respondent.
             *          if (weightingFilter.Respondents.Contains(idRespondent))
             *          {
             *              weightingVariable = weightingFilter.WeightingVariable;
             *
             *              break;
             *          }
             *      }
             *
             *      if (weightingVariable == null && weightingFilters.DefaultWeighting != null)
             *          weightingVariable = weightingFilters.DefaultWeighting;
             *  }
             *
             *  // Check if the respondent was already added to the result.
             *  if (!result.ContainsKey(idRespondent))
             *      result.Add(idRespondent, new double[1]);
             *
             *  if (weightingVariable != null)
             *  {
             *      double weight = 1.0;
             *
             *      if (xmlNode.Attributes[weightingVariable] != null)
             *          double.TryParse(xmlNode.Attributes[weightingVariable].Value, out weight);
             *
             *      result[idRespondent][0] += weight;
             *  }
             *  else
             *  {
             *      result[idRespondent][0] += 1.0;
             *  }
             * }
             *
             * // Return the result list of respondent ids.
             * return result;*/
        }
예제 #23
0
        public List <EquationValidationError> SecurityCheck(
            Data filter,
            StorageMethods.Database storageMethod,
            WeightingFilterCollection weights
            )
        {
            //return new List<EquationValidationError>();

            List <EquationValidationError> result = new List <EquationValidationError>();

            string equation = this.Render(false);

            string fileName = Path.Combine(
                Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", "")),
                "Resources",
                "EquationValidatorConfiguration.xml"
                );

            XmlDocument document = new XmlDocument();

            document.Load(fileName);

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

            foreach (XmlNode xmlNode in document.DocumentElement.ChildNodes)
            {
                validKeys.Add(xmlNode.InnerText);
            }

            // To remove the string values:
            int index = 0;

            while (index != -1)
            {
                if (index + 1 >= equation.Length)
                {
                    break;
                }

                index = equation.IndexOf('"', index + 1);

                if (index == -1)
                {
                    break;
                }

                int index2 = equation.IndexOf('"', index + 1);

                if (index2 == -1)
                {
                    break;
                }

                equation = equation.Remove(index + 1, (index2 - 1) - index);

                index += 2;
            }

            string[] parts = equation.Split(new string[] {
                " ",
                ",",
                "(",
                ")",
                "+",
                "-",
                "~",
                "*",
                "/",
                "==",
                "<",
                "<=",
                ">",
                ">=",
                "?",
                ":",
                ";",
                "=",
                "{",
                "}",
                "\t"
            }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string part in parts)
            {
                if (part.StartsWith("\"") && part.EndsWith("\"") && part.Count(x => x == '"') == 2)
                {
                    continue;
                }

                if (part.StartsWith("[") && part.EndsWith("]"))
                {
                    int v;

                    if (int.TryParse(part.Substring(1, part.Length - 2), out v))
                    {
                        continue;
                    }
                }

                double value;

                if (double.TryParse(part, out value))
                {
                    continue;
                }

                if (part.StartsWith("var_"))
                {
                    continue;
                }

                if (!validKeys.Contains(part))
                {
                    result.Add(new EquationValidationError(
                                   EquationValidationErrorType.MethodNotSupported,
                                   part
                                   ));
                }
            }

            return(result);
        }
        public override void Render(
            StringBuilder result,
            DashboardRenderContext context,
            Data filter,
            WeightingFilterCollection weight
            )
        {
            DataCore.Classes.Data data = filter;
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Dashboard.Core,
                null,
                this.Dashboard.Settings.ReportSettings.WeightMissingValue
                );

            if (this.Categories.Count == 0)
            {
                data = storageMethod.GetRespondents(
                    this.IdVariable,
                    true,
                    base.Dashboard.Core.CaseDataLocation,
                    data,
                    weight
                    );
            }
            else
            {
                if (this.Operator == DashboardFilterOperator.AND)
                {
                    foreach (Guid idCategory in this.Categories.Keys)
                    {
                        data = storageMethod.GetRespondents(
                            idCategory,
                            this.IdVariable,
                            true,
                            base.Dashboard.Core.CaseDataLocation,
                            data,
                            weight
                            );
                    }
                }
                else
                {
                    if (data == null)
                    {
                        data = new Data();
                    }

                    foreach (Guid idCategory in this.Categories.Keys)
                    {
                        Data d = storageMethod.GetRespondents(
                            idCategory,
                            this.IdVariable,
                            true,
                            base.Dashboard.Core.CaseDataLocation,
                            data,
                            weight
                            );

                        foreach (Guid idRespondent in d.Responses.Keys)
                        {
                            if (!data.Responses.ContainsKey(idRespondent))
                            {
                                data.Responses.Add(idRespondent, d.Responses[idRespondent]);
                            }
                        }
                    }
                }
            }

            // Run through all child dashboard nodes.
            foreach (DashboardNode children in base.Children)
            {
                children.Render(
                    result,
                    context,
                    data,
                    weight
                    );
            }
        }
예제 #25
0
        private void GetValue(HttpContext context)
        {
            LogRequest(context);

            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                Global.Core,
                null
                );

            Calculation calculation = Calculation.Total;

            if (context.Request.Params["Calculation"] != null)
            {
                if (!Enum.TryParse <Calculation>(
                        context.Request.Params["Calculation"],
                        true,
                        out calculation
                        ))
                {
                    if (context.Request.Params["Category"] != null)
                    {
                        calculation = Calculation.Difference;
                    }
                }
            }
            else
            {
                if (context.Request.Params["Category"] != null)
                {
                    calculation = Calculation.Difference;
                }
            }

            Data filter = null;

            /*filter = storageMethod.GetRespondentsNumeric(
             *  idVariable.Value,
             *  true,
             *  Global.Core.CaseDataLocation,
             *  filter
             * );*/

            WeightingFilterCollection weighting = null;

            Guid?idWeightingVariable = null;

            if (context.Request.Params["WeightingVariable"] != null)
            {
                idWeightingVariable = FindVariable(context.Request.Params["WeightingVariable"]);

                if (!idWeightingVariable.HasValue)
                {
                    context.Response.Write(
                        Global.LanguageManager.GetText("Error_VariableNotExists"));
                    return;
                }

                weighting = new WeightingFilterCollection(null, Global.Core, null);
                weighting.DefaultWeighting = idWeightingVariable;
                weighting.LoadRespondents(filter);
            }

            if (context.Request.Params["Filter"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );
                }
            }

            if (context.Request.Params["Filter2"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter2"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );
                }
            }

            if (context.Request.Params["Filter3"] != null)
            {
                object[] category = FindCategory(context.Request.Params["Filter3"]);

                if (category != null)
                {
                    filter = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );
                }
            }

            double result = 0.0;

            if (calculation != Calculation.Difference && filter == null)
            {
                if (idWeightingVariable.HasValue)
                {
                    filter = storageMethod.GetRespondentsNumeric(
                        idWeightingVariable.Value,
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );
                }
                else
                {
                    filter = new Data();
                }
            }

            switch (calculation)
            {
            case Calculation.Average:
            case Calculation.Mean:
                result = filter.Value / filter.Responses.Count;

                result = Math.Round(result, 2);

                if (result > 1000)
                {
                    result = Math.Round(result, 0);
                }

                context.Response.Write(string.Format(
                                           Global.LanguageManager.GetText("Output_Value"),
                                           calculation,
                                           result
                                           ));
                break;

            case Calculation.Total:
                result = filter.Value;

                result = Math.Round(result, 2);

                if (result > 1000)
                {
                    result = Math.Round(result, 0);
                }

                context.Response.Write(string.Format(
                                           Global.LanguageManager.GetText("Output_Value"),
                                           calculation,
                                           result,
                                           idWeightingVariable.HasValue ? context.Request.Params["WeightingVariable"] : ""
                                           ));
                break;

            case Calculation.Difference:
            case Calculation.Up:
            case Calculation.Increased:
                Data     data     = filter;
                object[] category = FindCategory(context.Request.Params["Category"]);

                if (category != null)
                {
                    data = storageMethod.GetRespondents(
                        (Guid)category[1],
                        (Guid)category[2],
                        true,
                        Global.Core.CaseDataLocation,
                        filter,
                        weighting
                        );
                }

                double value1    = data.Value;
                double baseValue = data.Value;

                category = FindCategory(context.Request.Params["CategoryCompare"]);

                data = storageMethod.GetRespondents(
                    (Guid)category[1],
                    (Guid)category[2],
                    true,
                    Global.Core.CaseDataLocation,
                    filter,
                    weighting
                    );

                value1 = data.Value - value1;

                result = Math.Round(result, 2);

                ValueChange valueChange = ValueChange.Increase;

                if (value1 < 10)
                {
                    valueChange = ValueChange.Decrease;
                }

                if (value1 == 0)
                {
                    context.Response.Write(string.Format(
                                               Global.LanguageManager.GetText("Output_Difference_NoChange"),
                                               context.Request.Params["WeightingVariable"],
                                               context.Request.Params["CategoryCompare"]
                                               ));
                }
                else
                {
                    value1 = Math.Round(Math.Abs(value1 * 100 / baseValue), 0);

                    if (value1 == 0)
                    {
                        value1 = Math.Round(Math.Abs(value1 * 100 / baseValue), 2);
                    }

                    string outputType = "Percent";
                    if (value1 > 200)
                    {
                        value1 = Math.Round(value1 / 100);

                        outputType  = "Times";
                        calculation = Calculation.Difference;
                    }

                    if (calculation == Calculation.Difference)
                    {
                        context.Response.Write(string.Format(
                                                   Global.LanguageManager.GetText("Output_Difference"),
                                                   context.Request.Params["WeightingVariable"],
                                                   Global.LanguageManager.GetText("Type_ValueChange_" + valueChange),
                                                   value1,
                                                   context.Request.Params["CategoryCompare"],
                                                   outputType
                                                   ));
                    }
                    else
                    {
                        context.Response.Write(string.Format(
                                                   Global.LanguageManager.GetText("Output_Difference2"),
                                                   context.Request.Params["WeightingVariable"],
                                                   Global.LanguageManager.GetText("Type_ValueChange_" + calculation + "_" + valueChange),
                                                   value1,
                                                   context.Request.Params["Category"]
                                                   ));
                    }
                }

                break;
            }
        }