Skip to content

Adding auto-reporting feature#232

Merged
Bachibouzouk merged 16 commits intodevfrom
feature/f2_autoreporting
Apr 27, 2020
Merged

Adding auto-reporting feature#232
Bachibouzouk merged 16 commits intodevfrom
feature/f2_autoreporting

Conversation

@mahendrark
Copy link
Copy Markdown
Contributor

@mahendrark mahendrark commented Mar 25, 2020

Fix #134

Changes proposed in this pull request:

  • Create a draft PR for this feature - "Basic report"
  • Develop "basic report" - using the plotly examples above recreate the word outline of the report in html (graphs inserted as png, no data from json file, but text and formatting) -> Add F2 module

The following steps were realized, as well (if applies):

  • Use in-line comments to explain your code
  • Write docstrings to your code
  • For new functionalities: Explain in readthedocs
  • Write test(s) for your new patch of code
  • Update the CHANGELOG.md
  • Apply black (black . --exclude docs/)
  • Check if tests pass

Please mark above checkboxes as following:

  • Open
  • Done

❌ Check not applicable to this PR

For more information on how to contribute check the CONTRIBUTING.md.

@smartie2076
Copy link
Copy Markdown
Collaborator

As discussed, you could use variables to define that input (strings) that are added to the html site that you create with plotly:

import dash_html_components as html

SCENARIO_NAME = "any string"

print("Bla, %s", INPUT_FOLDER)

html.Div([
    html.H1('%s', SCENARIO_NAME),
    html.Div([
        html.P('Dash converts Python classes into %s', INPUT_FOLDER),
        html.P('This conversion happens behind the scenes by Dash's JavaScript front-end')
    ])
])

(I do not konw if %s and so on is the right way to use variables with the dash library, but something like that).

@Bachibouzouk
Copy link
Copy Markdown
Collaborator

Bachibouzouk commented Mar 25, 2020

If you have questions with Dash, I can help :)

import dash_html_components as html

SCENARIO_NAME = "any string"

print("Bla, %s", INPUT_FOLDER)

html.Div([
    html.H1(SCENARIO_NAME),
    html.Div([
        html.P('Dash converts Python classes into {}'.format(INPUT_FOLDER)),
        html.P('This conversion happens behind the scenes by Dash's JavaScript front-end')
    ])
])

using '%s' is the older way, now the syntax uses '{}'.format(variable_name} or directly f'{variable_name}'

@mahendrark
Copy link
Copy Markdown
Contributor Author

thank you @Bachibouzouk
I will get in touch should a doubt arise
I am just looking into Dash HTML docs on Plotly websit

@smartie2076
Copy link
Copy Markdown
Collaborator

smartie2076 commented Mar 30, 2020

Hi @mahendrark, is anything you can push to this branch? I would be really happy to have a look at the HTML/dash HTML/code until our call on Wednesday! :)

Copy link
Copy Markdown
Collaborator

@smartie2076 smartie2076 left a comment

Choose a reason for hiding this comment

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

Cool, thanks for the update!
Can you add the libraries I have to install to test the code in the requirements.txt?

@smartie2076
Copy link
Copy Markdown
Collaborator

smartie2076 commented Mar 31, 2020

Can you add the libraries I have to install to test the code in the requirements.txt?

This will probably have to be added:

dash==1.4.1
dash-core-components==1.3.1
dash-html-components==1.0.1

@mahendrark
Copy link
Copy Markdown
Contributor Author

@smartie2076 , I will add the packages used to requirements.txt once I am done with the HTML Layout script. Other packages might be needed as well.

In addition to the changes you suggested, I will also make branch-id as a separate variable so that we can use the technic @SabineHaas suggested in the issue thread #134

@smartie2076
Copy link
Copy Markdown
Collaborator

@smartie2076 , I will add the packages used to requirements.txt once I am done with the HTML Layout script. Other packages might be needed as well.

I think it is better to include them step by step, so that when I or so. else pulls your branch to test it can also execute it effortlessly.

In addition to the changes you suggested, I will also make branch-id as a separate variable so that we can use the technic @SabineHaas suggested in the issue thread #134

👍

@smartie2076
Copy link
Copy Markdown
Collaborator

smartie2076 commented Apr 1, 2020

Maybe this will help with the tables? Link to plotly dash tutorial
Search for "table" or "Reusable Components", it seems a really nice code excerpt.

@smartie2076 smartie2076 requested a review from Bachibouzouk April 1, 2020 14:39
@smartie2076
Copy link
Copy Markdown
Collaborator

Hi @mahendrark, I suppose I did something not quite proper by directly committing "Add simDate=today()" to the branch - sorry. It defines simDate directly with todays date.

