-
Notifications
You must be signed in to change notification settings - Fork 1
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
HTML outputs for GTFS data. #112
Merged
Merged
Changes from 17 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
7d2d483
Add code for producing HTML outputs for GTFS data
CBROWN-ONS fc1d255
Update requirements.txt
CBROWN-ONS 6d32925
fix: Update tests to reflect changes
CBROWN-ONS a26ad76
Merge branch 'gtfs-html-new' of https://github.com/datasciencecampus/…
CBROWN-ONS a71ccad
Added better file ext checking; update tests; added new tests
CBROWN-ONS 2e7f5e1
chore: Clean up docstrings to comply with numpy formatting
CBROWN-ONS cbad501
chore: Add additional raises in docstrings
CBROWN-ONS c5f9b80
chore: Bring up to date with dev
9c3f1b4
chore: Breaking changes with dev resolved
d9da952
refactor: Several type utils -> _type_defence
7a728b7
fix: Undo accidental overwrite with review branch
5743d11
Merge pull request #123 from datasciencecampus/review-_type_defence
CBROWN-ONS b649429
Merge branch 'gtfs-html-new' of https://github.com/datasciencecampus/…
CBROWN-ONS 7ce1b9e
test: _type_defence raises with single or multiple types
a0ef054
test: _type_defence pass on single & multiple values to types
2f46b63
Merge branch 'gtfs-html-new' of https://github.com/datasciencecampus/…
1ca03b0
Refactor save paths for plotting summaries (#124)
CBROWN-ONS d613772
feat: Tests for _check_column_in_df()
CBROWN-ONS c32af5d
fix: Added another stage of testing for set_up_report_dir() which imp…
CBROWN-ONS acaf557
Updated gtfs_utils.py and corresponding tests. Removed scheme param. …
CBROWN-ONS 5c4b07d
Make TemplateHtml methods private; Update docstring
CBROWN-ONS bbd5830
Updated error message for replace_multiple=False and multiple placeho…
CBROWN-ONS ae17f6d
Updated test_report_utils.py to reflect private functions
CBROWN-ONS ce0113e
Updated _set_up_report_dir() to better suite check_parent_dir_exists(…
CBROWN-ONS 2d6c957
Update tests in test_report_utils
CBROWN-ONS cf1ed87
Only .lower() orientation in one place, rather than 2
CBROWN-ONS 151d357
Create small helper function to remove duplicate logic; added testing
CBROWN-ONS 47a35e9
Move test to test__plot_summary_defences() as it is more appropriate
CBROWN-ONS 291b3b5
Refactore validation.py to only use _plot_summary();Added additional …
CBROWN-ONS c1d415e
Update check_attribute() due to save error
CBROWN-ONS 14442ff
Update defence.py
CBROWN-ONS 8fed07d
Update defence.py for missing char
CBROWN-ONS 3dfef83
chore: Run pre-commit against all files
c45e4ed
docs: Update private methods in docstring
2b6fd16
chore: Remove lint
77d8c6e
refactor: Param formatting in Error message
93545dc
Merge branch 'dev' into gtfs-html-new
CBROWN-ONS 6adc245
refactor: Rm str replace carriage returns logic in test
5e07121
Merge branch 'gtfs-html-new' of https://github.com/datasciencecampus/…
b516ce5
chore: Remove filterwarning
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,13 @@ | |
import geopandas as gpd | ||
from shapely.geometry import box | ||
from pyprojroot import here | ||
import plotly.graph_objects as go | ||
import pandas as pd | ||
|
||
from transport_performance.utils.defence import ( | ||
_is_expected_filetype, | ||
_check_list, | ||
_type_defence, | ||
) | ||
|
||
|
||
|
@@ -60,3 +63,88 @@ def bbox_filter_gtfs( | |
print(f"Filtered feed written to {out_pth}.") | ||
|
||
return None | ||
|
||
|
||
# NOTE: Possibly move to a more generalised utils file | ||
def convert_pandas_to_plotly( | ||
df: pd.DataFrame, return_html=False, scheme: str = "dsc" | ||
) -> go.Figure: | ||
"""Convert a pandas dataframe to a visual plotly figure. | ||
|
||
Parameters | ||
---------- | ||
df : pd.DataFrame | ||
A pandas dataframe to convert to plotly | ||
(single index only) | ||
return_html : bool, optional | ||
Whether or not to return the html element, | ||
by default False | ||
scheme : str, optional | ||
The colour scheme of the dataframe, | ||
by default "dsc" | ||
|
||
Returns | ||
------- | ||
go.Figure | ||
A plotly figure containing the drawn dataframe | ||
|
||
Raises | ||
------ | ||
LookupError | ||
An error raised if an invalid colour scheme is passed | ||
TypeError | ||
An error raised if the given pandas dataframe is MultiIndex | ||
|
||
""" | ||
# pre-defined colour schemes | ||
schemes = { | ||
"dsc": { | ||
"header_fill": "#12436D", | ||
"header_font_colour": "white", | ||
"cell_fill": "#A285D1", | ||
"cell_font_colour": "black", | ||
"font_family": "sans-serif", | ||
"line_colour": "black", | ||
} | ||
} | ||
# defences | ||
_type_defence(df, "df", pd.DataFrame) | ||
_type_defence(return_html, "return_html", bool) | ||
if scheme not in list(schemes.keys()): | ||
raise LookupError( | ||
f"{scheme} is not a valid colour scheme." | ||
f"Valid colour schemes include {list(schemes.keys())}" | ||
) | ||
if isinstance(df.columns, pd.MultiIndex): | ||
raise TypeError( | ||
"Pandas dataframe must have a single index," "not MultiIndex" | ||
) | ||
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. Passes on df with multi index but raises when columns are multi index. Is this the behaviour you need? If so, make clear in TypeError. Possibly raise when either index or columns are multi? |
||
|
||
# create plotly df | ||
fig = go.Figure( | ||
data=go.Table( | ||
header=dict( | ||
values=df.columns.values, | ||
fill_color=schemes[scheme]["header_fill"], | ||
font=dict( | ||
color=schemes[scheme]["header_font_colour"], | ||
family=schemes[scheme]["font_family"], | ||
), | ||
line_color=schemes[scheme]["line_colour"], | ||
), | ||
cells=dict( | ||
values=[df[col_name] for col_name in df.columns], | ||
fill_color="#A285D1", | ||
font=dict( | ||
color=schemes[scheme]["cell_font_colour"], | ||
family=schemes[scheme]["font_family"], | ||
), | ||
align="left", | ||
line_color=schemes[scheme]["line_colour"], | ||
), | ||
) | ||
) | ||
|
||
if return_html: | ||
return fig.to_html(full_html=False) | ||
return fig |
195 changes: 195 additions & 0 deletions
195
src/transport_performance/gtfs/report/css_styles/styles.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
* { | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
font-family: 'Poppins', sans-serif; | ||
} | ||
|
||
body { | ||
min-height: 100vh; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
|
||
} | ||
|
||
li { | ||
list-style: none; | ||
} | ||
|
||
h1, | ||
h2 { | ||
color: black; | ||
} | ||
|
||
h3 { | ||
color: #999; | ||
} | ||
|
||
table { | ||
overflow: hidden; | ||
overflow-x: scroll; | ||
max-width: 1500px; | ||
display: block; | ||
overflow-y: scroll; | ||
max-height: 800px; | ||
} | ||
|
||
thead { | ||
position: sticky; | ||
top: -10px; | ||
} | ||
|
||
.btn { | ||
background: #f05462; | ||
color: white; | ||
padding: 5px 10px; | ||
text-align: center; | ||
} | ||
|
||
.btn:hover { | ||
color: #f05462; | ||
background: white; | ||
padding: 3px 8px; | ||
border: 2px solid #f05462; | ||
} | ||
|
||
.title { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-around; | ||
padding: 15px 10px; | ||
border-bottom: 2px solid #999; | ||
} | ||
|
||
table { | ||
padding: 10px; | ||
} | ||
|
||
th, | ||
td { | ||
text-align: left; | ||
padding: 8px; | ||
} | ||
|
||
.side-menu { | ||
position: fixed; | ||
background: #28A197; | ||
width: 20vw; | ||
min-height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.side-menu .side-menu-title { | ||
height: 10vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
font-weight: bold | ||
} | ||
|
||
.side-menu li { | ||
font-size: 24px; | ||
padding: 10px 40px; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.side-menu li:hover { | ||
background: white; | ||
color: #28A197; | ||
|
||
} | ||
|
||
.side-menu li:hover .option{ | ||
color: #28A197; | ||
background-color: white; | ||
} | ||
|
||
.side-menu .option { | ||
color: white; | ||
} | ||
|
||
.side-menu .option:hover{ | ||
color: #28A197; | ||
background-color: white; | ||
} | ||
|
||
.container { | ||
position: absolute; | ||
right: 0; | ||
width: 80vw; | ||
height: 100vh; | ||
background: #f1f1f1; | ||
} | ||
|
||
.container .content { | ||
position: relative; | ||
background: #f1f1f1; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
} | ||
|
||
.container .content .analysis-cont { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: flex-start; | ||
flex-wrap: wrap; | ||
background-color: #f1f1f1; | ||
padding: 20px; | ||
} | ||
|
||
.container .content .analysis-cont .summary div { | ||
display: block; | ||
} | ||
|
||
|
||
.container .content .analysis-cont .summary dd { | ||
font-weight: bold; | ||
margin-inline-start: 0; | ||
display: inline-block; | ||
min-width: 130px; | ||
} | ||
|
||
.container .content .analysis-cont .summary dt { | ||
display: inline-block; | ||
} | ||
|
||
.analysis-title { | ||
font-weight: bold; | ||
font-size: large; | ||
margin-bottom: 10px; | ||
} | ||
|
||
hr { | ||
border: 0; | ||
clear:both; | ||
display:block; | ||
width: 100%; | ||
background-color: black; | ||
height: 5px; | ||
} | ||
|
||
.container .header { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
width: 80vw; | ||
height: 10vh; | ||
background: #801650; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); | ||
z-index: 1; | ||
} | ||
|
||
.container .header .header-title { | ||
display: flex; | ||
align-items: center; | ||
color: #F46A25; | ||
font-weight: bold; | ||
font-size: xx-large; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently, there are no alternative schemes, providing this parameter potentially misleading. Suggest removing parameter and associated logic and keeping the hardcoded
schemes
variable.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.
return_html=False
needs type setting