Skip to content

Commit

Permalink
Network statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
emembrives committed Jan 13, 2018
1 parent 1c09e6a commit 0179b8c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
9 changes: 4 additions & 5 deletions dispotrains.webapp/src/statistics/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type storageStatus struct {
}

type NetworkStats struct {
Good int
Bad int
Good int
Bad int
LongBad int
}

Expand Down Expand Up @@ -101,7 +101,7 @@ func ComputeGlobalStatistics(session *mgo.Session) (*NetworkStats, error) {
results := make([]bson.M, 0)
pipe := cStatistics.Pipe(
[]bson.M{
bson.M{"$match": bson.M{"end": bson.M{"$gte": time.Now().AddDate(0, 0, -2)}}},
bson.M{"$match": bson.M{"end": bson.M{"$gte": time.Now().AddDate(0, 0, -10)}}},
bson.M{"$sort": bson.M{"end": 1}},
bson.M{"$group": bson.M{
"_id": "$elevator",
Expand All @@ -124,10 +124,9 @@ func ComputeGlobalStatistics(session *mgo.Session) (*NetworkStats, error) {
if !ok {
panic(elevator["begin"])
}
ns.Bad++
if beginTime.Before(longLimit) {
ns.LongBad++
} else {
ns.Bad++
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<titlebar [title]="'DispoTrains'" [root]="true"></titlebar>
<mat-card>
<mat-card-content>
{{ (stats|async).good }} ascenseurs en service;
{{ (stats|async).bad }} ({{ (stats|async).PercentBad() | number:'1.0-0' }}%) en panne dont
{{ (stats|async).longBad }} ({{ (stats|async).PercentLongBad() | number:'1.0-0' }}%) depuis 3 jours ou plus.
</mat-card-content>
</mat-card>
<mat-nav-list>
<a mat-list-item *ngFor="let line of lines | async" [routerLink]="['/ligne', line.id]">{{ line.network }} {{ line.id }}</a>
</mat-nav-list>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Observable } from 'rxjs/Observable';

import { LinesService } from '../lines.service';
import { StationService } from '../station.service';
import { Line } from '../station';
import { Line, NetworkStats } from '../station';


@Component({
Expand All @@ -16,14 +16,12 @@ import { Line } from '../station';
})
export class LineListComponent implements OnInit {
lines: Promise<Line[]>;
stats: Promise<NetworkStats>;

constructor(private linesService: LinesService) { }

ngOnInit(): void {
this.lines = this.linesService.getLines();
}

gotoDetail(line: Line): void {

this.stats = this.linesService.getStats();
}
}
6 changes: 5 additions & 1 deletion dispotrains.webapp/src/web/src/app/lines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Observable } from 'rxjs/Observable';
import { combineLatest } from 'rxjs/observable/combineLatest';

import { StationService } from './station.service';
import { Line, Station } from './station';
import { Line, Station, NetworkStats } from './station';
import { SorterUtils } from './sorting';

@Injectable()
Expand All @@ -16,6 +16,10 @@ export class LinesService {
.then(this.findLine(id));
}

getStats(): Promise<NetworkStats> {
return this.stationService.getStats();
}

private findLine(id: string): (lines: Line[]) => Line {
return function(lines: Line[]) {
for (let line of lines) {
Expand Down
8 changes: 8 additions & 0 deletions dispotrains.webapp/src/web/src/app/station.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ export class NetworkStats {
this.bad = data['Bad'];
this.longBad = data['LongBad'];
}

PercentBad(): number {
return (this.bad * 100) / (this.good + this.bad);
}

PercentLongBad(): number {
return (this.longBad * 100) / (this.good + this.bad);
}
}

export class Line {
Expand Down

0 comments on commit 0179b8c

Please sign in to comment.