Add new values to the UI

This commit is contained in:
2020-07-17 12:54:50 +00:00
parent ec0b3c9eb1
commit cff381b831
6 changed files with 37 additions and 56 deletions

View File

@@ -13,6 +13,22 @@
{{ latestReading.PressureTemperature.toFixed(2) }}°F
</td>
</tr>
<tr *ngIf="latestReading.HeatIndex">
<td class="weather-current-header">
Heat Index
</td>
<td>
{{ latestReading.HeatIndex.toFixed(2) }}°F
</td>
</tr>
<tr *ngIf="latestReading.WindChill">
<td class="weather-current-header">
Wind Chill
</td>
<td>
{{ latestReading.WindChill.toFixed(2) }}°F
</td>
</tr>
<tr>
<td class="weather-current-header">
Humidity
@@ -21,6 +37,14 @@
{{ latestReading.Humidity.toFixed(2) }}%
</td>
</tr>
<tr>
<td class="weather-current-header">
Dew point
</td>
<td>
{{ latestReading.DewPoint.toFixed(2) }}°F
</td>
</tr>
<tr>
<td class="weather-current-header">
Pressure
@@ -28,7 +52,7 @@
<td>
{{ (latestReading.Pressure / 33.864 / 100).toFixed(2) }}"
<span *ngIf="pressureDifference !== null" class="pressure-trend-arrow" [ngClass]="rotationClass()" title="Trend: {{ pressureDifference.toFixed(1) }}"></span>
<span class="pressure-trend-arrow" [ngClass]="rotationClass()" title="Trend: {{ latestReading.PressureTrend.toFixed(1) }}"></span>
</td>
</tr>
<tr>

View File

@@ -1,11 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { WeatherReading } from 'src/app/models/weather/weather-reading';
import { WeatherService } from 'src/app/services/weather/weather.service';
import { WeatherValueType } from 'src/app/models/weather/weather-value-type';
import { WeatherValue } from 'src/app/models/weather/weather-value';
import * as moment from 'moment';
import * as regression from 'regression';
@Component({
selector: 'app-weather-current',
@@ -13,57 +8,28 @@ import * as regression from 'regression';
styleUrls: ['./weather-current.component.scss']
})
export class WeatherCurrentComponent implements OnInit {
public pressureDifference: number = null;
public latestReading: WeatherReading;
constructor(private weatherService: WeatherService) { }
ngOnInit() {
this.update();
setInterval(() => this.update(), 60000);
this.weatherService.getLatestReading().subscribe(r => this.latestReading = r);
}
async update() {
this.pressureDifference = null;
const end: moment.Moment = moment();
const start: moment.Moment = moment(end).subtract(3, 'hours');
const weatherData = await this.weatherService.getReadingValueHistory(WeatherValueType.Pressure, start, end);
if (!weatherData) {
return;
}
const points: [number, number][] = [];
weatherData.forEach((weatherValue: WeatherValue) => {
const point: [number, number] = [moment(weatherValue.timestamp).unix(), weatherValue.value / 100];
points.push(point);
});
const result = regression.linear(points, { precision: 10 });
const regressionPoints = result.points;
this.pressureDifference = regressionPoints[regressionPoints.length - 1][1] - regressionPoints[0][1];
}
rotationClass(): string {
if (!this.pressureDifference) {
const pressureDifference = this.latestReading.PressureTrend;
if (!pressureDifference) {
return '';
} else if (Math.abs(this.pressureDifference) <= 1.0) {
} else if (Math.abs(pressureDifference) <= 1.0) {
return '';
} else if (this.pressureDifference > 1.0 && this.pressureDifference <= 2.0) {
} else if (pressureDifference > 1.0 && pressureDifference <= 2.0) {
return 'up-low';
} else if (this.pressureDifference > 2.0) {
} else if (pressureDifference > 2.0) {
return 'up-high';
} else if (this.pressureDifference < -1.0 && this.pressureDifference >= -2.0) {
} else if (pressureDifference < -1.0 && pressureDifference >= -2.0) {
return 'down-low';
} else if (this.pressureDifference < -2.0) {
} else if (pressureDifference < -2.0) {
return 'down-high';
}
}

View File

@@ -16,4 +16,8 @@ export class WeatherReading {
Altitude: number;
SatelliteCount: number;
GpsTimestamp: Date;
WindChill: number;
HeatIndex: number;
DewPoint: number;
PressureTrend: number;
}