Commit 4c5c1cd4 authored by 神楽坂玲奈's avatar 神楽坂玲奈

fix

parent 98bdb218
Pipeline #16067 passed with stages
in 2 minutes and 18 seconds
...@@ -3,18 +3,19 @@ import { HttpClient } from '@angular/common/http'; ...@@ -3,18 +3,19 @@ import { HttpClient } from '@angular/common/http';
import { firstValueFrom, mergeMap, timer } from 'rxjs'; import { firstValueFrom, mergeMap, timer } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root'
}) })
export class ApiService { export class ApiService {
routers!: any[]; routers!: any[];
connections!: Record<number, Record<number, any>>; connections!: Record<number, Record<number, Connection>>;
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
} }
async init() { async init() {
this.routers = await firstValueFrom(this.http.get<any[]>('http://10.198.0.7:500/api/routers')); this.connections = await firstValueFrom(this.http.get<Record<number, Record<number, Connection>>>('http://10.198.0.7:500/api/connections'));
this.connections = await firstValueFrom(this.http.get<Record<number, Record<number, any>>>('http://10.198.0.7:500/api/routers')); this.routers = await firstValueFrom(this.http.get<RouterStatus[]>('http://10.198.0.7:500/api/routers'));
console.log( console.log(
this.routers this.routers
...@@ -23,7 +24,7 @@ export class ApiService { ...@@ -23,7 +24,7 @@ export class ApiService {
Host: item.name, Host: item.name,
HostName: item.host, HostName: item.host,
User: item.user, User: item.user,
Port: item.sshPort, Port: item.sshPort
}) })
.filter(([key, value]) => value) .filter(([key, value]) => value)
.map((line) => line.join(' ')) .map((line) => line.join(' '))
...@@ -43,9 +44,6 @@ export class ApiService { ...@@ -43,9 +44,6 @@ export class ApiService {
export interface RouterStatus { export interface RouterStatus {
id: number, id: number,
name: string,
address: string,
location: string,
peers: Record<number, PeerQuality>, peers: Record<number, PeerQuality>,
via: Record<number, number> via: Record<number, number>
} }
...@@ -56,6 +54,20 @@ export interface PeerQuality { ...@@ -56,6 +54,20 @@ export interface PeerQuality {
reliability: number; reliability: number;
} }
export interface Router {
id: number;
name: string;
location: string;
host: string;
port: number;
user: string;
}
export interface Connection {
metric: number;
protocol: string;
}
// const connected: Record<number, Record<number, string>> = {}; // const connected: Record<number, Record<number, string>> = {};
// for (const from of data) { // for (const from of data) {
// if (!connected[from.id]) connected[from.id] = {} // if (!connected[from.id]) connected[from.id] = {}
......
...@@ -15,21 +15,20 @@ export class AppComponent implements OnInit { ...@@ -15,21 +15,20 @@ export class AppComponent implements OnInit {
async ngOnInit() { async ngOnInit() {
await this.api.init(); await this.api.init();
const protos = []; // const protos = [];
const routers = this.api.routers; // for (const from of this.api.routers) {
for (const from of routers) { // for (const [id1, peer] of Object.entries(from.peers)) {
for (const [id1, peer] of Object.entries(from.peers)) { // const id = parseInt(id1);
const id = parseInt(id1); // const reverse = this.api.routers.find(r => r.id === id)?.peers?.[from.id];
const reverse = routers.find(r => r.id === id)?.peers?.[from.id]; // if (!reverse) continue;
if (!reverse) continue; // const link = this.api.connections[from.id][id];
const link = this.api.connections[from.id][id]; // if (!link) continue;
if (!link) continue; // // @ts-ignore
// @ts-ignore // if (peer.reliability * reverse.reliability <= 0.01) {
if (peer.reliability * reverse.reliability <= 0.01) { // protos.push(link.proto);
protos.push(link.proto); // }
} // }
} // }
} // console.log(_.groupBy(protos));
console.log(_.groupBy(protos));
} }
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
</mat-card-title> </mat-card-title>
</mat-card-header> </mat-card-header>
<mat-card-content> <mat-card-content>
<table mat-table [dataSource]="links" *ngIf="routers" fixedLayout [trackBy]="trackById"> <table mat-table [dataSource]="links" *ngIf="api.routers" fixedLayout [trackBy]="trackById">
<ng-container matColumnDef="name"> <ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef>name</th> <th mat-header-cell *matHeaderCellDef>name</th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td> <td mat-cell *matCellDef="let element"> {{element.name}} </td>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
<th mat-header-cell *matHeaderCellDef>id</th> <th mat-header-cell *matHeaderCellDef>id</th>
<td mat-cell *matCellDef="let element"> {{element.id}} </td> <td mat-cell *matCellDef="let element"> {{element.id}} </td>
</ng-container> </ng-container>
<ng-container *ngFor="let router of routers"> <ng-container *ngFor="let router of api.routers">
<ng-container [matColumnDef]="router.name"> <ng-container [matColumnDef]="router.name">
<th mat-header-cell *matHeaderCellDef><span class="id">{{router.id}}</span><span <th mat-header-cell *matHeaderCellDef><span class="id">{{router.id}}</span><span
class="head">{{router.name}}</span></th> class="head">{{router.name}}</span></th>
......
import {Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import {map} from 'rxjs/operators'; import { map } from 'rxjs/operators';
import {ApiService, RouterStatus} from "../api.service"; import { ApiService, RouterStatus } from '../api.service';
import * as _ from "lodash-es"; import * as _ from 'lodash-es';
import {firstValueFrom} from "rxjs"; import { Quality } from '../Quality';
import {Quality} from "../Quality";
@Component({ @Component({
selector: 'app-dashboard', selector: 'app-dashboard',
templateUrl: './dashboard.component.html', templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.scss'], styleUrls: ['./dashboard.component.scss']
// changeDetection: ChangeDetectionStrategy.OnPush // changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class DashboardComponent implements OnInit { export class DashboardComponent implements OnInit {
routers: RouterStatus[] = []; // routers: RouterStatus[] = [];
displayedColumns: string[] = []; displayedColumns: string[] = [];
links = this.api.state().pipe( links = this.api.state().pipe(
map(routers => routers.map(router => map(routers => routers.map(router =>
({ ({
id: router.id, id: router.id,
name: router.name, name: this.api.routers.find(r => r.id == router.id)!.name,
peers: _.mapValues(router.peers, (quality, id1) => this.displayQuality(routers, router, parseInt(id1))) peers: _.mapValues(router.peers, (quality, id1) => this.displayQuality(routers, router, parseInt(id1)))
}) })
)) ))
); );
routed = false; routed = false;
constructor(private api: ApiService) { constructor(public api: ApiService) {
} }
displayQuality(routers: RouterStatus[], from: RouterStatus, toId: number) { displayQuality(routers: RouterStatus[], from: RouterStatus, toId: number) {
...@@ -45,7 +44,8 @@ export class DashboardComponent implements OnInit { ...@@ -45,7 +44,8 @@ export class DashboardComponent implements OnInit {
decoration: quality.hop <= 2 ? '' : `underline hsl(${this.mapNumber(quality.hop, 4, 8, 120, 0)}, 100%, 40%)` decoration: quality.hop <= 2 ? '' : `underline hsl(${this.mapNumber(quality.hop, 4, 8, 120, 0)}, 100%, 40%)`
}; };
} else { } else {
const link = this.api.link(from.id, toId); const link = this.api.connections[from.id]?.[toId];
console.log(link);
if (!link) return; if (!link) return;
if (!to.peers[from.id]) return; if (!to.peers[from.id]) return;
...@@ -56,35 +56,23 @@ export class DashboardComponent implements OnInit { ...@@ -56,35 +56,23 @@ export class DashboardComponent implements OnInit {
const decorations: Record<string, string> = { const decorations: Record<string, string> = {
oc: 'underline blue', oc: 'underline blue',
wg: 'underline red', wg: 'underline red',
tun: 'underline greed', tun: 'underline greed'
} };
return { return {
delay: quality.reliability <= 0.01 ? 'x' : quality.delay, delay: quality.reliability <= 0.01 ? 'x' : quality.delay,
color: `hsl(${this.mapNumber(quality.reliability, 0.9, 1, 0, 120)}, 100%, 40%)`, color: `hsl(${this.mapNumber(quality.reliability, 0.9, 1, 0, 120)}, 100%, 40%)`,
decoration: decorations[link.split(',')[1]] decoration: decorations[link.protocol]
}; };
} }
} }
displayQuality2(router: RouterStatus, routers: RouterStatus[]) {
return {
name: router.name,
peers: _.mapValues(router.peers, (quality, id) => {
// const reverse = routers.find(r => r.id === parseInt(id))?.peers?.[router.id];
// if (!reverse) return undefined;
// return this.displayQuality2(quality, reverse);
})
}
}
mapNumber(value: number, minFrom: number, maxFrom: number, minTo: number, maxTo: number) { mapNumber(value: number, minFrom: number, maxFrom: number, minTo: number, maxTo: number) {
return minTo + (maxTo - minTo) * ((_.clamp(value, minFrom, maxFrom) - minFrom) / (maxFrom - minFrom)); return minTo + (maxTo - minTo) * ((_.clamp(value, minFrom, maxFrom) - minFrom) / (maxFrom - minFrom));
} }
async ngOnInit() { async ngOnInit() {
this.routers = await firstValueFrom(this.api.state()) this.displayedColumns = ['name', 'id'].concat(this.api.routers.map(r => r.name));
this.displayedColumns = ['name', 'id'].concat(this.routers.map(r => r.name));
} }
value(from: number, to: number) { value(from: number, to: number) {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
"target": "es2020", "target": "es2020",
"module": "es2020", "module": "es2020",
"lib": [ "lib": [
"es2022", "es2021",
"dom" "dom"
] ]
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment