-
Notifications
You must be signed in to change notification settings - Fork 0
#15:feat:report generation as HTML #39
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
base: main
Are you sure you want to change the base?
Changes from all 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 |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| print("Starting script...") | ||
| # import pandas as pd | ||
| import os | ||
| from jinja2 import Environment, FileSystemLoader | ||
|
|
||
| # Sample data | ||
| data = { | ||
| "listing_id": [1, 2, 3, 4, 5, 6, 7], | ||
| "address": ["11 ABC street.", "22 ABC street.", "33 ABC street.", "44 ABC street.", "55 ABC street.", "66 ABC street.", "77 ABC street."], | ||
| "policy_A": [True, False, True, False, True, False, True] | ||
| } | ||
|
|
||
|
|
||
| ######################################################################## | ||
| ######################################################################## | ||
| # USING JINJA2 TO HTML | ||
| ######################################################################## | ||
| ######################################################################## | ||
|
|
||
|
|
||
| # Get the absolute path to the directory containing report_generator.py | ||
| dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
|
||
| # Use this path to set the correct path to the template/ directory | ||
| template_dir = os.path.join(dir_path, 'template') | ||
|
|
||
|
|
||
| # Create a Jinja2 environment | ||
| env = Environment(loader=FileSystemLoader(template_dir)) | ||
| template = env.get_template('reporttemplate.html') | ||
|
|
||
| # get the date of report generation as the current date | ||
| from datetime import datetime | ||
| today = datetime.now() | ||
| todayStr = today.strftime('%Y-%m-%d %H:%M') | ||
|
|
||
| # render the template with the data | ||
| html_out = template.render( | ||
| data=data, | ||
| date=todayStr | ||
| ) | ||
|
|
||
| # Get the absolute path to the directory containing the script | ||
| script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| # Construct the absolute path to the output file | ||
| output_file = os.path.join(script_dir, '../report_store/output.html') | ||
|
|
||
| # Write the HTML table to the output file | ||
| print("Writing HTML table to output.html...") | ||
| with open(output_file, 'w') as f: | ||
| f.write(html_out) | ||
|
|
||
| print("Done!") | ||
|
|
||
|
|
||
| ######################################################################## | ||
| ######################################################################## | ||
| # USING DATAFRAME TO HTML | ||
| ######################################################################## | ||
| ######################################################################## | ||
|
|
||
|
|
||
| # # Convert the array to a DataFrame | ||
| # df = pd.DataFrame(data) | ||
| # print("Converted data to DataFrame") | ||
|
|
||
| # # Convert the DataFrame to an HTML table | ||
| # html_table = df.to_html(index=False) | ||
| # print("Converted DataFrame to HTML table") | ||
|
|
||
| # # Get the absolute path to the directory containing the script | ||
| # script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
|
||
| # # Construct the absolute path to the output file | ||
| # output_file = os.path.join(script_dir, '../report_store/output.html') | ||
|
|
||
|
|
||
| # # Write the HTML table to the output file | ||
| # print("Writing HTML table to output.html...") | ||
| # with open(output_file, 'w') as f: | ||
| # f.write(html_table) | ||
|
|
||
| # print("Done!") | ||
|
Member
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. newline |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <!-- HTML template to render result from report_generator.py --> | ||
|
|
||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Open_BC Airbnb regulation report on {{date}}</title> | ||
| <style> | ||
| table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| } | ||
| table, th, td { | ||
| border: 1px solid black; | ||
| } | ||
| th, td { | ||
| padding: 15px; | ||
| text-align: left; | ||
| } | ||
| th { | ||
| background-color: #f2f2f2; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Open_BC Airbnb regulation report on {{date}}</h1> | ||
| <table> | ||
| <thead> | ||
| <tr style="text-align: right;"> | ||
| <th>listing_id</th> | ||
| <th>address</th> | ||
| <th>policy_A</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| {% for i in range(data.listing_id|length) %} | ||
| <tr> | ||
| <td>{{data.listing_id[i]}}</td> | ||
| <td>{{data.address[i]}}</td> | ||
| <td>{{data.policy_A[i]}}</td> | ||
| </tr> | ||
| {% endfor %} | ||
| </tbody> | ||
| </table> | ||
| </body> | ||
| </html> | ||
|
Member
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. newline |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| <!-- HTML template to render result from report_generator.py --> | ||
|
|
||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
|
Comment on lines
+1
to
+4
Member
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. report store is a class where it can take a file and store it. it can mock the storage for now. i.e |
||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Open_BC Airbnb regulation report on 2024-02-12 23:12</title> | ||
| <style> | ||
| table { | ||
| width: 100%; | ||
| border-collapse: collapse; | ||
| } | ||
| table, th, td { | ||
| border: 1px solid black; | ||
| } | ||
| th, td { | ||
| padding: 15px; | ||
| text-align: left; | ||
| } | ||
| th { | ||
| background-color: #f2f2f2; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Open_BC Airbnb regulation report on 2024-02-12 23:12</h1> | ||
| <table> | ||
| <thead> | ||
| <tr style="text-align: right;"> | ||
| <th>listing_id</th> | ||
| <th>address</th> | ||
| <th>policy_A</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
|
|
||
| <tr> | ||
| <td>1</td> | ||
| <td>11 ABC street.</td> | ||
| <td>True</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>2</td> | ||
| <td>22 ABC street.</td> | ||
| <td>False</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>3</td> | ||
| <td>33 ABC street.</td> | ||
| <td>True</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>4</td> | ||
| <td>44 ABC street.</td> | ||
| <td>False</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>5</td> | ||
| <td>55 ABC street.</td> | ||
| <td>True</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>6</td> | ||
| <td>66 ABC street.</td> | ||
| <td>False</td> | ||
| </tr> | ||
|
|
||
| <tr> | ||
| <td>7</td> | ||
| <td>77 ABC street.</td> | ||
| <td>True</td> | ||
| </tr> | ||
|
|
||
| </tbody> | ||
| </table> | ||
| </body> | ||
| </html> | ||
|
Member
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. newline |
||
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.
these should be encapsulated into its own class and it should invoke the policy class. i think alja had some pseudo code in the readme whcih demonstrates how the report generation should be done. @alchuu00