Ejemplo n.º 1
0
    def test_isoformat(self):
        td = Timedelta(days=6, minutes=50, seconds=3,
                       milliseconds=10, microseconds=10, nanoseconds=12)
        expected = 'P6DT0H50M3.010010012S'
        result = td.isoformat()
        assert result == expected

        td = Timedelta(days=4, hours=12, minutes=30, seconds=5)
        result = td.isoformat()
        expected = 'P4DT12H30M5S'
        assert result == expected

        td = Timedelta(nanoseconds=123)
        result = td.isoformat()
        expected = 'P0DT0H0M0.000000123S'
        assert result == expected

        # trim nano
        td = Timedelta(microseconds=10)
        result = td.isoformat()
        expected = 'P0DT0H0M0.00001S'
        assert result == expected

        # trim micro
        td = Timedelta(milliseconds=1)
        result = td.isoformat()
        expected = 'P0DT0H0M0.001S'
        assert result == expected

        # don't strip every 0
        result = Timedelta(minutes=1).isoformat()
        expected = 'P0DT0H1M0S'
        assert result == expected
Ejemplo n.º 2
0
    def test_isoformat(self):
        td = Timedelta(days=6, minutes=50, seconds=3,
                       milliseconds=10, microseconds=10, nanoseconds=12)
        expected = 'P6DT0H50M3.010010012S'
        result = td.isoformat()
        self.assertEqual(result, expected)

        td = Timedelta(days=4, hours=12, minutes=30, seconds=5)
        result = td.isoformat()
        expected = 'P4DT12H30M5S'
        self.assertEqual(result, expected)

        td = Timedelta(nanoseconds=123)
        result = td.isoformat()
        expected = 'P0DT0H0M0.000000123S'
        self.assertEqual(result, expected)

        # trim nano
        td = Timedelta(microseconds=10)
        result = td.isoformat()
        expected = 'P0DT0H0M0.00001S'
        self.assertEqual(result, expected)

        # trim micro
        td = Timedelta(milliseconds=1)
        result = td.isoformat()
        expected = 'P0DT0H0M0.001S'
        self.assertEqual(result, expected)

        # don't strip every 0
        result = Timedelta(minutes=1).isoformat()
        expected = 'P0DT0H1M0S'
        self.assertEqual(result, expected)
Ejemplo n.º 3
0
def generate_plot_task(
    plot_task_template: typing.Dict,
    start_time: pd.Timestamp,
    forecast_time: pd.Timedelta,
    data_source: typing.Dict,
) -> typing.Optional[typing.Dict]:
    """
    Generate plot task for GISET.

    Parameters
    ----------
    plot_task_template
    data_path

    Returns
    -------

    """
    data_path = get_data_path(data_source,
                              start_time=start_time,
                              forecast_time=forecast_time,
                              data_type="grib2/orig")

    if data_path is None:
        logger.warning("WARNING: data is not found", start_time, forecast_time)
        return None

    plot_task = plot_task_template.copy()
    for layer in plot_task["maplayer"]:
        layer["file_path"] = str(data_path)

    task = {
        'steps': [
            {
                'step_type': 'plotter',
                'type': 'ploto_gidat.plotter.meteor_draw_plotter',
                'plot_task': plot_task,
            },
            {
                'step_type': 'distributor',
                'type': 'ploto_gidat.distributor.giset_distributor',
                "username": data_source["username"],
                "user_id": data_source["user_id"],
                "routing_key": data_source["routing_key"],
                "test_ID": data_source["test_ID"],
                "meteor_type": plot_task["maplayer"][0]["meteor_type"],
                "start_time": start_time.isoformat(),
                "forecast_time": forecast_time.isoformat(),
            },
        ],
    }

    return task
Ejemplo n.º 4
0
 def to_tree(cls, node: pd.Timedelta, ctx):
     """Serialize timedelta to tree."""
     tree = {}
     tree["value"] = node.isoformat()
     return tree
Ejemplo n.º 5
0
 def to_yaml_tree(self, obj: pd.Timedelta, tag, ctx) -> str:
     """Convert to iso format string."""
     return obj.isoformat()