Skip to content

Commit

Permalink
Docstrings, cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tsmbland committed Jan 31, 2024
1 parent 5999390 commit 27654d8
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 74 deletions.
47 changes: 30 additions & 17 deletions validated/dash_apps/finished_apps/daily_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from validated.tables import create_daily_table, create_detail_table
from variable.models import Variable

# Create a Dash app
DEFAULT_FONT = "Open Sans, Raleway, Dosis, Ubuntu, sans-serif"

app = DjangoDash("DailyValidation")

# Filters (in final app this will get data from forms)
Expand Down Expand Up @@ -50,22 +51,25 @@
y=data["series"]["measurement"]["average"],
mode="lines",
name="Measurement",
line=dict(color="black"),
)
)
plot.add_trace(
go.Scatter(
x=data["series"]["validated"]["time"],
y=data["series"]["validated"]["average"],
x=data["series"]["selected"]["time"],
y=data["series"]["selected"]["average"],
mode="lines",
name="Validated",
name="Selected",
line=dict(color="#636EFA"),
)
)
plot.add_trace(
go.Scatter(
x=data["series"]["selected"]["time"],
y=data["series"]["selected"]["average"],
x=data["series"]["validated"]["time"],
y=data["series"]["validated"]["average"],
mode="lines",
name="Selected",
name="Validated",
line=dict(color="#00CC96"),
)
)

Expand All @@ -74,13 +78,22 @@
table_detail = create_detail_table(data_detail)

# Layout
app.layout = html.Div([table_daily, table_detail, dcc.Graph(figure=plot)])

# Callback: check boxes


"""
To do:
- Reformat time column
"""
app.layout = html.Div(
children=[
html.H1(
children="Daily Report",
style={"font-family": DEFAULT_FONT},
),
table_daily,
html.H1(
children="Detail of Selected Day",
style={"font-family": DEFAULT_FONT},
),
table_detail,
html.H1(
children="Plot",
style={"font-family": DEFAULT_FONT},
),
dcc.Graph(figure=plot),
]
)
177 changes: 120 additions & 57 deletions validated/tables.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,85 @@
from dash_ag_grid import AgGrid


def get_columns_daily(value_columns):
def create_daily_table(data: dict) -> AgGrid:
"""Creates Daily Report table
Args:
data (dict): Daily report data (from functions.daily_validation)
Returns:
AgGrid: Daily report table
"""
table = AgGrid(
id="table",
rowData=data["data"],
columnDefs=get_columns_daily(value_columns=data["value_columns"]),
columnSize="sizeToFit",
defaultColDef={
"resizable": True,
"sortable": True,
"checkboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelectionFilteredOnly": True,
},
dashGridOptions={"rowSelection": "multiple", "suppressRowClickSelection": True},
selectAll=True,
)
return table


def create_detail_table(data: dict) -> AgGrid:
"""Creates Detail table for a specific date
Args:
data (dict): Detail data (from functions.detail_list)
Returns:
AgGrid: Detail table
"""
table = AgGrid(
id="table_detail",
rowData=data["series"],
columnDefs=get_columns_detail(value_columns=data["value_columns"]),
columnSize="sizeToFit",
defaultColDef={
"resizable": True,
"sortable": True,
"checkboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelectionFilteredOnly": True,
},
dashGridOptions={"rowSelection": "multiple", "suppressRowClickSelection": True},
selectAll=True,
)
return table


def get_columns_daily(value_columns: list) -> list:
"""Creates columns for Daily Report table
Args:
value_columns (list): List of value columns
Returns:
list: List of columns
"""
styles = get_daily_style_data_conditional()

