Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Feature/awf/cleanup time agg param#212 #231

Merged
merged 4 commits into from
Sep 1, 2017

Conversation

CloudNiner
Copy link

Overview

Replaces the string type of the time_aggregation indicator param with a new enum type TimeAggParam. This allows for improved type checking.

Assigned both of you so you can see this change. @flibbertigibbet because I mentioned I was making it in a previous PR you authored, and @fungjj92 so it can inform your work on the percentile indicator params.

Demo

No user facing changes

Notes

To make this easier, I replaced the subclassing of IndicatoryQueryOpts by making IndicatorQueryOpts.params have a new IndicatorParams interface that can be extended instead of the QueryOpts interfaces. This provides a much improved type interface for these, and allows us to better type check the params as they're passed around the app, especially when we construct requests to IndicatorService and when we pass the params around via EventEmitters.

The models folder is getting pretty big, and its now very unwieldy to import one item from each file everywhere. I considered adding an index.ts to the models folder and exporting all of the items in that folder there and updating import statements across the app, but that would have cluttered the intent of this PR. Maybe a good separate issue.

Testing Instructions

App should continue to function

Closes #212

CloudNiner added 3 commits August 31, 2017 15:03
Refactor such that IndicatorQueryOpts.params
now has type IndicatorParams which can be
extended with additional parameters for some
indicators. Improves type checking and prevents
us from having to write duplicate interface defs
for indicators that need to extend the params
of IndicatorQueryOpts
Gives these EventEmitters a more specific API
contract, to always be of type IndicatorParams,
which includes "subtypes" such as
ThresholdIndicatorParams
Includes a few more places where we can better typecast
params to the new IndicatorParam type
@CloudNiner
Copy link
Author

Most of below lifted from an offline discussion, but copied here for visibility (@jcahail):

I chose to go with only the yearly time agg option and not provide a user selectable dropdown. The quarterly and monthly options provide too much noise unless a user is zoomed in to a few year's time range, at which point it's not really possible to glean useful information from it.

Monthly option for all years:
screen shot 2017-09-01 at 10 04 56

Monthly option at ~5yr range:
screen shot 2017-09-01 at 10 06 32

We could potentially revisit this if we hear a bunch of users requesting it, but for now its less effort and less complicated for users to just omit the option.

@@ -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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the data object removed here? You had asked for it to be added in another PR.

Copy link
Author

Choose a reason for hiding this comment

The 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 EventEmitters work. What's here now is the proper way to return data via event emitters, if you do not need the DOM Event

import { TimeAggParam } from './time-agg-param.enum';

export interface IndicatorParams {
climateModels?: ClimateModel[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed these are all optional. Shouldn't they be required?

Copy link
Author

Choose a reason for hiding this comment

The 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.

@@ -17,7 +17,6 @@ export class ChartService {

private timeOptions = {
'yearly': '%Y',
'daily': '%Y-%m-%d',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a quarterly format added here?

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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 D3.timeParse. We'd need this refactor for pretty much all of the other remaining valid time aggs if we chose to display them in the lab UI.

@@ -115,18 +116,15 @@ export class ChartComponent implements OnChanges, OnDestroy, AfterViewInit {
this.cancelDataRequest();
}

updateChart(extraParams: any) {
updateChart(extraParams: IndicatorParams) {
this.cancelDataRequest();
this.chartData = [];
this.rawChartData = [];

Copy link
Contributor

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

Copy link
Author

@CloudNiner CloudNiner Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because interface ThresholdIndicatorParams extends interface IndicatorParams

Copy link
Contributor

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.

@@ -0,0 +1,10 @@
import { ClimateModel } from './climate-model.model';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now there are two models:
indicator-parameters.model.ts
indicator-params.model.ts

in the models folder, and that is confusing

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using the term "extra params"
Maybe
indicator-extra-params?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps indicator-query-parameters

Copy link
Author

Choose a reason for hiding this comment

The 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:

  • IndicatorQueryOpts -> IndicatorRequestOpts
  • IndicatorParams -> IndicatorGetParams
  • Leave IndicatorParam unchanged

Copy link
Contributor

@fungjj92 fungjj92 Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK IndicatorRequestOpts
2 -- > IndicatorParamsList? or IndicatorQueryStringParams?
OK IndicatorParam

Copy link
Author

@CloudNiner CloudNiner Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IndicatorQueryParams would just be a shorter version of your second option that isn't any less descriptive. How about that? Definitely like your second suggestion, which is more properly named than even IndicatorGetParams, than the first.

To hopefully reduce confusion:
- IndicatorQueryOpts -> IndicatorRequestOpts
- IndicatorParams -> IndicatorQueryParams
- No change to IndicatorParam
@CloudNiner CloudNiner merged commit 544ee98 into develop Sep 1, 2017
@CloudNiner CloudNiner deleted the feature/awf/cleanup-time-agg-param#212 branch September 1, 2017 16:00
fungjj92 added a commit that referenced this pull request Sep 1, 2017
fungjj92 added a commit that referenced this pull request Sep 1, 2017
fungjj92 added a commit that referenced this pull request Sep 1, 2017
fungjj92 added a commit that referenced this pull request Sep 1, 2017
fungjj92 added a commit that referenced this pull request Sep 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants