Ejemplo n.º 1
0
def return_sur() -> Survey:
    q = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    s1 = Student(1, "John")
    s2 = Student(2, "Carl")
    s3 = Student(3, "Anne")
    a1 = Answer([1, 2, 3, 4])
    a2 = Answer([1])
    a3 = Answer([1])
    s1.set_answer(q, a1)
    s2.set_answer(q, a2)
    s3.set_answer(q, a3)
    c = LonelyMemberCriterion()
    sur = Survey([q])
    sur.set_weight(1, q)
    sur.set_criterion(c, q)
    q_2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    a4 = Answer([1, 2])
    a5 = Answer([1, 2])
    a6 = Answer([1, 2])
    s1.set_answer(q_2, a4)
    s2.set_answer(q_2, a5)
    s3.set_answer(q_2, a6)
    sur2 = Survey([q, q_2])
    sur2.set_weight(1, q_2)
    sur2.set_criterion(c, q_2)
    return sur2
Ejemplo n.º 2
0
def test_make_window_grouping() -> None:
    grouper_ = grouper.GreedyGrouper(2)
    q = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    s1 = Student(1, "John")
    s2 = Student(2, "Carl")
    s3 = Student(3, "Anne")
    a1 = Answer([1, 2, 3, 4])
    a2 = Answer([1])
    a3 = Answer([1])
    s1.set_answer(q, a1)
    s2.set_answer(q, a2)
    s3.set_answer(q, a3)
    c = LonelyMemberCriterion()
    sur = Survey([q])
    sur.set_weight(1, q)
    sur.set_criterion(c, q)
    q_2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    a4 = Answer([1, 2])
    a5 = Answer([1, 2])
    a6 = Answer([1, 2])
    s1.set_answer(q_2, a4)
    s2.set_answer(q_2, a5)
    s3.set_answer(q_2, a6)
    sur2 = Survey([q, q_2])
    sur2.set_weight(1, q_2)
    sur2.set_criterion(c, q_2)
    cr = Course('dd')
    cr.enroll_students([s1, s2, s3])
    assert grouper_.make_grouping(
        cr, sur).get_groups()[0].get_members()[0].name == "John"
    assert grouper_.make_grouping(
        cr, sur).get_groups()[0].get_members()[1].name == "Carl"
    assert grouper_.make_grouping(
        cr, sur).get_groups()[1].get_members()[0].name == "Anne"
Ejemplo n.º 3
0
def test_score_students() -> None:
    q = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    s1 = Student(1, "John")
    s2 = Student(2, "Carl")
    s3 = Student(3, "Anne")
    a1 = Answer([1, 2, 3, 4])
    a2 = Answer([1])
    a3 = Answer([1])
    s1.set_answer(q, a1)
    s2.set_answer(q, a2)
    s3.set_answer(q, a3)
    c = LonelyMemberCriterion()
    sur = Survey([q])
    sur.set_weight(1, q)
    sur.set_criterion(c, q)
    assert sur.score_students([s1, s2, s3]) == 0.0
    q_2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    a4 = Answer([1, 2])
    a5 = Answer([1, 2])
    a6 = Answer([1, 2])
    s1.set_answer(q_2, a4)
    s2.set_answer(q_2, a5)
    s3.set_answer(q_2, a6)
    sur1 = Survey([q_2])
    sur2 = Survey([q, q_2])
    sur2.set_weight(1, q_2)
    sur2.set_criterion(c, q_2)
    assert sur1.score_students([s1, s2, s3]) == 1
    assert sur2.score_students([s1, s2, s3]) == 0.5
Ejemplo n.º 4
0
def createDummy():
    survey = Survey(eis_id='123',
                    first_name='Michael',
                    nbl_finish_timestamp=datetime.fromtimestamp(1539546879),
                    survey_send_time=datetime.fromtimestamp(1539719679))
    survey.set_defaults()
    return survey.put().urlsafe()
