From 8b71eccd8ade278daf3649b363712ac03a74621c Mon Sep 17 00:00:00 2001 From: Matthias Vonend Date: Tue, 20 Apr 2021 14:35:48 +0000 Subject: [PATCH] Add generated docs --- docs/coverage/index.html | 60 ++++++++-------- docs/coverage/src/agent/brains/index.html | 44 ++++++------ .../src/agent/brains/random.brain.ts.html | 38 +++++++--- .../src/agent/brains/szenario.brain.ts.html | 64 ++++++++++++++--- .../src/agent/models/agent.model.ts.html | 2 +- .../src/agent/models/brain.model.ts.html | 42 ++++++++--- docs/coverage/src/agent/models/index.html | 32 ++++----- .../src/agent/services/agent.service.ts.html | 2 +- .../src/agent/services/brain.service.ts.html | 2 +- docs/coverage/src/agent/services/index.html | 2 +- docs/coverage/src/app.controller.ts.html | 2 +- docs/coverage/src/app.service.ts.html | 2 +- .../src/baseline/baseline.service.ts.html | 2 +- docs/coverage/src/baseline/index.html | 2 +- docs/coverage/src/index.html | 2 +- docs/coverage/src/market/index.html | 2 +- .../src/market/market.service.ts.html | 2 +- docs/coverage/src/news/index.html | 2 +- .../coverage/src/news/news.controller.ts.html | 2 +- docs/coverage/src/news/news.service.ts.html | 2 +- docs/coverage/src/szenarios/index.html | 28 ++++---- .../src/szenarios/szenario.controller.ts.html | 42 +++++++++-- .../src/szenarios/szenario.service.ts.html | 71 +++++++++++++++---- .../src/szenarios/szenarioStart.dto.ts.html | 23 ++++-- 24 files changed, 323 insertions(+), 149 deletions(-) diff --git a/docs/coverage/index.html b/docs/coverage/index.html index a192ff9..228eba2 100644 --- a/docs/coverage/index.html +++ b/docs/coverage/index.html @@ -23,30 +23,30 @@

All files

- 46.45% + 43.52% Statements - 131/282 + 131/301
- 29.17% + 26.92% Branches - 14/48 + 14/52
- 40.85% + 37.18% Functions - 29/71 + 29/78
- 45.63% + 42.59% Lines - 115/252 + 115/270
@@ -89,32 +89,32 @@

All files

src/agent/brains - -
+ +
- 30.16% - 19/63 + 26.76% + 19/71 0% - 0/4 - 21.74% - 5/23 - 31.67% - 19/60 + 0/6 + 20.83% + 5/24 + 27.94% + 19/68 src/agent/models - -
+ +
- 100% - 5/5 + 83.33% + 5/6 100% 0/0 - 66.67% - 2/3 - 100% - 5/5 + 50% + 2/4 + 83.33% + 5/6 @@ -183,13 +183,13 @@

All files

0% - 0/68 + 0/78 0% - 0/8 + 0/10 0% - 0/12 + 0/17 0% - 0/58 + 0/67 @@ -200,7 +200,7 @@

All files

diff --git a/docs/coverage/src/agent/brains/index.html b/docs/coverage/src/agent/brains/index.html index 4818f0a..db8bafe 100644 --- a/docs/coverage/src/agent/brains/index.html +++ b/docs/coverage/src/agent/brains/index.html @@ -23,30 +23,30 @@

All files src/agent/brains

- 30.16% + 26.76% Statements - 19/63 + 19/71
0% Branches - 0/4 + 0/6
- 21.74% + 20.83% Functions - 5/23 + 5/24
- 31.67% + 27.94% Lines - 19/60 + 19/68
@@ -74,32 +74,32 @@

All files src/agent/brains

random.brain.ts - -
+ +
- 72.22% - 13/18 + 68.42% + 13/19 0% - 0/2 + 0/4 55.56% 5/9 - 72.22% - 13/18 + 68.42% + 13/19 szenario.brain.ts - -
+ +
- 13.33% - 6/45 + 11.54% + 6/52 0% 0/2 0% - 0/14 - 14.29% - 6/42 + 0/15 + 12.24% + 6/49 @@ -110,7 +110,7 @@

All files src/agent/brains