'/logo-eland-original.svg', width='370px'),
html.H1('MULTI VECTOR SIMULATION - REPORT SHEET')],
style={
'textAlign': 'center',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is better to save all the style setting in a class def in a cssfile, then use the prop className to link to the class. For small project inline styling is ok though.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can save the css file in a folde rnamed assets then dash will automatically load it (the folder should be in the same path as the file defining the app)


html.Div(className='inpdatabox', children=[html.H2('INPUT DATA')],
style={
'textAlign': 'center',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In the css file you can add this to

.inpdatabox h2{
    ...
}

@Bachibouzouk
Copy link
Copy Markdown
Collaborator

@mahendrark - I don't see graphs or tables here, could you push everytime you make progress on this branch? You can create functions which return an html.Div to avoid duplicate code, ie, if many graphs or dashtables have silimar layout you can generate them with these functions you defined (with content as argument of the function).

A good thing to do is to always make the rough html structure of the whole report, then fill the sections

import dash_html_components as html
import time
import pandas as pd
import reverse_geocoder as rg
Copy link
Copy Markdown
Collaborator

@smartie2076 smartie2076 Apr 8, 2020

Choose a reason for hiding this comment

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

Please add this also to requirements.txt:

reverse_geocoder=1.5.1
scipy=1.4.1

# This script generates a report of the simulation automatically, with all the important data.

# Importing necessary packages
import dash
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"Updates" is not a very helpful commit message, especially if all your commit messages are "Updates" :)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You can stlll change it by doing git commit --amendand then git push -f

@mahendrark
Copy link
Copy Markdown
Contributor Author

@smartie2076
can you please run the updated f2 script and let me know if you see the demand and pv input time series images in the dash rendering on the browser?

For some reason, the browser doesnt render those when I run the script.

@Bachibouzouk
Copy link
Copy Markdown
Collaborator

Bachibouzouk commented Apr 21, 2020

@mahendrark - I know why, you can't directly provide png :) Let me find the process for you:

your_image = base64.b64encode(open('<path to your image>.png', 'rb').read())

html.Img(src='data:image/png;base64,{}'.format(your_image.decode()))

@smartie2076
Copy link
Copy Markdown
Collaborator

You can find the plot functions in F1. Specifically, here

@mahendrark
Copy link
Copy Markdown
Contributor Author

@smartie2076 & @Bachibouzouk,
I have some questions related to the time series plots
Since the aim is to automate everything, how should I go about reading in the images of the plots?

Which plots to choose if there are multiple PV components and demand time series?
Will the names of the plots' images always be in a standardized format?

@smartie2076
Copy link
Copy Markdown
Collaborator

Which plots to choose if there are multiple PV components and demand time series?

In the future, there will be multiple PV components/demands - they should all be in the automatic report at some point. Basically, we only have to wrap a loop around the calls of html.Img() to add them all in later.

Will the names of the plots' images always be in a standardized format?

Yeah, there is a standardized format - we can create the loop from that format but also the json_processed file.

For now, please concencrate on the simple example given with the "inputs" on dev. The other stuff comes in the next iteration! :)

@Bachibouzouk
Copy link
Copy Markdown
Collaborator

@mahendrark - you can use the raw data to make plotly plots :)

@mahendrark
Copy link
Copy Markdown
Contributor Author

@Bachibouzouk

I am struggling a bit with the pdf report generation. Can you please help me out?

Specific question.. how do we save a HTML file from the dash web app ?
If I have that, then I could xhtml2pdf library and create a PDF?




dfprojectData = pd.read_csv('../inputs/csv_elements/project_data.csv')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Did you run black . prior to committing? I am not sure why you commit 3 empty spaces?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops. This is a mistake. I wanted to read the data just below the three empty lines from JSONs as well. But then postponed it and forgot to remove these lines. Consider them placeholders xD

@smartie2076
Copy link
Copy Markdown
Collaborator

smartie2076 commented Apr 27, 2020

@Bachibouzouk agreed to take over the task of integrating F2 into the mvs.

  • Add an argument (or a simulation_setting) to activate/deactivate creating the report with F2
  • Enable creating a pdf from the plotly dash html, store to output path (can also be finished together with @mahendrark )
  • Update requirements.txt
  • Reformat F2 to be a callable function and call it in F0 here, below l. 104, create a test in F0 that pdf is created
  • Update variable calls within F2 to constants.py and dict_values (the dict structure is as in json_with_results.json

@Bachibouzouk
Copy link
Copy Markdown
Collaborator

@mahendrark - I would say that this PR should be merged and subsequent PR should be made for

  1. the integration of F2 with MVS
  2. improvment of F2

@mahendrark
Copy link
Copy Markdown
Contributor Author

@Bachibouzouk
please go ahead and merge it as the most important tasks have been ticked off.

I will take up all other tasks in the next PR, as you suggested.

@Bachibouzouk Bachibouzouk force-pushed the feature/f2_autoreporting branch from 51c2e2d to 44b6df9 Compare April 27, 2020 19:57
@Bachibouzouk Bachibouzouk marked this pull request as ready for review April 27, 2020 19:57
@Bachibouzouk Bachibouzouk self-requested a review April 27, 2020 19:58
Copy link
Copy Markdown
Collaborator

@Bachibouzouk Bachibouzouk left a comment

Choose a reason for hiding this comment

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

This will be merged as is and subsequent PR will be opened for improvements to the feature of auto-reporting and integration into mvs

@Bachibouzouk Bachibouzouk merged commit bc91f2c into dev Apr 27, 2020
@Bachibouzouk Bachibouzouk deleted the feature/f2_autoreporting branch April 27, 2020 20:07
@Bachibouzouk Bachibouzouk mentioned this pull request May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Feature: Automatic generation of simulation reports

3 participants