Ejemplo n.º 5
0
def test_survey_survey_set_criterion_invalid() -> None:
    """A test for set_criterion() in class Survey."""
    q1 = CheckboxQuestion(1, 'ABC', ['a', '1', ','])
    q2 = YesNoQuestion(2, 'BBC')
    s = Survey([q1])
    c = HomogeneousCriterion()
    assert s.set_criterion(c, q2) is False
Ejemplo n.º 6
0
def test_survey_survey_score_grouping() -> None:
    """A test for score_grouping() in class Survey."""
    q1 = YesNoQuestion(1, 'BBC')
    q2 = MultipleChoiceQuestion(2, 'ABC', ['A', 'B', 'C'])
    a1 = Answer(True)
    a2 = Answer('A')
    a3 = Answer(True)
    a4 = Answer('C')
    a5 = Answer(True)
    a6 = Answer('B')
    a7 = Answer(False)
    a8 = Answer('C')
    stu1 = Student(100, 'Jack')
    stu2 = Student(200, 'Mike')
    stu3 = Student(300, 'Diana')
    stu4 = Student(400, 'Tom')
    stu1.set_answer(q1, a1)
    stu1.set_answer(q2, a2)
    stu2.set_answer(q1, a3)
    stu2.set_answer(q2, a4)
    stu3.set_answer(q1, a5)
    stu3.set_answer(q2, a6)
    stu4.set_answer(q1, a7)
    stu4.set_answer(q2, a8)
    s = Survey([q1, q2])
    c = HomogeneousCriterion()
    s.set_weight(2.0, q1)
    s.set_criterion(c, q1)
    s.set_criterion(c, q2)
    g1 = Group([stu1, stu2])
    g2 = Group([stu3, stu4])
    grouping = Grouping()
    grouping.add_group(g1)
    grouping.add_group(g2)
    assert s.score_grouping(grouping) == 0.5
Ejemplo n.º 7
0
def test_survey_survey_get_questions() -> None:
    """A test for get_questions() in class Survey."""
    q1 = CheckboxQuestion(1, 'ABC', ['a', '1', ','])
    q2 = YesNoQuestion(2, 'BBC')
    s = Survey([q1, q2])
    lst = s.get_questions()
    assert q1 in lst and q2 in lst
Ejemplo n.º 8
0
def editSurvey(id):
    if (user.type != 1):
        return redirect("/")
    id = int(id)
    chosenSurvey = handle.getSurvey(id)
    print("create survey page")
    if request.method == "POST":
        s = Survey(id)
        s.setName(request.form["name"])
        s.setStatus(0)
        print("courses recieved: ",
              map(int, request.form["course-IDs"].split(',')))
        for course in map(int, request.form["course-IDs"].split(',')):
            s.addCourse(course)
            print("hello course: ", course)
        for q in request.form.getlist("question"):
            print("is working", q)
            s.addQuestion(int(q))
        print("adding: ", s.getQuestions())
        s = handle.updateSurvey(s)
        chosenSurvey = s
        return redirect("/")

    else:
        cList = [handle.getClass(c) for c in chosenSurvey.getCourses()]
        return render_template("editSurvey.html", survey = chosenSurvey, \
            qList = handle.getQuestion(None), courses = cList, cList = handle.getClass(None))
Ejemplo n.º 9
0
    def __init__(self, peaks, screen):
        seed(666)
        self.screen = screen

        self.survey = Survey()
        self.artificial = True

        self.dim = self.screen.height
        self.peaks = peaks
        self.previous_traces = deque()
        self.current_trace = None
        self.next_trace = None

        self.reference_trace = None

        self.top_pad = 10
        self.bottom_pad = 10

        self.level_params = {
            "switch_probability": 0.05,
            "peak_shift_distance_min": 100,
            "peak_shift_distance_max": 400,
            "peak_shift_spread": 1.0
        }

        self.interpreted_traces = []
        self.current_real_trace = 0
