-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/awf/cleanup time agg param#212 #231
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { AfterViewInit, Component, EventEmitter, Input, Output, OnInit } from '@ | |
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
|
||
import { Indicator } from '../../models/indicator.model'; | ||
import { ThresholdIndicatorParams } from '../../models/threshold-indicator-params.model'; | ||
|
||
import * as _ from 'lodash'; | ||
|
||
|
@@ -16,7 +17,8 @@ import * as _ from 'lodash'; | |
export class ThresholdComponent implements AfterViewInit, OnInit { | ||
|
||
@Input() indicator: Indicator; | ||
@Input() extraParams: any; | ||
@Input() extraParams: ThresholdIndicatorParams; | ||
@Output() thresholdParamSelected = new EventEmitter<ThresholdIndicatorParams>(); | ||
|
||
thresholdForm: FormGroup; | ||
|
||
|
@@ -50,8 +52,6 @@ export class ThresholdComponent implements AfterViewInit, OnInit { | |
|
||
@Input() thresholdUnits: any[] = this.thresholdTemperatureUnits; | ||
|
||
@Output() thresholdParamSelected = new EventEmitter<any>(); | ||
|
||
constructor(private formBuilder: FormBuilder) {} | ||
|
||
ngOnInit() { | ||
|
@@ -62,11 +62,11 @@ export class ThresholdComponent implements AfterViewInit, OnInit { | |
ngAfterViewInit() { | ||
// Since valueChanges triggers initially before parent is ready, wait until | ||
// parent is ready here and trigger it to draw chart with extra parameters. | ||
this.thresholdParamSelected.emit({data: { | ||
this.thresholdParamSelected.emit({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I had misunderstood what the original problem was based on the comments before, combined with forgetting the details of how |
||
'threshold_comparator': this.thresholdForm.controls.comparatorCtl.value, | ||
'threshold': this.thresholdForm.controls.thresholdCtl.value, | ||
'threshold_units': this.thresholdForm.controls.thresholdUnitCtl.value | ||
}}); | ||
}); | ||
} | ||
|
||
createForm() { | ||
|
@@ -78,12 +78,11 @@ export class ThresholdComponent implements AfterViewInit, OnInit { | |
}); | ||
|
||
this.thresholdForm.valueChanges.debounceTime(700).subscribe(form => { | ||
this.thresholdParamSelected.emit({data: { | ||
'event': event, | ||
this.thresholdParamSelected.emit({ | ||
'threshold_comparator': form.comparatorCtl, | ||
'threshold': form.thresholdCtl, | ||
'threshold_units': form.thresholdUnitCtl | ||
}}); | ||
}); | ||
}); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ClimateModel } from './climate-model.model'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now there are two models: in the models folder, and that is confusing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any suggestions for better names? otherwise I'll try to come up with something There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been using the term "extra params" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or perhaps indicator-query-parameters There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have indicator-query-opts and these params aren't always the subset that are the extra params. They're really the GET params to an API request. What about the following refactor:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK IndicatorRequestOpts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
import { TimeAggParam } from './time-agg-param.enum'; | ||
|
||
export interface IndicatorParams { | ||
climateModels?: ClimateModel[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just noticed these are all optional. Shouldn't they be required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because none of these params are required to make an API request, they all have defaults. |
||
years?: string[]; | ||
time_aggregation?: TimeAggParam; | ||
agg?: string; | ||
unit?: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
import { City } from './city.model'; | ||
import { Indicator } from './indicator.model'; | ||
import { IndicatorParams } from './indicator-params.model'; | ||
import { ClimateModel } from './climate-model.model'; | ||
import { Scenario } from './scenario.model'; | ||
|
||
export interface IndicatorQueryOpts { | ||
indicator: Indicator; | ||
city: City; | ||
scenario: Scenario; | ||
params: { | ||
climateModels?: ClimateModel[]; | ||
years?: string[]; | ||
time_aggregation?: string; | ||
unit?: string; | ||
} | ||
params: IndicatorParams; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IndicatorParams } from './indicator-params.model'; | ||
|
||
export interface ThresholdIndicatorParams extends IndicatorParams { | ||
threshold: Number; | ||
threshold_units: string; | ||
threshold_comparator: string; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export enum TimeAggParam { | ||
Yearly = 'yearly', | ||
Quarterly = 'quarterly', | ||
Monthly = 'monthly' | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ export class ChartService { | |
|
||
private timeOptions = { | ||
'yearly': '%Y', | ||
'daily': '%Y-%m-%d', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be a quarterly format added here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we don't use it but it wouldn't hurt to be thorough There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, can't do this now. It would require additional refactoring. In the quarterly case, we need to convert the keys in the API (e.g. 2010-3) into the start date for a "quarter" which would be July 1, 2010 for 2010-3, and that can't be done with |
||
'monthly': '%Y-%m' | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not understanding why the typecheck doesn't complain when ThresholdIndicatorParams are sent through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
interface ThresholdIndicatorParams
extendsinterface IndicatorParams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting. Extending works the opposite direction I was expecting, then. Cool.