notha99y commited on
Commit
b4dddca
·
1 Parent(s): 1105c60

fix instruction, fix for missing timeslot

Browse files
Files changed (3) hide show
  1. src/search.py +5 -6
  2. src/streamlit_app.py +2 -2
  3. src/utils.py +15 -0
src/search.py CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
3
  from utils import (
4
  check_conflict,
5
  check_solution_is_valid,
 
6
  print_solution,
7
  refine_time_parsing,
8
  )
@@ -12,8 +13,8 @@ max_retries = 100
12
 
13
  def get_solution(df, num_combi):
14
  retry_counter = 0
15
- df = df.replace(r"^\s*$", pd.NA, regex=True).dropna()
16
- print(df)
17
  dummy_module_names = ["Module A", "Module B", "Module C", "Module D"]
18
  export_cols = ["Module", "Class", "Lecture", "Tutorial"]
19
  num_units = len(dummy_module_names)
@@ -27,10 +28,8 @@ def get_solution(df, num_combi):
27
  # Reapply refined parsing to lecture and tutorial times
28
  df_cleaned = refine_time_parsing(df, "Lecture")
29
  df_cleaned = refine_time_parsing(df, "Tutorial")
30
- df_cleaned["lecture_day"] = df["Lecture"].apply(lambda x: x.split(" ")[0])
31
- df_cleaned["tutorial_day"] = df["Tutorial"].apply(
32
- lambda x: x.split(" ")[0]
33
- )
34
  print(df_cleaned.head())
35
  df_cleaned["module_mapped"] = df_cleaned["Module"].apply(
36
  lambda x: unit_map[x]
 
3
  from utils import (
4
  check_conflict,
5
  check_solution_is_valid,
6
+ get_day,
7
  print_solution,
8
  refine_time_parsing,
9
  )
 
13
 
14
  def get_solution(df, num_combi):
15
  retry_counter = 0
16
+ # df = df.replace(r"^\s*$", pd.NA, regex=True).dropna()
17
+ # print(df)
18
  dummy_module_names = ["Module A", "Module B", "Module C", "Module D"]
19
  export_cols = ["Module", "Class", "Lecture", "Tutorial"]
20
  num_units = len(dummy_module_names)
 
28
  # Reapply refined parsing to lecture and tutorial times
29
  df_cleaned = refine_time_parsing(df, "Lecture")
30
  df_cleaned = refine_time_parsing(df, "Tutorial")
31
+ df_cleaned["lecture_day"] = df["Lecture"].apply(get_day)
32
+ df_cleaned["tutorial_day"] = df["Tutorial"].apply(get_day)
 
 
33
  print(df_cleaned.head())
34
  df_cleaned["module_mapped"] = df_cleaned["Module"].apply(
35
  lambda x: unit_map[x]
src/streamlit_app.py CHANGED
@@ -13,7 +13,7 @@ def main():
13
  "Paste values in the format: Module, Class, Lecture, Tutorial (tab-separated)"
14
  )
15
  st.write(
16
- "Lecture and Tutorial Format is day, start_time , end_time. e.g. Mon 1030am to 1230pm"
17
  )
18
 
19
  num_combi = st.number_input("Number of Combination", min_value=0, value=4)
@@ -45,7 +45,7 @@ def main():
45
  # Button to run the solution
46
  if st.button("Run"):
47
  result_df = get_solution(edited_df, num_combi)
48
- if result_df is not None:
49
  st.session_state.solution_df = (
50
  result_df # Store solution in session state
51
  )
 
13
  "Paste values in the format: Module, Class, Lecture, Tutorial (tab-separated)"
14
  )
15
  st.write(
16
+ "Lecture and Tutorial Format is day, start_time , end_time. e.g. Mon 4.30pm to 6pm"
17
  )
18
 
19
  num_combi = st.number_input("Number of Combination", min_value=0, value=4)
 
45
  # Button to run the solution
46
  if st.button("Run"):
47
  result_df = get_solution(edited_df, num_combi)
48
+ if result_df:
49
  st.session_state.solution_df = (
50
  result_df # Store solution in session state
51
  )
src/utils.py CHANGED
@@ -2,6 +2,18 @@ import re
2
  from datetime import datetime
3
 
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def refine_time_parsing(df, time_column):
6
  """
7
  Improves the parsing of time ranges by handling edge cases and filling in missing values.
@@ -34,6 +46,9 @@ def check_overlap(first_class, second_class):
34
  """
35
  class: (day, start_time, end_time)
36
  """
 
 
 
37
  if first_class[1] is None:
38
  return False
39
 
 
2
  from datetime import datetime
3
 
4
 
5
+ def get_day(timeslot):
6
+ """
7
+ assume timeslot is Day starttime to endtime
8
+ """
9
+
10
+ if type(timeslot) != str:
11
+ # assume it is na
12
+ return None
13
+ else:
14
+ return timeslot.split(" ")[0]
15
+
16
+
17
  def refine_time_parsing(df, time_column):
18
  """
19
  Improves the parsing of time ranges by handling edge cases and filling in missing values.
 
46
  """
47
  class: (day, start_time, end_time)
48
  """
49
+ if type(first_class[0]) != str or type(second_class[1]) != str:
50
+ return False
51
+
52
  if first_class[1] is None:
53
  return False
54