Table of Contents

Class WeatherFeedIndexer

Namespace
EncDotNet.S100.Collections.Weather
Assembly
EncDotNet.S100.Collections.dll

Indexes a WeatherFeedSource (#1075; design note weather-sources.md ยง6.3) into one online item per model or dataset: the latest run, as one download of the chosen parameters and hours.

public sealed class WeatherFeedIndexer : ICollectionSourceIndexer
Inheritance
WeatherFeedIndexer
Implements
Inherited Members

Remarks

  • GRIB2 models (NOMADS GRIB filter, AWS noaa-gfs-bdp-pds): runs are tried newest first, every CadenceHours back to a day, and the first whose .idx for the last chosen hour answers is the latest run, so a run still being published isn't offered. Its item downloads one request per forecast hour (the filter's subset, or the chosen fields' byte ranges from each file's .idx), appended into one GRIB2 file. The item carries the run (RunProperty), so a downloaded run is outdated once a newer one is listed, and a newer run's download replaces it.
  • Alerts (api.weather.gov): the alerts in force for the area's marine zones, read at each index (they are small) for their count and updated time, and downloaded as NWS GeoJSON.
  • ERDDAP: each dataset's info gives its axes and time coverage; the item downloads a NetCDF subset from now to the last chosen hour (or the dataset's last hours, when it has ended).

Each item carries the source's licence and attribution (LicenceProperty, AttributionProperty). With a downloads folder, pinned runs (Pin(EncCellDownloader, CollectionItem)) are listed as local items beside the latest, and a service that can't be reached lists its downloaded run instead (stale, with the error). Every request sends a User-Agent (UserAgent), as the NWS API requires. Weather sources are re-read on every index (no fingerprint): finding the latest run is the index.

Constructors

WeatherFeedIndexer(HttpClient, string?, TimeProvider?)

Creates an indexer.

public WeatherFeedIndexer(HttpClient httpClient, string? downloadsDirectory = null, TimeProvider? timeProvider = null)

Parameters

httpClient HttpClient

The client requests are made with.

downloadsDirectory string

The hosts' downloads root (pinned and downloaded runs are listed from it), or null.

timeProvider TimeProvider

The clock; the system clock when null.

Fields

AlertCountProperty

The item property holding how many alerts an alerts item has.

public const string AlertCountProperty = "alerts"

Field Value

string

RunsTried

How many runs back the latest run is looked for.

public const int RunsTried = 5

Field Value

int

Properties

UserAgent

The User-Agent sent when the client sets none; DefaultUserAgent by default.

public string UserAgent { get; init; }

Property Value

string

Methods

CanIndex(CollectionSource)

Returns true when this indexer handles source.

public bool CanIndex(CollectionSource source)

Parameters

source CollectionSource

Returns

bool

DescribeAsync(WeatherFeedSource, CancellationToken)

What feed's service has now (its latest run, the alerts in force, the datasets' titles), for the Add-to-Library dialog.

public Task<WeatherServiceSummary> DescribeAsync(WeatherFeedSource feed, CancellationToken cancellationToken = default)

Parameters

feed WeatherFeedSource
cancellationToken CancellationToken

Returns

Task<WeatherServiceSummary>

Exceptions

HttpRequestException

The service can't be reached.

DownloadFolderFor(WeatherFeedSource)

The managed folder, relative to the downloads root, a source's runs download into: one per source, e.g. weather/nomads.ncep.noaa.gov-3f2a9c1b.

public static string DownloadFolderFor(WeatherFeedSource feed)

Parameters

feed WeatherFeedSource

Returns

string

FindLatestRunAsync(WeatherFeedSource, CancellationToken)

The latest run of a GRIB2 source whose last chosen hour is published, newest first over RunsTried cycles; null when none is.

public Task<DateTimeOffset?> FindLatestRunAsync(WeatherFeedSource feed, CancellationToken cancellationToken = default)

Parameters

feed WeatherFeedSource
cancellationToken CancellationToken

Returns

Task<DateTimeOffset?>

Exceptions

HttpRequestException

The server can't be reached (as opposed to a run not being there).

GetFingerprintAsync(CollectionSource, CancellationToken)

Cheaply computes a fingerprint of the source's current state. When it equals a previous index's Fingerprint, that index is still valid. Returns null when the state cannot be determined (for example the source is unavailable).

public ValueTask<string?> GetFingerprintAsync(CollectionSource source, CancellationToken cancellationToken)

Parameters

source CollectionSource
cancellationToken CancellationToken

Returns

ValueTask<string>

Remarks

Always null: a weather source is re-read on every index.

IndexAsync(CollectionSource, IProgress<IndexProgress>?, CancellationToken)

Indexes source.

public ValueTask<SourceIndex> IndexAsync(CollectionSource source, IProgress<IndexProgress>? progress, CancellationToken cancellationToken)

Parameters

source CollectionSource
progress IProgress<IndexProgress>
cancellationToken CancellationToken

Returns

ValueTask<SourceIndex>

Pin(EncCellDownloader, CollectionItem)

Keeps the downloaded copy of item's run (a weather item, through its source's downloader) beside the latest, so a later run doesn't replace it: the copy is listed by the next index as a pinned, local item.

public static string? Pin(EncCellDownloader downloader, CollectionItem item)

Parameters

downloader EncCellDownloader
item CollectionItem

Returns

string

The pinned copy's download name, or null when the item has no downloaded copy.

Unpin(EncCellDownloader, CollectionItem)

Deletes a pinned copy (a IsPinned(CollectionItem) item); true when one was deleted.

public static bool Unpin(EncCellDownloader downloader, CollectionItem pinned)

Parameters

downloader EncCellDownloader
pinned CollectionItem

Returns

bool