예제 #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
예제 #2
0
 def plain_table(self):
     """Simplest report, showing all of the approval indications."""
     if not hasattr(self, "_plain_table"):
         rows = [[indication] for indication in self.all_indications]
         cols = ["Full List of Drug Indications"]
         self._plain_table = Reporter.Table(rows, columns=cols)
     return self._plain_table
예제 #3
0
 def build_tables(self):
     """Serve up the table."""
     query = db.Query("session s", *self.FIELDS).order("s.last_act")
     query.join("usr u", "u.id = s.usr")
     query.where("s.ended IS NULL")
     rows = query.execute(self.cursor).fetchall()
     desc = self.cursor.description
     cols = [d[0].replace("_", " ").title() for d in desc]
     return Reporter.Table(rows, columns=cols)
예제 #4
0
    def table(self):
        """Status counts table (or None if we have no matching documents)."""

        if not hasattr(self, "_table"):
            self._table = None
            if self.rows:
                opts = dict(caption=self.name, columns=self.COLUMNS)
                self._table = Reporter.Table(self.rows, **opts)
        return self._table
예제 #5
0
    def table(self):
        """Create the table for the document's internal links."""

        if not hasattr(self, "_table"):
            self._table = None
            if self.rows:
                caption = f"Links for CDR{self.doc.id} ({self.doc.title})"
                opts = dict(columns=self.COLUMNS, caption=caption)
                self._table = Reporter.Table(self.rows, **opts)
        return self._table
예제 #6
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
예제 #7
0
    def drug_table(self):
        """Report grouping the information by drug."""

        if self.include_brands:
            cols = "CDR ID", "Drug Name (Brand Name)", "Approved Indication(s)"
        else:
            cols = "CDR ID", "Drug Name", "Approved Indication(s)"
        rows = []
        for drug in self.drugs:
            if self.include_brands and drug.brands:
                name = Reporter.Table.B.SPAN(drug.name, drug.brand_span)
            else:
                name = drug.name
            row = drug.link, name, drug.indications
            rows.append(row)
        return Reporter.Table(rows, columns=cols, caption=self.caption)
    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
예제 #9
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)
예제 #10
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)
예제 #11
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)
예제 #12
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()
예제 #13
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 build_tables(self):
        """Assemble the table for the report."""

        opts = dict(caption=self.caption, columns=self.columns)
        return Reporter.Table(self.rows, **opts)