Ejemplo n.º 10
0
 def setUp(self):
     """
     Create a survey and a set of responses for use in all test methods.
     """
     question = "What language did you first learn to speak?"
     self.my_survey = Survey(question)
     self.responses = ['English', 'Spanish', 'Mandarin']
def main():
    # create objects of questions and sections for servey
    qualify1 = Question('1', 'Question 1 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    qualify2 = Question('2', 'Question 2 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    qualify3 = Question('3', 'Question 3 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})

    q4 = Question('1', 'Question1 Section1 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q5 = Question('2', 'Question2 Section1 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q6 = Question('3', 'Question3 Section1 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})

    q7 = Question('1', 'Question1 Section2 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q8 = Question('2', 'Question2 Section2 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q9 = Question('3', 'Question3 Section2 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})

    q10 = Question('1', 'Question1 Section3 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q11 = Question('2', 'Question2 Section3 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})
    q12 = Question('3', 'Question3 Section3 12 text? ', {'a': 'AnswerA', 'b': 'AnswerB', 'c': 'AnswerC'})

    section_a = Section('SectionA Title', 'Here is some info about what we covered in section_a', [q4, q5, q6], qualify1)
    section_b = Section('SectionB Title', 'Here is some info about what we covered in section_b', [q7, q8, q9], qualify2)
    section_c = Section('SectionC Title', 'Here is some info about what we covered in section_c', [q10, q11, q12], qualify3)
    qualifyquestion = [qualify1, qualify2, qualify3]

    my_survey = Survey('SheCodes Survey', 'This is a placeholder for Description on Survey', qualifyquestion, [section_a, section_b, section_c])
    my_survey.survey_introduction()
Ejemplo n.º 12
0
 def testUpdateFromJson(self):
     s = Survey(eis_id='a',
                first_name='b',
                nbl_finish_timestamp=datetime.now(),
                survey_send_time=datetime.now() + timedelta(hours=24))
     s.set_defaults()
     s.put()
     headAffected = True
     headPain = 5
     j = {
         'questions': {
             'pain': True
         },
         'bodyparts': {
             'head': {
                 'affected': headAffected,
                 'pain': headPain
             }
         }
     }
     s.update_from_json(j)
     s.put()
     head = ''
     for part in s.bodyparts:
         if part.name == 'head':
             head = part
             break
     self.assertEqual(s.pain, True)
     self.assertEqual(head.affected, headAffected)
     self.assertEqual(head.pain, headPain)
Ejemplo n.º 13
0
    def testPostSurvey(self):
        # First create one
        data = {
            'questions': {
                'treatments': ['x']
            },
            'bodyparts': {
                'head': {
                    'cuts': True
                }
            }
        }

        j = json.dumps(data)

        # Create a survey to be updated
        s = Survey(eis_id='a',
                   first_name='b',
                   nbl_finish_timestamp=datetime.now(),
                   survey_send_time=datetime.now() + timedelta(hours=24))
        s.set_defaults()
        key = s.put().urlsafe()

        response = self.app.post('/api/survey/%s' % key, data=j)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ndb.Key(urlsafe=key).get().treatments, ['x'])
Ejemplo n.º 14
0
def test_survey_get_weight() -> None:
    q1 = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    q2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    q3 = CheckboxQuestion(3, "choose", [1, 2, 3, 4])
    q_list = [q1, q2, q3]
    s = Survey(q_list)
    assert s._get_weight(q1) == 1
Ejemplo n.º 15
0
def test_survey_get_criterion() -> None:
    q1 = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    q2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    q3 = CheckboxQuestion(3, "choose", [1, 2, 3, 4])
    q_list = [q1, q2, q3]
    s = Survey(q_list)
    assert isinstance(s._get_criterion(q1), HomogeneousCriterion)
Ejemplo n.º 16
0
def test_survey_len() -> None:
    q1 = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    q2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    q3 = CheckboxQuestion(3, "choose", [1, 2, 3, 4])
    q_list = [q1, q2, q3]
    s = Survey(q_list)
    assert len(s) == 3
Ejemplo n.º 17
0
    def getSurvey(self, surveyID):

        survey = self._controller.getSurvey(surveyID)
        if (survey == -1):
            return -1
        sList = []
        #print("survey is: ", survey)
        for surv in survey:
            #print("surv is: ", surv)
            s = Survey(surv[sDict['id']])
            s.setName(surv[sDict['name']])
            s.setStatus(surv[sDict['status']])
            s.setOpen(surv[sDict['open']])
            s.setClose(surv[sDict['close']])
            for q in surv[sDict['qs']]:
                s.addQuestion(q)
            for c in surv[sDict['class']]:
                s.addCourse(c)
            for student in surv[sDict['completed']]:
                s.addCompleted(student)
                #print("this is in comp:",s.getCompleted())
                s.setOpen(surv[sDict['open']])
                s.setClose(surv[sDict['close']])
            sList.append(s)
        if surveyID == None:
            return sList
        else:
            #print(sList)
            return sList[0]
Ejemplo n.º 18
0
 def __init__(self):
     super().__init__("respond")
     # two for inserting new respond
     self.__mcq = RespondMcq()
     self.__text = RespondText()
     # check the type of question
     self.__survey = Survey()
     self.__question = Question()
Ejemplo n.º 19
0
 def testJsonify(self):
     s = Survey(eis_id='a',
                first_name='b',
                nbl_finish_timestamp=datetime.now(),
                survey_send_time=datetime.now() + timedelta(hours=24))
     s.set_defaults()
     j = s.jsonify()
     self.assertIn('head', j['bodyparts'])
     self.assertIn('cuts', j['bodyparts']['head'])
Ejemplo n.º 20
0
 def setUp(self):
     global survey
     survey = Survey()
     q = survey.add(Question(1, "Question1"))
     q.add(Answer(1, "answer1"))
     q.add(Answer(2, "answer2"))
     q = survey.add(Question(2, "Question2"))
     q.add(Answer(3, "answer3"))
     q.add(Answer(4, "answer4"))
     q.add(Answer(5, "answer5"))
Ejemplo n.º 21
0
 def create_survey(self):
     """
     Create the Survey from the previously created Questions, Attributes and
     Respondents, and the cleaned data.
     """
     self.survey = Survey(name=self.survey_name,
                          data=self.survey_data,
                          questions=self.questions,
                          respondents=self.respondents,
                          attributes=self.respondent_attributes)
Ejemplo n.º 22
0
 def test_store_single_response(self):
     question = 'what language did you first learn to speak? '
     my_survey = Survey(question)
     # my_survey.store_response('English')
     # self.assertIn('English', my_survey.responses)
     responses = ['english', 'chinese', 'japanese']
     for res in responses:
         my_survey.store_response(res)
     for res in responses:
         self.assertIn(res, my_survey.responses)
Ejemplo n.º 23
0
def test_survey_contains() -> None:
    q1 = CheckboxQuestion(1, "choose", [1, 2, 3, 4])
    q2 = CheckboxQuestion(2, "choose", [1, 2, 3, 4])
    q3 = CheckboxQuestion(3, "choose", [1, 2, 3, 4])
    q4 = 5
    q_list = [q1, q2]
    s = Survey(q_list)
    assert q1 in s
    assert q3 not in s
    assert q4 not in s
Ejemplo n.º 24
0
 def testFetchSurvey(self):
     # First create one
     s = Survey(eis_id='a',
                first_name='b',
                nbl_finish_timestamp=datetime.now(),
                survey_send_time=datetime.now() + timedelta(hours=24))
     s.set_defaults()
     key = s.put().urlsafe()
     response = self.app.get('/api/survey/%s' % key)
     data = json.loads(response.data)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(data['eisId'], 'a')
Ejemplo n.º 25
0
def bk(code):
    q = Survey('https://tellburgerking.com.cn/', code)
    try:
        q.setup_session()
        q.submit_cn()
    except Exception as e:
        print('failed to setup survey session')
        return 'failed to setup session err %s,<h>pls check your survey code</h>'%(e,)
    for i in range(28):
        q.submit_data()
        if q.done:
            return q.resptext
    return 'nothing here..'
Ejemplo n.º 26
0
 def __init__(self, **kwargs):
     global_idmap.update({'kivysurvey': self})
     self.db_interface = DBInterface(self)
     super(KivySurvey, self).__init__(**kwargs)
     self.transition = SlideTransition()
     json = JsonStore(construct_target_file_name('survey.json', __file__))
     for each in json:
         print(each)
     self.survey = Survey(json)
     try:
         gps.configure(on_location=self.receive_gps)
     except:
         pass
     Clock.schedule_once(self.start_gps)
Ejemplo n.º 27
0
def test_grouper_alpha_make_grouping() -> None:
    """A test for make_grouping() in class AlphaGrouper."""
    q = MultipleChoiceQuestion(1, 'abc', ['a'])
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    s3 = Student(3, 'C')
    s4 = Student(4, 'D')
    c = Course('CS')
    c.enroll_students([s3, s4, s2, s1])
    a = AlphaGrouper(2)
    s = Survey([q])
    result = a.make_grouping(c, s).get_groups()
    assert s1 in result[0] and s2 in result[0]
    assert s3 in result[1] and s4 in result[1]
Ejemplo n.º 28
0
def createSurvey():
    allSessions = loadAllCourseObjects(server.coursesCSVReader)                             # Creates a list of sessionOffering objects for all sessions/courses
    if (request.method == "POST"):
        if (request.form["bt"] == "back"):
            return redirect(url_for("landing"))
        if (request.form["name"].strip() != ""):
            newSurvey = Survey(randomKey(), 0, 0, request.form["name"].strip(), request.form["description"], [0])                   # Make the new survey object from HTML input fields
            writeSurvey(CSVWriter("csv/surveyform_"+newSurvey.getKey()+".csv"), server.qaaCSVReader, newSurvey, [])                 # Write a new survey form csv
            compoundKey = [allSessions[int(request.form["course"])].getName(), allSessions[int(request.form["course"])].getSession()] # Create the compound key required for search
            associateCourse(server.coursesCSVReader, server.coursesCSVWriter, compoundKey, newSurvey.getKey())                      # Append the new survey onto its associated course
            return redirect(url_for("modifySurvey", key = newSurvey.getKey()))                                                      # Redirect to modify survey page after creation
        else:
            flash("Surveys must have a name and an associated course")                                                              # Flash user message for bad input
    return render_template("createSurvey.html", courses = allSessions, is_authenticated = server.user.getPermissions())
Ejemplo n.º 29
0
def createSurv(key, active, phase, name, desc):
    session = server.DBSession()
    survey = Survey()
    survey.key = key
    survey.active = active
    survey.phase = phase
    currentTime = time.mktime(datetime.datetime.now().timetuple())
    survey.createtime = currentTime
    survey.name = name
    survey.desc = desc
    survey.questions = {}
    survey.responses = []
    session.add(survey)
    session.commit()
    session.close()
    return key
Ejemplo n.º 30
0
def test_course_all_answered() -> None:
    """A test for all_answered() in class Course."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    c = Course('CS')
    c.enroll_students([s1, s2])
    q1 = YesNoQuestion(2, 'F')
    q2 = YesNoQuestion(3, 'K')
    a1 = Answer(True)
    a2 = Answer(False)
    survey = Survey([q1, q2])
    s1.set_answer(q1, a1)
    s1.set_answer(q2, a2)
    s2.set_answer(q1, a1)
    s2.set_answer(q2, a2)
    assert c.all_answered(survey) is True