<commit_before>from ..utils import TableMaker, DOCXReport


class NtpEpiAniResults(DOCXReport):

    def build_res_tbl(self, caption, studies):

        colWidths = [1.5, 1.5, 1.5, 1.0, 1.0, 1.0, 2.5]
        styles = {
            "title": "RoCTabletitle",
            "header": "RoCColumnheading",
            "body": "RoCTablebody",
            "subheading" : None
        }
        tbl = TableMaker(colWidths, styles=styles, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_tbl_title(caption)

        # write header
        tbl.new_th(1, 0, "Reference & year, animal, study duration")
        tbl.new_th(1, 1, "Substance & purity")
        tbl.new_th(1, 2, "Dosing regimen")
        tbl.new_th(1, 3, "Dose levels")
        tbl.new_th(1, 4, "# animals at sacrifice")
        tbl.new_th(1, 5, "Tumor incidence (n/N) (%)")
        tbl.new_th(1, 6, "Comments, strengths, and limitations")

        # write additional rows
        rows = 2
        for st in studies:

            # get row-span for each study
            for res in st["results"]:
                res["_rowspan"] = len(res["riskEstimates"])+1
                if res["hasTrendTest"]:
                    res["_rowspan"] += 1

            st_rowspan = sum(res["_rowspan"] for res in st["results"])

            # Column A
            runs = [
                tbl.new_run(st["reference"]["name"], b=True),
                tbl.new_run(st.get("eligibilityCriteria", "")),
                tbl.new_run(st.get("enrollmentDates", "")),
            ]
            tbl.new_td_run(rows, 0, runs, rowspan=st_rowspan)

            # Column B
            runs = [
                tbl.new_run(st["location"]),
                tbl.new_run(st["coexposuresList"]),
            ]
            tbl.new_td_run(rows, 1, runs, rowspan=st_rowspan)

            # Column C
            runs = [
                tbl.new_run(st.get("exposureAssessmentNotes", ""))
            ]
            tbl.new_td_run(rows, 2, runs, rowspan=st_rowspan)

            # Columns D, E, F
            irows = rows
            covariates = []
            for res in st["results"]:
                runs = [
                    tbl.new_run(res.get("covariatesControlledText", ""), b=True, newline=False),
                ]
                tbl.new_td_run(irows, 3, runs, colspan=3, style="Tablesubheadings")

                for i, est in enumerate(res["riskEstimates"]):
                    tbl.new_td_txt(irows+i+1, 3, est["exposureCategory"])
                    tbl.new_td_txt(irows+i+1, 4, unicode(est["numberExposed"]))
                    txt = u"{}/{} ({}%)".format(est["riskLow"], est["riskHigh"], est["riskMid"])
                    tbl.new_td_txt(irows+i+1, 5, txt)

                if res["hasTrendTest"]:
                    txt = u"Trend-test p-value: {}".format(res["trendTest"])
                    tbl.new_td_txt(irows+i+2, 3, txt, colspan=3)

                covariates.extend(res["covariates"])
                irows += res["_rowspan"]

            # Column G
            covariates = u", ".join(set(covariates))
            runs = [
                tbl.new_run(covariates),
                tbl.new_run("Strengths: ", b=True, newline=False),
                tbl.new_run(st["strengths"]),
                tbl.new_run("Limitations: ", b=True, newline=False),<commit_msg>italicize the p in p-value<commit_after>from ..utils import TableMaker, DOCXReport


class NtpEpiAniResults(DOCXReport):

    def build_res_tbl(self, caption, studies):

        colWidths = [1.5, 1.5, 1.5, 1.0, 1.0, 1.0, 2.5]
        styles = {
            "title": "RoCTabletitle",
            "header": "RoCColumnheading",
            "body": "RoCTablebody",
            "subheading" : None
        }
        tbl = TableMaker(colWidths, styles=styles, numHeaders=2, tblStyle="ntpTbl")

        # write title
        tbl.new_tbl_title(caption)

        # write header
        tbl.new_th(1, 0, "Reference & year, animal, study duration")
        tbl.new_th(1, 1, "Substance & purity")
        tbl.new_th(1, 2, "Dosing regimen")
        tbl.new_th(1, 3, "Dose levels")
        tbl.new_th(1, 4, "# animals at sacrifice")
        tbl.new_th(1, 5, "Tumor incidence (n/N) (%)")
        tbl.new_th(1, 6, "Comments, strengths, and limitations")

        # write additional rows
        rows = 2
        for st in studies:

            # get row-span for each study
            for res in st["results"]:
                res["_rowspan"] = len(res["riskEstimates"])+1
                if res["hasTrendTest"]:
                    res["_rowspan"] += 1

            st_rowspan = sum(res["_rowspan"] for res in st["results"])

            # Column A
            runs = [
                tbl.new_run(st["reference"]["name"], b=True),
                tbl.new_run(st.get("eligibilityCriteria", "")),
                tbl.new_run(st.get("enrollmentDates", "")),
            ]
            tbl.new_td_run(rows, 0, runs, rowspan=st_rowspan)

            # Column B
            runs = [
                tbl.new_run(st["location"]),
                tbl.new_run(st["coexposuresList"]),
            ]
            tbl.new_td_run(rows, 1, runs, rowspan=st_rowspan)

            # Column C
            runs = [
                tbl.new_run(st.get("exposureAssessmentNotes", ""))
            ]
            tbl.new_td_run(rows, 2, runs, rowspan=st_rowspan)

            # Columns D, E, F
            irows = rows
            covariates = []
            for res in st["results"]:
                runs = [
                    tbl.new_run(res.get("covariatesControlledText", ""), b=True, newline=False),
                ]
                tbl.new_td_run(irows, 3, runs, colspan=3, style="Tablesubheadings")

                for i, est in enumerate(res["riskEstimates"]):
                    tbl.new_td_txt(irows+i+1, 3, est["exposureCategory"])
                    tbl.new_td_txt(irows+i+1, 4, unicode(est["numberExposed"]))
                    txt = u"{}/{} ({}%)".format(est["riskLow"], est["riskHigh"], est["riskMid"])
                    tbl.new_td_txt(irows+i+1, 5, txt)

                if res["hasTrendTest"]:
                    runs = [
                        tbl.new_run("Trend-test ", newline=False),
                        tbl.new_run("p", i=True, newline=False),
                        tbl.new_run("-value: {}".format(res["trendTest"]), newline=False),
                    ]
                    tbl.new_td_run(irows+i+2, 3, runs, colspan=3)

                covariates.extend(res["covariates"])
                irows += res["_rowspan"]

            # Column G
            covariates = u", ".join(set(covariates))
            runs = [
                tbl.new_run(covariates),
                tbl.new_run("Strengths: ", b=True, newline=False),
                tbl.new_run(st["strengths"]),
                tbl.new_run("Limitations: ", b=True, newline=False),
{'fraction_non_alphanumeric': 0.14185741361714535, 'fraction_numerical': 0.013413033969966468, 'mean_word_length': 1.6744639376218324, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4144701', 'n_tokens_mistral': 2375, 'n_tokens_neox': 2141, 'n_words': 402}