diff --git a/package-lock.json b/package-lock.json index 542e0f1..9a6d270 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1971,6 +1971,39 @@ "supports-color": "^5.3.0" } }, + "chart.js": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.7.3.tgz", + "integrity": "sha512-3+7k/DbR92m6BsMUYP6M0dMsMVZpMnwkUyNSAbqolHKsbIzH2Q4LWVEHHYq7v0fmEV8whXE0DrjANulw9j2K5g==", + "requires": { + "chartjs-color": "^2.1.0", + "moment": "^2.10.2" + } + }, + "chartjs-color": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.3.0.tgz", + "integrity": "sha512-hEvVheqczsoHD+fZ+tfPUE+1+RbV6b+eksp2LwAhwRTVXEjCSEavvk+Hg3H6SZfGlPh/UfmWKGIvZbtobOEm3g==", + "requires": { + "chartjs-color-string": "^0.6.0", + "color-convert": "^0.5.3" + }, + "dependencies": { + "color-convert": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-0.5.3.tgz", + "integrity": "sha1-vbbGnOZg+t/+CwAHzER+G59ygr0=" + } + } + }, + "chartjs-color-string": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.6.0.tgz", + "integrity": "sha512-TIB5OKn1hPJvO7JcteW4WY/63v6KwEdt6udfnDE9iCAZgy+V4SrbSxoIbTw/xkUIapjEI4ExGtD0+6D3KyFd7A==", + "requires": { + "color-name": "^1.0.0" + } + }, "chokidar": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.0.4.tgz", @@ -2147,8 +2180,7 @@ "color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, "colors": { "version": "1.1.2", @@ -4614,9 +4646,9 @@ "dev": true }, "handlebars": { - "version": "4.0.12", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.12.tgz", - "integrity": "sha512-RhmTekP+FZL+XNhwS1Wf+bTTZpdLougwt5pcgA1tuz6Jcx0fpH/7z0qd71RKnZHBCxIRBHfBOnio4gViPemNzA==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.0.tgz", + "integrity": "sha512-l2jRuU1NAWK6AW5qqcTATWQJvNPEwkM7NEKSiv/gqOsoSQbVoWyqVEY5GS+XPQ88zLNmqASRpzfdm8d79hJS+w==", "dev": true, "requires": { "async": "^2.5.0", @@ -4626,12 +4658,12 @@ }, "dependencies": { "async": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/async/-/async-2.6.1.tgz", - "integrity": "sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==", + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/async/-/async-2.6.2.tgz", + "integrity": "sha512-H1qVYh1MYhEEFLsP97cVKqCGo7KfCyTt6uEWqsTBr9SO84oK9Uwbyd/yCW+6rKJLHksBNUVWZDAjfS+Ccx0Bbg==", "dev": true, "requires": { - "lodash": "^4.17.10" + "lodash": "^4.17.11" } }, "source-map": { @@ -6821,6 +6853,11 @@ "minimist": "0.0.8" } }, + "moment": { + "version": "2.24.0", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz", + "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/package.json b/package.json index 772f007..2becbdb 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@angular/platform-browser": "^6.1.10", "@angular/platform-browser-dynamic": "^6.1.10", "@angular/router": "^6.1.10", + "chart.js": "^2.7.3", "core-js": "^2.6.3", "hammerjs": "^2.0.8", "rxjs": "^6.2.2", diff --git a/src/app/header/header.component.html b/src/app/header/header.component.html index a4f2b12..96dc1f9 100644 --- a/src/app/header/header.component.html +++ b/src/app/header/header.component.html @@ -7,20 +7,22 @@ @@ -28,7 +30,7 @@
+ class=" d-block img-fluid py-3 pl-3" alt="Kinsley image">
diff --git a/src/app/services/names.service.spec.ts b/src/app/services/names.service.spec.ts new file mode 100644 index 0000000..a83901b --- /dev/null +++ b/src/app/services/names.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { NamesService } from './names.service'; + +describe('NamesService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: NamesService = TestBed.get(NamesService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/names.service.ts b/src/app/services/names.service.ts new file mode 100644 index 0000000..4c88b34 --- /dev/null +++ b/src/app/services/names.service.ts @@ -0,0 +1,182 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class NamesService { + + constructor() { } + + convertNames(input, type) { + const convChart = [ + ['L1 - L2 Voltage', 'l1.l2.voltage'], + ['L2 - L3 Voltage', 'l2.l3.voltage'], + ['L3 - L1 Voltage', 'l3.l1.voltage'], + ['L1 - L0 Voltage', 'l1.l0.voltage'], + ['L2 - L0 Voltage', 'l2.l0.voltage'], + ['L3 - L0 Voltage', 'l3.l0.voltage'], + ['L1 Current', 'l1.current'], + ['L2 Current', 'l2.current'], + ['L3 Current', 'l3.current'], + ['Frequency', 'frequency'], + ['Total kW', 'total.kw'], + ['Percent of Rated kW', 'rate.kw'], + ['Total Power Factor', 'total.pf'], + ['L1 kW', 'l1.kw'], + ['L1 Power Factor', 'l1.pf'], + ['L2 kW', 'l2.kw'], + ['L2 Power Factor', 'l2.pf'], + ['L3 kW', 'l3.kw'], + ['L3 Power Factor', 'l3.pf'], + ['Total kVAR', 'total.kvar'], + ['L1 kVAR', 'l1.kvar'], + ['L2 kVAR', 'l2.kvar'], + ['L3 kVAR', 'l3.kvar'], + ['Total kVA', 'total.kva'], + ['L1 kVA', 'l1.kva'], + ['L2 kVA', 'l2.kva'], + ['L3 kVA', 'l3.kva'], + // 'Current Lead / Lag', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + ['Oil Pressure *', 'oil.pressure'], + ['Coolant Temperature *', 'coolant.temp'], + ['Engine Speed *', 'engine.rpm'], + ['Local Battery Voltage *', 'battery.voltage'], + ['Fuel Pressure *', 'fuel.pressure'], + ['Fuel Temperature *', 'fuel.temp'], + ['Fuel Rate *', 'fuel.rate'], + // 'Used Last Run *', + ['Coolant Pressure *', 'coolant.pressure'], + ['Coolant Level *', 'coolant.level'], + ['Lube Oil Temperature *', 'oil.temp'], + ['Oil Level *', 'oil.level'], + ['Crankcase Pressure *', 'crankcase.pressure'], + ['Ambient Temperature *', 'ambient.temp'], + ['ECM Battery Voltage *', 'ecm.battery.voltage'], + // 'ECM Status', + ['Intake Air Temperature', 'intake.temp'], + ['Intake Air Pressure', 'intake.pressure'] + ]; + + let conv; + if (type === 'layman') { + for (conv of convChart) { + if (conv[1] === input) { + return conv[0]; + } + } + } else if (type === 'metric') { + for (conv of convChart) { + if (conv[0] === input) { + return conv[1]; + } + } + } + } + + getAllNames(type) { + if (type === 'layman') { + return [ + 'L1 - L2 Voltage', + 'L2 - L3 Voltage', + 'L3 - L1 Voltage', + 'L1 - L0 Voltage', + 'L2 - L0 Voltage', + 'L3 - L0 Voltage', + 'L1 Current', + 'L2 Current', + 'L3 Current', + 'Frequency', + 'Total kW', + 'Percent of Rated kW', + 'Total Power Factor', + 'L1 kW', + 'L1 Power Factor', + 'L2 kW', + 'L2 Power Factor', + 'L3 kW', + 'L3 Power Factor', + 'Total kVAR', + 'L1 kVAR', + 'L2 kVAR', + 'L3 kVAR', + 'Total kVA', + 'L1 kVA', + 'L2 kVA', + 'L3 kVA', + // 'Current Lead / Lag', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + // 'Reserved For Future Use', + 'Oil Pressure *', + 'Coolant Temperature *', + 'Engine Speed *', + 'Local Battery Voltage *', + 'Fuel Pressure *', + 'Fuel Temperature *', + 'Fuel Rate *', + // 'Used Last Run *', + 'Coolant Pressure *', + 'Coolant Level *', + 'Lube Oil Temperature *', + 'Oil Level *', + 'Crankcase Pressure *', + 'Ambient Temperature *', + 'ECM Battery Voltage *', + // 'ECM Status', + 'Intake Air Temperature', + 'Intake Air Pressure' + ]; + } else if (type === 'metric') { + return [ + 'l1.l2.voltage', + 'l2.l3.voltage', + 'l3.l1.voltage', + 'l1.l0.voltage', + 'l2.l0.voltage', + 'l3.l0.voltage', + 'l1.current', + 'l2.current', + 'l3.current', + 'frequency', + 'total.kw', + 'rate.kw', + 'total.pf', + 'l1.kw', + 'l1.pf', + 'l2.kw', + 'l2.pf', + 'l3.kw', + 'l3.pf', + 'total.kvar', + 'l1.kvar', + 'l2.kvar', + 'l3.kvar', + 'total.kva', + 'l1.kva', + 'l2.kva', + 'l3.kva', + 'oil.pressure', + 'coolant.temp', + 'engine.rpm', + 'battery.voltage', + 'fuel.pressure', + 'fuel.temp', + 'fuel.rate', + 'coolant.pressure', + 'coolant.level', + 'oil.temp', + 'oil.level', + 'crankcase.pressure', + 'ambient.temp', + 'ecm.battery.voltage', + 'intake.temp', + 'intake.pressure' + ]; + } + } +} diff --git a/src/app/services/visualize.service.spec.ts b/src/app/services/visualize.service.spec.ts new file mode 100644 index 0000000..819970f --- /dev/null +++ b/src/app/services/visualize.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { VisualizeService } from './visualize.service'; + +describe('VisualizeService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: VisualizeService = TestBed.get(VisualizeService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/visualize.service.ts b/src/app/services/visualize.service.ts new file mode 100644 index 0000000..984bb3f --- /dev/null +++ b/src/app/services/visualize.service.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +@Injectable({ + providedIn: 'root' +}) +export class VisualizeService { + + constructor(private http: HttpClient) { } + + getData(token, query) { + return this.http.get('http://sd5-backend.engr.uconn.edu/data/query' + query, { + headers: { + Authorization: 'Bearer ' + token + } + }); + } + +} diff --git a/src/app/visualize-all/visualize-all.component.css b/src/app/visualize-all/visualize-all.component.css index e69de29..95f7fb8 100644 --- a/src/app/visualize-all/visualize-all.component.css +++ b/src/app/visualize-all/visualize-all.component.css @@ -0,0 +1,23 @@ +div#textinput { + width: 300px; +} + +select#gen_select { + width: 300px; +} + +select#func_select { + width: 300px; +} + +select#data_select { + width: 300px; +} + +select#time_type_select { + width: 300px; +} + +p#visMessage { + color: white; +} \ No newline at end of file diff --git a/src/app/visualize-all/visualize-all.component.html b/src/app/visualize-all/visualize-all.component.html index 940637a..b412555 100644 --- a/src/app/visualize-all/visualize-all.component.html +++ b/src/app/visualize-all/visualize-all.component.html @@ -1,3 +1,50 @@ -

- visualize-all works! -

+
+
+
+

Visualization

+ {{chart}} +
+ +
+ + +
+
+
\ No newline at end of file diff --git a/src/app/visualize-all/visualize-all.component.ts b/src/app/visualize-all/visualize-all.component.ts index 40bd866..b16276b 100644 --- a/src/app/visualize-all/visualize-all.component.ts +++ b/src/app/visualize-all/visualize-all.component.ts @@ -1,4 +1,12 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { GeneratorService } from '../services/generator.service'; +import { VisualizeService } from '../services/visualize.service'; +import { Router } from '@angular/router'; +import { Chart } from 'chart.js'; +import { Injectable } from '@angular/core'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import 'rxjs/add/operator/map'; +import { $ } from 'protractor'; @Component({ selector: 'app-visualize-all', @@ -6,10 +14,111 @@ import { Component, OnInit } from '@angular/core'; styleUrls: ['./visualize-all.component.css'] }) export class VisualizeAllComponent implements OnInit { + public generators$: Object; + public chart$: Object; + public chart: any = null; + // @ViewChild('lineChart') private chartRef; + // chart: any; - constructor() { } + constructor(public graphData: VisualizeService, public genData: GeneratorService, private router: Router, private http: HttpClient) { } + + // create real chart based off of user data + resetAndRemakeChart() { + const genVals = Array.prototype.slice.call(document.querySelectorAll('#gen_select option:checked'), 0).map(function(v, i, a) { + return v.value; + }); + const funcVals = Array.prototype.slice.call(document.querySelectorAll('#func_select option:checked'), 0).map(function(v, i, a) { + return v.value; + }); + const dataVals = Array.prototype.slice.call(document.querySelectorAll('#data_select option:checked'), 0).map(function(v, i, a) { + return v.value; + }); + const timeTypeVals = Array.prototype.slice.call(document.querySelectorAll('#data_type_select option:checked'), 0) + .map(function(v, i, a) { + return v.value; + }); + + const visDataJson = { + // 'time span': this.time_span.nativeElement.value + // 'generators': $('#gen_select').val(), + 'generators': genVals, + 'function': funcVals[0], + 'data type': dataVals[0], + 'time type': timeTypeVals[0] + }; + console.log(visDataJson); + + } ngOnInit() { + const jsonToken = localStorage.getItem('auth_token'); + try { + this.genData.getGenerators(jsonToken).subscribe((genData) => { + this.generators$ = genData; + return this.generators$; + }); + } catch (err) { + return err; + } + + let labels = []; + let data = []; + try { + + // create example chart + this.graphData.getData(jsonToken, '?start=1y-ago&m=sum:oil.temp').subscribe((graphData) => { + this.chart$ = graphData; + const count = Object.keys(this.chart$).length; + let i; + for (i = 0; i < count; i++) { + for (let n = 0; n < (Object.keys(this.chart$[i].dps).length); n++) { + labels = Object.keys(this.chart$[i].dps); + data = Object.values(this.chart$[i].dps); + + } + } + this.chart = new Chart('canvas', { + type: 'line', + data: { + labels: labels, + datasets: [{ + label: i, + fill: false, + data: data, + backgroundColor: [ + 'rgba(255, 99, 132, 0.2)', + 'rgba(54, 162, 235, 0.2)', + 'rgba(255, 206, 86, 0.2)', + 'rgba(75, 192, 192, 0.2)', + 'rgba(153, 102, 255, 0.2)', + 'rgba(255, 159, 64, 0.2)' + ], + borderColor: 'red', + borderWidth: 1 + }] + }, + options: { + scales: { + yAxes: [{ + ticks: { + beginAtZero: true + } + }] + } + } + }); + }); + } catch (err) { + return err; + } + + + + + + + + } } diff --git a/src/assets/images/graph.jpg b/src/assets/images/graph.jpg new file mode 100644 index 0000000..bf3f07a Binary files /dev/null and b/src/assets/images/graph.jpg differ diff --git a/src/assets/images/home.png b/src/assets/images/home.png index f6c0022..15930e4 100644 Binary files a/src/assets/images/home.png and b/src/assets/images/home.png differ