Ujjwal123 commited on
Commit
228f684
1 Parent(s): 076da67

Fixed evaluation metrics errors

Browse files
Files changed (2) hide show
  1. Solver_inf.py +35 -1
  2. main.py +2 -2
Solver_inf.py CHANGED
@@ -110,4 +110,38 @@ class Solver:
110
  print(letter_frac_log)
111
  print(letter_acc_log)
112
 
113
- return letter_frac_log, letter_acc_log
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  print(letter_frac_log)
111
  print(letter_acc_log)
112
 
113
+ return letter_frac_log, letter_acc_log
114
+
115
+ def evaluate1(self, solution):
116
+ # print puzzle accuracy results given a generated solution
117
+ letters_correct = 0
118
+ letters_total = 0
119
+ for i in range(len(self.crossword.letter_grid)):
120
+ for j in range(len(self.crossword.letter_grid[0])):
121
+ if self.crossword.letter_grid[i][j] != "":
122
+ letters_correct += (self.crossword.letter_grid[i][j] == solution[i][j])
123
+ letters_total += 1
124
+ words_correct = 0
125
+ words_total = 0
126
+ for var in self.crossword.variables:
127
+ cells = self.crossword.variables[var]["cells"]
128
+ matching_cells = [self.crossword.letter_grid[cell[0]][cell[1]] == solution[cell[0]][cell[1]] for cell in cells]
129
+ if len(cells) == sum(matching_cells):
130
+ words_correct += 1
131
+ else:
132
+ # print('evaluation: correct word', ''.join([self.crossword.letter_grid[cell[0]][cell[1]] for cell in cells]), 'our prediction:', ''.join([solution[cell[0]][cell[1]] for cell in cells]))
133
+ pass
134
+ words_total += 1
135
+
136
+ print("Letters Correct: {}/{} | Words Correct: {}/{}".format(int(letters_correct), int(letters_total), int(words_correct), int(words_total)))
137
+ print("Letters Correct: {}% | Words Correct: {}%".format(float(letters_correct/letters_total*100), float(words_correct/words_total*100)))
138
+
139
+ info = {
140
+ "total_letters" : int(letters_total),
141
+ "total_words" : int(words_total),
142
+ "correct_letters" : int(letters_correct),
143
+ "correct_words" : int(words_correct),
144
+ "correct_letters_percent" : float(letters_correct/letters_total*100),
145
+ "correct_words_percent" : float(words_correct/words_total*100),
146
+ }
147
+ return info
main.py CHANGED
@@ -64,8 +64,8 @@ async def solve_puzzle(json):
64
 
65
  solution = await solve_method_async()
66
 
67
- evaluation1 = await asyncio.to_thread(solver.evaluate, solution['first pass model']['grid'])
68
- evaluation2 = await asyncio.to_thread(solver.evaluate, solution['second pass model']['final grid'])
69
 
70
  return solution['second pass model']['final grid'], evaluation1, solution['second pass model']['final grid'], evaluation2
71
 
 
64
 
65
  solution = await solve_method_async()
66
 
67
+ evaluation1 = await asyncio.to_thread(solver.evaluate1, solution['first pass model']['grid'])
68
+ evaluation2 = await asyncio.to_thread(solver.evaluate1, solution['second pass model']['final grid'])
69
 
70
  return solution['second pass model']['final grid'], evaluation1, solution['second pass model']['final grid'], evaluation2
71