Example #1
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());
            }
        }
Example #2
0
        private void RenderMeasure(LinkBiDefinitionDimension measure, string _selection, StringBuilder writer, int columnOffset, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            // Check if the measure is a numeric variable.
            if (measure.Type == VariableType.Numeric)
            {
                string label = "";

                if (measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null)
                {
                    if (measure.IsTaxonomy)
                    {
                        label = (string)this.Core.TaxonomyVariableLabels.GetValue(
                            "Label",
                            new string[] { "IdTaxonomyVariable", "IdLanguage" },
                            new object[] { measure.Identity, this.Definition.Settings.IdLanguage }
                            );
                    }
                    else
                    {
                        label = (string)this.Core.VariableLabels.GetValue(
                            "Label",
                            new string[] { "IdVariable", "IdLanguage" },
                            new object[] { measure.Identity, this.Definition.Settings.IdLanguage }
                            );
                    }

                    measure.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label);
                }

                label = measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value;

                string selection = _selection + string.Format(
                    "\"{0}\",",
                    (label)
                    );

                Data result = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                writer.Append("[" + selection);

                //empty for responses
                writer.Append(string.Format(
                                  "\"{0}\",",
                                  ""
                                  ));
                writer.Append(string.Format(
                                  "\"{0}\",",
                                  result.Base.ToString(new CultureInfo("en-GB"))
                                  ));

                writer.Append(string.Format(
                                  "\"{0}\",",
                                  result.Value.ToString(new CultureInfo("en-GB"))
                                  ));
                //writer.Append(string.Format(
                //    "\"{0}\"",
                //    result.GetStdDev(1, result.GetMean(1)).ToString(new CultureInfo("en-GB"))
                //));
                writer.Append(string.Format(
                                  "\"\""
                                  ));

                writer.Append("],");
            }
            else
            {
                // Create a new report calculator to calculate the
                // significant difference between categories.
                ReportCalculator calculator = new ReportCalculator(
                    null,
                    base.Core,
                    null
                    );

                filter = storageMethod.GetRespondents(measure, filter, this.Definition.WeightingFilters);
                string baseValue     = filter.Base.ToString(new CultureInfo("en-GB"));
                string uBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                string eBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB"));

                int rowOffset = i;

                Dictionary <Guid, double> categoryValues = new Dictionary <Guid, double>();

                TaskCollection tasks = new TaskCollection();
                tasks.Synchronously = true;

                // Run through all scores of the measure.

                /*foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                 * {
                 *  if (score.Equation != null)
                 *  {
                 *      tasks.Synchronously = true;
                 *      break;
                 *  }
                 * }*/

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    tasks.Add(() =>
                    {
                        Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);

                        categoryValues.Add(score.Identity, scoreFilter.Value);
                    });
                }

                tasks.WaitAll();

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    string label = "";

                    if (score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null)
                    {
                        if (measure.IsTaxonomy)
                        {
                            label = (string)this.Core.TaxonomyCategoryLabels.GetValue(
                                "Label",
                                new string[] { "IdTaxonomyCategory", "IdLanguage" },
                                new object[] { score.Identity, this.Definition.Settings.IdLanguage }
                                );
                        }
                        else
                        {
                            label = (string)this.Core.CategoryLabels.GetValue(
                                "Label",
                                new string[] { "IdCategory", "IdLanguage" },
                                new object[] { score.Identity, this.Definition.Settings.IdLanguage }
                                );
                        }

                        score.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label);
                    }

                    label = score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value;


                    string selection = _selection + string.Format(
                        " \"{0}\",",
                        measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value
                        );

                    writer.Append("[" + selection);

                    writer.Append(string.Format(
                                      "\"{0}\",",
                                      (label)
                                      ));
                    if (this.Definition.Settings.DisplayUnweightedBase)
                    {
                        writer.Append(string.Format(
                                          "\"{0}\",",
                                          uBaseValueStr
                                          ));
                    }
                    if (this.Definition.Settings.DisplayEffectiveBase)
                    {
                        writer.Append(string.Format(
                                          "\"{0}\",",
                                          eBaseValueStr
                                          ));
                    }
                    writer.Append(string.Format(
                                      "\"{0}\",",
                                      baseValue
                                      ));

                    double catgValue = categoryValues.ContainsKey(score.Identity) ? categoryValues[score.Identity] : 0;
                    writer.Append(string.Format(
                                      "\"{0}\"",
                                      catgValue
                                      ));
                    if (this.Definition.Settings.ExportPercentage)
                    {
                        double percent = 0;

                        if (!string.IsNullOrEmpty(baseValue))
                        {
                            percent = (catgValue / double.Parse(baseValue)) * 100;
                        }

                        writer.Append(string.Format(
                                          ",\"{0}\"",
                                          percent
                                          ));
                    }
                    writer.Append("],");

                    i++;
                }
            }
        }
        private void RenderMeasure(LinkBiDefinitionDimension measure, ExcelWriter writer, int columnOffset, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            int rowOffset = i;

            if (measure.Type == VariableType.Numeric)
            {
                Data result = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                double baseValue     = result.Base;
                string uBaseValueStr = result.Responses.Count.ToString(new CultureInfo("en-GB"));
                string eBaseValueStr = result.Responses.Count.ToString(new CultureInfo("en-GB"));
                string baseValueStr  = baseValue.ToString(new CultureInfo("en-GB"));

                writer.Write(
                    columnOffset + 2,
                    i,
                    baseValueStr
                    );

                writer.Write(
                    columnOffset + 3,
                    i,
                    result.Responses.Values.Sum(x => x[0]).ToString(new CultureInfo("en-GB"))
                    );

                i++;

                if (totalToProcess != 0)
                {
                    int progress = i * 100 / totalToProcess;

                    if (progress == 100)
                    {
                        base.Progress = 99;
                    }
                    else
                    {
                        base.Progress = progress;
                    }
                }
            }
            else
            {
                filter = storageMethod.GetRespondents(
                    measure,
                    filter,
                    this.Definition.WeightingFilters
                    );

                double baseValue     = filter.Base;
                string uBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                string eBaseValueStr = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                string baseValueStr  = baseValue.ToString(new CultureInfo("en-GB"));

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (score.Hidden)
                    {
                        continue;
                    }

                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    DefinitionObject _score = new DefinitionObject(
                        this.Core,
                        this.Definition.FileName,
                        score.XmlNode
                        );

                    /*writer.Write(
                     *  columnOffset + 1,
                     *  i,
                     *  score.Label
                     * );*/

                    writer.Write(
                        columnOffset + 1,
                        i,
                        _score.GetLabel(this.Definition.Settings.IdLanguage)
                        );

                    int columnOffset2 = 0;

                    if (this.DisplayUnweightedBase)
                    {
                        columnOffset2 = 1;

                        writer.Write(
                            columnOffset + 2,
                            i,
                            uBaseValueStr
                            );
                    }



                    if (this.DisplayEffectiveBase)
                    {
                        columnOffset2 = 1;

                        writer.Write(
                            columnOffset + 2,
                            i,
                            eBaseValueStr
                            );
                    }

                    writer.Write(
                        columnOffset + columnOffset2 + 2,
                        i,
                        baseValueStr
                        );

                    double value;

                    Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);


                    value = scoreFilter.Value;

                    writer.Write(
                        columnOffset + columnOffset2 + 3,
                        i,
                        value.ToString(new CultureInfo("en-GB"))
                        );

                    if (this.ExportPercentage)
                    {
                        double percentage = (value * 100 / baseValue);

                        if (double.IsNaN(percentage))
                        {
                            percentage = 0.0;
                        }

                        writer.Write(
                            columnOffset + columnOffset2 + 4,
                            i,
                            percentage.ToString(new CultureInfo("en-GB"))
                            );
                    }

                    i++;

                    if (totalToProcess != 0)
                    {
                        int progress = i * 100 / totalToProcess;

                        if (progress == 100)
                        {
                            base.Progress = 99;
                        }
                        else
                        {
                            base.Progress = progress;
                        }
                    }
                }
            }

            for (int a = rowOffset; a < i; a++)
            {
                DefinitionObject _measure = new DefinitionObject(
                    this.Core,
                    this.Definition.FileName,
                    measure.XmlNode
                    );

                /*writer.Write(
                 *  columnOffset,
                 *  a,
                 *  measure.Label
                 * );*/
                writer.Write(
                    columnOffset,
                    a,
                    _measure.GetLabel(this.Definition.Settings.IdLanguage)
                    );
            }
        }
        private void RenderMeasure(LinkBiDefinitionDimension measure, StringBuilder writer, int columnOffset, string selection, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            // Check if the measure's variable is a numeric variable.
            if (measure.Type == VariableType.Numeric)
            {
                Data data = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                writer.Append(data.Value.ToString(new CultureInfo("en-GB")));
                writer.Append(",");

                i++;

                if (totalToProcess != 0)
                {
                    int progress = (int)(i * 100 / totalToProcess);

                    if (progress == 100)
                    {
                        base.Progress = 99;
                    }
                    else
                    {
                        base.Progress = progress;
                    }
                }
            }
            else
            {
                filter = storageMethod.GetRespondents(measure, filter, this.Definition.WeightingFilters);
                string baseValue  = filter.Base.ToString(new CultureInfo("en-GB"));
                string uBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));

                int rowOffset = i;

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (score.Hidden)
                    {
                        continue;
                    }

                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    DefinitionObject _score = new DefinitionObject(
                        this.Core,
                        this.Definition.FileName,
                        score.XmlNode.GetXPath()
                        );

                    Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);

                    for (int r = 0; r < scoreFilter.Responses.Count; r++)
                    {
                        //writer.Append(selection);

                        writer.Append(_score.GetLabel(this.Definition.Settings.IdLanguage).Replace(",", "&#44;") + ",");

                        //writer.Append(Environment.NewLine);

                        break;
                    }


                    i++;

                    if (totalToProcess != 0)
                    {
                        int progress = (int)(i * 100 / totalToProcess);

                        if (progress == 100)
                        {
                            base.Progress = 99;
                        }
                        else
                        {
                            base.Progress = progress;
                        }
                    }
                }
            }
        }
