Beispiel #1
0
async def plot_sensor(config: Config[t.Any, t.Any], plot: _AxesBase,
                      location_names: t.Dict[UUID, str],
                      **kwargs: t.Any) -> _AxesBase:
    locations = []
    if config.get_data is None:
        raise ValueError("You must provide a get_data function")
    async for deployment_id, query_results in config.get_data(**kwargs):
        if deployment_id == GLOBAL:
            name = "Global"
        else:
            try:
                deployment = await get_deployment_by_id(deployment_id)
            except IndexError:
                name = str(deployment_id)
                colour = None
            else:
                name = deployment.name or str(deployment_id)
                colour = deployment.colour
        # Mypy currently doesn't understand callable fields on datatypes: https://github.com/python/mypy/issues/5485
        points = [dp
                  async for dp in config.clean(query_results)]  # type: ignore
        if not points:
            continue
        locations.append(name)
        x, y = zip(*points)
        plot.set_title(config.title)
        plot.set_ylabel(config.ylabel)
        if config.draw is None:
            raise ValueError("You must provide a get_data function")
        config.draw(plot, x, y, colour)
    plot.legend(locations)
    return plot
Beispiel #2
0
async def plot_sensor(config: Config, plot: _AxesBase,
                      location_names: t.Dict[UUID, str], **kwargs):
    locations = []
    async for deployment, query_results in get_data_by_deployment(
            sensor_name=config.sensor_name, **kwargs):
        # Mypy currently doesn't understand callable fields on datatypes: https://github.com/python/mypy/issues/5485
        points = [dp
                  async for dp in config.clean(query_results)]  # type: ignore
        if not points:
            continue
        locations.append(deployment)
        x, y = zip(*points)
        plot.set_title(config.title)
        plot.set_ylabel(config.ylabel)
        plot.plot_date(x, y, f"-", xdate=True)
    plot.legend([location_names.get(l, l) for l in locations])
    return plot