Example #1
0
        /// <summary>
        /// Checks if all of the study's respondent have a weight.
        /// </summary>
        /// <param name="idVariable">The weighting variable.</param>
        public List <DataAnalyserLog> CheckWeights(Variable variable)
        {
            // Create a list that stores all result data analyser log messages.
            List <DataAnalyserLog> result = new List <DataAnalyserLog>();

            List <object[]> respondentsMissing;
            List <object[]> respondentsZero;

            if (this.Core.CaseDataLocation == CaseDataLocation.Sql)
            {
                respondentsMissing = this.Core.Respondents.ExecuteReader(string.Format(
                                                                             "SELECT (SELECT OriginalRespondentID FROM Respondents WHERE Respondents.Id=IdRespondent), IdRespondent FROM resp.[Var_{0}] WHERE IdRespondent NOT IN (SELECT Id FROM Respondents WHERE IdStudy='{1}')",
                                                                             variable.Id,
                                                                             this.IdStudy
                                                                             ));

                // Get all respondents that have a response in the weight variable, but the value is zero.
                respondentsZero = this.Core.Respondents.ExecuteReader(string.Format(
                                                                          "SELECT (SELECT OriginalRespondentID FROM Respondents WHERE Respondents.Id=IdRespondent), IdRespondent FROM resp.[Var_{0}] WHERE [NumericAnswer]=0",
                                                                          variable.Id,
                                                                          this.IdStudy
                                                                          ));
            }
            else
            {
                CaseDataCore1.CaseDataLink dataLink = new CaseDataCore1.CaseDataLink();

                List <object[]> _respondents = this.Core.Respondents.GetValues(
                    new string[] { "OriginalRespondentID", "Id" },
                    new string[] { "IdStudy" },
                    new object[] { this.IdStudy }
                    );

                Dictionary <Guid, List <object> > responses = dataLink.Select(
                    string.Format("SELECT IdRespondent, NumericAnswer FROM [resp].[Var_{0}]", variable.Id),
                    this.Core.ClientName
                    );

                respondentsMissing = new List <object[]>();
                respondentsZero    = new List <object[]>();

                foreach (object[] respondent in _respondents)
                {
                    if (responses.ContainsKey((Guid)respondent[1]))
                    {
                        if ((double)(responses[(Guid)respondent[1]])[0] == 0.0)
                        {
                            respondentsZero.Add(respondent);
                        }

                        continue;
                    }

                    respondentsMissing.Add(respondent);
                }
            }

            // Run through all respondents without a response in the weight variable.
            foreach (object[] respondent in respondentsMissing)
            {
                DataAnalyserLog log = new DataAnalyserLog();
                log.Message = string.Format(
                    "The respondent with the id '{0}' hasn't got a response in the weighting variable '{1}'",
                    respondent[0],
                    variable.Name
                    );

                result.Add(log);
            }

            // Run through all respondents that have a response
            // in the weight variable, but the value is zero.
            foreach (object[] respondent in respondentsZero)
            {
                DataAnalyserLog log = new DataAnalyserLog();
                log.Message = string.Format(
                    "The respondent with the id '{0}' has a weight value of zero in the weighting variable '{1}'",
                    respondent[0],
                    variable.Name
                    );

                result.Add(log);
            }

            return(result);
        }