From c5296965d5454a1bc6dfe102facc9d05a6ecb38b Mon Sep 17 00:00:00 2001 From: Jenny Fung Date: Fri, 30 Dec 2016 13:59:39 -0500 Subject: [PATCH 1/2] Fix lab to accomodate API changes up to 12/30/16 --- src/app/charts/chart.component.ts | 5 ++++- src/app/models/chart-data.model.ts | 14 +++++++++++--- src/app/models/indicator-query-opts.model.ts | 3 ++- src/app/models/indicator.model.ts | 5 ++++- src/app/services/chart.service.ts | 4 ++-- src/app/services/indicator.service.ts | 3 +++ src/app/sidebar/sidebar.component.ts | 9 ++------- 7 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/app/charts/chart.component.ts b/src/app/charts/chart.component.ts index 2a698883..a70c185d 100644 --- a/src/app/charts/chart.component.ts +++ b/src/app/charts/chart.component.ts @@ -51,7 +51,10 @@ export class ChartComponent implements OnChanges { indicator: this.chart.indicator, scenario: this.scenario, city: this.city, - climateModels: this.models + climateModels: this.models, + // As a temporary solution, the time agg defaults to the 1st valid option. + // Really, this should a user selectable option + time_aggregation: this.chart.indicator.valid_aggregations[0] }).subscribe(data => this.chartData = this.chartService.convertChartData([data])); } diff --git a/src/app/models/chart-data.model.ts b/src/app/models/chart-data.model.ts index 4158c79e..de0d280b 100644 --- a/src/app/models/chart-data.model.ts +++ b/src/app/models/chart-data.model.ts @@ -1,8 +1,16 @@ import { MultiDataPoint } from './multi-data-point.model'; +import { Indicator } from './indicator.model'; +import { City } from './city.model'; +import { ClimateModel } from './climate-model.model'; +import { Scenario } from './scenario.model'; export class ChartData { - indicator: string; + indicator: Indicator; data: MultiDataPoint[]; - time_agg: string[]; + time_aggregation: string; time_format: string; -} \ No newline at end of file + city?: City; + climate_models?: ClimateModel[]; + scenario?: Scenario; + units?: string +} diff --git a/src/app/models/indicator-query-opts.model.ts b/src/app/models/indicator-query-opts.model.ts index d16a8d5a..f8f27523 100644 --- a/src/app/models/indicator-query-opts.model.ts +++ b/src/app/models/indicator-query-opts.model.ts @@ -9,4 +9,5 @@ export interface IndicatorQueryOpts { scenario: Scenario; climateModels?: ClimateModel[]; years?: string[]; -} \ No newline at end of file + time_aggregation?: string; +} diff --git a/src/app/models/indicator.model.ts b/src/app/models/indicator.model.ts index 0106d184..7c7fab4f 100644 --- a/src/app/models/indicator.model.ts +++ b/src/app/models/indicator.model.ts @@ -4,5 +4,8 @@ export class Indicator { description: string; time_aggregation: string; variables: string[]; + available_units?: string[]; + default_units?: string; + parameters?: any[]; + valid_aggregations?: string[]; } - diff --git a/src/app/services/chart.service.ts b/src/app/services/chart.service.ts index 94935aaa..cf8753ff 100644 --- a/src/app/services/chart.service.ts +++ b/src/app/services/chart.service.ts @@ -60,7 +60,7 @@ export class ChartService { _.each(data, obj => { let indicatorData: MultiDataPoint[] = []; let indicator = obj.indicator; - let timeFormat = this.timeOptions[indicator.time_aggregation]; + let timeFormat = this.timeOptions[obj.time_aggregation]; let parseTime = D3.timeParse(timeFormat); _.each(obj.data, (values, key) => { @@ -75,7 +75,7 @@ export class ChartService { chartData.push({ 'indicator': indicator, 'data': indicatorData, - 'time_agg': indicator.time_aggregation, + 'time_aggregation': indicator.time_aggregation, 'time_format': timeFormat } as ChartData); } diff --git a/src/app/services/indicator.service.ts b/src/app/services/indicator.service.ts index d432f56f..2d5c6f2d 100644 --- a/src/app/services/indicator.service.ts +++ b/src/app/services/indicator.service.ts @@ -28,6 +28,9 @@ export class IndicatorService { if (options.climateModels) { searchParams.append('models', options.climateModels.map(m => m.name).join(',')); } + if (options.time_aggregation) { + searchParams.append('time_aggregation', options.time_aggregation); + } let requestOptions = new RequestOptions({search: searchParams}); return this.apiHttp.get(url, requestOptions).map(resp => resp.json()); diff --git a/src/app/sidebar/sidebar.component.ts b/src/app/sidebar/sidebar.component.ts index 25cd57a9..c96b0316 100644 --- a/src/app/sidebar/sidebar.component.ts +++ b/src/app/sidebar/sidebar.component.ts @@ -32,15 +32,10 @@ export class SidebarComponent implements OnInit { private groupIndicators(indicators: Indicator[]) { this.tempIndicators = indicators.filter(i => { - return this.isValidIndicator(i) && - (i.variables.indexOf('tasmax') !== -1 || i.variables.indexOf('tasmin') !== -1); + return (i.variables.indexOf('tasmax') !== -1 || i.variables.indexOf('tasmin') !== -1); }); this.precipIndicators = indicators.filter(i => { - return this.isValidIndicator(i) && i.variables.indexOf('pr') !== -1; + return i.variables.indexOf('pr') !== -1; }); } - - private isValidIndicator(indicator: Indicator): boolean { - return indicator.time_aggregation !== 'daily'; - } } From e28377698a740499c54bddf524c22e2e59e9a42e Mon Sep 17 00:00:00 2001 From: Jenny Fung Date: Fri, 30 Dec 2016 14:51:32 -0500 Subject: [PATCH 2/2] Fix obsolete constraints on multi chart scrubber --- src/app/charts/line-graph.component.ts | 4 ++-- src/app/services/chart.service.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/charts/line-graph.component.ts b/src/app/charts/line-graph.component.ts index 2863ebaf..f436dfbb 100644 --- a/src/app/charts/line-graph.component.ts +++ b/src/app/charts/line-graph.component.ts @@ -101,7 +101,7 @@ export class LineGraphComponent implements OnInit, OnDestroy { ngOnInit(): void { // Set up global chart mouseover communication chain if set to multi-chart scrubber // ** CURRENTLY ONLY FOR YEARLY INDICATORS** - if (this.multiChartScrubber && this.indicator.time_aggregation === 'yearly') { + if (this.multiChartScrubber && this.data[0].time_aggregation === 'yearly') { this.multiChartScrubberHoverSubscription = this.chartService.multiChartScrubberHoverObservable.subscribe(data => { this.hover = data; this.hover ? $('.' + this.id).toggleClass('hidden', false) : $('.' + this.id).toggleClass('hidden', true); @@ -116,7 +116,7 @@ export class LineGraphComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { - if (this.multiChartScrubber && this.indicator.time_aggregation === 'yearly') { + if (this.multiChartScrubber && this.data[0].time_aggregation === 'yearly') { this.multiChartScrubberInfoSubscription.unsubscribe(); this.multiChartScrubberHoverSubscription.unsubscribe(); } diff --git a/src/app/services/chart.service.ts b/src/app/services/chart.service.ts index cf8753ff..f1f5d943 100644 --- a/src/app/services/chart.service.ts +++ b/src/app/services/chart.service.ts @@ -75,7 +75,7 @@ export class ChartService { chartData.push({ 'indicator': indicator, 'data': indicatorData, - 'time_aggregation': indicator.time_aggregation, + 'time_aggregation': obj.time_aggregation, 'time_format': timeFormat } as ChartData); }