def get_task_html(self, req: CamcopsRequest) -> str: answers = { None: None, 0: "0 — " + self.wxstring(req, "a0"), 1: "1 — " + self.wxstring(req, "a1"), 2: "2 — " + self.wxstring(req, "a2"), 3: "3 — " + self.wxstring(req, "a3"), 4: "4 — " + self.wxstring(req, "a4"), } subscore_html = "" answer_html = "" for info in self.GROUPS: heading = self.wxstring(req, info.heading_xstring_name) subscore = info.subscore(self) subscore_html += tr(heading, (answer(round(subscore, DISPLAY_DP)) + " / {}".format(info.max_score))) answer_html += subheading_spanning_two_columns(heading) for q in info.fieldnames: if q == self.OPTIONAL_Q: # insert additional row answer_html += tr_qa(self.xstring(req, "prefer_no_answer"), self.ignore_s_q7) answer_val = getattr(self, q) answer_html += tr_qa(self.wxstring(req, q), get_from_dict(answers, answer_val)) tscore = round(self.total_score(), DISPLAY_DP) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {subscore_html} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {answer_html} """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score"), answer(tscore) + " / {}".format(self.MAX_SCORE_TOTAL)), subscore_html=subscore_html, answer_html=answer_html, ) h += """ </table> """ return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_cutoff_1 = score >= 6 exceeds_cutoff_2 = score >= 11 main_dict = { None: None, "Y": req.wappstring("yes"), "N": req.wappstring("no") } q_a = "" for q in range(1, Dast.NQUESTIONS + 1): q_a += tr( self.wxstring(req, "q" + str(q)), answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + " — " + answer(str(self.get_score(q))) ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {exceeds_standard_cutoff_1} {exceeds_standard_cutoff_2} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="80%">Question</th> <th width="20%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.COPYRIGHT}"> DAST: Copyright © Harvey A. Skinner and the Centre for Addiction and Mental Health, Toronto, Canada. Reproduced here under the permissions granted for NON-COMMERCIAL use only. You must obtain permission from the copyright holder for any other use. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / {}".format(self.NQUESTIONS)), exceeds_standard_cutoff_1=tr_qa( self.wxstring(req, "exceeds_standard_cutoff_1"), get_yes_no(req, exceeds_cutoff_1) ), exceeds_standard_cutoff_2=tr_qa( self.wxstring(req, "exceeds_standard_cutoff_2"), get_yes_no(req, exceeds_cutoff_2) ), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: tto_qol = self.get_tto_qol() rs_qol = self.get_rs_qol() mean_qol = mean([tto_qol, rs_qol]) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {mean_qol} </table> </div> <div class="{CssClass.EXPLANATION}"> Quality of life (QoL) has anchor values of 0 (none) and 1 (perfect health), and can be asked about in several ways. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="33%">Scale</th> <th width="33%">Answer</th> <td width="33%">Implied QoL</th> </tr> {tto} {rs} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), mean_qol=tr( "Mean QoL", answer( ws.number_to_dp(mean_qol, DP, default=None), formatter_answer=identity, ), ), tto=tr( self.wxstring(req, "tto_q_s"), answer(ws.number_to_dp(self.tto, DP, default=None)), answer( ws.number_to_dp(tto_qol, DP, default=None), formatter_answer=identity, ), ), rs=tr( self.wxstring(req, "rs_q_s"), answer(ws.number_to_dp(self.rs, DP, default=None)), answer( ws.number_to_dp(rs_qol, DP, default=None), formatter_answer=identity, ), ), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for q in ALL: q_a += tr( f"{q}. " + self.wxstring(req, "q" + str(q)) + " (<i>" + self.question_category(q) + "</i>)", answer(self.get_frequency(q)), answer( self.get_distress_score(q) if self.endorsed(q) else None, default=str(MIN_SCORE_PER_Q), ), ) raw_overall = tr( f"Overall <sup>[1]</sup> ({ALL_MIN}–{ALL_MAX})", self.frequency_score(ALL), self.distress_score(ALL), ) raw_positive = tr( f"Positive symptoms ({POS_MIN}–{POS_MAX})", self.frequency_score(POSITIVE), self.distress_score(POSITIVE), ) raw_negative = tr( f"Negative symptoms ({NEG_MIN}–{NEG_MAX})", self.frequency_score(NEGATIVE), self.distress_score(NEGATIVE), ) raw_depressive = tr( f"Depressive symptoms ({DEP_MIN}–{DEP_MAX})", self.frequency_score(DEPRESSIVE), self.distress_score(DEPRESSIVE), ) weighted_overall = tr( f"Overall ({len(ALL)} questions)", ws.number_to_dp(self.weighted_frequency_score(ALL), DP), ws.number_to_dp(self.weighted_distress_score(ALL), DP), ) weighted_positive = tr( f"Positive symptoms ({len(POSITIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(POSITIVE), DP), ws.number_to_dp(self.weighted_distress_score(POSITIVE), DP), ) weighted_negative = tr( f"Negative symptoms ({len(NEGATIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(NEGATIVE), DP), ws.number_to_dp(self.weighted_distress_score(NEGATIVE), DP), ) weighted_depressive = tr( f"Depressive symptoms ({len(DEPRESSIVE)} questions)", ws.number_to_dp(self.weighted_frequency_score(DEPRESSIVE), DP), ws.number_to_dp(self.weighted_distress_score(DEPRESSIVE), DP), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: target_symptoms = "" for col in self.TARGET_COLUMNS: target_symptoms += tr(col.comment, answer(getattr(self, col.name))) q_a = "" for qi in self.QINFO: fieldname = "q" + qi[0] value = getattr(self, fieldname) q_a += tr( self.wxstring(req, fieldname + "_title"), answer( self.wxstring(req, fieldname + "_a" + str(value), value ) if value is not None else None), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() likelihood = self.likelihood(req) main_dict = { None: None, "Y": req.sstring(SS.YES), "N": req.sstring(SS.NO), } q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr( self.wxstring(req, "q" + str(q)), answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + " — " + str(self.get_score(q)), ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {problem_likelihood} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="80%">Question</th> <th width="20%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] Total score ≥3 probable, ≥2 possible, 0–1 unlikely. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(score) + f" / {self.NQUESTIONS}", ), problem_likelihood=tr_qa( self.wxstring(req, "problem_likelihood") + " <sup>[1]</sup>", likelihood, ), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 0: "0 — " + self.wxstring(req, "q1to3_option0"), 1: "1 — " + self.wxstring(req, "q1to3_option1"), 2: "2 — " + self.wxstring(req, "q1to3_option2"), 3: "3 — " + self.wxstring(req, "q1to3_option3"), 4: "4 — " + self.wxstring(req, "q1to3_option4"), } q4_dict = { None: None, 0: "0 — " + self.wxstring(req, "q4_option0"), 2: "2 — " + self.wxstring(req, "q4_option2"), 4: "4 — " + self.wxstring(req, "q4_option4"), } q_a = tr_qa(self.wxstring(req, "q1"), get_from_dict(main_dict, self.q1)) q_a += tr_qa(self.wxstring(req, "q2"), get_from_dict(main_dict, self.q2)) q_a += tr_qa(self.wxstring(req, "q3"), get_from_dict(main_dict, self.q3)) q_a += tr_qa(self.wxstring(req, "q4"), get_from_dict(q4_dict, self.q4)) tr_total_score = tr( req.sstring(SS.TOTAL_SCORE), answer(self.total_score()) + f" / {self.MAX_SCORE}", ) tr_positive = tr_qa( self.wxstring(req, "positive") + " <sup>[1]</sup>", get_yes_no(req, self.is_positive()), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() severity = self.severity(req) answer_dicts_dict = {} for q in self.SCORED_QUESTIONS: d = {None: None} for option in range(0, 8): if option > 4 and q == "q10": continue d[option] = self.wxstring(req, q + "_option" + str(option)) answer_dicts_dict[q] = d q_a = "" for q in range(1, Ciwa.NSCOREDQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q) + "_s"), get_from_dict( answer_dicts_dict["q" + str(q)], getattr(self, "q" + str(q)), ), ) tr_total_score = tr(req.sstring(SS.TOTAL_SCORE), answer(score) + f" / {self.MAX_SCORE}") tr_severity = tr_qa( self.wxstring(req, "severity") + " <sup>[1]</sup>", severity) return f"""
def get_html_correct_by_block(self, trialarray: List[ExpDetTrial]) -> str: if not trialarray: return div(italic("No trials")) html = """ <table class="{CssClass.EXTRADETAIL}"> <tr> <th>Block</th> <th>P(detected | present)</th> <th>P(detected | absent)</th> <th>c</th> <th>d'</th> </tr> """.format(CssClass=CssClass) for b in range(self.num_blocks): (p_detected_given_present, p_detected_given_absent, c, dprime, n_trials) = self.get_p_detected(trialarray, [b], None) html += tr( b, a(p_detected_given_present), a(p_detected_given_absent), a(c), a(dprime), ) html += """ </table> """ return html
def get_task_html(self, req: CamcopsRequest) -> str: h = f""" <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {self.get_is_complete_tr(req)} <tr> <td>Total score (16–80)</td> <td>{answer(self.total_score())}</td> </td> </table> </div> <div class="{CssClass.EXPLANATION}"> Anchor points are 1 = {self.wxstring(req, "anchor1")}, 5 = {self.wxstring(req, "anchor5")}. Questions {", ".join(str(x) for x in self.REVERSE_SCORE)} are reverse-scored. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="15%">Answer (1–5)</th> <th width="15%">Score (1–5)</th> </tr> """ for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) score = self.score(q) h += tr(self.wxstring(req, "q" + str(q)), answer(a), score) h += """ </table> """ return h
def get_task_html(self, req: CamcopsRequest) -> str: def bprs_string(x: str) -> str: return req.wxstring("bprs", x) main_dict = { None: None, 0: "0 — " + bprs_string("old_option0"), 1: "1 — " + bprs_string("old_option1"), 2: "2 — " + bprs_string("old_option2"), 3: "3 — " + bprs_string("old_option3"), 4: "4 — " + bprs_string("old_option4"), 5: "5 — " + bprs_string("old_option5"), 6: "6 — " + bprs_string("old_option6"), 7: "7 — " + bprs_string("old_option7"), } q_a = "" for i in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(i) + "_s"), get_from_dict(main_dict, getattr(self, "q" + str(i))), ) total_score = tr( req.sstring(SS.TOTAL_SCORE) + f" (0–{self.MAX_SCORE}; 24–{self.MAX_SCORE} if all rated)", answer(self.total_score()), ) return f"""
def get_html_table_row(self) -> str: return tr( self.seqnum, answer(ws.webify(self.code)), answer(ws.webify(self.description)), answer(ws.webify(self.comment)), )
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_cutoff = score >= 2 q_a = "" for q in range(1, Cage.NQUESTIONS + 1): q_a += tr_qa( str(q) + " — " + self.wxstring(req, "q" + str(q)), getattr(self, "q" + str(q))) # answer is itself Y/N/NULL # noqa h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {over_threshold} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="30%">Answer</th> </tr> {q_a} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / {}".format(self.NQUESTIONS)), over_threshold=tr_qa(self.wxstring(req, "over_threshold"), get_yes_no(req, exceeds_cutoff)), q_a=q_a, ) return h
def answer_row_html(self, req: CamcopsRequest, q: int) -> str: qtext = self.wxstring(req, "q" + str(q)) v = getattr(self, "q" + str(q)) atext = self.answer_text(req, q, v) s = self.recode(q) return tr(qtext, answer(v) + ": " + answer(atext), answer(s, formatter_answer=identity))
def get_html_table_row(self) -> str: return tr( a(self.group_num), a(self.cue), a(self.target_modality), a(self.target_number), a(self.n_target), a(self.n_no_target), )
def get_task_html(self, req: CamcopsRequest) -> str: h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Endorsed</td> <td>{e} / 12</td> </td> <tr> <td>Severity score</td> <td>{s} / 36</td> </td> <tr> <td>Distress score</td> <td>{d} / 60</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="40%">Question</th> <th width="20%">Endorsed</th> <th width="20%">Severity (patient)</th> <th width="20%">Distress (carer)</th> </tr> """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), e=self.n_endorsed(), s=self.severity_score(), d=self.distress_score(), ) for q in range(1, self.NQUESTIONS + 1): qstr = str(q) e = getattr(self, ENDORSED + qstr) s = getattr(self, SEVERITY + qstr) d = getattr(self, DISTRESS + qstr) qtext = "<b>{}:</b> {}".format( self.wxstring(req, "t" + qstr), self.wxstring(req, "q" + qstr), ) etext = get_yes_no_unknown(req, e) if e: stext = self.wxstring(req, "severity_{}".format(s), s, provide_default_if_none=False) dtext = self.wxstring(req, "distress_{}".format(d), d, provide_default_if_none=False) else: stext = "" dtext = "" h += tr(qtext, answer(etext), answer(stext), answer(dtext)) h += """ </table> """ + DATA_COLLECTION_UNLESS_UPGRADED_DIV return h
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() nsevere = self.num_severe() somatoform_likely = nsevere >= 3 severity = self.severity(req) answer_dict = {None: None} for option in range(0, 3): answer_dict[option] = str(option) + " – " + \ self.wxstring(req, "a" + str(option)) q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr_qa( self.wxstring(req, "q" + str(q)), get_from_dict(answer_dict, getattr(self, "q" + str(q)))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {n_severe_symptoms} {exceeds_somatoform_cutoff} {symptom_severity} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="70%">Question</th> <th width="30%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] In males, maximum score is actually 28. [2] Questions with scores ≥2 are considered severe. [3] ≥3 severe symptoms. [4] Total score ≥15 severe, ≥10 moderate, ≥5 mild, otherwise none. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score") + " <sup>[1]</sup>", answer(score) + " / {}".format(self.MAX_TOTAL)), n_severe_symptoms=tr_qa( self.wxstring(req, "n_severe_symptoms") + " <sup>[2]</sup>", nsevere), exceeds_somatoform_cutoff=tr_qa( self.wxstring(req, "exceeds_somatoform_cutoff") + " <sup>[3]</sup>", get_yes_no(req, somatoform_likely)), symptom_severity=tr_qa( self.wxstring(req, "symptom_severity") + " <sup>[4]</sup>", severity), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: option_dict = {None: None} for a in range(self.MIN_SCORE, self.MAX_SCORE + 1): option_dict[a] = req.wappstring("iesr_a" + str(a)) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {complete_tr} <tr> <td>Total score</td> <td>{total} / {maxtotal}</td> </td> <tr> <td>Avoidance score</td> <td>{avoidance} / {maxavoidance}</td> </td> <tr> <td>Intrusion score</td> <td>{intrusion} / {maxintrusion}</td> </td> <tr> <td>Hyperarousal score</td> <td>{hyperarousal} / {maxhyperarousal}</td> </td> </table> </div> <table class="{CssClass.TASKDETAIL}"> {tr_event} </table> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="75%">Question</th> <th width="25%">Answer (0–4)</th> </tr> """.format( CssClass=CssClass, complete_tr=self.get_is_complete_tr(req), total=answer(self.total_score()), maxtotal=self.MAX_TOTAL, avoidance=answer(self.avoidance_score()), maxavoidance=self.MAX_AVOIDANCE, intrusion=answer(self.intrusion_score()), maxintrusion=self.MAX_INTRUSION, hyperarousal=answer(self.hyperarousal_score()), maxhyperarousal=self.MAX_HYPERAROUSAL, tr_event=tr_qa(req.wappstring("event"), self.event), ) for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) fa = ("{}: {}".format(a, get_from_dict(option_dict, a)) if a is not None else None) h += tr(self.wxstring(req, "q" + str(q)), answer(fa)) h += """ </table> """ + DATA_COLLECTION_UNLESS_UPGRADED_DIV return h
def get_task_html(self, req: CamcopsRequest) -> str: option_dict = {None: None} for a in range(self.MIN_PER_Q, self.MAX_PER_Q + 1): option_dict[a] = req.wappstring(AS.WSAS_A_PREFIX + str(a)) q_a = "" for q in range(1, self.NQUESTIONS + 1): a = getattr(self, "q" + str(q)) fa = get_from_dict(option_dict, a) if a is not None else None q_a += tr(self.wxstring(req, "q" + str(q)), answer(fa)) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() q1_dict = {None: None} q2_dict = {None: None} q3_dict = {None: None} for option in range(0, 5): q1_dict[option] = str(option) + " – " + \ self.wxstring(req, "q1_option" + str(option)) if option == 0: # special! q2_dict[option] = str(option) + " – " + \ self.wxstring(req, "c_q2_option0") else: q2_dict[option] = str(option) + " – " + \ self.wxstring(req, "q2_option" + str(option)) q3_dict[option] = str(option) + " – " + \ self.wxstring(req, "q3to8_option" + str(option)) # noinspection PyUnresolvedReferences h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="50%">Question</th> <th width="50%">Answer</th> </tr> {q1} {q2} {q3} </table> <div class="{CssClass.COPYRIGHT}"> AUDIT: Copyright © World Health Organization. Reproduced here under the permissions granted for NON-COMMERCIAL use only. You must obtain permission from the copyright holder for any other use. AUDIT-C: presumed to have the same restrictions. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / 12"), q1=tr_qa(self.wxstring(req, "c_q1_question"), get_from_dict(q1_dict, self.q1)), q2=tr_qa(self.wxstring(req, "c_q2_question"), get_from_dict(q2_dict, self.q2)), q3=tr_qa(self.wxstring(req, "c_q3_question"), get_from_dict(q3_dict, self.q3)), ) return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 1: "1 — " + self.wxstring(req, "wemwbs_a1"), 2: "2 — " + self.wxstring(req, "wemwbs_a2"), 3: "3 — " + self.wxstring(req, "wemwbs_a3"), 4: "4 — " + self.wxstring(req, "wemwbs_a4"), 5: "5 — " + self.wxstring(req, "wemwbs_a5"), } q_a = "" for i in range(1, self.N_QUESTIONS + 1): nstr = str(i) q_a += tr_qa( self.wxstring(req, "wemwbs_q" + nstr), get_from_dict(main_dict, getattr(self, "q" + nstr)), ) h = """ <div class="{css_summary}"> <table class="{css_summary}"> {tr_is_complete} {tr_total_score} </table> </div> <div class="{css_explanation}"> Ratings are over the last 2 weeks. </div> <table class="{css_taskdetail}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{css_copyright}"> WEMWBS: from Tennant et al. (2007), <i>Health and Quality of Life Outcomes</i> 5:63, <a href="http://www.hqlo.com/content/5/1/63"> http://www.hqlo.com/content/5/1/63</a>; © 2007 Tennant et al.; distributed under the terms of the Creative Commons Attribution License. </div> """.format( css_summary=CssClass.SUMMARY, tr_is_complete=self.get_is_complete_tr(req), tr_total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(self.total_score()) + f" (range {self.MINTOTALSCORE}–{self.MAXTOTALSCORE})", ), css_explanation=CssClass.EXPLANATION, css_taskdetail=CssClass.TASKDETAIL, q_a=q_a, css_copyright=CssClass.COPYRIGHT, ) return h
def get_html_correct_by_half_and_probability( self, trialarray: List[ExpDetTrial], grouparray: List[ExpDetTrialGroupSpec]) -> str: if (not trialarray) or (not grouparray): return div(italic("No trials or no groups")) n_target_highprob = max([x.n_target for x in grouparray]) n_target_lowprob = min([x.n_target for x in grouparray]) groups_highprob = [x.group_num for x in grouparray if x.n_target == n_target_highprob] groups_lowprob = [x.group_num for x in grouparray if x.n_target == n_target_lowprob] html = """ <div><i> High probability groups (cues): {high}.\n Low probability groups (cues): {low}.\n </i></div> <table class="{CssClass.EXTRADETAIL}"> <tr> <th>Half (0 first, 1 second)</th> <th>Target probability given stimulus (0 low, 1 high)</th> <th>P(detected | present)</th> <th>P(detected | absent)</th> <th>c</th> <th>d'</th> </tr> """.format( CssClass=CssClass, high=", ".join([str(x) for x in groups_highprob]), low=", ".join([str(x) for x in groups_lowprob]) ) for half in [0, 1]: for prob in [0, 1]: blocks = list(range(half * self.num_blocks // 2, self.num_blocks // (2 - half))) groups = groups_lowprob if prob == 0 else groups_highprob (p_detected_given_present, p_detected_given_absent, c, dprime, n_trials) = self.get_p_detected(trialarray, blocks, groups) html += tr( half, a(prob), a(p_detected_given_present), a(p_detected_given_absent), a(c), a(dprime), ) html += """ </table> """ return html
def get_task_html(self, req: CamcopsRequest) -> str: q_a = "" for q in range(1, self.NQUESTIONS + 1): fieldname = "q" + str(q) qtext = self.wxstring(req, fieldname) # happens to be the same avalue = getattr(self, "q" + str(q)) atext = (self.wxstring(req, "q{}_{}".format(q, avalue)) if q is not None else None) score = self.score(fieldname) q_a += tr(qtext, answer(atext), score) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 0: "0 — " + self.wxstring(req, "q1to3_option0"), 1: "1 — " + self.wxstring(req, "q1to3_option1"), 2: "2 — " + self.wxstring(req, "q1to3_option2"), 3: "3 — " + self.wxstring(req, "q1to3_option3"), 4: "4 — " + self.wxstring(req, "q1to3_option4"), } q4_dict = { None: None, 0: "0 — " + self.wxstring(req, "q4_option0"), 2: "2 — " + self.wxstring(req, "q4_option2"), 4: "4 — " + self.wxstring(req, "q4_option4"), } q_a = tr_qa(self.wxstring(req, "q1"), get_from_dict(main_dict, self.q1)) # noqa q_a += tr_qa(self.wxstring(req, "q2"), get_from_dict(main_dict, self.q2)) # noqa q_a += tr_qa(self.wxstring(req, "q3"), get_from_dict(main_dict, self.q3)) # noqa q_a += tr_qa(self.wxstring(req, "q4"), get_from_dict(q4_dict, self.q4)) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {positive} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] Negative if Q1 = 0. Positive if Q1 ≥ 3. Otherwise positive if total score ≥ 3. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score"), answer(self.total_score()) + " / {}".format(self.MAX_SCORE)), positive=tr_qa( self.wxstring(req, "positive") + " <sup>[1]</sup>", get_yes_no(req, self.is_positive())), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: def bprs_string(x: str) -> str: return req.wxstring("bprs", x) main_dict = { None: None, 0: "0 — " + bprs_string("old_option0"), 1: "1 — " + bprs_string("old_option1"), 2: "2 — " + bprs_string("old_option2"), 3: "3 — " + bprs_string("old_option3"), 4: "4 — " + bprs_string("old_option4"), 5: "5 — " + bprs_string("old_option5"), 6: "6 — " + bprs_string("old_option6"), 7: "7 — " + bprs_string("old_option7") } q_a = "" for i in range(1, self.NQUESTIONS + 1): q_a += tr_qa(self.wxstring(req, "q" + str(i) + "_s"), get_from_dict(main_dict, getattr(self, "q" + str(i)))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} </table> </div> <div class="{CssClass.EXPLANATION}"> Each question has specific answer definitions (see e.g. tablet app). </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer <sup>[1]</sup></th> </tr> {q_a} </table> <div class="{CssClass.FOOTNOTES}"> [1] All answers are in the range 1–7, or 0 (not assessed, for some). </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.wappstring("total_score") + " (0–{maxscore}; 24–{maxscore} if all rated)".format( maxscore=self.MAX_SCORE), answer(self.total_score())), q_a=q_a, ) return h
def get_question_rows(first, last): html = "" for q in range(first, last + 1): f = getattr(self, "frequency" + str(q)) d = getattr(self, "distress" + str(q)) fa = (f"{f}: {get_from_dict(freq_dict, f)}" if f is not None else None) da = (f"{d}: {get_from_dict(distress_dict, d)}" if d is not None else None) html += tr(self.wxstring(req, "q" + str(q)), answer(fa), answer(da)) return html
def get_task_html(self, req: CamcopsRequest) -> str: h = f""" <table class="{CssClass.TASKDETAIL}"> <tr> <th width="55%">Symptom</th> <th width="15%">Current</th> <th width="15%">Past</th> <th width="15%">Principal</th> </tr> """ for group in self.GROUPS: h += subheading_spanning_four_columns( self.wxstring(req, self.SC_PREFIX + group)) for item in self.ITEMS: if not item.startswith(group): continue h += tr( self.wxstring(req, self.SC_PREFIX + item), answer( get_ternary( getattr(self, item + self.SUFFIX_CURRENT), value_true="Current", value_false="", value_none="", )), answer( get_ternary( getattr(self, item + self.SUFFIX_PAST), value_true="Past", value_false="", value_none="", )), answer( get_ternary( getattr(self, item + self.SUFFIX_PRINCIPAL), value_true="Principal", value_false="", value_none="", )), ) if item.endswith(self.SUFFIX_OTHER): h += f""" <tr> <td><i>Specify:</i></td> <td colspan="3">{ answer(getattr(self, item + self.SUFFIX_DETAIL), "")}</td> </tr> """ h += f""" </table> {DATA_COLLECTION_UNLESS_UPGRADED_DIV} """ return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 1: "1 — " + self.wxstring(req, "wemwbs_a1"), 2: "2 — " + self.wxstring(req, "wemwbs_a2"), 3: "3 — " + self.wxstring(req, "wemwbs_a3"), 4: "4 — " + self.wxstring(req, "wemwbs_a4"), 5: "5 — " + self.wxstring(req, "wemwbs_a5"), } q_a = "" for i in range(1, self.N_QUESTIONS + 1): nstr = str(i) q_a += tr_qa( self.wxstring(req, "swemwbs_q" + nstr), get_from_dict(main_dict, getattr(self, "q" + nstr)), ) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} </table> </div> <div class="{CssClass.EXPLANATION}"> Ratings are over the last 2 weeks. </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="60%">Question</th> <th width="40%">Answer</th> </tr> {q_a} </table> <div class="{CssClass.COPYRIGHT}"> SWEMWBS: from Stewart-Brown et al. (2009), <i>Health and Quality of Life Outcomes</i> 7:15, http://www.hqlo.com/content/7/1/15; © 2009 Stewart-Brown et al.; distributed under the terms of the Creative Commons Attribution License. </div> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr( req.sstring(SS.TOTAL_SCORE), answer(self.total_score()) + f" (range {self.MINTOTALSCORE}–{self.MAXTOTALSCORE})", ), q_a=q_a, ) return h
def get_task_html(self, req: CamcopsRequest) -> str: main_dict = { None: None, 0: "0 — " + self.wxstring(req, "old_option0"), 1: "1 — " + self.wxstring(req, "old_option1"), 2: "2 — " + self.wxstring(req, "old_option2"), 3: "3 — " + self.wxstring(req, "old_option3"), 4: "4 — " + self.wxstring(req, "old_option4"), 5: "5 — " + self.wxstring(req, "old_option5"), 6: "6 — " + self.wxstring(req, "old_option6"), 7: "7 — " + self.wxstring(req, "old_option7"), } q19_dict = { None: None, 1: self.wxstring(req, "q19_option1"), 2: self.wxstring(req, "q19_option2"), 3: self.wxstring(req, "q19_option3"), 4: self.wxstring(req, "q19_option4"), 5: self.wxstring(req, "q19_option5"), 6: self.wxstring(req, "q19_option6"), 7: self.wxstring(req, "q19_option7"), } q20_dict = { None: None, 0: self.wxstring(req, "q20_option0"), 1: self.wxstring(req, "q20_option1"), 2: self.wxstring(req, "q20_option2"), 3: self.wxstring(req, "q20_option3"), 4: self.wxstring(req, "q20_option4"), 5: self.wxstring(req, "q20_option5"), 6: self.wxstring(req, "q20_option6"), 7: self.wxstring(req, "q20_option7"), } q_a = "" for i in range(1, Bprs.NQUESTIONS - 1): # only does 1-18 q_a += tr_qa( self.wxstring(req, "q" + str(i) + "_title"), get_from_dict(main_dict, getattr(self, "q" + str(i))), ) q_a += tr_qa(self.wxstring(req, "q19_title"), get_from_dict(q19_dict, self.q19)) q_a += tr_qa(self.wxstring(req, "q20_title"), get_from_dict(q20_dict, self.q20)) total_score = tr( req.sstring(SS.TOTAL_SCORE) + f" (0–{self.MAX_SCORE}; 18–{self.MAX_SCORE} if all rated) " "<sup>[1]</sup>", answer(self.total_score()), ) return f"""
def get_task_html(self, req: CamcopsRequest) -> str: score = self.total_score() exceeds_threshold = self.exceeds_ross_threshold() main_dict = { None: None, "Y": req.wappstring("yes"), "N": req.wappstring("no") } q_a = "" for q in range(1, self.NQUESTIONS + 1): q_a += tr(self.wxstring(req, "q" + str(q)), ( answer(get_from_dict(main_dict, getattr(self, "q" + str(q)))) + answer(" — " + str(self.get_score(q))))) h = """ <div class="{CssClass.SUMMARY}"> <table class="{CssClass.SUMMARY}"> {tr_is_complete} {total_score} {exceeds_threshold} </table> </div> <table class="{CssClass.TASKDETAIL}"> <tr> <th width="80%">Question</th> <th width="20%">Answer</th> </tr> {q_a} </table> """.format( CssClass=CssClass, tr_is_complete=self.get_is_complete_tr(req), total_score=tr(req.wappstring("total_score"), answer(score) + " / {}".format(self.MAX_SCORE)), exceeds_threshold=tr_qa(self.wxstring(req, "exceeds_threshold"), get_yes_no(req, exceeds_threshold)), q_a=q_a, ) return h