def __record_cells(self, answer_json):
     book_id = self.get_book_id()
     page_num = self.task.info["page"]
     page = data_manager.get_page(book_id, page_num)
     
     if (page == None):
         logger.warn("The page from the book " + book_id + " and page number " +  str(page_num) + " doesn't exist.")
         return
     
     cells = answer_json['cells']
     human_values = answer_json['human_values']
     
     for i in range(0, len(cells)):
         cell = cells[i]
         human_value = human_values[i]
         
         # retrieve page table
         page_table = data_manager.get_page_table_by_local_url(page.id, self.task.info["img_url"])
         
         if (page_table == None):
             logger.warn("The page table from the book " + book_id + " and page " +  str(page.id) + " doesn't exist.")
             return
         
         cell_info_dict = dict(bookid=book_id, pageid=page.id, pagetableid=page_table.id, text=human_value, x0=cell[0], y0=cell[1], x1=cell[2], y1=cell[3])
         data_manager.record_cell(cell_info_dict)
 def __record_page_table_and_metadata(self, answers):
     # retrieve page (testar none)
     book_id = self.get_book_id()
     page_num = self.task.info["page"]
     page = data_manager.get_page(book_id, page_num)
     
     if (page == None):
         logger.warn("The page from the book " + book_id + " and page number " +  str(page_num) + " doesn't exist.")
         return
     
     for i in range(0, len(answers)):
         answer = answers[i]
         page_table_dict = dict(bookid=book_id, pageid=page.id, local_url="/books/" + book_id + "/metadados/tabelasBaixa/image" + str(page_num) + "_" + str(i) + ".png", top_pos=answer['top'], left_pos=answer['left'], right_pos=(answer['left'] + answer['width']), bottom_pos=(answer['top'] + answer['height']))
         data_manager.record_page_table(page_table_dict)
         
         # retrieve page table
         page_table = data_manager.get_page_table_by_position(page.id, page_table_dict['top_pos'], page_table_dict['left_pos'], page_table_dict['right_pos'], page_table_dict['bottom_pos'])
         
         if (page_table == None):
             logger.warn("The page table from the book " + book_id + " and page " +  str(page.id) + " doesn't exist.")
             return
         
         metadata = answer['text']
         subject_name = priority_task_manager.get_subject(metadata['assunto'])
         
         data_manager.record_metadata(dict(bookid=book_id, pageid=page.id, pagetableid=page_table.id, source=metadata['fontes'], title=metadata['titulo'], subtitle=metadata['subtitulo'], subject=(metadata['outros'] if subject_name == "Outros" else subject_name), initial_date=metadata['dataInicial'], final_date=metadata['dataFinal']))
def get_page(book_id, num_page):
    return data_mngr.get_page(book_id, num_page)