Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ steps:
'--image', '$_GCR/$_PROJ_NAME/$_REPO_NAME/$_IMG_NAME',
'--region', '$_REGION',
'--memory', '$_MEMORY',
'--cpu', '$_CPU']
'--cpu', '$_CPU',
'--set-secrets', 'CARTO_API_KEY=carto-api-key:latest']
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
import os
import platform


Expand All @@ -11,6 +12,7 @@ class AppConfig:
PORT = 8080
PROCESSES = 1
THREADED = True
CARTO_API_KEY = os.environ.get("CARTO_API_KEY", "")


class UnitSystem(str, Enum):
Expand Down
3 changes: 2 additions & 1 deletion pages/lib/charts_summary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pandas as pd
import plotly.express as px
from pages.lib.global_variables import Variables
from pages.lib.utils import apply_carto_basemap


def world_map(meta):
Expand Down Expand Up @@ -32,6 +33,6 @@ def world_map(meta):
height=300,
size="Size",
)
fig.update_layout(mapbox_style="carto-positron")
apply_carto_basemap(fig)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
return fig
2 changes: 0 additions & 2 deletions pages/lib/global_element_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ class ElementIds(str, Enum):
WIND_PROFILE_GRAPH = "wind-profile-graph"
TDB_PROFILE_GRAPH = "tdb-profile-graph"
RH_PROFILE_GRAPH = "rh-profile-graph"
ID_LAYOUT_ALERT_AUTO = "alert-auto"
ID_LAYOUT_INTERVAL_COMPONENT = "interval-component"
FOOTER_CONTAINER = "footer-container"
STORE = "store"
BURGER_BUTTON = "burger-button"
Expand Down
40 changes: 0 additions & 40 deletions pages/lib/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,32 +296,6 @@ def create_header():
),
],
),
dmc.Alert(
[
"If you have a moment, help us improve Clima and take a ",
dmc.Anchor(
"quick user survey",
href="https://forms.gle/k289zP3R92jdu14M7",
target="_blank",
c="white",
underline="always",
),
"! ☀️",
],
id=ElementIds.ID_LAYOUT_ALERT_AUTO,
title="CBE Clima User Survey",
icon=dmc.ThemeIcon(
DashIconify(icon="tabler:info-circle", color="white"),
),
color="blue",
variant="filled",
withCloseButton=True,
w=400,
pos="fixed",
top="1em",
right="1em",
style={"zIndex": 1002, "display": "none"},
),
],
)

Expand Down Expand Up @@ -422,11 +396,6 @@ def create_stores():
data=get_default_global_filter_store_data(),
storage_type="session",
),
dcc.Interval(
id=ElementIds.ID_LAYOUT_INTERVAL_COMPONENT,
interval=12 * 1000,
n_intervals=0,
),
],
)

Expand Down Expand Up @@ -522,15 +491,6 @@ def update_nav_active_state(pathname):
]


@callback(
Output(ElementIds.ID_LAYOUT_ALERT_AUTO, "style"),
Input(ElementIds.ID_LAYOUT_INTERVAL_COMPONENT, "n_intervals"),
prevent_initial_call=True,
)
def show_alert_after_delay(n_intervals):
return {"display": "block" if n_intervals == 1 else "none"}


@callback(
Output(ElementIds.TOOLS_GLOBAL_FILTER_STORE, "data"),
[
Expand Down
20 changes: 19 additions & 1 deletion pages/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,29 @@
from dash import html, dcc
import dash_mantine_components as dmc

from config import UnitSystem
from config import AppConfig, UnitSystem
from pages.lib.global_scheme import fig_config, month_lst
from pages.lib.global_variables import Variables, VariableInfo


def apply_carto_basemap(fig):
"""Apply the Carto Positron basemap, authenticated with our API key."""
fig.update_layout(
mapbox_style="white-bg",
mapbox_layers=[
{
"below": "traces",
"sourcetype": "raster",
"sourceattribution": "© OpenStreetMap contributors, © CARTO",
"source": [
f"https://basemaps.cartocdn.com/rastertiles/light_all/{{z}}/{{x}}/{{y}}.png?key={AppConfig.CARTO_API_KEY}"
],
}
],
)
return fig


def code_timer(func):
"""Print the runtime of the decorated function"""

Expand Down
8 changes: 6 additions & 2 deletions pages/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
from pages.lib.global_element_ids import ElementIds
from pages.lib.global_tab_names import TabNames
from config import PageUrls, PageInfo
from pages.lib.utils import generate_chart_name, get_default_global_filter_store_data
from pages.lib.utils import (
apply_carto_basemap,
generate_chart_name,
get_default_global_filter_store_data,
)

dash.register_page(
__name__,
Expand Down Expand Up @@ -367,7 +371,7 @@ def plot_location_epw_files(pathname):
height=500,
)
fig.add_trace(fig2.data[0])
fig.update_layout(mapbox_style="carto-positron")
apply_carto_basemap(fig)
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})

return dcc.Graph(
Expand Down
Loading