def formdata_to_payload(cls, form_dict):
        """Formats the result of a forecast webform into an API payload.

        Parameters
        ----------
        form_dict:  dict
            The posted form data parsed into a dict.
        Returns
        -------
        dictionary
            Form data formatted to the API spec.
        """
        fx_metadata = {}
        fx_metadata = {
            key: form_dict[key]
            for key in cls.direct_keys if form_dict.get(key) is not None
        }
        fx_metadata.update(utils.get_location_id(form_dict))
        fx_metadata['issue_time_of_day'] = utils.parse_hhmm_field_from_form(
            form_dict, 'issue_time_of_day')
        fx_metadata['lead_time_to_start'] = utils.parse_timedelta_from_form(
            form_dict, 'lead_time_to_start')
        fx_metadata['run_length'] = utils.parse_timedelta_from_form(
            form_dict, 'run_length')
        fx_metadata['interval_length'] = utils.parse_timedelta_from_form(
            form_dict, 'interval_length')
        return fx_metadata
    def formdata_to_payload(cls, form_dict):
        """Converts an aggregate form submission dict to an api post payload.

        Parameters
        ----------
        form_dict: dict
            The posted form data parsed into a dict.

        Returns
        -------
        dict
            Form data formatted to API spec.
        """
        formatted = {
            key: form_dict[key]
            for key in cls.direct_keys if form_dict.get(key) is not None
        }
        formatted['interval_length'] = utils.parse_timedelta_from_form(
            form_dict, 'interval_length')
        return formatted
    def formdata_to_payload(cls, form_dict):
        """Formats the result of a observation webform into an API payload.

        Parameters
        ----------
        form_dict:  dict
            The posted form data parsed into a dict.
        Returns
        -------
        dictionary
            Form data formatted to the API spec.
        """
        obs_metadata = {}
        obs_metadata = {
            key: form_dict[key]
            for key in cls.direct_keys if form_dict.get(key) is not None
        }
        if obs_metadata['uncertainty'] == '':
            obs_metadata['uncertainty'] = None
        obs_metadata['interval_length'] = utils.parse_timedelta_from_form(
            form_dict, 'interval_length')
        return obs_metadata
Пример #4
0
def test_parse_timedelta_from_form(data, root, expected):
    assert utils.parse_timedelta_from_form(data, root) == expected