diff --git a/docs/coverage/src/agent/brains/random.brain.ts.html b/docs/coverage/src/agent/brains/random.brain.ts.html index cdf6aad..07320eb 100644 --- a/docs/coverage/src/agent/brains/random.brain.ts.html +++ b/docs/coverage/src/agent/brains/random.brain.ts.html @@ -23,16 +23,16 @@

All files / src/agent diff --git a/docs/coverage/src/agent/brains/szenario.brain.ts.html b/docs/coverage/src/agent/brains/szenario.brain.ts.html index cba08d1..5326e48 100644 --- a/docs/coverage/src/agent/brains/szenario.brain.ts.html +++ b/docs/coverage/src/agent/brains/szenario.brain.ts.html @@ -23,9 +23,9 @@

All files / src/agent
- 13.33% + 11.54% Statements - 6/45 + 6/52
@@ -39,14 +39,14 @@

All files / src/agent
0% Functions - 0/14 + 0/15
- 14.29% + 12.24% Lines - 6/42 + 6/49
@@ -185,7 +185,21 @@

All files / src/agent 126 127 128 -129  +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143  2x 2x 2x @@ -203,6 +217,8 @@

All files / src/agent       +  +        @@ -229,6 +245,7 @@

All files / src/agent       +        @@ -236,6 +253,12 @@

All files / src/agent       +  +  +  +  +  +        @@ -249,8 +272,13 @@

All files / src/agent       +  +  +  +      +        @@ -314,7 +342,7 @@

All files / src/agent      
import { Logger } from '@nestjs/common';
-import { addMinutes } from 'date-fns';
+import { addMinutes, differenceInSeconds } from 'date-fns';
 import { timer } from 'rxjs';
 import { map, take, takeWhile } from 'rxjs/operators';
  
@@ -331,6 +359,8 @@ 

All files / src/agent private marketService: Readonly<MarketService>;   private startDate = null; + private endDate = null; + private finishedPercent = 0; private szenarioData: any;   private token: string; @@ -356,6 +386,7 @@

