Greg Thompson commited on
Commit
a34228d
1 Parent(s): d53af6d

Add tests to curriculum mapper functions

Browse files
mathtext_fastapi/curriculum_mapper.py CHANGED
@@ -5,46 +5,45 @@ import re
5
  from pathlib import Path
6
 
7
 
8
- def read_and_preprocess_spreadsheet():
9
- # path = list(Path.cwd().glob('Rori_Framework_v1.xlsx'))
10
- DATA_DIR = Path(__file__).parent.parent / "mathtext_fastapi" / "data" / "Rori_Framework_v1.xlsx"
11
  script_df = pd.read_excel(DATA_DIR, engine='openpyxl')
 
12
  script_df.columns = script_df.columns[:2].tolist() + script_df.columns[2:11].astype(int).astype(str).tolist() + script_df.columns[11:].tolist()
13
  script_df.fillna('', inplace=True)
14
  return script_df
15
 
16
 
17
- def build_horizontal_transitions_by_row(direction, skill_code, row):
18
- match_arr = []
19
- sideways_transitions = []
20
-
21
- second_match = match+1
22
- if direction == 'left':
23
- second_match = match-1
24
-
25
- for i in range(9):
26
- # Grade column
27
- current_grade = i+1
28
- if row[current_grade].lower().strip() == 'x':
29
- match_arr.append(i)
30
-
31
- for match in match_arr:
32
- if match_arr[-1] != match:
33
- sideways_transitions.append([
34
- direction,
35
- f"{skill_code}_G{match}",
36
- f"{skill_code}_G{second_match}"
37
- ])
38
- return sideways_transitions
39
 
 
 
40
 
41
- def extract_skill_code(skill):
 
 
 
 
42
  pattern = r'[A-Z][0-9]\.\d+\.\d+'
43
  result = re.search(pattern, skill)
44
  return result.group()
45
 
46
 
47
  def build_horizontal_transitions(script_df):
 
 
 
 
 
 
 
 
 
 
 
 
48
  horizontal_transitions = []
49
  for index, row in script_df.iterrows():
50
  skill_code = extract_skill_code(row['Knowledge or Skill'])
@@ -82,6 +81,18 @@ def build_horizontal_transitions(script_df):
82
 
83
 
84
  def gather_all_vertical_matches(script_df):
 
 
 
 
 
 
 
 
 
 
 
 
85
  all_matches = []
86
  columns = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
87
 
@@ -99,6 +110,18 @@ def gather_all_vertical_matches(script_df):
99
 
100
 
101
  def build_vertical_transitions(script_df):
 
 
 
 
 
 
 
 
 
 
 
 
102
  vertical_transitions = []
103
 
104
  all_matches = gather_all_vertical_matches(script_df)
@@ -129,6 +152,18 @@ def build_vertical_transitions(script_df):
129
 
130
 
131
  def build_all_states(all_transitions):
 
 
 
 
 
 
 
 
 
 
 
 
132
  all_states = []
133
  for transition in all_transitions:
134
  for index, state in enumerate(transition):
@@ -140,7 +175,7 @@ def build_all_states(all_transitions):
140
 
141
 
142
  def build_curriculum_logic():
143
- script_df = read_and_preprocess_spreadsheet()
144
  horizontal_transitions = build_horizontal_transitions(script_df)
145
  vertical_transitions = build_vertical_transitions(script_df)
146
  all_transitions = horizontal_transitions + vertical_transitions
 
5
  from pathlib import Path
6
 
7
 
8
+ def read_and_preprocess_spreadsheet(file_name):
9
+ """ Creates a pandas dataframe from the curriculum overview spreadsheet """
10
+ DATA_DIR = Path(__file__).parent.parent / "mathtext_fastapi" / "data" / file_name
11
  script_df = pd.read_excel(DATA_DIR, engine='openpyxl')
12
+ # Ensures the grade level columns are integers instead of floats
13
  script_df.columns = script_df.columns[:2].tolist() + script_df.columns[2:11].astype(int).astype(str).tolist() + script_df.columns[11:].tolist()
14
  script_df.fillna('', inplace=True)
15
  return script_df
16
 
17
 
