def get_weekly_extract_start_date(self, ut=False, weekdays_at_least_of_max=<NUM_LIT>,<EOL>verbose=False, download_date_override=None):
daily_trip_counts = self.get_trip_counts_per_day()<EOL>if isinstance(download_date_override, str):<EOL><INDENT>search_start_date = datetime.datetime.strptime(download_date_override, "<STR_LIT>")<EOL><DEDENT>elif isinstance(download_date_override, datetime.datetime):<EOL><INDENT>search_start_date = download_date_override<EOL><DEDENT>else:<EOL><INDENT>assert download_date_override is None<EOL>download_date_str = self.meta['<STR_LIT>']<EOL>if download_date_str == "<STR_LIT>":<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>" + self.get_weekly_extract_start_date.__name__ +<EOL>"<STR_LIT>")<EOL>search_start_date = daily_trip_counts['<STR_LIT:date>'].min()<EOL><DEDENT>else:<EOL><INDENT>search_start_date = datetime.datetime.strptime(download_date_str, "<STR_LIT>")<EOL><DEDENT><DEDENT>feed_min_date = daily_trip_counts['<STR_LIT:date>'].min()<EOL>feed_max_date = daily_trip_counts['<STR_LIT:date>'].max()<EOL>assert (feed_max_date - feed_min_date >= datetime.timedelta(days=<NUM_LIT:7>)),"<STR_LIT>"<EOL>next_monday_from_search_start_date = search_start_date + timedelta(days=(<NUM_LIT:7> - search_start_date.weekday()))<EOL>if not (feed_min_date <= next_monday_from_search_start_date <= feed_max_date):<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>next_monday_from_search_start_date = feed_min_date + timedelta(days=(<NUM_LIT:7> - feed_min_date.weekday()))<EOL><DEDENT>max_trip_count = daily_trip_counts['<STR_LIT>'].quantile(<NUM_LIT>)<EOL>threshold = weekdays_at_least_of_max * max_trip_count<EOL>threshold_fulfilling_days = daily_trip_counts['<STR_LIT>'] > threshold<EOL>search_start_monday_index = daily_trip_counts[daily_trip_counts['<STR_LIT:date>'] == next_monday_from_search_start_date].index[<NUM_LIT:0>]<EOL>while_loop_monday_index = search_start_monday_index<EOL>while len(daily_trip_counts.index) >= while_loop_monday_index + <NUM_LIT:7>:<EOL><INDENT>if all(threshold_fulfilling_days[while_loop_monday_index:while_loop_monday_index + <NUM_LIT:5>]):<EOL><INDENT>row = daily_trip_counts.iloc[while_loop_monday_index]<EOL>if ut:<EOL><INDENT>return self.get_day_start_ut(row.date_str)<EOL><DEDENT>else:<EOL><INDENT>return row['<STR_LIT:date>']<EOL><DEDENT><DEDENT>while_loop_monday_index += <NUM_LIT:7><EOL><DEDENT>while_loop_monday_index = search_start_monday_index - <NUM_LIT:7><EOL>while while_loop_monday_index >= <NUM_LIT:0>:<EOL><INDENT>if all(threshold_fulfilling_days[while_loop_monday_index:while_loop_monday_index + <NUM_LIT:5>]):<EOL><INDENT>row = daily_trip_counts.iloc[while_loop_monday_index]<EOL>if ut:<EOL><INDENT>return self.get_day_start_ut(row.date_str)<EOL><DEDENT>else:<EOL><INDENT>return row['<STR_LIT:date>']<EOL><DEDENT><DEDENT>while_loop_monday_index -= <NUM_LIT:7><EOL><DEDENT>raise RuntimeError("<STR_LIT>")<EOL>
Find a suitable weekly extract start date (monday).
The goal is to obtain as 'usual' week as possible.
The weekdays of the weekly extract week should contain
at least 0.9 of the total maximum of trips.

Parameters
----------
ut: return unixtime?
weekdays_at_least_of_max: float

download_date_override: str, semi-optional
    Download-date in format %Y-%m-%d, weeks close to this.
    Overrides the (possibly) recorded downloaded date in the database

Returns
-------
date: int or str

Raises
------
error: RuntimeError
    If no download date could be found.