Exemple #1
0
    def content(self) -> Union[str, Dict[str, str], None]:
        """Reads localization files and returns text (for md) or dict (for yml) files.

        Infers template location from `localization_file` and `language` attributes.

        Raises:
            Key error if unknown
        """
        if self._content is None:
            if self.localization_file is None:
                self._content = {}
            else:
                if self.localization_file.endswith(".yml"):
                    self._content = read_localization_yml(
                        self.localization_file, self.language
                    )
                elif self.localization_file.endswith(".md"):
                    self._content = read_localization_markdown(
                        self.localization_file, self.language
                    )
                else:
                    raise KeyError(
                        "Unknown content file extension 'file'".format(
                            file=self.localization_file
                        )
                    )
        return self._content
Exemple #2
0
 def callback(self, *args, **kwargs):
     """
     """
     pars = kwargs["pars"]
     intro = read_localization_markdown(LOCALIZATION_FILE_1, self.language)
     detection_prob_str = ("{detection_probability:.0%}".format(
         detection_probability=kwargs["model"].detection_probability)
                           if kwargs["model"].detection_probability
                           is not None else "?")
     return [
         intro.format(
             total_infections=kwargs["model"].infected,
             initial_infections=pars.known_infected,
             detection_prob_str=detection_prob_str,
             current_hosp=pars.current_hospitalized,
             hosp_rate=pars.hospitalized.rate,
             S=pars.susceptible,
             market_share=pars.market_share,
             recovery_days=pars.recovery_days,
             r_naught=kwargs["model"].r_naught,
             doubling_time=kwargs["pars"].doubling_time,
             relative_contact_rate=pars.relative_contact_rate,
             r_t=kwargs["model"].r_t,
             doubling_time_t=kwargs["model"].doubling_time_t,
         )
     ]
Exemple #3
0
 def callback(self, *args, **kwargs) -> List[Any]:
     """Renders the parameter dependent values in the introduction markdown
     """
     pars = kwargs["pars"]
     tool_details = read_localization_markdown(LOCALIZATION_FILE_2,
                                               self.language)
     regions = "- " + "| \n".join(
         f"{key} = {value} "
         for key, value in self.defaults.region.__dict__.items()
         if key != "_s")
     return [
         tool_details.format(
             regions=regions,
             recovery_days=int(pars.doubling_time),
             doubling_time=pars.doubling_time,
             r_naught=kwargs["model"].r_naught,
             relative_contact_rate=pars.relative_contact_rate,
             doubling_time_t=kwargs["model"].doubling_time_t,
             r_t=kwargs["model"].r_t,
         ) if kwargs["show_tool_details"] else ""
     ]
Exemple #4
0
def latest_updates(language: str) -> List[ComponentMeta]:
    """Initializes the header dash html
    """
    content = read_localization_markdown(LOCALIZATION_FILE_2, language)

    return [Markdown(content)]
Exemple #5
0
def introducing_chime(language: str) -> List[ComponentMeta]:
    """Initializes the header dash html
    """
    content = read_localization_markdown(LOCALIZATION_FILE_1, language)

    return [Markdown(content)]