示例#1
0
    def build_tables(self):
        """Test essential imports and show versions."""
        caption = "Module Import Status"
        cols = "Module", "Description", "Status"
        rows = []

        # This strange bit is needed because the ndscheduler package
        # is poorly implemented, and writes to stdout when it is loaded.
        stdout = sys.stdout
        sys.stdout = open(devnull, "w")
        for name, description in self.MODULES:
            try:
                import_module(name)
                status = Reporter.Cell("OK", classes="success center")
            except Exception as e:
                status = Reporter.Cell(str(e), classes="failure center")
            rows.append((name, description, status))

        # Restore sanity to the world.
        sys.stdout = stdout
        tables = [Reporter.Table(rows, columns=cols, caption=caption)]
        caption = "Module Versions"
        cols = "Module", "Version"
        rows = [("Python", str(sys.version))]
        env = Environment()
        for key in sorted(env, key=str.lower):
            for package in env[key]:
                rows.append(str(package).split())
        tables.append(Reporter.Table(rows, columns=cols, caption=caption))
        return tables
    def summary_table(self):
        """Table showing the totals for each status."""

        if not hasattr(self, "_summary_table"):
            approved = rejected = unreviewed = 0
            for audio_set in self.sets:
                approved += audio_set.approved
                rejected += audio_set.rejected
                unreviewed += audio_set.unreviewed
            row = [
                Reporter.Cell(approved, center=True),
                Reporter.Cell(rejected, center=True),
                Reporter.Cell(unreviewed, center=True),
            ]
            opts = dict(columns=self.STATUSES, caption="Status Totals")
            self._summary_table = Reporter.Table([row], **opts)
        return self._summary_table
示例#3
0
    def rows(self):
        """Table rows for the report."""

        if not hasattr(self, "_rows"):
            rows = []
            root = self.doc.root
            for node in root.xpath(self.control.xpath, **self.XPATH_OPTS):
                parent = node.getparent()
                tag = parent.tag
                node_id = str(parent.get(self.CDR_ID))
                row = (
                    Reporter.Cell(self.doc.cdr_id, center=True),
                    self.doc.title,
                    tag,
                    Reporter.Cell(node_id, center=True),
                )
                rows.append(row)
            self._rows = rows
        return self._rows
示例#4
0
    def table_by_board(self):
        """Create the 'by board' flavor of the report."""

        boards = {}
        for meeting in self.meetings:
            if meeting.board.name not in boards:
                boards[meeting.board.name] = [meeting]
            else:
                boards[meeting.board.name].append(meeting)
        rows = []
        for board in sorted(boards):
            if rows:
                rows.append(["\xA0"])
            rows.append([Reporter.Cell(board, bold=True)])
            for meeting in boards[board]:
                if meeting.canceled:
                    meeting = Reporter.Cell(meeting, classes="strikethrough")
                rows.append([meeting])
        return Reporter.Table(rows, caption=self.caption)
示例#5
0
    def rows(self):
        """Sequence of table rows (empty if we have no matching docs)."""

        if not hasattr(self, "_rows"):
            self._rows = []
            if self.counts:
                for name in NewDocument.STATUSES:
                    cell = Reporter.Cell(self.counts.get(name, 0), right=True)
                    self._rows.append((name, cell))
        return self._rows
示例#6
0
        def html_row(self, summary_id, summary_title):
            """
            Construct an HTML report row for this match

            Pass:
              summary_id - unique integer for the CDR summary document ID
              summary_title - string for the summary's title

            Return:
              sequence of column values for the report's row
            """

            standard_wording = self.standard_wording and "Yes" or "No"
            return [
                summary_id,
                summary_title,
                self.text,
                Reporter.Cell(self.span),
                Reporter.Cell(standard_wording, classes="center"),
            ]
