예제 #1
0
 def load(input: Dict) -> "Cohort":
     if input["output_type"] == "patients":
         return Cohort(input["name"], input["name"],
                       read_data_frame(input["output_path"]))
     else:
         return Cohort(
             input["name"],
             "subjects with event {}".format(input["name"]),
             read_data_frame(input["population_path"]),
             read_data_frame(input["output_path"]),
         )
예제 #2
0
    def from_json(json_content: Dict) -> "SingleTable":
        """
        Build single table from metadata.

        Parameters
        ----------
        json_content : Dict, single table part in metadata.

        See Also
        --------
        FlatTableCollection.from_json(json_file) : FlatTableCollection.
        FlatTable.from_json(json_content, single_tables) : FlatTable.

        Notes
        -----
        Generally, this method is called by FlatTableCollection.from_json(json_file).
        We got a single table by FlatTable.single_tables.get(single_table_name).
        """
        path = "{}/{}".format(json_content["output_path"],
                              json_content["output_table"])
        return SingleTable(
            json_content["output_table"],
            read_data_frame(path),
            json_content["output_table"],
        )
예제 #3
0
    def from_json(json_content: Dict,
                  single_tables: Dict[str, SingleTable]) -> "FlatTable":
        """
        Build flat table from metadata.

        Parameters
        ----------
        json_content : Dict, flat table part in metadata.
        single_tables: Dict, single tables in this flat table.

        See Also
        --------
        FlatTableCollection.from_json(json_file) : FlatTableCollection.
        SingleTable.from_json(json_content) : SingleTable.

        Notes
        -----
        Generally, this method is called by FlatTableCollection.from_json(json_file).
        We got a flat table by FlatTableCollection.get(flat_table_name).
        """
        path = "{}/{}".format(json_content["output_path"],
                              json_content["output_table"])
        return FlatTable(
            json_content["output_table"],
            read_data_frame(path),
            json_content["output_table"],
            json_content["join_keys"],
            single_tables,
        )
def compare_stats_patients_on_months(
    figure: Figure,
    his_patients: Dict[str, str],
    show=False,
    show_func=print,
    save_path=None,
    years: List[int] = None,
) -> Figure:
    """
    This method is used to compare histories of patients on months.

    Parameters
    ----------
    figure: matplotlib.figure.Figure, users can define it like plt.figure() or plt.gcf().
    his_patients: Dict, a dict of paths of patients stats
    show: {False, True}, optional,
        If show the pandas table of confidence degree, default first when optional.
    show_func: optional
        Function to show a pandas table, print by default.
    save_path: str, optional
       the HDFS path to persist the pandas table, None by default, the save data can be
       used in stat history api.
    years: a list of special years in which the data will be loaded, default is None.

    Examples
    --------
    This is an example to illustrate how to use the function in jupyter.

    >>> his = {"A":"/path/A", "B":"/path/B"}
    ... compare_stats_patients_on_months(plt.gcf(), his, show=True, show_func=display)
    ... plt.show()
    """
    data = {
        name: read_data_frame(path)
        for (name, path) in his_patients.items()
    }
    cohort = HistoryTable.build("Histories of patients",
                                "Histories of patients", data)
    return _compare_stats_each_year_on_months(
        figure,
        cohort,
        show=show,
        show_func=show_func,
        save_path=save_path,
        title="History of patients",
        ylabel="number of patients",
        years=years,
    )