Skip to content

Commit

Permalink
Merge pull request #832 from stadtnavi/feat/weather-station-values
Browse files Browse the repository at this point in the history
feat(weather-station): fix existing and add more sensors
  • Loading branch information
andreashelms authored Dec 3, 2024
2 parents fa3e8a8 + 57f6626 commit 29a5e7e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 55 deletions.
86 changes: 58 additions & 28 deletions app/component/map/sidebar/WeatherStationContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@ import PropTypes from 'prop-types';
import React from 'react';
import { FormattedMessage, intlShape } from 'react-intl';
import moment from 'moment-timezone';
import { isNumber } from 'lodash';
import SidebarContainer from './SidebarContainer';

const makeValue = number => {
return {
sensorValue: number,
sensorUnit: '°C',
};
};

/*
0 = kein Niederschlag
60 = Regen
Expand Down Expand Up @@ -77,15 +69,18 @@ const translateRoadCondition = num => {
const WeatherStationContent = ({ match }, { intl }) => {
const {
airTemperatureC,
airPressureRelhPa,
moisturePercentage,
precipitationType,
roadCondition,
roadTemperatureC,
icePercentage,
updatedAt,
address,
} = match.location.query;

const airTemperatureSensor = makeValue(airTemperatureC);
const roadTemperatureSensor = makeValue(roadTemperatureC);
const isValidValue = value => !Number.isNaN(value) && value !== undefined;

return (
<SidebarContainer
name={intl.formatMessage({
Expand All @@ -97,7 +92,7 @@ const WeatherStationContent = ({ match }, { intl }) => {
>
<table className="component-list">
<tbody>
{airTemperatureSensor && (
{isValidValue(airTemperatureC) && (
<tr>
<td>
<FormattedMessage
Expand All @@ -107,13 +102,36 @@ const WeatherStationContent = ({ match }, { intl }) => {
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>{`${Math.round(airTemperatureC)} °C`}</td>
</tr>
)}
{isValidValue(airPressureRelhPa) && (
<tr>
<td>
<FormattedMessage
id="air-pressure"
defaultMessage="Air pressure"
>
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>{`${Math.round(airPressureRelhPa)} hPa`}</td>
</tr>
)}
{isValidValue(moisturePercentage) && (
<tr>
<td>
{`${Math.round(airTemperatureSensor.sensorValue)}
${airTemperatureSensor.sensorUnit}`}
<FormattedMessage
id="air-moisture"
defaultMessage="Air moisture"
>
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>{`${Math.round(moisturePercentage)} %`}</td>
</tr>
)}
{roadTemperatureSensor && (
{isValidValue(roadTemperatureC) && (
<tr>
<td>
<FormattedMessage
Expand All @@ -123,13 +141,25 @@ const WeatherStationContent = ({ match }, { intl }) => {
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>{`${Math.round(roadTemperatureC)} °C`}</td>
</tr>
)}
{isValidValue(roadCondition) && (
<tr>
<td>
<FormattedMessage id="condition" defaultMessage="Condition">
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>
{`${Math.round(roadTemperatureSensor.sensorValue)}
${roadTemperatureSensor.sensorUnit}`}
<FormattedMessage
id={translateRoadCondition(Number(roadCondition))}
defaultMessage={translateRoadCondition(Number(roadCondition))}
/>
</td>
</tr>
)}
{isNumber(precipitationType) && (
{isValidValue(precipitationType) && (
<tr>
<td>
<FormattedMessage
Expand All @@ -141,25 +171,25 @@ const WeatherStationContent = ({ match }, { intl }) => {
</td>
<td>
<FormattedMessage
id={translatePrecipitation(precipitationType)}
defaultMessage={translatePrecipitation(precipitationType)}
id={translatePrecipitation(Number(precipitationType))}
defaultMessage={translatePrecipitation(
Number(precipitationType),
)}
/>
</td>
</tr>
)}
{isNumber(roadCondition) && (
{isValidValue(icePercentage) && (
<tr>
<td>
<FormattedMessage id="condition" defaultMessage="Condition">
<FormattedMessage
id="ice-probability"
defaultMessage="Ice probability"
>
{(...content) => `${content}:`}
</FormattedMessage>
</td>
<td>
<FormattedMessage
id={translateRoadCondition(roadCondition)}
defaultMessage={translateRoadCondition(roadCondition)}
/>
</td>
<td>{`${Math.round(icePercentage)} %`}</td>
</tr>
)}
{updatedAt && (
Expand All @@ -168,7 +198,7 @@ const WeatherStationContent = ({ match }, { intl }) => {
<FormattedMessage
id="last-updated"
defaultMessage="Last updated"
values={{ time: moment(updatedAt).format('LT') || '' }}
values={{ time: moment(updatedAt).format('LLL') || '' }}
/>
</td>
</tr>
Expand Down
6 changes: 6 additions & 0 deletions app/component/map/tile-layer/TileLayerContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,12 @@ class TileLayerContainer extends GridLayer {
) {
const {
airTemperatureC,
airPressureRelhPa,
moisturePercentage,
precipitationType,
roadCondition,
roadTemperatureC,
icePercentage,
updatedAt,
address,
} = this.state.selectableTargets[0].feature.properties;
Expand All @@ -446,9 +449,12 @@ class TileLayerContainer extends GridLayer {
lat,
lng,
airTemperatureC,
airPressureRelhPa,
moisturePercentage,
precipitationType,
roadCondition,
roadTemperatureC,
icePercentage,
updatedAt,
address,
},
Expand Down
60 changes: 33 additions & 27 deletions app/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ const translations = {
'address-or-stop': 'Adresse oder Haltestelle',
agency: 'Betreiber',
'air-temperature': 'Lufttemperatur',
'air-pressure': 'Luftdruck',
'air-moisture': 'Luftfeuchtigkeit',
'ice-probability': 'Eisprozent',
airplane: 'Flug',
'airplane-with-route-number': 'Flug {routeNumber}',
'airport-check-in': 'Falls Sie sich noch nicht im voraus eingecheckt haben, tun Sie dies direkt nach der Ankunft.',
Expand Down Expand Up @@ -977,11 +980,11 @@ const translations = {
precipitation: 'Niederschlag',
'precipitation-hail': 'Hagel',
'precipitation-icy-rain': 'Eisregen',
'precipitation-none': 'keiner',
'precipitation-rain': 'Regen',
'precipitation-none': 'kein Niederschlag',
'precipitation-rain': 'flüssiger Niederschlag, z.B. Regen',
'precipitation-sleet': 'Schneeregen',
'precipitation-snow': 'Schnee',
'precipitation-unknown': 'unbekannt',
'precipitation-snow': 'fester Niederschlag, z.B. Schnee',
'precipitation-unknown': 'Unbekannt',
'prefer-walking': 'Gehen bevorzugen',
preview: 'Vorschau',
previous: 'Vorherige',
Expand All @@ -1002,15 +1005,15 @@ const translations = {
'return-scooter-to': 'Den Scooter zurückgeben:',
'return-car-to': 'Carsharing-Fahrzeug zurückgeben:',
'right-now': 'Jetzt',
'road-condition-dry': 'trocken',
'road-condition-dry': 'Trocken',
'road-condition-frosty': 'Frost/Reif',
'road-condition-icy': 'Eis',
'road-condition-moist': 'feucht',
'road-condition-moist-salty': 'feucht mit Salz',
'road-condition-snowy': 'Schneet',
'road-condition-unknown': 'unbekannt',
'road-condition-wet': 'nass',
'road-condition-wet-salty': 'nass mit Salz',
'road-condition-moist': 'Feucht',
'road-condition-moist-salty': 'Feucht mit Salz',
'road-condition-snowy': 'Schnee',
'road-condition-unknown': 'Unbekannt',
'road-condition-wet': 'Nass',
'road-condition-wet-salty': 'Nass mit Salz',
'road-temperature': 'Straßentemperatur',
'road-weather': 'Straßenwetter',
route: 'Linie',
Expand Down Expand Up @@ -1403,6 +1406,9 @@ const translations = {
'add-work': 'Add work',
'additional-info': 'Hier werden Informationen erscheinen...',
'air-temperature': 'Air temperature',
'air-pressure': 'Air pressure',
'air-moisture': 'Air moisture',
'ice-probability': 'Ice probability',
'alert:bikerental:free-floating-drop-off':
'Destination is not a designated drop-off area. Rental cannot be completed here. Please check terms & conditions for additional fees.',
all: 'All',
Expand Down Expand Up @@ -1965,13 +1971,13 @@ const translations = {
'platform-short-no-num': 'Plat.',
position: 'Position',
precipitation: 'Precipitation',
'precipitation-hail': 'hail',
'precipitation-icy-rain': 'sleet',
'precipitation-none': 'none',
'precipitation-rain': 'rain',
'precipitation-sleet': 'sleet',
'precipitation-snow': 'snow',
'precipitation-unknown': 'unknown',
'precipitation-hail': 'Hail',
'precipitation-icy-rain': 'Freezing rain',
'precipitation-none': 'No precipitation',
'precipitation-rain': 'Liquid precipitation, e.g. rain',
'precipitation-sleet': 'Sleet',
'precipitation-snow': 'Solid precipitation, e.g. snow',
'precipitation-unknown': 'Unknown',
'prefer-walking': 'Prefer walking',
preview: 'Preview',
previous: 'Previous',
Expand All @@ -1994,15 +2000,15 @@ const translations = {
'return-bicycle-to': 'Return the bike:',
'return-scooter-to': 'Return the kick scooter:',
'right-now': 'Right now',
'road-condition-dry': 'dry',
'road-condition-frosty': 'frost',
'road-condition-icy': 'icy',
'road-condition-moist': 'moist',
'road-condition-moist-salty': 'moist/salty',
'road-condition-snowy': 'snow',
'road-condition-unknown': 'unknown',
'road-condition-wet': 'wet',
'road-condition-wet-salty': 'wet/salty',
'road-condition-dry': 'Dry',
'road-condition-frosty': 'Frost',
'road-condition-icy': 'Ice',
'road-condition-moist': 'Humid',
'road-condition-moist-salty': 'Humid with salt',
'road-condition-snowy': 'Snow',
'road-condition-unknown': 'Unknown',
'road-condition-wet': 'Wet',
'road-condition-wet-salty': 'Wet with salt',
'road-temperature': 'Road temperature',
'road-weather': 'road weather',
route: 'Route',
Expand Down

0 comments on commit 29a5e7e

Please sign in to comment.