示例#7
0
 def row(self):
     """Assemble the report row for this summary."""
     if not hasattr(self, "_row"):
         self._row = [self.link, self.title]
         for markup_type in self.__control.types:
             count = self.__counts[markup_type]
             if count:
                 self._row.append(Reporter.Cell(count, center=True))
             else:
                 self._row.append("")
     return self._row
    def subtotals(self):
        """Row in the report table for this set's subtotals."""

        if not hasattr(self, "_subtotals"):
            subtotals = []
            for status in Control.STATUSES:
                subtotals.append(f"{status}={self.counts.get(status[0], 0)}")
            subtotals = "\xa0 ".join(subtotals)
            language = self.control.language
            subtotals = f"{language} names in this set:\xa0 {subtotals}"
            cell = Reporter.Cell(subtotals, center=True, colspan=3)
            self._subtotals = [cell]
        return self._subtotals
示例#9
0
 def build_tables(self):
     """Show the documents the user has locked."""
     fields = "c.dt_out", "t.name", "d.id", "d.title"
     query = Query("usr u", *fields).order(*fields[:3])
     query.join("checkout c", "c.usr = u.id")
     query.join("document d", "d.id = c.id")
     query.join("doc_type t", "t.id = d.doc_type")
     query.where("c.dt_in IS NULL")
     query.where(query.Condition("u.id", self.user.id))
     rows = []
     for dt_out, doc_type, doc_id, title in query.execute(self.cursor):
         doc_id = Reporter.Cell(doc_id, center=True)
         rows.append([str(dt_out)[:19], doc_type, doc_id, title])
     caption = f"Checked out by {self.user.fullname or self.user.name}"
     return Reporter.Table(rows, caption=caption, columns=self.COLUMNS)
示例#10
0
    def row(self):
        """Table row for the report."""

        if not hasattr(self, "_row"):
            ver_date = str(self.ver_date)[:10] if self.ver_date else ""
            self._row = (
                Reporter.Cell(self.doc_id, center=True),
                self.doc_title,
                Reporter.Cell(self.cre_user, center=True),
                Reporter.Cell(str(self.cre_date)[:10], center=True),
                Reporter.Cell(ver_date, center=True),
                Reporter.Cell(self.ver_user, center=True),
                Reporter.Cell(self.pv, center=True),
                Reporter.Cell("Y" if self.epv else "N", center=True),
            )
        return self._row
示例#11
0
 def indication_table(self):
     """Group the report by approval indication."""
     cols = "Approved Indication", "Drug Name", "Brand Name(s)"
     rows = []
     for indication in sorted(self.indications, key=str.lower):
         drugs = sorted(self.indications[indication])
         if len(drugs) > 1:
             name = Reporter.Cell(indication, rowspan=len(drugs))
         else:
             name = indication
         for drug in drugs:
             link = Reporter.Table.B.A(drug.cdr_id, href=drug.url)
             span = Reporter.Table.B.SPAN(f"{drug.name} (", link, ")")
             if name:
                 row = name, span, drug.brands or ""
             else:
                 row = span, drug.brands or ""
             rows.append(row)
             name = None
     return Reporter.Table(rows, columns=cols, caption=self.caption)
示例#12
0
 def build_tables(self):
     parms = {SESSION: self.session, REQUEST: "View", "full": "full"}
     ids = []
     rows = []
     for doc in FilterSet.get_filters(self.session):
         parms[DOCID] = doc.cdr_id
         url = f"EditFilter.py?{urlencode(parms)}"
         id_cell = Reporter.Cell(doc.cdr_id, href=url)
         ids.append((doc.id, id_cell, doc.title))
         rows.append((id_cell, doc.title))
     columns = (
         Reporter.Column("CDR ID", classes="id-col"),
         Reporter.Column("Filter Title", classes="title-col"),
     )
     caption = f"{len(rows):d} CDR Filters (Sorted By Title)"
     opts = dict(caption=caption, columns=columns, id="titlesort")
     opts["logger"] = self.logger
     tables = [Reporter.Table(rows, **opts)]
     rows = [(deepcopy(row[1]), row[2]) for row in sorted(ids)]
     opts["caption"] = f"{len(rows):d} CDR Filters (Sorted By CDR ID)"
     opts["id"] = "idsort"
     tables.append(Reporter.Table(rows, **opts))
     return tables
