示例#1
0
    def callback(self, *args, **kwargs) -> List[Any]:
        """Renders the parameter dependent plots and tables
        """
        pars = kwargs.get("pars")
        projection_admits, census_df = self._build_frames(**kwargs)

        # Create admissions figure
        admissions_data = plot_dataframe(
            projection_admits.head(pars.n_days - 10), max_y_axis=pars.max_y_axis,
        )
        # Create admissions table data
        if kwargs["as_date"]:
            projection_admits.index = projection_admits.index.strftime("%b, %d")
        admissions_table_data = (
            df_to_html_table(projection_admits, data_only=True, n_mod=7)
            if kwargs["show_tables"]
            else None
        )

        # Create census figure
        census_data = plot_dataframe(
            census_df.head(pars.n_days - 10), max_y_axis=pars.max_y_axis
        )
        # Create admissions table data
        if kwargs["as_date"]:
            census_df.index = census_df.index.strftime("%b, %d")
        census_table_data = (
            df_to_html_table(census_df, data_only=True, n_mod=7)
            if kwargs["show_tables"]
            else None
        )

        return [admissions_data, admissions_table_data, census_data, census_table_data]
def prepare_visualization_group(df: DataFrame = None, **kwargs) -> List[Any]:
    """Creates plot, table and download link for data frame.
    """
    result = [{}, None, None]
    if df is not None and isinstance(df, DataFrame):
        plot_data = plot_dataframe(
            df.dropna().set_index("date").drop(columns=["day"]),
            max_y_axis=kwargs.get("max_y_axis", None),
        )

        table = (
            df_to_html_table(
                build_table(
                    df=df,
                    labels=kwargs.get("labels", df.columns),
                    modulo=kwargs.get("table_mod", 7),
                ),
                format={
                    float: int,
                    (date, datetime): lambda d: d.strftime(DATE_FORMAT),
                },
            )
            # if kwargs.get("show_tables", None)
            # else None
        )

        csv = build_csv_download(df)
        result = [plot_data, table, csv]

    return result
示例#3
0
def prepare_visualization_group(df: DataFrame = None, **kwargs) -> List[Any]:
    """Creates plot, table and download link for data frame.

    Arguments:
        df: The Dataframe to plot
        content: Dict[str, str]
            Mapping for translating columns and index.
        labels: List[str]
            Columns to display
        table_mod: int
            Displays only each `table_mod` row in table

    """
    result = [{}, None, None]
    if df is not None and isinstance(df, DataFrame):

        date_column = "date"
        day_column = "day"

        # Translate column and index if specified
        content = kwargs.get("content", None)
        if content:
            columns = {col: content[col] for col in df.columns if col in content}
            index = (
                {df.index.name: content[df.index.name]}
                if df.index.name and df.index.name in content
                else None
            )
            df = df.rename(columns=columns, index=index)
            date_column = content.get(date_column, date_column)
            day_column = content.get(day_column, day_column)

        plot_data = plot_dataframe(
            df.dropna().set_index(date_column).drop(columns=[day_column])
        )

        # translate back for backwards compability of build_table
        column_map = {day_column: "day", date_column: "date"}
        table = (
            df_to_html_table(
                build_table(
                    df=df.rename(columns=column_map),
                    labels=kwargs.get("labels", df.columns),
                    modulo=kwargs.get("table_mod", 7),
                ),
                formats={
                    float: int,
                    (date, datetime): lambda d: d.strftime(DATE_FORMAT),
                },
            )
            # if kwargs.get("show_tables", None)
            # else None
        )

        # Convert columnnames to lowercase
        column_map = {col: col.lower() for col in df.columns}
        csv = build_csv_download(df.rename(columns=column_map))
        result = [plot_data, table, csv]

    return result
示例#4
0
    def callback(self, *args, **kwargs) -> List[Any]:
        """Renders the parameter dependent plots and tables
        """
        pars = kwargs["pars"]

        if kwargs["show_additional_projections"]:
            title = self.content["infected-v-revovered-title"]

            time_evolution = self._build_frame(**kwargs)

            time_evolution_data = plot_dataframe(
                time_evolution.drop(columns=self.content["susceptible"]),
                max_y_axis=pars.max_y_axis,
            )

            children = [
                H4(title, id="infected-v-revovered-title"),
                Graph(figure=time_evolution_data,
                      id="infected-v-revovered-graph"),
            ]

            if kwargs["show_tables"]:
                if kwargs["as_date"]:
                    time_evolution.index = time_evolution.index.strftime(
                        "%b, %d")
                time_evolution_table_data = (df_to_html_table(
                    time_evolution, data_only=True, n_mod=7)
                                             if kwargs["show_tables"] else {})
                children.append(
                    Table(time_evolution_table_data,
                          id="infected-v-revovered-table"))

        else:
            children = []

        return [children]