18
+ def extract_skill_code(skill):
19
+ """ Looks within a curricular skill description for its descriptive code
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ Input
22
+ - skill: str - a brief description of a curricular skill
23
 
24
+ >>> extract_skill_code('A3.3.4 - Solve inequalities')
25
+ 'A3.3.4'
26
+ >>> extract_skill_code('A3.3.2 - Graph linear equations, and identify the x- and y-intercepts or the slope of a line')
27
+ 'A3.3.2'
28
+ """
29
  pattern = r'[A-Z][0-9]\.\d+\.\d+'
30
  result = re.search(pattern, skill)
31
  return result.group()
32
 
33
 
34
  def build_horizontal_transitions(script_df):
35
+ """ Build a list of transitional relationships within a curricular skill
36
+
37
+ Inputs
38
+ - script_df: pandas dataframe - an overview of the curriculum skills by grade level
39
+
40
+ Output
41
+ - horizontal_transitions: array of arrays - transition data with label, from state, and to state
42
+
43
+ >>> script_df = read_and_preprocess_spreadsheet('curriculum_framework_for_tests.xlsx')
44
+ >>> build_horizontal_transitions(script_df)
45
+ [['right', 'N1.1.1_G1', 'N1.1.1_G2'], ['right', 'N1.1.1_G2', 'N1.1.1_G3'], ['right', 'N1.1.1_G3', 'N1.1.1_G4'], ['right', 'N1.1.1_G4', 'N1.1.1_G5'], ['right', 'N1.1.1_G5', 'N1.1.1_G6'], ['left', 'N1.1.1_G6', 'N1.1.1_G5'], ['left', 'N1.1.1_G5', 'N1.1.1_G4'], ['left', 'N1.1.1_G4', 'N1.1.1_G3'], ['left', 'N1.1.1_G3', 'N1.1.1_G2'], ['left', 'N1.1.1_G2', 'N1.1.1_G1'], ['right', 'N1.1.2_G1', 'N1.1.2_G2'], ['right', 'N1.1.2_G2', 'N1.1.2_G3'], ['right', 'N1.1.2_G3', 'N1.1.2_G4'], ['right', 'N1.1.2_G4', 'N1.1.2_G5'], ['right', 'N1.1.2_G5', 'N1.1.2_G6'], ['left', 'N1.1.2_G6', 'N1.1.2_G5'], ['left', 'N1.1.2_G5', 'N1.1.2_G4'], ['left', 'N1.1.2_G4', 'N1.1.2_G3'], ['left', 'N1.1.2_G3', 'N1.1.2_G2'], ['left', 'N1.1.2_G2', 'N1.1.2_G1']]
46
+ """
47
  horizontal_transitions = []
48
  for index, row in script_df.iterrows():
49
  skill_code = extract_skill_code(row['Knowledge or Skill'])
 
81
 
82
 
83
  def gather_all_vertical_matches(script_df):
84
+ """ Build a list of transitional relationships within a grade level across skills
85
+
86
+ Inputs
87
+ - script_df: pandas dataframe - an overview of the curriculum skills by grade level
88
+
89
+ Output
90
+ - all_matches: array of arrays - represents skills at each grade level
91
+
92
+ >>> script_df = read_and_preprocess_spreadsheet('curriculum_framework_for_tests.xlsx')
93
+ >>> gather_all_vertical_matches(script_df)
94
+ [['N1.1.1', '1'], ['N1.1.2', '1'], ['N1.1.1', '2'], ['N1.1.2', '2'], ['N1.1.1', '3'], ['N1.1.2', '3'], ['N1.1.1', '4'], ['N1.1.2', '4'], ['N1.1.1', '5'], ['N1.1.2', '5'], ['N1.1.1', '6'], ['N1.1.2', '6']]
95
+ """
96
  all_matches = []
97
  columns = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
98
 
 
110
 
111
 
112
  def build_vertical_transitions(script_df):
