def _handle_survey_data(bs, survey_data):
    pk = survey_data.pop('id', None)
    survey = None
    question_data = survey_data.pop('question_responses', {})
    if pk:
        survey = survey_models.Survey.objects.get(pk=pk)
    else:
        #  Something's wrong
        return bs

    if survey:
        sb, c = survey_models.SurveyBuilding.objects.get_or_create(
            survey=survey,
            canonical_building=bs.canonical_building
        )
        sb.date_collected = convert_datestr(
            survey_data.get('date_collected', None)
        )
        sb.comment = survey_data.get('comment', None)
        sb.completion_time = survey_data.get('completion_time', None)
        sb.save()
    for question_id, answer in question_data.items():
        answer_id = answer.pop('id', None)
        answer['question_id'] = question_id
        answer['canonical_building_id'] = bs.canonical_building.pk
        if answer_id:
            # Updating an existing answer.
            a = survey_models.SurveyAnswer.objects.get(pk=answer_id)
            a.answer = answer.get('answer', None)
            a.answer_bool = answer.get('answer_bool', None)
            a.canonical_building_id = bs.canonical_building.pk
        elif answer:
            # for multi-selects we should create a SurveyAnswers per checked
            if survey_models.SurveyQuestion.objects.get(
                pk=question_id
            ).question_type == survey_models.ENUM:
                del(answer['question_id'])
                del(answer['canonical_building_id'])
                for sa, checked in answer.items():
                    if checked:
                        survey_models.SurveyAnswer.objects.create(
                            question_id=question_id,
                            canonical_building_id=bs.canonical_building.pk,
                            answer=sa
                        )
                    else:
                        # remove any unchecked answers
                        survey_models.SurveyAnswer.objects.filter(
                            question_id=question_id,
                            canonical_building_id=bs.canonical_building.pk,
                            answer=sa
                        ).delete()
            else:
                # Create a new answer if there's an answer, but no previous id.
                a = survey_models.SurveyAnswer.objects.create(**answer)
        else:
            continue

        a.save()

    return bs
Runs server
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/models.py/_handle_survey_data--crossover with--dataset/ETHPy150Open SmokinCaterpillar/pypet/pypet/utils/mpwrappers.py/LockerServer.run