Pushed new battery page
This commit is contained in:
parent
8d55d182d2
commit
c0a15a9950
@ -24,7 +24,7 @@ import { LoginComponent } from './login/login.component';
|
|||||||
import {environment} from '../environments/environment';
|
import {environment} from '../environments/environment';
|
||||||
import * as firebase from 'firebase/app';
|
import * as firebase from 'firebase/app';
|
||||||
import { ServiceWorkerModule } from '@angular/service-worker';
|
import { ServiceWorkerModule } from '@angular/service-worker';
|
||||||
import {LineChartModule} from '@swimlane/ngx-charts';
|
import {LineChartModule, NgxChartsModule} from '@swimlane/ngx-charts';
|
||||||
|
|
||||||
export const firebaseApp = firebase.initializeApp(environment.firebase);
|
export const firebaseApp = firebase.initializeApp(environment.firebase);
|
||||||
|
|
||||||
@ -55,6 +55,7 @@ export const firebaseApp = firebase.initializeApp(environment.firebase);
|
|||||||
MatProgressSpinnerModule,
|
MatProgressSpinnerModule,
|
||||||
MatSidenavModule,
|
MatSidenavModule,
|
||||||
MatToolbarModule,
|
MatToolbarModule,
|
||||||
|
NgxChartsModule,
|
||||||
ServiceWorkerModule.register('ngsw-worker.js', { enabled: false }),
|
ServiceWorkerModule.register('ngsw-worker.js', { enabled: false }),
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
@ -1,8 +1,38 @@
|
|||||||
<h1>BATTERY LEVEL: <span class="text-muted">{{batteryService.charging == null ? 'UNKNOWN' : batteryService.average}}</span></h1>
|
<h1>POWER WALL:
|
||||||
<mat-card>
|
<span *ngIf="batteryService.batteries.length" class="text-muted">{{batteryService.average * 100}}%</span>
|
||||||
<h3>EMULATOR: <span class="text-muted">75%</span></h3>
|
<span *ngIf="!batteryService.batteries.length" class="text-muted">UNKNOWN</span>
|
||||||
<div>
|
</h1>
|
||||||
<mat-icon style="font-size: 128px; height:128px; width:128px">{{batteryService.icon}}</mat-icon>
|
<div class="d-flex flex-column flex-md-row">
|
||||||
<i class="wi wi-fw wi-thermometer-exterior"></i> {{tempHist[tempHist.length - 1]}} °C
|
<div style="overflow: auto">
|
||||||
|
<ngx-charts-bar-vertical
|
||||||
|
[results]="batteryService.percentageData"
|
||||||
|
[scheme]="airScheme"
|
||||||
|
[view]="[400, 200]"
|
||||||
|
[xAxis]="true"
|
||||||
|
[yAxis]="true"
|
||||||
|
[yScaleMin]="0"
|
||||||
|
[yScaleMax]="100"
|
||||||
|
></ngx-charts-bar-vertical>
|
||||||
</div>
|
</div>
|
||||||
|
<div style="overflow: auto">
|
||||||
|
<ngx-charts-bar-vertical
|
||||||
|
[results]="batteryService.temperatureData"
|
||||||
|
[scheme]="fireScheme"
|
||||||
|
schemeType="linear"
|
||||||
|
[view]="[400, 200]"
|
||||||
|
[xAxis]="true"
|
||||||
|
[yAxis]="true"
|
||||||
|
[yScaleMin]="0"
|
||||||
|
[yScaleMax]="100"
|
||||||
|
></ngx-charts-bar-vertical>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<mat-card *ngFor="let b of batteryService.batteries" class="mt-3">
|
||||||
|
{{b.name}}
|
||||||
|
<br>
|
||||||
|
{{b.history[0].percentage * 100}}%
|
||||||
|
<br>
|
||||||
|
{{b.history[0].temp}} °C
|
||||||
|
<br>
|
||||||
|
Charging: {{b.history[0].charging}}
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
@ -1,17 +1,25 @@
|
|||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {BatteryService} from './battery.service';
|
import {BatteryService} from './battery.service';
|
||||||
import {firebaseApp} from '../app.module';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-batterys',
|
selector: 'app-batterys',
|
||||||
templateUrl: './battery.component.html'
|
templateUrl: './battery.component.html'
|
||||||
})
|
})
|
||||||
export class BatteryComponent {
|
export class BatteryComponent {
|
||||||
tempHist = [];
|
|
||||||
|
|
||||||
constructor(public batteryService: BatteryService) {
|
airScheme = {
|
||||||
firebaseApp.firestore().collection('Battery').doc('TEMP').onSnapshot(snap => {
|
name: 'air',
|
||||||
this.tempHist.push(Math.round(snap.get('temp') * 10) / 10);
|
selectable: true,
|
||||||
})
|
group: 'Continuous',
|
||||||
}
|
domain: ['#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6f6', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b']
|
||||||
|
};
|
||||||
|
|
||||||
|
fireScheme = {
|
||||||
|
name: 'flame',
|
||||||
|
selectable: false,
|
||||||
|
group: 'Continuous',
|
||||||
|
domain: ['#00deff', '#3db0ff', '#a274d7', '#c42576', '#9f0000']
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(public batteryService: BatteryService) { }
|
||||||
}
|
}
|
||||||
|
@ -1,36 +1,56 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
|
import {firebaseApp} from '../app.module';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class BatteryService {
|
export class BatteryService {
|
||||||
percentage: number[] = [0];
|
readonly firestore;
|
||||||
charging?: boolean;
|
|
||||||
|
|
||||||
get average() {
|
average = 0;
|
||||||
return this.percentage.reduce((acc, battery) => acc + battery, 0) / this.percentage.length;
|
temperatureData = [];
|
||||||
|
percentageData = [];
|
||||||
|
batteries = [];
|
||||||
|
last: Date;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.firestore = firebaseApp.firestore();
|
||||||
|
this.firestore.settings({timestampsInSnapshots: true});
|
||||||
|
this.firestore.collection('Battery').doc('TEMP').onSnapshot(snap => {
|
||||||
|
this.last = new Date();
|
||||||
|
|
||||||
|
let data = snap.data();
|
||||||
|
this.batteries = Object.keys(data).map(key => ({name: key, history: data[key].reverse()}));
|
||||||
|
this.average = this.batteries.reduce((acc, battery) => acc + battery.history[0].percentage, 0) / this.batteries.length;
|
||||||
|
this.percentageData = this.batteries.map(battery => ({name: battery.name, value: battery.history[0].percentage * 100}));
|
||||||
|
this.temperatureData = this.batteries.map(battery => ({name: battery.name, value: Math.round(battery.history[0].temp * 10) / 10}));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get icon() {
|
get icon() {
|
||||||
if (this.charging == null) return 'battery_unknown';
|
if (!this.batteries.length) return 'battery_alert';
|
||||||
|
if (!this.last || this.last.getTime() < new Date().setMinutes(new Date().getMinutes() - 2).getTime()) return 'battery_warn';
|
||||||
|
|
||||||
|
return 'battery_20';
|
||||||
|
|
||||||
let temp = 'battery';
|
let temp = 'battery';
|
||||||
if (this.charging) temp += '_charging';
|
//if (this.batteries.length) temp += '_charging';
|
||||||
|
|
||||||
let average = this.average;
|
if (this.average <= 20) {
|
||||||
if (average <= 20) {
|
|
||||||
temp += '_20';
|
temp += '_20';
|
||||||
} else if (average <= 30) {
|
} else if (this.average <= 30) {
|
||||||
temp += '_30';
|
temp += '_30';
|
||||||
} else if (average <= 50) {
|
} else if (this.average <= 50) {
|
||||||
temp += '_50';
|
temp += '_50';
|
||||||
} else if (average <= 60) {
|
} else if (this.average <= 60) {
|
||||||
temp += '_60';
|
temp += '_60';
|
||||||
} else if (average <= 80) {
|
} else if (this.average <= 80) {
|
||||||
temp += '_80';
|
temp += '_80';
|
||||||
} else if (average <= 90) {
|
} else if (this.average <= 90) {
|
||||||
temp += '_90';
|
temp += '_90';
|
||||||
} else if (average > 90) {
|
} else if (this.average > 90) {
|
||||||
temp += 'full'
|
temp += 'full'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,12 @@ html, body {
|
|||||||
background-color: #2F323A;
|
background-color: #2F323A;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ngx-charts {
|
||||||
|
text {
|
||||||
|
fill: #ffffff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.center {
|
.center {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
|
Loading…
Reference in New Issue
Block a user