Skip to content

Commit

Permalink
πŸ’„ Enhance dataset preview adjustments (#3778)
Browse files Browse the repository at this point in the history
* ✨ dataset preview: minor adjustments

* πŸ’„ Update primary color in theme configuration

* ✨ Update dataset preview alias and description

* ✨ Enhance dataset filtering and caching functionality
  • Loading branch information
lucasrodes authored Dec 31, 2024
1 parent ca95e89 commit 1f062e1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/wizard/app_pages/dataset_preview/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def prompt_dataset_options(dataset_options):
# Correct dataset id
if dataset_id is None:
dataset_index = None
dataset_options = [dataset_id for dataset_id in dataset_options if DATASETS[dataset_id]["isArchived"] == 0]
else:
dataset_id = int(dataset_id)
if dataset_id in dataset_options:
Expand Down
11 changes: 6 additions & 5 deletions apps/wizard/app_pages/dataset_preview/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import pandas as pd
import streamlit as st

from apps.wizard.utils import TTL_DEFAULT
from etl.config import OWID_ENV
from etl.db import read_sql
from etl.grapher.model import Dataset
from etl.indicator_upgrade.indicator_update import find_charts_from_variable_ids


@st.cache_data
@st.cache_data(show_spinner="Getting explorer data...", ttl=TTL_DEFAULT)
def get_explorers(variable_ids):
query = """select explorerSlug, variableId from explorer_variables where variableId in %s;"""
param = (tuple(variable_ids),)
Expand All @@ -24,7 +25,7 @@ def get_explorers(variable_ids):
return df


@st.cache_data
@st.cache_data(show_spinner="Getting chart analytics...", ttl=TTL_DEFAULT)
def get_charts_views():
"""Get views of charts."""
query = """SELECT SUBSTRING_INDEX(url, '/', -1) AS slug, views_7d, views_365d FROM analytics_pageviews WHERE url LIKE %s;"""
Expand All @@ -38,7 +39,7 @@ def get_charts_views():
return df.set_index("slug").to_dict(orient="index")


@st.cache_data
@st.cache_data(show_spinner="Getting explorer analytics...", ttl=TTL_DEFAULT)
def get_explorers_views():
"""Get views of explorers."""
query = """SELECT url, SUBSTRING_INDEX(url, '/', -1) AS slug, views_7d, views_365d FROM analytics_pageviews WHERE url LIKE %s;"""
Expand All @@ -56,7 +57,7 @@ def get_explorers_views():
return df.set_index("slug").to_dict(orient="index")


@st.cache_data
@st.cache_data(show_spinner="Getting datasets...", ttl=TTL_DEFAULT)
def get_datasets() -> Dict[int, Dict[str, Any]]:
"""Get list of datasets.
Expand All @@ -74,7 +75,7 @@ def get_datasets() -> Dict[int, Dict[str, Any]]:
return dix # type: ignore


@st.cache_data
@st.cache_data(show_spinner="Getting users...", ttl=TTL_DEFAULT)
def get_users():
"""Get users.
Expand Down
4 changes: 2 additions & 2 deletions apps/wizard/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ sections:
icon: ":material/tv_gen:"
image_url: "https://cdn.pixabay.com/photo/2018/09/04/17/02/indicator-3654257_960_720.jpg"
- title: "Dataset preview"
alias: dataexp
description: "Explore datasets and their metadata"
alias: datasets
description: "Preview datasets and their indicators"
maintainer: "@lucas"
entrypoint: app_pages/dataset_preview/app.py
icon: ":material/search:"
Expand Down
3 changes: 3 additions & 0 deletions apps/wizard/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
# Logger
log = get_logger()

# TTL for cached functions
TTL_DEFAULT = "2h"

# Path to variable configs
DAG_WIZARD_PATH = DAG_DIR / "wizard.yml"

Expand Down

0 comments on commit 1f062e1

Please sign in to comment.