All files / src/agent this.szenarioData = szenarioData; this.token = token; this.stock = stock; + this.speedMultiplicator = speedMultiplicator; this.marketService.setWatch( this.convertSpeedMultiplicator(speedMultiplicator), stock, @@ -363,8 +394,14 @@

All files / src/agent   const sorted = szenarioData .map(({ time }) => new Date(time)) - .sort((a, b) => a.getTime() - b.getTime()); - this.startDate = sorted[0]; + .sort((a, b) => b.getTime() - a.getTime()); +  + this.startDate = sorted[sorted.length - 1]; + this.endDate = sorted[0]; + } +  + getStatus() { + return this.finishedPercent; }   animate(): PromiseOrValue<void> { @@ -375,10 +412,15 @@

All files / src/agent map((time) => addMinutes(this.startDate, time)), ) .subscribe(async (time) => { - console.log(time); const datapoint = this.szenarioData.find( (d) => new Date(d.time).getTime() === time.getTime(), ); +  + const totalDuration = differenceInSeconds(this.startDate, this.endDate); + const progressDuration = differenceInSeconds(this.startDate, time); + this.finishedPercent = + 100 * Math.min(1, progressDuration / totalDuration); +  if (!datapoint) return;   const currentMarket = await this.marketService.onInformationAvailable @@ -448,7 +490,7 @@

All files / src/agent

diff --git a/docs/coverage/src/agent/models/agent.model.ts.html b/docs/coverage/src/agent/models/agent.model.ts.html index 355b12d..b94d052 100644 --- a/docs/coverage/src/agent/models/agent.model.ts.html +++ b/docs/coverage/src/agent/models/agent.model.ts.html @@ -88,7 +88,7 @@

All files / src/agent diff --git a/docs/coverage/src/agent/models/brain.model.ts.html b/docs/coverage/src/agent/models/brain.model.ts.html index 57c7db6..5889680 100644 --- a/docs/coverage/src/agent/models/brain.model.ts.html +++ b/docs/coverage/src/agent/models/brain.model.ts.html @@ -23,9 +23,9 @@

All files / src/agent -
+

-	
-	
+	
-	
-	
+	
+	
-	
-	
-	
-	
+	
+	
+	
+	
@@ -110,7 +110,7 @@ 

All files src/agent/models

diff --git a/docs/coverage/src/agent/services/agent.service.ts.html b/docs/coverage/src/agent/services/agent.service.ts.html index 1d0eb56..3bebc99 100644 --- a/docs/coverage/src/agent/services/agent.service.ts.html +++ b/docs/coverage/src/agent/services/agent.service.ts.html @@ -154,7 +154,7 @@

All files / src/agent diff --git a/docs/coverage/src/agent/services/brain.service.ts.html b/docs/coverage/src/agent/services/brain.service.ts.html index 2e61d8b..8d555f7 100644 --- a/docs/coverage/src/agent/services/brain.service.ts.html +++ b/docs/coverage/src/agent/services/brain.service.ts.html @@ -163,7 +163,7 @@

All files / src/agent diff --git a/docs/coverage/src/agent/services/index.html b/docs/coverage/src/agent/services/index.html index 79196ba..4f7ff84 100644 --- a/docs/coverage/src/agent/services/index.html +++ b/docs/coverage/src/agent/services/index.html @@ -110,7 +110,7 @@

All files src/agent/services

diff --git a/docs/coverage/src/app.controller.ts.html b/docs/coverage/src/app.controller.ts.html index 928dac0..f6c919e 100644 --- a/docs/coverage/src/app.controller.ts.html +++ b/docs/coverage/src/app.controller.ts.html @@ -100,7 +100,7 @@

All files / src app.con diff --git a/docs/coverage/src/app.service.ts.html b/docs/coverage/src/app.service.ts.html index ccf0924..ce92fc1 100644 --- a/docs/coverage/src/app.service.ts.html +++ b/docs/coverage/src/app.service.ts.html @@ -94,7 +94,7 @@

All files / src app.ser diff --git a/docs/coverage/src/baseline/baseline.service.ts.html b/docs/coverage/src/baseline/baseline.service.ts.html index 5f0743e..0338cec 100644 --- a/docs/coverage/src/baseline/baseline.service.ts.html +++ b/docs/coverage/src/baseline/baseline.service.ts.html @@ -244,7 +244,7 @@

All files / src/baseline diff --git a/docs/coverage/src/baseline/index.html b/docs/coverage/src/baseline/index.html index 92cbea3..4e07563 100644 --- a/docs/coverage/src/baseline/index.html +++ b/docs/coverage/src/baseline/index.html @@ -95,7 +95,7 @@

All files src/baseline

diff --git a/docs/coverage/src/index.html b/docs/coverage/src/index.html index 73dba00..99379fa 100644 --- a/docs/coverage/src/index.html +++ b/docs/coverage/src/index.html @@ -110,7 +110,7 @@

All files src

diff --git a/docs/coverage/src/market/index.html b/docs/coverage/src/market/index.html index 534ea9d..72a149c 100644 --- a/docs/coverage/src/market/index.html +++ b/docs/coverage/src/market/index.html @@ -95,7 +95,7 @@

All files src/market

diff --git a/docs/coverage/src/market/market.service.ts.html b/docs/coverage/src/market/market.service.ts.html index 9924ac5..a85ee3a 100644 --- a/docs/coverage/src/market/market.service.ts.html +++ b/docs/coverage/src/market/market.service.ts.html @@ -400,7 +400,7 @@

All files / src/market Code coverage generated by istanbul - at Fri Apr 16 2021 05:35:38 GMT+0000 (Coordinated Universal Time) + at Tue Apr 20 2021 14:35:47 GMT+0000 (Coordinated Universal Time) diff --git a/docs/coverage/src/news/index.html b/docs/coverage/src/news/index.html index 1daaa85..13f5197 100644 --- a/docs/coverage/src/news/index.html +++ b/docs/coverage/src/news/index.html @@ -110,7 +110,7 @@

All files src/news

diff --git a/docs/coverage/src/news/news.controller.ts.html b/docs/coverage/src/news/news.controller.ts.html index a624b76..f5600a4 100644 --- a/docs/coverage/src/news/news.controller.ts.html +++ b/docs/coverage/src/news/news.controller.ts.html @@ -130,7 +130,7 @@

All files / src/news diff --git a/docs/coverage/src/news/news.service.ts.html b/docs/coverage/src/news/news.service.ts.html index 5a395ef..38b5fcd 100644 --- a/docs/coverage/src/news/news.service.ts.html +++ b/docs/coverage/src/news/news.service.ts.html @@ -187,7 +187,7 @@

All files / src/news diff --git a/docs/coverage/src/szenarios/index.html b/docs/coverage/src/szenarios/index.html index 623bfbb..71f2bfb 100644 --- a/docs/coverage/src/szenarios/index.html +++ b/docs/coverage/src/szenarios/index.html @@ -25,28 +25,28 @@

All files src/szenarios

0% Statements - 0/68 + 0/78
0% Branches - 0/8 + 0/10
0% Functions - 0/12 + 0/17
0% Lines - 0/58 + 0/67
@@ -78,13 +78,13 @@

All files src/szenarios

- + - + - + @@ -93,13 +93,13 @@

All files src/szenarios

- - - + - + + + @@ -108,13 +108,13 @@

All files src/szenarios

- + - + @@ -125,7 +125,7 @@

All files src/szenarios

diff --git a/docs/coverage/src/szenarios/szenario.controller.ts.html b/docs/coverage/src/szenarios/szenario.controller.ts.html index 563eb51..d184b18 100644 --- a/docs/coverage/src/szenarios/szenario.controller.ts.html +++ b/docs/coverage/src/szenarios/szenario.controller.ts.html @@ -25,7 +25,7 @@

All files / src/szenario
0% Statements - 0/16 + 0/18
@@ -39,14 +39,14 @@

All files / src/szenario
0% Functions - 0/4 + 0/5
0% Lines - 0/13 + 0/15
@@ -120,7 +120,17 @@

All files / src/szenario 61 62 63 -64

1 2 @@ -104,7 +104,15 @@

All files / src/agent 45 46 47 -48

  +48 +49 +50 +51 +52 +53 +54 +55 +56        @@ -133,6 +141,14 @@

All files / src/agent       +  +  +  +  +  +  +  +        @@ -174,6 +190,14 @@

All files / src/agent abstract onMarketInit( marketService: Readonly<MarketService>, ): PromiseOrValue<void>; +  + /** + * Returns the finishing state in percent + * @returns the percent of finished or null if no state is important + */ + getStatus(): number | null { + return null; + }   /** * Registers additional data which the brain can use for decision making. @@ -205,7 +229,7 @@

All files / src/agent diff --git a/docs/coverage/src/agent/models/index.html b/docs/coverage/src/agent/models/index.html index c49c98a..1dbf12a 100644 --- a/docs/coverage/src/agent/models/index.html +++ b/docs/coverage/src/agent/models/index.html @@ -23,9 +23,9 @@

All files src/agent/models

- 100% + 83.33% Statements - 5/5 + 5/6
@@ -37,16 +37,16 @@

All files src/agent/models

- 66.67% + 50% Functions - 2/3 + 2/4
- 100% + 83.33% Lines - 5/5 + 5/6
@@ -88,18 +88,18 @@

All files src/agent/models

brain.model.ts -
+
brain.model.ts +
100%2/266.67%2/3 100% 0/050%1/2100%2/233.33%1/366.67%2/3
0%0/160/18 0% 0/2 0%0/40/5 0%0/130/15
0%0/470%0/60/54 0% 0/8 0%0/400/120%0/46
0%0/50/6 100% 0/0 100% 0/0 0%0/50/6
  +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74        @@ -164,6 +174,16 @@

All files / src/szenario       +  +  +  +  +  +  +  +  +  +        @@ -220,6 +240,16 @@

All files / src/szenario public getAvailable() { return this.szenarioService.get(); } +  + @Get('status') + @ApiResponse({ + status: 200, + type: Number, + }) + @ApiOperation({ description: 'Gets the execution state of a szenario in percent. 100 means its a the szenario is finished' }) + public async getSzenarioProgress() { + return this.szenarioService.getSzenarioProgress(); + }   @Post() @ApiBody({ @@ -234,7 +264,7 @@

All files / src/szenario @Body() szenarioDto: SzenarioStartDto, @Headers('Authorization') auth: string, ) { - if (!auth) throw new UnauthorizedException(); // TODO: + if (!auth) throw new UnauthorizedException(); return this.szenarioService.runSzenario(szenarioDto, auth); }   @@ -253,7 +283,7 @@

All files / src/szenario diff --git a/docs/coverage/src/szenarios/szenario.service.ts.html b/docs/coverage/src/szenarios/szenario.service.ts.html index 50a8afa..a996cf6 100644 --- a/docs/coverage/src/szenarios/szenario.service.ts.html +++ b/docs/coverage/src/szenarios/szenario.service.ts.html @@ -25,28 +25,28 @@

All files / src/szenario
0% Statements - 0/47 + 0/54
0% Branches - 0/6 + 0/8
0% Functions - 0/8 + 0/12
0% Lines - 0/40 + 0/46
@@ -172,7 +172,22 @@

All files / src/szenario 113 114 115 -116

  +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131        @@ -180,6 +195,7 @@

All files / src/szenario       +        @@ -227,14 +243,24 @@

All files / src/szenario       +        +  +        +  +  +  +      +  +  +        @@ -248,7 +274,8 @@

All files / src/szenario       -  +  +        @@ -262,6 +289,9 @@

All files / src/szenario       +  +  +        @@ -295,6 +325,7 @@

All files / src/szenario import { filter, map, mergeAll, switchMap, tap, toArray } from 'rxjs/operators'; import { Agent } from 'src/agent/models/agent.model'; import { AgentService } from 'src/agent/services/agent.service'; +import { NewsService } from 'src/news/news.service'; import { SzenarioStartDto } from './szenarioStart.dto';   const SZENARIO_FOLDER = join(__dirname, '../assets/szenarios'); @@ -342,19 +373,29 @@

All files / src/szenario private runningSzenario: number; private szenarioAgents: Agent[] = [];   - constructor(private readonly agentService: AgentService) { + constructor( + private readonly agentService: AgentService, + private readonly newsService: NewsService + ) { this.loadSzenarios(); } +  + async getSzenarioProgress() { + if (this.runningSzenario === null || !this.isRunningSzenario) return 100; +  + const percentages = this.szenarioAgents + .map(({ brain }) => brain.getStatus()) + .filter((v) => v !== null); + return percentages.reduce((a, b) => a + b, 0) / percentages.length; + }   private async loadSzenarios() { for (const fileName of await readdir(SZENARIO_FOLDER)) { - if (!fileName.startsWith('Transformed')) continue; -  const path = join(SZENARIO_FOLDER, fileName); const contents = JSON.parse(await readFile(path, 'utf-8')); this.availableSzenarios.push({ id: this.availableSzenarios.length, - name: fileName, + name: fileName.replace('.json', ''), data: contents, }); } @@ -362,11 +403,12 @@

All files / src/szenario   public getSzenario(id: number) { if (id > this.availableSzenarios.length) throw new BadRequestException(); - console.log(this.availableSzenarios[id]); return this.availableSzenarios[id]; }   - get(id?: number) { + get(): Szenario[]; + get(id: number): Szenario; + get(id?: number): Szenario | Szenario[] { if (id) return this.getSzenario(id); return this.availableSzenarios; } @@ -377,6 +419,9 @@

All files / src/szenario   this.isRunningSzenario = true; //TODO: Ende des szenarios this.runningSzenario = szenario.szenario; +  + await this.newsService.sendNews(szenario.message); +  const agent = await this.agentService.agentFactory( 'szenario', this.getSzenario(szenario.szenario).data, @@ -409,7 +454,7 @@

All files / src/szenario diff --git a/docs/coverage/src/szenarios/szenarioStart.dto.ts.html b/docs/coverage/src/szenarios/szenarioStart.dto.ts.html index 3456039..48f5bbc 100644 --- a/docs/coverage/src/szenarios/szenarioStart.dto.ts.html +++ b/docs/coverage/src/szenarios/szenarioStart.dto.ts.html @@ -25,7 +25,7 @@

All files / src/szenario
0% Statements - 0/5 + 0/6
@@ -46,7 +46,7 @@

All files / src/szenario
0% Lines - 0/5 + 0/6
@@ -75,7 +75,12 @@

All files / src/szenario 16 17 18 -19

  +19 +20 +21 +22 +23 +24        @@ -93,6 +98,11 @@

All files / src/szenario       +  +  +  +  +   

import { ApiProperty } from '@nestjs/swagger';
  
 export class SzenarioStartDto {
@@ -110,6 +120,11 @@ 

All files / src/szenario description: 'How fast the szenario should be executed', }) speedMultiplicator: number; +  + @ApiProperty({ + description: 'Which message should be sent into the news channel', + }) + message: string; }  

@@ -118,7 +133,7 @@

All files / src/szenario