@@ -3,12 +3,10 @@ import { LoadingController, Platform } from '@ionic/angular';
3
3
import { ActionType , BBCHAction , BrixAction } from './../../models/action.model' ;
4
4
import { STATS_OPTIONS } from './../../conf/statistics.config' ;
5
5
import { StatisticsService } from './../../services/statistics.service' ;
6
- import { VineyardService } from './../../services/vineyard.service' ;
7
- import { MeteoStatEntry , Vineyard } from './../../models/vineyard.model' ;
6
+ import { MeteoStatEntry , TimeSeriesEntry , Vineyard } from './../../models/vineyard.model' ;
8
7
import { AfterViewInit , Component , ElementRef , Input , OnChanges , SimpleChanges , ViewChild } from '@angular/core' ;
9
8
import * as Highcharts from 'highcharts/highstock' ;
10
9
import { Action } from 'src/app/models/action.model' ;
11
- import { TitleCasePipe } from '@angular/common' ;
12
10
import * as moment from 'moment' ;
13
11
import { Variety } from '../../models/variety.model' ;
14
12
import { COLOR , ColorService } from '../../services/color.service' ;
@@ -25,13 +23,14 @@ enum StatTypes {
25
23
ACTIONS = 'Actions' ,
26
24
BBCH = 'BBCH' ,
27
25
METEO = 'Meteo' ,
26
+ NDVI = 'NDVI' ,
28
27
DGD = 'Growing Days' ,
29
28
BRIX = 'Brix' ,
30
29
SUNHOURS = 'Sun Hours' ,
31
30
HUMIDITY = 'Humidity' ,
32
31
}
33
32
34
- const PREMIUM_TYPES : StatTypes [ ] = [ StatTypes . METEO , StatTypes . DGD ] ;
33
+ const PREMIUM_TYPES : StatTypes [ ] = [ StatTypes . METEO , StatTypes . NDVI , StatTypes . DGD ] ;
35
34
36
35
@Component ( {
37
36
selector : 'app-statistics' ,
@@ -76,9 +75,7 @@ export class StatisticsComponent implements AfterViewInit, OnChanges {
76
75
77
76
constructor (
78
77
private utilService : UtilService ,
79
- private vineyardService : VineyardService ,
80
78
private statService : StatisticsService ,
81
- private titlecasePipe : TitleCasePipe ,
82
79
private platform : Platform ,
83
80
private colorService : ColorService ,
84
81
private integrationsService : IntegrationsService ,
@@ -177,6 +174,7 @@ export class StatisticsComponent implements AfterViewInit, OnChanges {
177
174
...this . getSunHoursAxis ( ) ,
178
175
...this . getHumidityAxis ( ) ,
179
176
...this . getBBCHAxis ( ) ,
177
+ ...this . getNDVIAxis ( ) ,
180
178
] ;
181
179
axes . forEach ( ( a : any ) => this . _chart . addAxis ( a ) ) ;
182
180
}
@@ -192,6 +190,10 @@ export class StatisticsComponent implements AfterViewInit, OnChanges {
192
190
requests . push ( this . getWeatherStationMeteoGraphs ( ) , this . getMeteoTimelines ( ) ) ;
193
191
}
194
192
193
+ if ( this . activeStats . includes ( StatTypes . NDVI ) ) {
194
+ requests . push ( this . getNDVITimelines ( ) ) ;
195
+ }
196
+
195
197
if ( this . activeStats . includes ( StatTypes . DGD ) ) {
196
198
requests . push ( this . getWeatherStationDGDGraphs ( ) , this . getDgdTimelines ( ) ) ;
197
199
}
@@ -252,6 +254,21 @@ export class StatisticsComponent implements AfterViewInit, OnChanges {
252
254
} ;
253
255
}
254
256
257
+ getNDVIAxis ( ) : any [ ] {
258
+ return [
259
+ {
260
+ id : 'ndvi' ,
261
+ labels : {
262
+ format : '{value}' ,
263
+ } ,
264
+ title : {
265
+ text : 'NDVI' ,
266
+ } ,
267
+ opposite : true ,
268
+ } ,
269
+ ] ;
270
+ }
271
+
255
272
getMeteoAxis ( ) : any [ ] {
256
273
return [
257
274
{
@@ -448,6 +465,41 @@ export class StatisticsComponent implements AfterViewInit, OnChanges {
448
465
) ;
449
466
}
450
467
468
+ getNDVITimelines ( ) : Observable < any > {
469
+ const stats : TimeSeriesEntry [ ] = this . statService . getNDVIListener ( ) . getValue ( ) ;
470
+ const years = stats
471
+ . map ( ( s : TimeSeriesEntry ) => s . date . year ( ) )
472
+ . filter ( ( y : number , idx : number , ys : number [ ] ) => ys . indexOf ( y ) === idx ) ;
473
+
474
+ return merge (
475
+ [ ] . concat (
476
+ ...years
477
+ . filter ( ( y : number ) => this . seasons . indexOf ( y ) >= 0 )
478
+ . map ( ( y : number , idx : number ) => [
479
+ {
480
+ id : `NDVI ${ y } ` ,
481
+ name : `NDVI ${ y } ` ,
482
+ type : 'spline' ,
483
+ yAxis : 'ndvi' ,
484
+ color : this . colorService . darken ( COLOR . NDVI , idx ) ,
485
+ showInNavigator : true ,
486
+ tooltip : {
487
+ formatter ( point ) {
488
+ return `<span style="color:${ point . color } ">●</span> <b>NDVI ${ y } </b>: ${ point . y } ` ;
489
+ } ,
490
+ } ,
491
+ data : stats
492
+ . filter ( ( s : TimeSeriesEntry ) => s . date . year ( ) === y )
493
+ . map ( ( e : TimeSeriesEntry ) => ( {
494
+ x : this . statService . getNormalizedDate ( e . date ) ,
495
+ y : e . value ,
496
+ } ) ) ,
497
+ } ,
498
+ ] )
499
+ )
500
+ ) ;
501
+ }
502
+
451
503
getMeteoTimelines ( ) : Observable < any > {
452
504
const stats : MeteoStatEntry [ ] = this . statService . getMeteoListener ( ) . getValue ( ) ;
453
505
const years = stats
0 commit comments