113
+ """ Build a list of transitional relationships within a grade level across skills
114
+
115
+ Inputs
116
+ - script_df: pandas dataframe - an overview of the curriculum skills by grade level
117
+
118
+ Output
119
+ - vertical_transitions: array of arrays - transition data with label, from state, and to state
120
+
121
+ >>> script_df = read_and_preprocess_spreadsheet('curriculum_framework_for_tests.xlsx')
122
+ >>> build_vertical_transitions(script_df)
123
+ [['down', 'N1.1.1_G1', 'N1.1.2_G1'], ['down', 'N1.1.2_G1', 'N1.1.1_G1'], ['down', 'N1.1.1_G2', 'N1.1.2_G2'], ['down', 'N1.1.2_G2', 'N1.1.1_G2'], ['down', 'N1.1.1_G3', 'N1.1.2_G3'], ['down', 'N1.1.2_G3', 'N1.1.1_G3'], ['down', 'N1.1.1_G4', 'N1.1.2_G4'], ['down', 'N1.1.2_G4', 'N1.1.1_G4'], ['down', 'N1.1.1_G5', 'N1.1.2_G5'], ['down', 'N1.1.2_G5', 'N1.1.1_G5'], ['down', 'N1.1.1_G6', 'N1.1.2_G6'], ['up', 'N1.1.2_G6', 'N1.1.1_G6'], ['up', 'N1.1.1_G6', 'N1.1.2_G6'], ['up', 'N1.1.2_G5', 'N1.1.1_G5'], ['up', 'N1.1.1_G5', 'N1.1.2_G5'], ['up', 'N1.1.2_G4', 'N1.1.1_G4'], ['up', 'N1.1.1_G4', 'N1.1.2_G4'], ['up', 'N1.1.2_G3', 'N1.1.1_G3'], ['up', 'N1.1.1_G3', 'N1.1.2_G3'], ['up', 'N1.1.2_G2', 'N1.1.1_G2'], ['up', 'N1.1.1_G2', 'N1.1.2_G2'], ['up', 'N1.1.2_G1', 'N1.1.1_G1']]
124
+ """
125
  vertical_transitions = []
126
 
127
  all_matches = gather_all_vertical_matches(script_df)
 
152
 
153
 
154
  def build_all_states(all_transitions):
155
+ """ Creates an array with all state labels for the curriculum
156
+
157
+ Input
158
+ - all_transitions: list of lists - all possible up, down, left, or right transitions in curriculum
159
+
160
+ Output
161
+ - all_states: list - a collection of state labels (skill code and grade number)
162
+
163
+ >>> all_transitions = [['right', 'N1.1.1_G1', 'N1.1.1_G2'], ['right', 'N1.1.1_G2', 'N1.1.1_G3'], ['right', 'N1.1.1_G3', 'N1.1.1_G4'], ['right', 'N1.1.1_G4', 'N1.1.1_G5'], ['right', 'N1.1.1_G5', 'N1.1.1_G6'], ['left', 'N1.1.1_G6', 'N1.1.1_G5'], ['left', 'N1.1.1_G5', 'N1.1.1_G4'], ['left', 'N1.1.1_G4', 'N1.1.1_G3'], ['left', 'N1.1.1_G3', 'N1.1.1_G2'], ['left', 'N1.1.1_G2', 'N1.1.1_G1'], ['right', 'N1.1.2_G1', 'N1.1.2_G2'], ['right', 'N1.1.2_G2', 'N1.1.2_G3'], ['right', 'N1.1.2_G3', 'N1.1.2_G4'], ['right', 'N1.1.2_G4', 'N1.1.2_G5'], ['right', 'N1.1.2_G5', 'N1.1.2_G6'], ['left', 'N1.1.2_G6', 'N1.1.2_G5'], ['left', 'N1.1.2_G5', 'N1.1.2_G4'], ['left', 'N1.1.2_G4', 'N1.1.2_G3'], ['left', 'N1.1.2_G3', 'N1.1.2_G2'], ['left', 'N1.1.2_G2', 'N1.1.2_G1'], ['down', 'N1.1.1_G1', 'N1.1.2_G1'], ['down', 'N1.1.2_G1', 'N1.1.1_G1'], ['down', 'N1.1.1_G2', 'N1.1.2_G2'], ['down', 'N1.1.2_G2', 'N1.1.1_G2'], ['down', 'N1.1.1_G3', 'N1.1.2_G3'], ['down', 'N1.1.2_G3', 'N1.1.1_G3'], ['down', 'N1.1.1_G4', 'N1.1.2_G4'], ['down', 'N1.1.2_G4', 'N1.1.1_G4'], ['down', 'N1.1.1_G5', 'N1.1.2_G5'], ['down', 'N1.1.2_G5', 'N1.1.1_G5'], ['down', 'N1.1.1_G6', 'N1.1.2_G6'], ['up', 'N1.1.2_G6', 'N1.1.1_G6'], ['up', 'N1.1.1_G6', 'N1.1.2_G6'], ['up', 'N1.1.2_G5', 'N1.1.1_G5'], ['up', 'N1.1.1_G5', 'N1.1.2_G5'], ['up', 'N1.1.2_G4', 'N1.1.1_G4'], ['up', 'N1.1.1_G4', 'N1.1.2_G4'], ['up', 'N1.1.2_G3', 'N1.1.1_G3'], ['up', 'N1.1.1_G3', 'N1.1.2_G3'], ['up', 'N1.1.2_G2', 'N1.1.1_G2'], ['up', 'N1.1.1_G2', 'N1.1.2_G2'], ['up', 'N1.1.2_G1', 'N1.1.1_G1']]
164
+ >>> build_all_states(all_transitions)
165
+ ['N1.1.1_G1', 'N1.1.1_G2', 'N1.1.1_G3', 'N1.1.1_G4', 'N1.1.1_G5', 'N1.1.1_G6', 'N1.1.2_G1', 'N1.1.2_G2', 'N1.1.2_G3', 'N1.1.2_G4', 'N1.1.2_G5', 'N1.1.2_G6']
166
+ """
167
  all_states = []