Example #5
0
        private void RenderMeasure(LinkBiDefinitionDimension measure, StringBuilder writer, int columnOffset, string selection, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            VariableType variableType = measure.VariableType;

            // Check if the measure's variable is a numeric variable.
            if (variableType == VariableType.Numeric)
            {
                Data data = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                selection += HttpUtility.HtmlEncode(measure.Label).Replace(",", "&#44;") + ",";

                writer.Append(selection);
                writer.Append(filter.Base.ToString(new CultureInfo(2057)));
                writer.Append(",");
                writer.Append(data.Value.ToString(new CultureInfo(2057)));
                writer.Append(Environment.NewLine);
            }
            else
            {
                filter = storageMethod.GetRespondents(measure, filter, this.Definition.WeightingFilters);
                string baseValue  = filter.Base.ToString(new CultureInfo("en-GB"));
                string uBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                string eBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));


                int rowOffset = i;

                selection += HttpUtility.HtmlEncode(measure.Label).Replace(",", "&#44;") + ",";

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (score.Hidden)
                    {
                        continue;
                    }

                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    DefinitionObject _score = new DefinitionObject(
                        this.Core,
                        this.Definition.FileName,
                        score.XmlNode.GetXPath()
                        );

                    writer.Append(selection);
                    writer.Append(_score.GetLabel(this.Definition.Settings.IdLanguage).Replace(",", "&#44;") + ",");

                    /*Data scoreFilter = storageMethod.GetRespondents(
                     *  score.Identity,
                     *  measure.Identity,
                     *  measure.IsTaxonomy,
                     *  filter,
                     *  this.Definition.WeightingFilters
                     * );*/
                    Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);

                    if (this.DisplayUnweightedBase)
                    {
                        writer.Append(uBaseValue + ",");
                    }

                    if (this.DisplayEffectiveBase)
                    {
                        writer.Append(eBaseValue + ",");
                    }

                    writer.Append(baseValue + ",");
                    writer.Append(scoreFilter.Value);

                    if (this.ExportPercentage)
                    {
                        writer.Append(",");

                        if (filter.Base != 0)
                        {
                            writer.Append((scoreFilter.Value * 100 / filter.Base).ToString(new CultureInfo("en-GB")));
                        }
                        else
                        {
                            writer.Append("0");
                        }
                    }

                    writer.Append(Environment.NewLine);

                    i++;

                    if (totalToProcess != 0)
                    {
                        int progress = i * 100 / totalToProcess;

                        if (progress == 100)
                        {
                            base.Progress = 99;
                        }
                        else
                        {
                            base.Progress = progress;
                        }
                    }
                }
            }
        }
        public void LoadRespondents(Data filter)
        {
            /*DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
             *  this.Owner.Settings.AggregateNonQAData,
             *  this.Core,
             *  null
             * );*/
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                this.Core,
                null
                );

            this.Respondents = new Dictionary <Guid, double>();

            if (this.DefaultWeighting != null)
            {
                //Guid idDefaultWeighting = (Guid)this.Core.Variables.GetValue("Id", "Name", this.WeightingVariables.DefaultWeighting);
                Guid idDefaultWeighting = this.DefaultWeighting.Value;

                if (this.DefaultWeighting != null)
                {
                    Data respondents = storageMethod.GetRespondentsNumeric(
                        idDefaultWeighting,
                        this.IsTaxonomy,
                        this.Core.CaseDataLocation,
                        filter,
                        null
                        );

                    // Run through all respondents.
                    foreach (KeyValuePair <Guid, double[]> respondent in respondents.Responses)
                    {
                        this.Respondents.Add(respondent.Key, respondent.Value[0]);
                    }
                }
            }

            foreach (WeightingFilter weightingFilter in this.ToArray())
            {
                Data respondents = weightingFilter.FilterCategoryOperator.GetRespondents(storageMethod);

                respondents = storageMethod.GetRespondentsNumeric(
                    weightingFilter.IdWeightingVariable,
                    true,
                    this.Owner.Core.CaseDataLocation,
                    respondents
                    );

                Dictionary <Guid, double> respondentsWeights = new Dictionary <Guid, double>();

                // Run through all respondent ids.
                foreach (Guid idRespondent in respondents.Responses.Keys)
                {
                    // Get the respondent's weight.
                    double weight = respondents.Responses[idRespondent][0];

                    respondentsWeights.Add(idRespondent, weight);
                }

                weightingFilter.Respondents = respondentsWeights;
            }
        }
