Skip to content

Commit

Permalink
fixed CSV output so single_choice output won't contain a prompt_id:va…
Browse files Browse the repository at this point in the history
…lue column if the prompt does not have values configured for it
  • Loading branch information
jshslsky committed Jun 27, 2011
1 parent e358872 commit 97a62d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
31 changes: 26 additions & 5 deletions src/org/ohmage/domain/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@


/**
* Immutable bean-style wrapper for accessing and validating campaign properties.
* Immutable bean-style wrapper for accessing and validating campaign configuration properties. The methods in this class assume
* that the caller has validated that the parameters (i.e., prompt ids, survey ids, repeatable set ids) are valid for a
* particular configuration instance.
*
* @author Joshua Selsky
*/
public class Configuration {
// private static Logger _logger = Logger.getLogger(Configuration.class);
//private static Logger _logger = Logger.getLogger(Configuration.class);
private String _urn;
private String _name;
private String _description;
Expand Down Expand Up @@ -169,11 +171,10 @@ public Prompt getPrompt(String surveyId, String repeatableSetId, String promptId
}

public int getIndexForPrompt(String surveyId, String promptId) {
// Check to see if the prompt is in a repeatable set
Survey survey = _surveyMap.get(surveyId);
String repeatableSetId = survey.getRepeatableSetIdForPromptId(promptId);

if(null != repeatableSetId) {
if(isPromptInRepeatableSet(surveyId, promptId)) {
String repeatableSetId = survey.getRepeatableSetIdForPromptId(promptId);
return ((RepeatableSet) survey.getSurveyItemMap().get(repeatableSetId)).getPromptMap().get(promptId).getIndex();
}

Expand All @@ -183,6 +184,26 @@ public int getIndexForPrompt(String surveyId, String promptId) {
public boolean isPromptInRepeatableSet(String surveyId, String promptId) {
return null != _surveyMap.get(surveyId).getRepeatableSetIdForPromptId(promptId);
}

public boolean promptContainsSingleChoiceValues(String promptId) {
if(null != promptId) {
String surveyId = getSurveyIdForPromptId(promptId);
if(isPromptInRepeatableSet(surveyId, promptId)) {
String repeatableSetId = _surveyMap.get(surveyId).getRepeatableSetIdForPromptId(promptId);
Prompt p = ((RepeatableSet) _surveyMap.get(surveyId).getSurveyItemMap().get(repeatableSetId)).getPromptMap().get(promptId);
if("single_choice".equals(p.getType())) {
return p.getProperties().containsKey("value");
}
} else {
Prompt p = ((Prompt) _surveyMap.get(surveyId).getSurveyItemMap().get(promptId));
if("single_choice".equals(p.getType())) {
return p.getProperties().containsKey("value");
}
}
}

return false;
}

public int getNumberOfPromptsInSurvey(String surveyId) {
return _surveyMap.get(surveyId).getSurveyItemMap().keySet().size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public String createMultiResultOutput(int numberOfSurveys,
// Build the column headers
// For the CSV output, user advocates have requested that the column names be made shorter and that single_choice
// prompts have both their label and value present in the output
List<String> copyOfCanonicalColumnList = new ArrayList<String> (canonicalColumnList);
List<String> copyOfCanonicalColumnList = new ArrayList<String> (canonicalColumnList);

int s = copyOfCanonicalColumnList.size();
int i = 0;
Expand All @@ -214,7 +214,13 @@ public String createMultiResultOutput(int numberOfSurveys,
String type = promptResponseMetadataMap.get(internalPromptId).getPromptType();

if("single_choice".equals(type)) {
shortHeader = internalPromptId + ":label," + internalPromptId + ":value";
Configuration config = req.getConfiguration();
if(config.promptContainsSingleChoiceValues(internalPromptId)) {
shortHeader = internalPromptId + ":label," + internalPromptId + ":value";
}
else {
shortHeader = internalPromptId + ":label";
}
}
else {
shortHeader = key.replace("urn:ohmage:prompt:id:", "");
Expand Down Expand Up @@ -365,8 +371,11 @@ else if(canonicalColumnId.contains("prompt:id")) {

SingleChoicePromptValueAndLabel valueLabel = (SingleChoicePromptValueAndLabel) promptResponseMap.get(promptId);

builder.append(valueLabel.getLabel()).append(",").append(valueLabel.getValue());

if(null != valueLabel.getValue()) {
builder.append(valueLabel.getLabel()).append(",").append(valueLabel.getValue());
} else {
builder.append(valueLabel.getLabel());
}
}
else {

Expand Down

0 comments on commit 97a62d2

Please sign in to comment.