Skip to content

Commit

Permalink
Merge pull request #133 from coolcrowd/answer-types
Browse files Browse the repository at this point in the history
@fix: Answer types in templates and experiments
  • Loading branch information
marcelhollerbach committed Feb 11, 2016
2 parents 5b9b487 + 8aecf9e commit 9cf8cd4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static Rating toRatingProto(RatingRecord ratingRecord, List<ConstraintRec
Function<ConstraintRecord, Constraint> mapper = (constraintRecord) -> Constraint.newBuilder().setId(constraintRecord.getIdConstraint()).setName(constraintRecord.getConstraint()).build();

return builder(Rating.newBuilder())
.set(ratingRecord.getExperiment(), Rating.Builder::setExperimentId)
.set(ratingRecord.getRating(), Rating.Builder::setRating)
.set(ratingRecord.getFeedback(), Rating.Builder::setFeedback)
.getBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Experiment toProto(ExperimentRecord record, Experiment.State state
.set(record.getTitle(), Experiment.Builder::setTitle)
.set(record.getDescription(), Experiment.Builder::setDescription)
.set(state, Experiment.Builder::setState)
.set(record.getAnswerType(), (builder, x) -> builder.setAnswerType(AnswerType.valueOf(x)))
.set(record.getAnswerType(), (builder, x) -> builder.setAnswerType(x == null ? AnswerType.TEXT : AnswerType.IMAGE))
.set(record.getAlgorithmTaskChooser(), (builder, x) -> builder.setAlgorithmTaskChooser(algo.apply(x)))
.set(record.getAlgorithmQualityAnswer(), (builder, x) -> builder.setAlgorithmQualityAnswer(algo.apply(x)))
.set(record.getAlgorithmQualityRating(), (builder, x) -> builder.setAlgorithmQualityRating(algo.apply(x)))
Expand Down Expand Up @@ -99,8 +99,12 @@ public static Experiment toProto(ExperimentRecord record, Experiment.State state
}

private static String transform(AnswerType answerType) {
if (answerType == AnswerType.INVALID || answerType == AnswerType.TEXT) return null;
return answerType.name();
switch (answerType) {
case IMAGE:
return "image/*";
default:
return null;
}
}

private static Experiment.RatingOption transform(RatingOptionExperimentRecord record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public static Template toProto(TemplateRecord record) {
* @return Template.
*/
public static Template toProto(TemplateRecord record, List<RatingOptionTemplateRecord> ratingOptions, List<TemplateTagRecord> tags, List<TemplateConstraintRecord> constraints) {
AnswerType answerType = "IMAGE".equals(record.getAnswerType())
? AnswerType.IMAGE
: AnswerType.TEXT;
AnswerType answerType = record.getAnswerType() == null
? AnswerType.TEXT
: AnswerType.IMAGE;

List<Template.RatingOption> options = ratingOptions.stream()
.map(option -> Template.RatingOption.newBuilder()
Expand Down Expand Up @@ -125,9 +125,12 @@ public static TemplateRecord mergeRecord(TemplateRecord target, Template templat
case Template.CONTENT_FIELD_NUMBER: record.setTemplate(template.getContent());
break;
case Template.ANSWER_TYPE_FIELD_NUMBER:
if ("IMAGE".equals(template.getAnswerType().name())) {
record.setAnswerType(template.getAnswerType().name());
if (template.getAnswerType() == AnswerType.IMAGE) {
record.setAnswerType("image/*");
} else {
record.setAnswerType(null);
}

break;
}
});
Expand Down

0 comments on commit 9cf8cd4

Please sign in to comment.