columns = [
{
"field": "id",
"headerName": "Id",
"filter": "agNumberColumnFilter",
"maxWidth": 150,
},
{
"field": "date",
Expand Down Expand Up @@ -64,13 +135,27 @@ def get_columns_daily(value_columns):
return columns


def get_columns_detail(value_columns):
def get_columns_detail(value_columns: list) -> list:
"""Creates columns for Detail table
Args:
value_columns (list): List of value columns
Returns:
list: List of columns
"""
styles = get_detail_style_data_conditional(value_columns)

columns = [
{"field": "id", "headerName": "Id", "filter": "agNumberColumnFilter"},
{
"field": "id",
"headerName": "Id",
"filter": "agNumberColumnFilter",
"maxWidth": 150,
},
{
"field": "time",
"valueFormatter": {"function": "params.value.split('T')[1].split('+')[0]"},
"headerName": "Time",
**styles["time"],
},
Expand All @@ -96,15 +181,31 @@ def get_columns_detail(value_columns):
return columns


def get_daily_style_data_conditional():
def get_daily_style_data_conditional() -> dict:
"""Creates style conditions for Daily Report table
Returns:
dict: Style conditions
"""
styles = {}

styles["id"] = {
"cellStyle": {
"styleConditions": [
{
"condition": "params.data['all_validated']",
"style": {"backgroundColor": "#00CC96"},
},
]
},
}

styles["date"] = {
"cellStyle": {
"styleConditions": [
{
"condition": "params.data['date_error'] > 0",
"style": {"backgroundColor": "sandybrown"},
"style": {"backgroundColor": "#E45756"},
},
]
},
Expand All @@ -115,7 +216,7 @@ def get_daily_style_data_conditional():
"styleConditions": [
{
"condition": "params.data['percentage_error']",
"style": {"backgroundColor": "sandybrown"},
"style": {"backgroundColor": "#E45756"},
},
]
},
Expand All @@ -126,7 +227,7 @@ def get_daily_style_data_conditional():
"styleConditions": [
{
"condition": "params.data['value_difference_error_count'] > 0",
"style": {"backgroundColor": "sandybrown"},
"style": {"backgroundColor": "#E45756"},
},
]
},
Expand All @@ -138,7 +239,7 @@ def get_daily_style_data_conditional():
"styleConditions": [
{
"condition": f"params.data['suspicious_{field}s_count'] > 0",
"style": {"backgroundColor": "sandybrown"},
"style": {"backgroundColor": "#E45756"},
},
]
},
Expand All @@ -147,7 +248,15 @@ def get_daily_style_data_conditional():
return styles


def get_detail_style_data_conditional(value_columns):
def get_detail_style_data_conditional(value_columns: list) -> dict:
"""Creates style conditions for Detail table
Args:
value_columns (list): List of value columns
Returns:
dict: Style conditions
"""
styles = {}

styles["time"] = {
Expand All @@ -157,7 +266,7 @@ def get_detail_style_data_conditional(value_columns):
"condition": f"params.data['time_lapse_status'] == {val}",
"style": {"backgroundColor": f"{col}"},
}
for val, col in zip([0, 2], ["sandybrown", "yellow"])
for val, col in zip([0, 2], ["#E45756", "#FFA15A"])
]
},
}
Expand All @@ -168,56 +277,10 @@ def get_detail_style_data_conditional(value_columns):
"styleConditions": [
{
"condition": f"params.data['{field}_error']",
"style": {"backgroundColor": "sandybrown"},
"style": {"backgroundColor": "#E45756"},
},
]
},
}

return styles


def create_daily_table(data):
table = AgGrid(
id="table",
rowData=data["data"],
columnDefs=get_columns_daily(value_columns=data["value_columns"]),
columnSize="sizeToFit",
defaultColDef={
"resizable": False,
"sortable": True,
"checkboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelectionFilteredOnly": True,
},
dashGridOptions={"rowSelection": "multiple", "suppressRowClickSelection": True},
selectAll=True,
)
return table


def create_detail_table(data_detail):
table = AgGrid(
id="table_detail",
rowData=data_detail["series"],
columnDefs=get_columns_detail(value_columns=data_detail["value_columns"]),
columnSize="sizeToFit",
defaultColDef={
"resizable": False,
"sortable": True,
"checkboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelection": {
"function": "params.column == params.columnApi.getAllDisplayedColumns()[0]"
},
"headerCheckboxSelectionFilteredOnly": True,
},
dashGridOptions={"rowSelection": "multiple", "suppressRowClickSelection": True},
selectAll=True,
)
return table

0 comments on commit 27654d8

Please sign in to comment.