示例#13
0
    def build_tables(self):
        """Create the report tables the user requested.

        If none were requested, fall back to the form.
        """

        tables = []
        for agent_type in self.agent_types:
            query = self.create_query(agent_type)
            rows = []
            for row in query.execute(self.cursor).fetchall():
                query = self.Query("query_term_pub", "value")
                query.where(f"path = '{self.TYPE_PATH}'")
                query.where(query.Condition("doc_id", row.id))
                types = query.execute(self.cursor).fetchall()
                types = ", ".join([t.value for t in types])
                cells = []
                if self.include_id:
                    cells = [Reporter.Cell(row.id, center=True)]
                cells.append(row.title)
                cells.append(types)
                if self.include_fda_approval:
                    cells.append("Yes" if row.accelerated else "")
                    cells.append("Yes" if row.approved_in_children else "")
                if self.include_blank_column:
                    cells.append("")
                rows.append(cells)
            caption = f"{self.AGENT_TYPES[agent_type]} ({len(rows)})"
            table = Reporter.Table(rows, columns=self.cols, caption=caption)
            if not self.show_gridlines:
                table.node.set("class", "no-gridlines")
            tables.append(table)
        if tables:
            return tables
        else:
            self.show_form()
示例#14
0
    def table_by_date(self):
        """Create the 'by date' flavor of the report."""

        cols = "Date", "Day", "Time", "WebEx", "Board"
        rows = []
        prev = None
        for meeting in sorted(self.meetings):
            if prev and prev < (meeting.date.year, meeting.date.month):
                rows.append([Reporter.Cell("\xA0", colspan=len(cols))])
            prev = meeting.date.year, meeting.date.month
            classes = ["strikethrough"] if meeting.canceled else []
            center = classes + ["center"]
            row = (
                Reporter.Cell(meeting.date, classes=center),
                Reporter.Cell(meeting.day, classes=center),
                Reporter.Cell(meeting.time, classes=center),
                Reporter.Cell("Yes" if meeting.webex else "", classes=center),
                Reporter.Cell(meeting.board.name, classes=classes),
            )
            rows.append(row)
        return Reporter.Table(rows, columns=cols, caption=self.caption)
示例#15
0
 def link(self):
     """Cell containing a link to the QC report for this summary."""
     url = self.URL.format(self.id)
     return Reporter.Cell(self.id, href=url, center=True)
示例#16
0
    def to_table(self, columns, modules=False):
        """
        Create a table showing the board's metadata and comprenehsive reviews.

        Pass:
            columns - column headers for the table
            modules - True if we're showing modules

        Return:
            `Reporter.Table` object
        """

        if modules:
            docs = self.modules
            what = "modules"
        else:
            docs = self.summaries
            what = "summaries"
        opts = dict(
            caption="%s Editorial Board (%s)" % (self.name, what),
            sheet_name=self.name,
            columns=columns,
        )
        if "Complementary" in self.name:
            opts["sheet_name"] = "IACT" # name is too big
        if modules:
            opts["sheet_name"] += " (m)"
        rows = []
        for doc in sorted(docs):
            reviews = []
            have_actual = False
            i = len(doc.reviews)
            while i > 0:
                i -= 1
                review = doc.reviews[i]
                if self.__control.show_all:
                    reviews.insert(0, review)
                elif not have_actual and review.state == "Actual":
                    reviews.insert(0, review)
                    have_actual = True
            row = []
            if self.__control.show_id:
                row.append(Reporter.Cell(doc.doc_id))
            row.append(Reporter.Cell(doc.title))
            if reviews:
                review = reviews[0]
                row.extend([
                    review.date,
                    Reporter.Cell(review.state, classes="center"),
                    review.comment or ""
                ])
            else:
                row.extend(["", "", ""])
            rows.append(row)
            for review in reviews[1:]:
                row = []
                if self.__control.show_id:
                    row.append(Reporter.Cell(doc.doc_id))
                row.append(Reporter.Cell(doc.title))
                row.extend([
                    review.date,
                    Reporter.Cell(review.state, classes="center"),
                    review.comment or ""
                ])
                rows.append(row)
        return Reporter.Table(rows, **opts)
 def row(self):
     return (self.name,
             Reporter.Cell(str(self.date)[:19],
                           center=True), self.user)
示例#18
0
 def link(self):
     """Table cell for a link to this drug's QC report."""
     if not hasattr(self, "_link"):
         self._link = Reporter.Cell(self.cdr_id, href=self.url, center=True)
     return self._link