Skip to content

Commit

Permalink
Add wind speed color coding and 30m average
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 28, 2024
1 parent 83bc26e commit 4c6f2ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/components/APITable/APIStatusText/APIStatusText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type APIStatusTextProps = {
defaultTooltipText?: string;
children: React.ReactNode;
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
color?: string;
};

export default function APIStatusText(props: APIStatusTextProps) {
Expand All @@ -26,6 +27,7 @@ export default function APIStatusText(props: APIStatusTextProps) {
defaultTooltipText,
children,
size = 'sm',
color,
} = props;

const tooltipText = React.useMemo(() => {
Expand All @@ -48,6 +50,7 @@ export default function APIStatusText(props: APIStatusTextProps) {
span
data-nodata={nodata}
data-error={error}
c={!nodata && !error ? color : 'undefined'}
>
{children}
</Text>
Expand Down
23 changes: 21 additions & 2 deletions src/components/APITables/WeatherTable/WeatherTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type WeatherResponse = {
wind_speed_avg: number;
wind_speed_max: number;
wind_speed_avg_5m: number;
wind_speed_avg_30m: number;
wind_dir_avg_5m: number;
wind_gust_5m: number;
relative_humidity: number;
Expand All @@ -34,6 +35,19 @@ type WeatherResponse = {
station: string;
}[];

function colourWindSpeed(speed: number | undefined) {
if (speed === undefined) return null;

let color: string | undefined = undefined;
if (speed >= 35) {
color = 'red.8';
} else if (speed >= 30) {
color = 'yellow.8';
}

return <APIStatusText color={color}>{speed.toFixed(1)} mph</APIStatusText>;
}

export default function WeatherTable() {
const [weather, , noData, refresh] = useAPICall<WeatherResponse>(
'/weather/report?delta_time=600&last=true',
Expand Down Expand Up @@ -76,10 +90,15 @@ export default function WeatherTable() {
value: weather?.[0]?.wind_speed_avg_5m.toFixed(1),
unit: ' mph',
},
{
key: 'wind_speed_30m',
label: 'Wind Speed (30m avg.)',
value: colourWindSpeed(weather?.[0]?.wind_speed_avg_30m),
},
{
key: 'wind_gust',
label: 'Wind Gust (5m max.)',
value: weather?.[0]?.wind_gust_5m.toFixed(1),
label: 'Wind Gust (1m max.)',
value: weather?.[0]?.wind_speed_max.toFixed(1),
unit: ' mph',
},
{
Expand Down

0 comments on commit 4c6f2ab

Please sign in to comment.