Reports - fdechaumont/micecraft GitHub Wiki
The Reports API let you create website with results in a few lines.
Example of a large report can be found here.
Main ideas
- The goal of the Report API is to generate static websites to let you explore your data (and to make this easy). The main principle is to create multiple report sections, and the API will create the website organizing all those sections for you.
- Each report can be text, table, graphs or your custom HTML output.
- This API creates a static website, meaning you can browse your data on your computer or send it on an ftp without any server configuration
- Others included tools helps you uploading your experiment data when they are running to compute reports while your system is running. See MiceCraft analysis examples for info.
Examples
My first report
Let's create a report with one item:
import os
from datetime import datetime
from micecraft.soft.report.WebSite import WebSite
from micecraft.soft.report.Report import Report
import webbrowser
if __name__ == '__main__':
print( f"Starting report generation example at {datetime.now()}")
startComputationTime = datetime.now()
# set output folder
currentFolder = os.path.dirname(os.path.abspath(__file__))
outFolder = currentFolder+"/html_output/"
# create the object WebSite
webSite = WebSite( outFolder=outFolder )
# remove existing files in out folder
webSite.initWebSiteOutFolder( )
# create a report on the main page
webSite.addReport( Report( "Report title", f"Here is a <b>Description</b>." , experimentName="main" ) )
# generate the WebSite based on the reports.
webSite.generateWebSite( )
# open the website in your browser.
webbrowser.open( f"{outFolder}/index.html" )
print("Done.")
... this code creates a simple webpage:
Adding items
If you add those lines:
webSite.addReport( Report( "Report title", f"Here is a <b>Description</b>." , experimentName="main" ) )
webSite.addReport( Report( "Another report", f"My text here" , experimentName="main" ) )
webSite.addReport( Report( "Another one", f"My other report" , experimentName="main" ) )
You now get 3 report items on the page:
Creating entries for each experiment
By changing the experimentName value, you create a new page
for i in range(10):
webSite.addReport( Report( "A report", f"Report text" , experimentName=f"experiment {i}" ) )
On the left side, you can now jump from one experiment to another.
[!NOTE] You can create reports in any order.
Different types of report
Interactive graphs with plotly
import plotly.express as px
df = px.data.gapminder().query("country=='Canada'")
fig = px.line(df, x="year", y="lifeExp", title='Life expectancy in Canada')
html = fig.to_html(full_html=False, include_plotlyjs='cdn', config= {'displaylogo': False} )
webSite.addReport( Report( "Graph example", html , experimentName="main" ) )
result:
Generating table with panda's dataframe:
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data)
webSite.addReport( Report( "Dataframe example", df , template="table.html", experimentName="main" ) )
result:
[!NOTE] The XLSX file is automatically generated
[!NOTE] You can one or several downloadable content to any report:
report.setDownloadableContent( "my custom download" , myDataFrame ) # note that this function only support dataframe at the moment. report.setDownloadableContent( "my other custom download" , myOtherDataFrame )
MiniCards
Useful to show status messages
webSite.addReport( Report( "Minicard 1", "Success text" , template="miniCard.html", experimentName="main", style="success" ) )
webSite.addReport( Report( "Minicard 2", "Neutral text" , template="miniCard.html", experimentName="main", style="secondary" ) )
webSite.addReport( Report( "Minicard 3", "Primary text" , template="miniCard.html", experimentName="main", style="primary" ) )
webSite.addReport( Report( "Minicard 4", "Warning text" , template="miniCard.html", experimentName="main", style="warning" ) )
webSite.addReport( Report( "Minicard 5", "Danger text" , template="miniCard.html", experimentName="main", style="danger" ) )
webSite.addReport( Report( "Minicard 6", "Inverted text" , template="miniCard.html", experimentName="main", style="text-light bg-dark" ) )
result:
Upload your website to your ftp
todo