Skip to content

Commit 57e14ce

Browse files
committed
Merge branch 'main' into package-manager
2 parents 071f1c4 + 6dc5e32 commit 57e14ce

File tree

5 files changed

+113
-14
lines changed

5 files changed

+113
-14
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Code Coverage"
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
coverage:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Set up Python
11+
uses: actions/setup-python@v5
12+
with:
13+
python-version: '3.11'
14+
- name: Install dependencies
15+
run: |
16+
pip install -r requirements.txt
17+
- name: Run pytest with coverage
18+
run: |
19+
pytest --cov=./ --cov-report=xml
20+
- name: Upload coverage to Codecov
21+
uses: codecov/codecov-action@v1
22+
with:
23+
file: ./coverage.xml
24+
flags: unittests
25+
name: codecov-umbrella
26+
fail_ci_if_error: false
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: "Code Security"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 5 * * 1'
10+
11+
jobs:
12+
CodeQL:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
- name: Initialize CodeQL
19+
uses: github/codeql-action/init@v2
20+
with:
21+
languages: python
22+
- name: Perform CodeQL Analysis
23+
uses: github/codeql-action/analyze@v2

.github/workflows/code_styling.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "Code Styling"
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
lint:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Set up Python
11+
uses: actions/setup-python@v5
12+
with:
13+
python-version: '3.11'
14+
- name: Install dependencies
15+
run: |
16+
pip install ruff
17+
- name: Run ruff linter
18+
run: |
19+
ruff check .

app.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
calculate = st.sidebar.button("Calculate Centers", type="primary", use_container_width=True)
5757

58+
school_df = None
5859
# Tabs
5960
tab1, tab2, tab3, tab4, tab5 = st.tabs([
6061
"School Center",
@@ -73,7 +74,9 @@
7374
# Show data in Tabs as soon as the files are uploaded
7475
if schools_file:
7576
df = pd.read_csv(schools_file, sep="\t")
77+
school_df = df
7678
tab3.dataframe(df)
79+
7780
else:
7881
tab3.info("Upload data to view it.", icon="ℹ️")
7982

@@ -193,9 +196,37 @@ def save_file_to_temp(file_obj):
193196
icon=folium.Icon(color="red")
194197
)
195198
)
199+
200+
# Initialize an empty dictionary to store school coordinates
201+
filtered_schools = {}
202+
203+
if school_df is not None:
204+
205+
for index, row in school_df.iterrows():
206+
scode = row['scode']
207+
school_lat = row['lat']
208+
school_long = row['long']
209+
210+
if scode in filtered_df['scode'].values:
211+
filtered_schools.setdefault(scode, []).append((school_lat, school_long))
212+
213+
for index, school in filtered_df.iterrows():
214+
lat_long_list = filtered_schools.get(school['scode'], [])
215+
216+
for school_lat, school_long in lat_long_list:
217+
if school_lat is not None and school_long is not None:
218+
fg.add_child(
219+
folium.Marker(
220+
location=[school_lat, school_long],
221+
popup=f"{school['school'].title()}\nAllocation: {school['allocation']}",
222+
tooltip=f"{school['school']}",
223+
icon=folium.Icon(color="blue")
224+
)
225+
)
226+
196227
m.add_child(fg)
197228
with tab1:
198-
st_folium( m, width=1200, height=400 )
229+
st_folium( m, width=1200, height=400)
199230

200231
tab1.divider()
201232
tab1.subheader('All Data')

school_center.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ def read_tsv(file_path: str) -> List[Dict[str, str]]:
101101
reader = csv.DictReader(file, delimiter='\t')
102102
for row in reader:
103103
data.append(dict(row))
104-
except FileNotFoundError:
105-
logger.error(f"File '{file_path}' not found.")
104+
except FileNotFoundError as e:
105+
logger.error(f"File '{file_path} : {e}' not found.")
106106
sys.exit(1)
107-
except PermissionError:
108-
logger.error(f"Permission denied while accessing file '{file_path}'.")
107+
except PermissionError as e:
108+
logger.error(f"Permission denied while accessing file '{file_path}' : {e}.")
109109
sys.exit(1)
110-
except IOError:
111-
logger.error(f"Error opening or reading file: {file_path}")
110+
except IOError as e:
111+
logger.error(f"Error opening or reading file: '{file_path}' : {e}")
112112
sys.exit(1)
113113
except Exception as e:
114-
logger.error(f"An unexpected error occurred while reading file '{file_path}': {e}")
114+
logger.error(f"An unexpected error occurred while reading file '{file_path}' : {e}")
115115
sys.exit(1)
116116
return data
117117

@@ -133,14 +133,14 @@ def read_prefs(file_path: str) -> Dict[str, Dict[str, int]]:
133133
prefs[row['scode']][row['cscode']] = int(row['pref'])
134134
else:
135135
prefs[row['scode']] = {row['cscode']: int(row['pref'])}
136-
except FileNotFoundError:
137-
logger.error(f"File '{file_path}' not found.")
136+
except FileNotFoundError as e:
137+
logger.error(f"File '{file_path} :{e}' not found.")
138138
sys.exit(1)
139-
except PermissionError:
140-
logger.error(f"Permission denied while accessing file '{file_path}'.")
139+
except PermissionError as e:
140+
logger.error(f"Permission denied while accessing file '{file_path}:{e}'.")
141141
sys.exit(1)
142-
except IOError:
143-
logger.error(f"Error opening or reading file: {file_path}")
142+
except IOError as e:
143+
logger.error(f"Error opening or reading file: {file_path} :{e}")
144144
sys.exit(1)
145145
except Exception as e:
146146
logger.error(f"An unexpected error occurred while reading file '{file_path}': {e}")

0 commit comments

Comments
 (0)