def test_student_get_answer() -> None: student = Student(1, "Jane") q1 = Question(1, "How are you") a1 = Answer("good") q2 = Question(2, "hello") a2 = Answer("hi") assert student.get_answer(q1) is None student.set_answer(q1, a1) student.set_answer(q2, a2) assert student.get_answer(q1) == a1 assert student.get_answer(q2) == a2
def test_student_set_answer(): student = Student(1, "Jane") q1 = Question(1, "How are you") a1 = Answer("good") q2 = Question(2, "hello") a2 = Answer("hi") a3 = Answer("test") student.set_answer(q1, a1) student.set_answer(q2, a2) student.set_answer(q2, a3) assert student.get_answer(q1) == a1 assert student.get_answer(q2) == a3
def cost(): q = Question(survey, 56) summ = q.summary.reset_index() summ["test"] = ["Affordability"] * len(summ) return alt.Chart(summ).mark_bar().encode( x={ "field": "Valid Percent", "type": "quantitative", "stack": "normalize", "axis": { "title": None }, }, y={ "field": "test", "type": "nominal", "axis": { "title": None }, }, color={ "field": 'index', "type": "nominal", "legend": { "title": None }, "scale": { "scheme": "pinkyellowgreen" }, "sort": "descending" }, )
def sentiment(q): sent = Question(survey, q) g = sent.summary.reset_index().melt(['index']) return alt.Chart(g).mark_bar().encode( x={ "field": "value", "stack": "normalize", "type": "quantitative", "axis": { "title": None, "format": "%", }, "sort": "descending" }, y={ "field": "index", "type": "nominal", "axis": { "title": None, "labelLimit": 350, }, }, color={ "field": 'variable', "type": "nominal", "legend": { "title": None }, "scale": { "scheme": "pinkyellowgreen" }, "sort": "descending" }, )
def test_student_get_answer() -> None: """A test for get_answer() in class Student.""" s = Student(123, 'Mike') ans = Answer(False) que = Question(2, 'F') s.set_answer(que, ans) test_ans = s.get_answer(que) assert ans == test_ans
import altair as alt import pandas as pd from survey import df, attended, Question, survey memb_recv = Question(survey, 47) memb_recv_ans = [l['answer'] for l in memb_recv.metadata['answers']['0']] out = pd.DataFrame() for ans in memb_recv_ans: summary = Question(survey, 121, df[memb_recv.metadata['question']] == ans).summary summary[memb_recv.metadata['question']] = [ans] * len(summary) out = out.append(summary) # tidy data out = out.reset_index().melt( ["When did you receive your membership?", "index"]) def transfers_value(): return alt.Chart(out).mark_bar().encode( x={ "field": "index", "type": "nominal", "axis": { "title": None } }, y={ "field": "value",
def test_student_has_answer() -> None: """A test for has_answer() in class Student.""" s = Student(123, 'Mike') que = Question(2, 'F') assert s.has_answer(que) is False