/// <summary> /// Firgures out the numerical rank of the question answer /// </summary> /// <param name="qaf">The question answer to get rankSum for</param> /// <param name="SQSelect">Contains the corresponding answer that matches the question asnwer</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns></returns> private int AddRankSum(QuestionAnswerFlat qaf, List <AnswerInfo> SQSelect, SurveyQuestionView surveyQuestions) { // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { //return qaf.Weight; List <QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList <QuestionAnswerFlat>(); // Try to get rank from the weight if (qaf.Weight != 0) { return(qaf.Weight); } else // if weight not set, take from AnswerNumber { return(RankSelect[0].AnswerNumber); } } return(0); }
/// <summary> /// Loads a summary of the responses to each question answer, including counts and averages based on survey responses /// </summary> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question/param> public void LoadResponseSummary(GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { List <QuestionInfo> qList = new List <QuestionInfo>(); List <QuestionAnswerFlat> qafList = new List <QuestionAnswerFlat>(); string qafQuestionID = ""; int totalResponses = 0; foreach (QuestionAnswerFlat qaf in surveyQuestions.SurveyWithAnswers) { if (qafQuestionID != qaf.QuestionID) // only recalculate if it is a new question { // Calculate total number of responses for each question in case not everyone answers every question qafQuestionID = qaf.QuestionID; totalResponses = GetTotalResponses(qaf, ResponseResultList); } qaf.TotalResponses = totalResponses; QuestionAnswerFlat qafSummary = GetQuestionAnswerSummary(qaf, ResponseResultList, surveyQuestions, false); qafList.Add(qaf); } SurveyWithAnswers = qafList; }
/// <summary> /// Firgures out the numerical rank of the question answer /// </summary> /// <param name="qaf">The question answer to get rankSum for</param> /// <param name="SQSelect">Contains the corresponding answer that matches the question asnwer</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns></returns> private int AddRankSum(QuestionAnswerFlat qaf, List<AnswerInfo> SQSelect, SurveyQuestionView surveyQuestions) { // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { //return qaf.Weight; List<QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList<QuestionAnswerFlat>(); // Try to get rank from the weight if (qaf.Weight != 0) { return qaf.Weight; } else // if weight not set, take from AnswerNumber { return RankSelect[0].AnswerNumber; } } return 0; }
/// <summary> /// Shows each respondent's answer to each question in a survey /// </summary> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="RespondentList">A list of respondents who answered the survey</param> /// <param name="SurveyQuestions">Contains a list of questions and a list of answers for each question/param> public void Flatten(GetResponsesResult[] ResponseResultList, RespondentInfo[] RespondentList, SurveyQuestionView SurveyQuestions) { List<ResponseWithAnswer> rwaList = new List<ResponseWithAnswer>(); foreach (GetResponsesResult response in ResponseResultList) { List<RespondentInfo> rList = RespondentList.Where(e => e.RespondentID == response.RespondentID).ToList<RespondentInfo>(); if (rList != null) { RespondentInfo respondant = rList[0]; foreach (QuestionInfo qInfo in response.QuestionList) { List<QuestionInfo> question = SurveyQuestions.QuestionList.Where(e => e.QuestionID == qInfo.QuestionID).ToList<QuestionInfo>(); QuestionInfo responseQuestion = question[0]; qInfo.QuestionType = responseQuestion.QuestionType; foreach (AnswerInfo aInfo in qInfo.QuestionAnswerList) { ResponseWithAnswer rwa = new ResponseWithAnswer(); AnswerInfo qi = new AnswerInfo(); QuestionFamilyEnum qaFamily = responseQuestion.QuestionType.Family; switch (qaFamily) { case QuestionFamilyEnum.SingleChoice: rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.MultipleChoice: rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.Matrix: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.OpenEnded: rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.DateTime: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.Demographic: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.NotSet: break; case QuestionFamilyEnum.Presentation: break; case QuestionFamilyEnum.CustomVariable: break; default: rwa.Answer = "Answer choice cannot be found in answer bank for this question"; break; } rwa.Question = responseQuestion.Heading; rwa.QuestionID = responseQuestion.QuestionID; rwa.QuestionSubtype = responseQuestion.QuestionType.Subtype; rwa.QuestionType = qaFamily; rwa.User = respondant.Email; rwa.RespondentID = respondant.RespondentID; rwa.RecipientID = respondant.RecipientID; rwaList.Add(rwa); } } } } ResponseAnswerList = rwaList; }
/// <summary> /// Gets the count and rankAverage for a question answer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns>An object that holds both the count and rank average for the question answer</returns> public CountAndAverage GetCountAndAverage(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { int count = 0; double rankSum = 0; int NAresponses = 0; // Count to ignore N/A responses when calculating average CountAndAverage caa = new CountAndAverage(); foreach (GetResponsesResult response in ResponseResultList) { foreach (QuestionInfo qInfo in response.QuestionList) { List<AnswerInfo> SQSelect = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.AnswerID || e.Column == qaf.AnswerID).ToList<AnswerInfo>(); int SQCount = SQSelect.Count; count += AddCount(qaf, qInfo, SQCount); // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { List<QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList<QuestionAnswerFlat>(); rankSum += AddRankSum(qaf, SQSelect, surveyQuestions); if (RankSelect[0].AnswerText == "N/A") { NAresponses++; } } } } caa.Count = count; caa.RankAvg = GetRankAvg(rankSum, count, NAresponses, qaf.TotalResponses); return caa; }
/// <summary> /// Gets a summary of the responses for a particular question answer, including counts and averages based on survey responses /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <param name="calcTotalResponses">"True" when the totalResponses for this question is unknown</param> /// <returns>An object that contains all of the summary data</returns> public QuestionAnswerFlat GetQuestionAnswerSummary(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions, bool calcTotalResponses = true) { // Calculate total number of responses if it is not provided if (qaf.TotalResponses == 0) { qaf.TotalResponses = GetTotalResponses(qaf, ResponseResultList); } CountAndAverage caa = GetCountAndAverage(qaf, ResponseResultList, surveyQuestions); qaf.Count = caa.Count; qaf.RankAvg = caa.RankAvg; qaf.RankType = GetRankType(qaf); return qaf; }
/// <summary> /// Loads a summary of the responses to each question answer, including counts and averages based on survey responses /// </summary> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question/param> public void LoadResponseSummary(GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { List<QuestionInfo> qList = new List<QuestionInfo>(); List<QuestionAnswerFlat> qafList = new List<QuestionAnswerFlat>(); string qafQuestionID = ""; int totalResponses = 0; foreach (QuestionAnswerFlat qaf in surveyQuestions.SurveyWithAnswers) { if(qafQuestionID != qaf.QuestionID) // only recalculate if it is a new question { // Calculate total number of responses for each question in case not everyone answers every question qafQuestionID = qaf.QuestionID; totalResponses = GetTotalResponses(qaf, ResponseResultList); } qaf.TotalResponses = totalResponses; QuestionAnswerFlat qafSummary = GetQuestionAnswerSummary(qaf, ResponseResultList, surveyQuestions, false); qafList.Add(qaf); } SurveyWithAnswers = qafList; }
/// <summary> /// Retrieve a given survey's metadata. /// Notes /// •Surveys with over 200 survey pages will not be returned /// •Surveys with over 1000 questions will not be returned /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_survey_details?api_key=your_api_key /// Example Request /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_survey_details/?api_key=your_api_key --data-binary '{"survey_id":"100399456"}' /// </summary> private void BtnGetSurveyDetails_Click(object sender, EventArgs e) { GetSurveyDetailsResponse surveyDetails; BasicRequestData brd = new BasicRequestData(); SurveyQuestionView surveyView = new SurveyQuestionView(); if (txtSurveyID.Text.Trim().Length > 0) { brd.SurveyID = txtSurveyID.Text; } else { brd.SurveyID = null; } if (brd.SurveyID == null) { MessageBox.Show("no survey id specified. Going to get error back."); } surveyDetails = SurveyRequest.GetSurveyDetails(brd); lblStatus.Text = surveyDetails.Status.ToString(); lblErrorMsg.Text = surveyDetails.ErrorMessage; try { if (chkSurveyAnswers.Checked) { surveyView.LoadSurvey(surveyDetails); dgvSurveyList.DataSource = surveyView.SurveyWithAnswers; } else { List<SurveyTInfo> sdrList = new List<SurveyTInfo>(); sdrList.Add(surveyDetails.SurveyDetailsResult); dgvSurveyList.DataSource = sdrList; } } catch { } // do nothing }
/// <summary> /// Returns a summary of how respondents answered each question, including counts and average ratings /// </summary> private void BtnGetResponseSummary_Click(object sender, EventArgs e) { GetSurveyDetailsResponse surveyDetails; GetResponsesResponse responses; GetRespondentListResponse respondent; BasicRequestData brd = GetRequestFields(); brd.PageSize = 1000; // get all respondents SurveyQuestionView surveyView = new SurveyQuestionView(); ResponseView responseView = new ResponseView(); if (brd.SurveyID == null) { MessageBox.Show("no survey id specified. Going to get error back."); } try { surveyDetails = SurveyRequest.GetSurveyDetails(brd); respondent = SurveyRequest.GetRespondentListFull(brd); List<string> respondantID = new List<string>(); bool isProcessed = false; responses = new GetResponsesResponse(); foreach (RespondentInfo rInfo in respondent.RespondantListResult.RespondantList) { respondantID.Add(rInfo.RespondentID); // maximum number of respondents that can be processed is 100 if (respondantID.Count == 100) { brd.RespondentIDList = respondantID.ToArray(); responses = GetRespondenses(responses, brd, isProcessed); isProcessed = true; respondantID.Clear(); } } if (respondantID.Count > 0) brd.RespondentIDList = respondantID.ToArray(); responses = GetRespondenses(responses, brd, isProcessed); surveyView.LoadSurvey(surveyDetails); responseView.LoadResponseSummary(responses.ResponseResultList, surveyView); lblStatus.Text = respondent.Status.ToString(); lblErrorMsg.Text = respondent.ErrorMessage; try { dgvSurveyList.DataSource = responseView.SurveyWithAnswers; //respondent.ResponseResultList; // update database with survey results } catch { } // do nothing } catch { MessageBox.Show("ERROR with respondants specified. No data submitted to SurveyMonkey"); } }
/// <summary> /// Takes a list of respondent ids and returns the responses that correlate to them.To be used with 'get_survey_details' /// Notes /// Surveys with over 500,000 reponses are not available via the API currently /// Text responses returned are truncated after 32,768 characters /// Max number of respondents per call is 100 /// Endpoint : https://api.surveymonkey.net/v2/surveys/get_responses?api_key=your_api_key /// Example Request /// curl -H 'Authorization:bearer XXXYYYZZZ' -H 'Content-Type: application/json' https://api.surveymonkey.net/v2/surveys/get_responses/?api_key=your_api_key --data-binary '{"survey_id":"103994756", "respondent_ids": ["2503019027", "2500039028", "2500039029", "2503019064"]}' /// </summary> private void BtnGetResponses_Click(object sender, EventArgs e) { GetSurveyDetailsResponse surveyDetails; GetResponsesResponse responses; GetRespondentListResponse respondent; BasicRequestData brd = GetRequestFields(); SurveyQuestionView surveyView = new SurveyQuestionView(); ResponseView responseView = new ResponseView(); if (brd.SurveyID == null) { MessageBox.Show("no survey id specified. Going to get error back."); } try { if ((brd.RespondentIDList == null) && (brd.RespondentIDList.Length == 0)) { MessageBox.Show("no respondants specified. May be error, or empty return."); } surveyDetails = SurveyRequest.GetSurveyDetails(brd); respondent = SurveyRequest.GetRespondentListFull(brd); responses = SurveyRequest.GetResponses(brd); surveyView.LoadSurvey(surveyDetails); responseView.Flatten(responses.ResponseResultList, respondent.RespondantListResult.RespondantList, surveyView); //List<ResponseWithAnswer> ResponseAnswerList { get; set; } lblStatus.Text = respondent.Status.ToString(); lblErrorMsg.Text = respondent.ErrorMessage; try { dgvSurveyList.DataSource = responseView.ResponseAnswerList; //respondent.ResponseResultList; } catch { } // do nothing } catch { MessageBox.Show("ERROR with respondants specified. No data submitted to SurveyMonkey"); } }
/// <summary> /// Shows each respondent's answer to each question in a survey /// </summary> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="RespondentList">A list of respondents who answered the survey</param> /// <param name="SurveyQuestions">Contains a list of questions and a list of answers for each question/param> public void Flatten(GetResponsesResult[] ResponseResultList, RespondentInfo[] RespondentList, SurveyQuestionView SurveyQuestions) { List <ResponseWithAnswer> rwaList = new List <ResponseWithAnswer>(); foreach (GetResponsesResult response in ResponseResultList) { List <RespondentInfo> rList = RespondentList.Where(e => e.RespondentID == response.RespondentID).ToList <RespondentInfo>(); if (rList != null) { RespondentInfo respondant = rList[0]; foreach (QuestionInfo qInfo in response.QuestionList) { List <QuestionInfo> question = SurveyQuestions.QuestionList.Where(e => e.QuestionID == qInfo.QuestionID).ToList <QuestionInfo>(); QuestionInfo responseQuestion = question[0]; qInfo.QuestionType = responseQuestion.QuestionType; foreach (AnswerInfo aInfo in qInfo.QuestionAnswerList) { ResponseWithAnswer rwa = new ResponseWithAnswer(); AnswerInfo qi = new AnswerInfo(); QuestionFamilyEnum qaFamily = responseQuestion.QuestionType.Family; switch (qaFamily) { case QuestionFamilyEnum.SingleChoice: rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.MultipleChoice: rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.Matrix: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = ProcessAnswer(responseQuestion, aInfo); break; case QuestionFamilyEnum.OpenEnded: rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.DateTime: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.Demographic: rwa.Row = ProcessRow(responseQuestion, aInfo); rwa.Answer = aInfo.Text; break; case QuestionFamilyEnum.NotSet: break; case QuestionFamilyEnum.Presentation: break; case QuestionFamilyEnum.CustomVariable: break; default: rwa.Answer = "Answer choice cannot be found in answer bank for this question"; break; } rwa.Question = responseQuestion.Heading; rwa.QuestionID = responseQuestion.QuestionID; rwa.QuestionSubtype = responseQuestion.QuestionType.Subtype; rwa.QuestionType = qaFamily; rwa.User = respondant.Email; rwa.RespondentID = respondant.RespondentID; rwa.RecipientID = respondant.RecipientID; rwaList.Add(rwa); } } } } ResponseAnswerList = rwaList; }
/// <summary> /// Gets the count and rankAverage for a question answer /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <returns>An object that holds both the count and rank average for the question answer</returns> public CountAndAverage GetCountAndAverage(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions) { int count = 0; double rankSum = 0; int NAresponses = 0; // Count to ignore N/A responses when calculating average CountAndAverage caa = new CountAndAverage(); foreach (GetResponsesResult response in ResponseResultList) { foreach (QuestionInfo qInfo in response.QuestionList) { List <AnswerInfo> SQSelect = qInfo.QuestionAnswerList.Where(e => e.Row == qaf.AnswerID || e.Column == qaf.AnswerID).ToList <AnswerInfo>(); int SQCount = SQSelect.Count; count += AddCount(qaf, qInfo, SQCount); // for calculating average for rankings and ratings if (SQSelect.Count > 0 && (qaf.QuestionSubtype == QuestionSubtypeEnum.Ranking || qaf.QuestionSubtype == QuestionSubtypeEnum.Rating) && qaf.AnswerType == AnswerTypeEnum.Row) { List <QuestionAnswerFlat> RankSelect = surveyQuestions.SurveyWithAnswers .Where(e => e.AnswerID == SQSelect[0].Column) .ToList <QuestionAnswerFlat>(); rankSum += AddRankSum(qaf, SQSelect, surveyQuestions); if (RankSelect[0].AnswerText == "N/A") { NAresponses++; } } } } caa.Count = count; caa.RankAvg = GetRankAvg(rankSum, count, NAresponses, qaf.TotalResponses); return(caa); }
/// <summary> /// Gets a summary of the responses for a particular question answer, including counts and averages based on survey responses /// </summary> /// <param name="qaf">The question answer choice to get a summary of responses about</param> /// <param name="ResponseResultList">A list of responses from each person who responded to the survey</param> /// <param name="surveyQuestions">Contains a list of questions and a list of answers for each question</param> /// <param name="calcTotalResponses">"True" when the totalResponses for this question is unknown</param> /// <returns>An object that contains all of the summary data</returns> public QuestionAnswerFlat GetQuestionAnswerSummary(QuestionAnswerFlat qaf, GetResponsesResult[] ResponseResultList, SurveyQuestionView surveyQuestions, bool calcTotalResponses = true) { // Calculate total number of responses if it is not provided if (qaf.TotalResponses == 0) { qaf.TotalResponses = GetTotalResponses(qaf, ResponseResultList); } CountAndAverage caa = GetCountAndAverage(qaf, ResponseResultList, surveyQuestions); qaf.Count = caa.Count; qaf.RankAvg = caa.RankAvg; qaf.RankType = GetRankType(qaf); return(qaf); }