Example #7
0
        private void RenderMeasure(LinkBiDefinitionDimension measure, string _selection, StringBuilder writer, int columnOffset, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            // Check if the measure is a numeric variable.
            if (measure.Type == VariableType.Numeric)
            {
                string label = "";

                if (measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null)
                {
                    if (measure.IsTaxonomy)
                    {
                        label = (string)this.Core.TaxonomyVariableLabels.GetValue(
                            "Label",
                            new string[] { "IdTaxonomyVariable", "IdLanguage" },
                            new object[] { measure.Identity, this.Definition.Settings.IdLanguage }
                            );
                    }
                    else
                    {
                        label = (string)this.Core.VariableLabels.GetValue(
                            "Label",
                            new string[] { "IdVariable", "IdLanguage" },
                            new object[] { measure.Identity, this.Definition.Settings.IdLanguage }
                            );
                    }

                    measure.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label);
                }

                label = measure.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value;

                string selection = _selection + string.Format(
                    "\"Label\": \"{0}\",",
                    label
                    );

                Data result = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                writer.Append("{" + selection);

                writer.Append(string.Format(
                                  "\"Base\": \"{0}\",",
                                  result.Base.ToString(new CultureInfo("en-GB"))
                                  ));

                writer.Append(string.Format(
                                  "\"Value\": \"{0}\",",
                                  result.Value.ToString(new CultureInfo("en-GB"))
                                  ));
                writer.Append(string.Format(
                                  "\"StdDev\": \"{0}\"",
                                  result.GetStdDev(1, result.GetMean(1)).ToString(new CultureInfo("en-GB"))
                                  ));

                writer.Append("},");
            }
            else
            {
                // Create a new report calculator to calculate the
                // significant difference between categories.
                ReportCalculator calculator = new ReportCalculator(
                    null,
                    base.Core,
                    null
                    );

                filter = storageMethod.GetRespondents(measure, filter);
                string baseValue = filter.Base.ToString(new CultureInfo("en-GB"));

                int rowOffset = i;

                Dictionary <Guid, double> categoryValues = new Dictionary <Guid, double>();

                TaskCollection tasks = new TaskCollection();
                tasks.Synchronously = true;

                // Run through all scores of the measure.

                /*foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                 * {
                 *  if (score.Equation != null)
                 *  {
                 *      tasks.Synchronously = true;
                 *      break;
                 *  }
                 * }*/

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    tasks.Add(() =>
                    {
                        Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);

                        categoryValues.Add(score.Identity, scoreFilter.Value);
                    });
                }

                tasks.WaitAll();

                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    string label = "";

                    if (score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage] == null)
                    {
                        if (measure.IsTaxonomy)
                        {
                            label = (string)this.Core.TaxonomyCategoryLabels.GetValue(
                                "Label",
                                new string[] { "IdTaxonomyCategory", "IdLanguage" },
                                new object[] { score.Identity, this.Definition.Settings.IdLanguage }
                                );
                        }
                        else
                        {
                            label = (string)this.Core.CategoryLabels.GetValue(
                                "Label",
                                new string[] { "IdCategory", "IdLanguage" },
                                new object[] { score.Identity, this.Definition.Settings.IdLanguage }
                                );
                        }

                        score.XmlNode.AddAttribute("Label" + this.Definition.Settings.IdLanguage, label);
                    }

                    label = score.XmlNode.Attributes["Label" + this.Definition.Settings.IdLanguage].Value;


                    string selection = _selection + string.Format(
                        "\"Label\": \"{0}\",",
                        HttpUtility.HtmlEncode(label)
                        );

                    writer.Append("{" + selection);

                    writer.Append(string.Format(
                                      "\"Base\": \"{0}\",",
                                      baseValue
                                      ));

                    writer.Append(string.Format(
                                      "\"Value\": \"{0}\"",
                                      categoryValues.ContainsKey(score.Identity) ? categoryValues[score.Identity] : 0
                                      ));

                    writer.Append("},");

                    i++;

                    if (totalToProcess != 0)
                    {
                        int progress = i * 100 / totalToProcess;

                        if (progress == 100)
                        {
                            base.Progress = 99;
                        }
                        else
                        {
                            base.Progress = progress;
                        }
                    }
                }
            }
        }
        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;
            }
        }
