Skip to content

datefilter

datefilter

Module for date filter

Classes

DateFilter

DateFilter(days_ago=14, min_shown_exp=5)

Bases: ExperimentFilter

Datefilter for selecting experiments

Source code in niceml/experiments/filters/datefilter.py
def __init__(self, days_ago: int = 14, min_shown_exp: int = 5):
    self.days_ago = days_ago
    self.selected_values = None
    self.min_shown_exp = min_shown_exp
Functions
filter
filter(exp_list)

filters the experiments which are inside the selected date range

Source code in niceml/experiments/filters/datefilter.py
def filter(self, exp_list: List[ExperimentData]) -> List[ExperimentData]:
    """filters the experiments which are inside the selected date range"""
    try:
        start_date, end_date = self.selected_values
    except ValueError:
        start_date = self.selected_values[0]
        end_date = date.today()
    date_filtered_list: List[ExperimentData] = []
    not_included_list: List[ExperimentData] = []
    for exp_data in exp_list:
        run_date = exp_data.get_run_date().date()
        if start_date <= run_date <= end_date:
            date_filtered_list.append(exp_data)
        else:
            not_included_list.append(exp_data)
    if len(date_filtered_list) < self.min_shown_exp:
        date_filtered_list += not_included_list[
            : self.min_shown_exp - len(date_filtered_list)
        ]

    date_filtered_list = sorted(
        date_filtered_list, key=lambda x: x.get_run_id(), reverse=True
    )
    return date_filtered_list
render
render(exp_list)

Shows the date selection and stores its values

Source code in niceml/experiments/filters/datefilter.py
def render(self, exp_list: List[ExperimentData]):
    """Shows the date selection and stores its values"""
    start_date = datetime.now() - timedelta(days=self.days_ago)
    end_date = datetime.now()
    self.selected_values = st.sidebar.date_input(
        label="date selection", value=(start_date, end_date)
    )