Commit 2c7fa1c8 authored by Ossi Laine's avatar Ossi Laine
Browse files

Fixed bug in randomized data exporting

parent 27719c7b
...@@ -427,9 +427,23 @@ def download_csv(): ...@@ -427,9 +427,23 @@ def download_csv():
.order_by(embody_answer.page_idpage) \ .order_by(embody_answer.page_idpage) \
.all() .all()
pages_and_questions = {}
for p in pages:
questions_list = [(p.idpage, a.idembody) for a in embody_questions]
pages_and_questions[p.idpage] = questions_list
_questions = [
item for sublist in pages_and_questions.values() for item in sublist]
_embody_answers = map_answers_to_questions(embody_answers, _questions)
answers_list = [] answers_list = []
for answer_data in embody_answers: for answer_data in _embody_answers:
if not answer_data:
answers_list.append('')
continue
try: try:
coordinates = json.loads(answer_data.coordinates) coordinates = json.loads(answer_data.coordinates)
......
...@@ -41,10 +41,14 @@ def get_values_from_list_of_answers(page_question, answers): ...@@ -41,10 +41,14 @@ def get_values_from_list_of_answers(page_question, answers):
page_id = page_question[0] page_id = page_question[0]
question_id = page_question[1] question_id = page_question[1]
for _answer in answers: for _answer in answers:
if _answer.question_idquestion == question_id and \ try:
_answer.page_idpage == page_id: if _answer.question_idquestion == question_id and \
return int(_answer.answer) _answer.page_idpage == page_id:
return int(_answer.answer)
except AttributeError:
if _answer.embody_question_idembody == question_id and \
_answer.page_idpage == page_id:
return _answer
return None return None
......
...@@ -106,6 +106,10 @@ if __name__ == '__main__': ...@@ -106,6 +106,10 @@ if __name__ == '__main__':
except NameError: except NameError:
print( print(
"Column didn't contain image data. Try again with different column number.") "Column didn't contain image data. Try again with different column number.")
except SyntaxError:
continue
except IndexError:
continue
np_array = np.transpose(np_array) np_array = np.transpose(np_array)
images.append(np_array) images.append(np_array)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment