-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving to faker stream to prep for signalr
- Loading branch information
Showing
5 changed files
with
166 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
export const defaultColor: string = 'horizon'; | ||
|
||
export const hours: string[] = ['Maintenance', 'Production', 'Downtime', 'Scheduled'] | ||
export const hours: string[] = ['Maintenance', 'Production', 'Downtime', 'Scheduled'] | ||
|
||
export enum Status { | ||
Up = "Up", | ||
Down = "Down", | ||
Stop = "Off", | ||
} | ||
export interface LightStatus { | ||
name?: string | ||
value?: number | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { FakerService } from './faker.service'; | ||
|
||
describe('FakerService', () => { | ||
let service: FakerService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(FakerService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { MultiSeries, Series } from '@swimlane/ngx-charts'; | ||
import { interval, Subject, Subscription } from 'rxjs'; | ||
import { LightStatus, Status } from '../config'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class FakerService { | ||
|
||
|
||
private newLightStatusSubject = new Subject<Series>(); | ||
|
||
newLightStatus$ = this.newLightStatusSubject.asObservable(); | ||
|
||
private ligthStatusSubscription = new Subscription(); | ||
|
||
private seed: number = 2014; | ||
|
||
constructor() { } | ||
|
||
startFakeLightStatusStream() { | ||
this.ligthStatusSubscription = | ||
interval(1000).subscribe(() => this.generateFakeLightStatus()); | ||
} | ||
stopFakeLightStatusGeneration() { | ||
this.ligthStatusSubscription.unsubscribe() | ||
} | ||
generateFakeLightStatus(): void { | ||
const currentDate = new Date(this.seed, | ||
Math.floor(Math.random() * 12), | ||
Math.floor(Math.random() * 30), | ||
Math.floor(Math.random() * 24), | ||
Math.floor(Math.random() * 60), | ||
Math.floor(Math.random() * 60)) | ||
|
||
const newEntry = { | ||
name: currentDate.toLocaleString(), | ||
series: [ | ||
{ | ||
name: Status.Up, | ||
value: 0, | ||
}, | ||
{ | ||
name: Status.Stop, | ||
value: 0, | ||
}, | ||
{ | ||
name: Status.Down, | ||
value: 0, | ||
} | ||
] | ||
} | ||
const index = Math.floor(Math.random() * 3); | ||
newEntry.series[index].value = 1; | ||
this.newLightStatusSubject.next(newEntry); | ||
} | ||
getData(): MultiSeries { | ||
|
||
const first = new Date(2011, 10, 30, 1, 10, 10).toLocaleString(); | ||
const second = new Date(2012, 10, 30, 1, 11, 10).toLocaleString(); | ||
const third = new Date(2013, 10, 30, 1, 12, 10).toLocaleString(); | ||
return [ | ||
{ | ||
"name": first, | ||
"series": [ | ||
{ | ||
"name": Status.Up, | ||
"value": 1 | ||
}, | ||
{ | ||
"name": Status.Stop, | ||
"value": 0 | ||
}, | ||
{ | ||
"name": Status.Down, | ||
"value": 0 | ||
} | ||
] | ||
}, | ||
|
||
{ | ||
"name": second, | ||
"series": [ | ||
{ | ||
"name": Status.Up, | ||
"value": 0 | ||
}, | ||
{ | ||
"name": Status.Stop, | ||
"value": 1 | ||
}, | ||
{ | ||
"name": Status.Down, | ||
"value": 0 | ||
} | ||
] | ||
}, | ||
|
||
{ | ||
"name": third, | ||
"series": [ | ||
{ | ||
"name": Status.Up, | ||
"value": 1 | ||
}, | ||
{ | ||
"name": Status.Stop, | ||
"value": 0 | ||
}, | ||
{ | ||
"name": Status.Down, | ||
"value": 0 | ||
} | ||
] | ||
}] | ||
} | ||
} |