168
  for transition in all_transitions:
169
  for index, state in enumerate(transition):
 
175
 
176
 
177
  def build_curriculum_logic():
178
+ script_df = read_and_preprocess_spreadsheet('Rori_Framework_v1.xlsx')
179
  horizontal_transitions = build_horizontal_transitions(script_df)
180
  vertical_transitions = build_vertical_transitions(script_df)
181
  all_transitions = horizontal_transitions + vertical_transitions
mathtext_fastapi/data/curriculum_framework_for_tests.xlsx ADDED
Binary file (510 kB). View file
 
mathtext_fastapi/data/text2int_results.csv CHANGED
@@ -20,10 +20,10 @@ eight oh,80.0,8.0,False
20
  eighty,80.0,80.0,True
21
  ate,8.0,1.0,False
22
  double eight,88.0,8.0,False
23
- eight three seven five three O nine,8375309.0,8375329.0,False
24
  eight three seven five three oh nine,8375309.0,8375309.0,True
25
  eight three seven five three zero nine,8375309.0,8375309.0,True
26
- eight three seven five three oh ni-ee-ine,8375309.0,837530619.0,False
27
  two eight,28.0,16.0,False
28
  seven oh eleven,7011.0,77.0,False
29
  seven elevens,77.0,77.0,True
@@ -31,10 +31,10 @@ seven eleven,711.0,77.0,False
31
  ninety nine oh five,9905.0,149.0,False
32
  seven 0 seven 0 seven 0 seven,7070707.0,7070707.0,True
33
  123 hundred,123000.0,223.0,False
34
- 5 o 5,505.0,525.0,False
35
- 15 o 5,1505.0,22.0,False
36
- 15-o 5,1505.0,22.0,False
37
- 15 o-5,1505.0,22.0,False
38
  911-thousand,911000.0,911000.0,True
39
  twenty-two twenty-two,2222.0,44.0,False
40
  twenty-two twenty-twos,484.0,44.0,False
 
20
  eighty,80.0,80.0,True
21
  ate,8.0,1.0,False
22
  double eight,88.0,8.0,False
23
+ eight three seven five three O nine,8375309.0,8375319.0,False
24
  eight three seven five three oh nine,8375309.0,8375309.0,True
25
  eight three seven five three zero nine,8375309.0,8375309.0,True
26
+ eight three seven five three oh ni-ee-ine,8375309.0,837530111.0,False
27
  two eight,28.0,16.0,False
28
  seven oh eleven,7011.0,77.0,False
29
  seven elevens,77.0,77.0,True
 
31
  ninety nine oh five,9905.0,149.0,False
32
  seven 0 seven 0 seven 0 seven,7070707.0,7070707.0,True
33
  123 hundred,123000.0,223.0,False
34
+ 5 o 5,505.0,515.0,False
35
+ 15 o 5,1505.0,21.0,False
36
+ 15-o 5,1505.0,21.0,False
37
+ 15 o-5,1505.0,21.0,False
38
  911-thousand,911000.0,911000.0,True
39
  twenty-two twenty-two,2222.0,44.0,False
40
  twenty-two twenty-twos,484.0,44.0,False