Example #9
0
        private void RenderMeasure(LinkBiDefinitionDimension measure, StringBuilder writer, int columnOffset, Data filter = null)
        {
            DataCore.Classes.StorageMethods.Database storageMethod = new DataCore.Classes.StorageMethods.Database(
                base.Core,
                null
                );

            string baseValue  = filter.Base.ToString(new CultureInfo("en-GB"));
            string uBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
            string eBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));

            int rowOffset = i;

            writer.Append(string.Format(
                              "<{0}",
                              measure.XmlNode.Name
                              ));

            foreach (XmlAttribute attribute in measure.XmlNode.Attributes)
            {
                writer.Append(string.Format(
                                  " {0}=\"{1}\"",
                                  attribute.Name,
                                  HttpUtility.HtmlEncode(attribute.Value)
                                  ));
            }

            writer.Append(">");

            if (measure.Type == DatabaseCore.Items.VariableType.Numeric)
            {
                Data result = storageMethod.GetRespondentsNumeric(
                    measure.Identity,
                    measure.IsTaxonomy,
                    this.Core.CaseDataLocation,
                    filter,
                    this.Definition.WeightingFilters
                    );

                writer.Append(string.Format(
                                  "<NumericValue Id=\"00000000-0000-0000-0000-000000000000\" Value=\"{0}\" Base=\"{1}\" />",
                                  result.Value,
                                  filter.Base
                                  ));

                i++;
            }
            else
            {
                filter = storageMethod.GetRespondents(
                    measure,
                    filter,
                    this.Definition.WeightingFilters
                    );
                baseValue  = filter.Base.ToString(new CultureInfo("en-GB"));
                uBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                eBaseValue = filter.Responses.Count.ToString(new CultureInfo("en-GB"));
                // Run through all scores of the measure.
                foreach (LinkBiDefinitionDimensionScore score in measure.Scores)
                {
                    if (score.Hidden)
                    {
                        continue;
                    }

                    if (measure.IsTaxonomy && score.Persistent &&
                        base.Definition.HierarchyFilter.TaxonomyCategories.ContainsKey(score.Identity) == false)
                    {
                        continue;
                    }

                    writer.Append(string.Format(
                                      "<{0}",
                                      score.XmlNode.Name
                                      ));

                    foreach (XmlAttribute attribute in score.XmlNode.Attributes)
                    {
                        if (attribute.Name == "Base" || attribute.Name == "Value")
                        {
                            continue;
                        }

                        writer.Append(string.Format(
                                          " {0}=\"{1}\"",
                                          attribute.Name,
                                          HttpUtility.HtmlEncode(attribute.Value)
                                          ));
                    }

                    /*Data scoreFilter = storageMethod.GetRespondents(
                     *  score.Identity,
                     *  measure.Identity,
                     *  measure.IsTaxonomy,
                     *  filter,
                     *  this.Definition.WeightingFilters
                     * );*/
                    Data scoreFilter = score.GetRespondents(filter, this.StorageMethod);

                    if (this.DisplayUnweightedBase)
                    {
                        writer.Append(string.Format(
                                          " UBase=\"{0}\"",
                                          uBaseValue
                                          ));
                    }
                    if (this.DisplayEffectiveBase)
                    {
                        writer.Append(string.Format(
                                          " eBase=\"{0}\"",
                                          uBaseValue
                                          ));
                    }

                    writer.Append(string.Format(
                                      " Base=\"{0}\"",
                                      baseValue
                                      ));

                    //double value = scoreFilter.Responses.Values.Sum(x => x[0]);
                    double value = scoreFilter.Value;

                    writer.Append(string.Format(
                                      " Value=\"{0}\"",
                                      value.ToString(new CultureInfo("en-GB"))
                                      ));

                    if (this.ExportPercentage)
                    {
                        writer.Append(string.Format(
                                          " Percentage=\"{0}\"",
                                          (value * 100 / filter.Base).ToString(new CultureInfo("en-GB"))
                                          ));
                    }

                    i++;

                    if (totalToProcess != 0)
                    {
                        int progress = i * 100 / totalToProcess;

                        if (progress == 100)
                        {
                            base.Progress = 99;
                        }
                        else
                        {
                            base.Progress = progress;
                        }
                    }

                    writer.Append(string.Format(
                                      "></{0}>",
                                      score.XmlNode.Name
                                      ));
                }
            }

            writer.Append(string.Format(
                              "</{0}>",
                              measure.XmlNode.Name
                              ));
        }