Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the existing dashboard to NREL's template #50

Merged
merged 24 commits into from
Sep 7, 2022
Merged

Move the existing dashboard to NREL's template #50

merged 24 commits into from
Sep 7, 2022

Conversation

zackAemmer
Copy link
Contributor

@zackAemmer zackAemmer commented Aug 24, 2022

Minimal changes to existing code, this simply copies the existing dashboard to the style/format in the NREL template.

Screen Shot 2022-08-24 at 9 08 20 AM

Screen Shot 2022-08-24 at 9 08 38 AM

@zackAemmer
Copy link
Contributor Author

zackAemmer commented Aug 24, 2022

Next steps:
-Change docker scripts/dashboard to use e-mission config files, so that they only run the notebooks relevant to their deployment.
-Make sure notebooks will work with NREL-hosted EFS (should be no changes).

@zackAemmer
Copy link
Contributor Author

Made some changes to support the dynamic configs PR: #51

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

I see that the metrics are dynamic, but what about the dates? It seems like if you knew what the start date was, generating the months after that should be not too bad. Fortunately, the months don't have the additional x and y parameters that the metrics do.

moment.js should make this relatively straightforward, not sure if we want to add that dependency. Not sure if there is an easy way without it that works across multiple years, though

const MONTHS = () => {
 const months = []
 const dateStart = moment()
 const dateEnd = moment().add(12, ‘month') while (dateEnd.diff(dateStart, ‘months') >= 0) {
  months.push(dateStart.format(‘M'))
  dateStart.add(1, ‘month')
 }
 return months
}

Comment on lines 18 to 9
<option value="ntrips_ebike_purpose" data-sizex="4" data-sizey="4">eBike trip count by purpose</option>
<option value="ntrips_ebike_replaced_mode" data-sizex="4" data-sizey="4">eBike trip count by replaced mode</option>
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this use the mode_of_interest from the config instead of the hardcoded eBike?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed all hard-coded plot names

Copy link
Contributor

Choose a reason for hiding this comment

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

You renamed all of them to "mode specific", which doesn't mean that much to an end user since it is not clear which mode you are targeting.

I think we should fill this in with the mode of interest instead. There are jquery templating plugins
https://www.endyourif.com/jquery-creating-templates-for-your-html-content/#jquery-template
but we should also be able to do something simpler with string replacement in javascript

@zackAemmer
Copy link
Contributor Author

Now the date list should populate from the date in the dynamic configs. Currently using numeric date for convenience, but could add a map from numbers to months.

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

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

Number of changes is going down...

Comment on lines 202 to 206
<li data-row="1" data-col="1" data-sizex="4" data-sizey="4">
Number of trips (Nov 2020)
<button class='remove'>x</button>
<img src='plots/ntrips_mode_confirm_2020_11_prepilot.png' width=90% height=90%>
</li>
Copy link
Contributor

Choose a reason for hiding this comment

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

we also need to change this to show the plots for the most recent month instead of the hardcoded results for 2020_11 which is way too old

@zackAemmer
Copy link
Contributor Author

Added DoE logo and text near bottom of page, to match the example more closely we could write some text at the top, or also the DoE logo could be at the top near the NREL logo. This is what ended up looking cleanest.

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Screen Shot 2022-09-06 at 7 13 16 PM

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

dropdowns are now in two rows instead of one.

Differences between the two are mainly additional overrides on the NREL site

NREL site 1 NREL site 2 NREL site 3 CanBikeCO site
Screen Shot 2022-09-06 at 7 19 50 PM Screen Shot 2022-09-06 at 7 20 42 PM Screen Shot 2022-09-06 at 7 21 30 PM Screen Shot 2022-09-06 at 7 21 48 PM

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Screen Shot 2022-09-06 at 7 33 31 PM

Collapsed Expanded
Screen Shot 2022-09-06 at 7 34 10 PM Screen Shot 2022-09-06 at 7 34 29 PM

Similar to the existing CanBikeCO
This also required some refactoring of the `getMonthList` function.

Without the refactoring, we would get into an infinite loop where we kept
iterating over dates forever. I am not 100% sure if this is because the current
month = 9 and the start month for the selected program was also 9, or whether
it was because the start_month was a string.

+ convert the configured values into ints otherwise you end up with a month
that is 91111111

This works now
Before this change, the "value" in the option was misformatted, AND did not
have the initial zero padding for the month.

Fixes are to create a padded value for the month
(https://bobbyhadz.com/blog/javascript-pad-number-with-leading-zeros)
and then use built-in javascript templates (back ticks) to construct the
options in a more legible fashion.
https://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

So now we have a solution for templating in raw javascript that does not depend
on any templating libraries.  Yay!
@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Malformatted choices integer values (non padded)
Screen Shot 2022-09-06 at 9 48 00 PM Screen Shot 2022-09-06 at 9 49 22 PM

Fixed now!!

Screen Shot 2022-09-06 at 10 17 07 PM

… interest

Attempts which did not work:
- using the backtick templates - were not replaced, probably because this was
  part of a different load
- using a different string - e.g. MODE_OF_INTEREST instead of
  `${data.intro.mode_of_interest}` - error while loading
- Removing ticks around the mode of interest - error while loading

Final solution is to load the data, and in the callback, change the text
manually using `replaceAll` and then set the options. That works properly.
@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Replaced in the text (albeit with a few extra ticks)
Screen Shot 2022-09-06 at 11 28 18 PM

Replaced in the value
Screen Shot 2022-09-06 at 11 28 53 PM

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Note that we display the mode of interest in the internal representation, not in the potentially translated representation.
Instead, the mode of interest should be outside the intro (it is not intro specific) and the translation(s) can be in the intro section, where we have translations for both Spanish and English.

Added to e-mission/e-mission-docs#788

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

At this point, the only tasks left are:

  • read the study name from an environment variable
  • create a production environment which copies all the files into the image
    • note that this needs to also be configured to accept the environment variable above.

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

oh wait, we also remove the hardcoding on the initial set of slots.

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

The problem with the javascript-based templating is that it only works on javascript, not in HTML.
So we need to workaround with jquery templates or with manual find/replace.
#50 (comment)

- The set of graphs are different from programs and studies
- we "hack" the graph creation by setting the values in the metric and then
  simulating a mouse click. This allows us to reuse the existing code to add
  metrics, which relies heavily on data in the select options
- we make sure to set the date to the most recent one so that the graphs that
  are displayed are for the most recent month and year
    - As a bonus, the most recent month and year are selected, which is what
      people expect :)
@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

Screen Shot 2022-09-07 at 8 05 40 AM

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

NOW, we can finally work on creating the production dockerfiles/docker-compose.

zackAemmer and others added 2 commits September 7, 2022 08:33
NREL OpenPATH dashboard makes it seem like this is *the* dashboard for NREL
OpenPATH. But in fact, it is the dashboard for each individual study or
program. So let's actually populate the title (page title + top visible title)
with the study-specific information.

As a bonus, this is an example for @sebastianbarry on how to configure text
without having to include a templating library.
@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

We may need to go through the existing program configs and change them a bit 😄

Screen Shot 2022-09-07 at 8 45 47 AM

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

@zackAemmer e267dcd is not actually a typo - it was an experiment to see where I needed to put the ticks. Once I figured it out, I didn't go back and change it.

Thanks for making it consistent with the others!

@shankari
Copy link
Contributor

shankari commented Sep 7, 2022

My changes approved by @zackAemmer

Screen Shot 2022-09-07 at 10 06 11 AM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants