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>");
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
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
                                           ));
            }
        }