Skip to content

Commit

Permalink
Merge pull request #416 from euanwm/feature/generate_filters_on_build
Browse files Browse the repository at this point in the history
feature/generate filters on build
  • Loading branch information
euanwm authored Dec 17, 2024
2 parents ab579d2 + a233f1b commit eed827a
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/deploy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
app-name: "dev-branch-backend"
api-key: "${{secrets.HEROKU_API_KEY}}"
path: "./backend/"
- name: Build Frontend Filters
uses: actions/checkout@v2
run: make build_frontend
- name: Deploy Development Frontend
uses: behe/heroku-build@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
# Ignore the event_data once it's compilation spot
/backend/event_data/
/backend/event_data/**/*.csv

# Ignore the autobuild folder
/frontend/autobuild/*.json
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
# OpenWeightlifting Makefile
# Shortcuts to the most common tools should be implemented here.

# Builds the backend server executable
.PHONY: build_backend
build_backend:
cp -r event_data/ backend/
cd backend && go build -o backend

# Builds the frontend files
.PHONY: build_frontend
build_frontend:
@cd python_tools && pipenv install && pipenv run python3 fe_builder.py
cd frontend && npm install

# Installs the python tools used to update the database
.PHONY: install_tools
install_tools:
Expand Down
7 changes: 7 additions & 0 deletions frontend/autobuild/filter_years.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"years": [
{
"All Years": "69"
}
]
}
20 changes: 6 additions & 14 deletions frontend/components/molecules/filters.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Select, SelectItem } from '@nextui-org/react'
import years from '../../autobuild/filter_years.json'

// todo: convert to enums?
const sortByList = [
{ value: 'total', label: 'Total' },
{ value: 'sinclair', label: 'Sinclair' },
]

const federationList = [
{ value: 'allfeds', label: 'ALL' },
{ value: 'UK', label: 'UK' },
Expand Down Expand Up @@ -42,19 +42,11 @@ const weightClassList = [
{ value: 'F87+', label: 'Women\'s +87kg' }
]

const yearsList = [
{ value: 69, label: 'All Years' },
{ value: 2015, label: '2015' },
{ value: 2016, label: '2016' },
{ value: 2017, label: '2017' },
{ value: 2018, label: '2018' },
{ value: 2019, label: '2019' },
{ value: 2020, label: '2020' },
{ value: 2021, label: '2021' },
{ value: 2022, label: '2022' },
{ value: 2023, label: '2023' },
{ value: 2024, label: '2024' },
]
const yearsList: {label: string, value: string}[] = years.years.map(year => {
const [label, value] = Object.entries(year)[0]
return { value, label }
})

export const Filters = ({ sortBy, federation, handleFilterChange, weightClass, year }: {sortBy: string, federation: string, handleFilterChange: any, weightClass: string, year: string}) => (
<div className="flex flex-col md:flex-row space-y-1 md:space-y-0 md:space-x-4 mt-4 mx-4">
<Select
Expand Down
42 changes: 42 additions & 0 deletions python_tools/fe_builder.py
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()

0 comments on commit eed827a

Please sign in to comment.