-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #416 from euanwm/feature/generate_filters_on_build
feature/generate filters on build
- Loading branch information
Showing
6 changed files
with
69 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"years": [ | ||
{ | ||
"All Years": "69" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import json | ||
from os import listdir | ||
from os.path import join | ||
|
||
from check_db import EVENT_DATA_PATH, assign_dataclass | ||
from database_handler.static_helpers import load_result_csv_as_list, load_json | ||
|
||
AUTOBUILD_FILTERS_PATH = "../frontend/autobuild/filter_years.json" | ||
|
||
def build_filters() -> None: | ||
fed_dir = [fed for fed in listdir(EVENT_DATA_PATH) if "." not in fed] | ||
years_available: list[int] = [] | ||
for fed in fed_dir: | ||
events = [event for event in listdir(join(EVENT_DATA_PATH, fed)) if "csv" in event] | ||
for event in events: | ||
event_path = join(EVENT_DATA_PATH, fed, event) | ||
event_year = __get_event_year(event_path) | ||
if event_year not in years_available and event_year != 0: | ||
years_available.append(event_year) | ||
__update_filters_json(years_available) | ||
|
||
|
||
def __get_event_year(event_result_name: str) -> int: | ||
single_event = load_result_csv_as_list(join(EVENT_DATA_PATH, event_result_name)) | ||
if len(single_event) == 0: | ||
return 0 | ||
event_date = assign_dataclass(single_event[0]).date | ||
event_year = int(event_date[:4]) | ||
return event_year | ||
|
||
def __update_filters_json(years: list[int]) -> None: | ||
filters_json = load_json(AUTOBUILD_FILTERS_PATH) | ||
years = sorted(years, reverse=True) | ||
for year in years: | ||
if year not in filters_json: | ||
year_entry = { str(year): str(year)} | ||
filters_json["years"].append(year_entry) | ||
with open(AUTOBUILD_FILTERS_PATH, "w") as f: | ||
json.dump(filters_json, f, indent=4) | ||
|
||
if __name__ == '__main__': | ||
build_filters() |