Beispiel #1
0
 def get(self, request, task_id, format=None):
     image_url_prefix = self.task.reel.url_prefix()
     urls = []
     for vol_page in range(self.task.reel.start_vol_page,
                           self.task.reel.end_vol_page + 1):
         url = get_image_url(self.task.reel, vol_page)
         urls.append(url)
     pagetask_numbers = [
         t.number for t in PageTask.objects.filter(
             pagerect__reel=self.task.reel).order_by('pagerect__page')
     ]
     correct_task_count = 2
     if self.task.typ == Task.TYPE_CORRECT_VERIFY:
         correct_task_count = Task.objects.filter(reel=self.task.reel, \
         batchtask=self.task.batchtask, typ=Task.TYPE_CORRECT).count()
     bar_line_count = self.task.reel.sutra.tripitaka.bar_line_count
     if bar_line_count.isdigit():
         bar_line_count = int(bar_line_count)
     else:
         bar_line_count = json.loads(bar_line_count)
     response = {
         'task_id': task_id,
         'correct_task_count': correct_task_count,
         'task_typ': self.task.typ,
         'status': self.task.status,
         'result': self.task.result,
         'cur_focus': self.task.cur_focus,
         'image_urls': urls,
         'pagetask_numbers': pagetask_numbers,
         'bar_line_count': bar_line_count,
     }
     return Response(response)
Beispiel #2
0
    def get(self, request, s_id, format=None):
        # 根据卷ID 获得页号 和页数
        reel = Reel.objects.get(id=s_id)
        reelPages = Page.objects.filter(reel=reel).order_by("reel_page_no")
        strURLRet = ''
        cut_Info_list = []

        for p in reelPages:
            image_url = get_image_url(reel, p.reel_page_no)
            cut_Info_list.append(p.cut_info)
            strURLRet = image_url + '|'
        reel_ocr_text = None
        reelcorrectid = -1
        try:
            reel_ocr_text = ReelCorrectText.objects.get(reel_id=int(s_id))
            reelcorrectid = reel_ocr_text.id
            text = reel_ocr_text.text
        except:
            reel_ocr_text = ReelOCRText.objects.get(reel_id=int(s_id))
            text = reel_ocr_text.text

        response = {
            'sutra': text,
            'pageurls': strURLRet,
            'cut_Info_list': cut_Info_list,
            'sutra_name': str(reel.sutra.name),
            'reelcorrectid': reelcorrectid,
            # 'punct_lst': punctuation,
        }
        return Response(response)
Beispiel #3
0
def cutfixed_page_detail(request, pid):
    page = get_object_or_404(Page, pid=pid)
    image_url = get_image_url(page.reel, page.page_no)
    return render(request, 'tools/cutfixed_page_detail.html', {
        'page': page,
        'image_url': image_url
    })
Beispiel #4
0
 def page_url(self):
     try:
         pid = self.start_char_pos[0:17]
         page = Page.objects.get(pid=pid)
         url = get_image_url(page.reel, page.page_no)
         return url
     except:
         pass
Beispiel #5
0
 def get(self, request, pk, format=None):
     correct_fb = CorrectFeedback.objects.get(id=pk)
     correct_text = correct_fb.correct_text
     text_list = []
     whole_text = correct_text.text
     page_txt_list = whole_text.split('p')
     for p_no, i in enumerate(page_txt_list):
         for line_no, k in enumerate(i.replace('b', '').split('\n')):
             for char_no, l in enumerate(k):
                 text_list.append((p_no, 0, line_no, char_no, l))
     original_txt_info = text_list[correct_fb.position]
     p_no = original_txt_info[0]
     b_no = original_txt_info[1]
     line_no = original_txt_info[2]
     char_no = original_txt_info[3]
     reel = correct_text.reel
     page = reel.page_set.all().order_by('reel_page_no')[p_no - 1]
     image_url = get_image_url(reel, page.reel_page_no)
     cut_list = []
     cid = 'c{0}{1}{2:02d}n{3:02d}'.format(p_no, b_no, line_no,
                                           char_no + 1)  # 切分信息中字符从1开始计数
     page_cuts = json.loads(page.cut_info)['char_data']
     for c_no, cut in enumerate(page_cuts):
         if cut['char_id'] == cid:
             cut_list = page_cuts[c_no:c_no + len(correct_fb.original_text)]
     page_lines = page_txt_list[p_no].split('\n')
     fb_line = page_lines[line_no]
     page_lines[
         line_no] = fb_line[:
                            char_no] + '<span class="difftext confirmed">' + fb_line[
                                char_no] + '</span>' + fb_line[char_no + 1:]
     if correct_fb.processor:
         processor = correct_fb.processor
         return Response({
             'fb_id': correct_fb.id,
             'origin_text': correct_fb.original_text,
             'fb_text': correct_fb.fb_text,
             'fb_comment': correct_fb.fb_comment,
             'cut_info': cut_list,
             'page_txt': page_lines,
             'image_url': image_url,
             'processor': processor.email,
             'response': correct_fb.get_response_display()
         })
     else:
         return Response({
             'fb_id': correct_fb.id,
             'origin_text': correct_fb.original_text,
             'fb_text': correct_fb.fb_text,
             'fb_comment': correct_fb.fb_comment,
             'cut_info': cut_list,
             'page_txt': page_lines,
             'image_url': image_url,
             'processor': '',
             'response': correct_fb.get_response_display()
         })
Beispiel #6
0
 def retrieve(self, request, *args, **kwargs):
     instance = self.get_object()
     if (not request.user.is_admin):
         if (instance.owner != request.user):
             return Response({"status": -1, "msg": "No Permission!"})
     serializer = self.get_serializer(instance)
     if isinstance(instance, PageTask):
         pagerect = instance.pagerect
         page_id = pagerect.page_id
         _rects = Rect.objects.filter(page_pid=page_id).all()
         rects = RectSerializer(data=_rects, many=True)
         rects.is_valid()
         page = pagerect.page
         image_url = get_image_url(page.reel, page.page_no)
         return Response({
             "status": instance.status,
             "rects": rects.data,
             "image_url": image_url,
             "page_info": str(page),
             "current_x": instance.current_x,
             "current_y": instance.current_y,
             "task_id": instance.pk
         })
     if isinstance(instance, PageVerifyTask):
         pagerect = instance.pagerect
         page_id = pagerect.page_id
         _rects = Rect.objects.filter(page_pid=page_id).all()
         rects = RectSerializer(data=_rects, many=True)
         rects.is_valid()
         page = pagerect.page
         image_url = get_image_url(page.reel, page.page_no)
         return Response({
             "status": instance.status,
             "rects": rects.data,
             "image_url": image_url,
             "page_info": str(page),
             "current_x": instance.current_x,
             "current_y": instance.current_y,
             "task_id": instance.pk
         })
     return Response(serializer.data)
Beispiel #7
0
 def get(self, request, rid, format=None):
     reel = Reel.objects.get(id=int(rid))
     img_lst = []
     for page_no in range(reel.start_vol_page, reel.end_vol_page + 1):
         img_lst.append({
             'image_url':
             encipher.get_image_url(reel, page_no),
             'page_code':
             "%s_%s_%d" %
             (reel.sutra.tripitaka.code, reel.path_str(), page_no)
         })
     return Response({'results': img_lst})
Beispiel #8
0
 def check_sutra(self, sutra):
     if sutra.sid[:2] not in tcode_lst:
         return
     for reel in sutra.reel_set.all():
         if reel.start_vol_page == 0 and reel.end_vol_page == 0:
             continue
         for vol_page in range(reel.start_vol_page, reel.end_vol_page + 1):
             url = get_image_url(reel, vol_page)
             r = requests.head(url)
             if r.status_code != 200:
                 print(
                     '%s_%03d: image not exists.' %
                     (sutra.sid, reel.reel_no), url, r.status_code)
             cut_url = url.replace('jpg', 'cut')
             try:
                 r = requests.get(cut_url)
                 if r.status_code != 200:
                     print(
                         '%s_%03d: cut not exists.' %
                         (sutra.sid, reel.reel_no), cut_url, r.status_code)
                 else:
                     try:
                         cut_json = json.loads(r.content)
                         if not cut_json.get('char_data', []):
                             print(
                                 '%s_%03d: no char data.' %
                                 (sutra.sid, reel.reel_no), cut_url)
                     except:
                         print(
                             '%s_%03d: not json format.' %
                             (sutra.sid, reel.reel_no), cut_url)
             except:
                 print(
                     '%s_%03d: check cut exception.' %
                     (sutra.sid, reel.reel_no), cut_url, r.status_code)
             txt_url = url.replace('jpg', 'txt')
             txt_exists = False
             try:
                 r = requests.get(cut_url)
                 if r.status_code == 200:
                     txt_exists = True
             except:
                 pass
             if not txt_exists:
                 print(
                     '%s_%03d: txt not exists.' % (sutra.sid, reel.reel_no),
                     txt_url, r.status_code)
Beispiel #9
0
def sutra_page_detail(request, pid):
    page = get_object_or_404(Page, pid=pid)
    reel = page.reel
    vol_page = reel.start_vol_page + page.reel_page_no - 1
    image_url = get_image_url(reel, vol_page)
    char_pos = request.GET.get('char_pos', '')
    s = char_pos[-5:]
    try:
        line_no = int(s[0:2])
        char_no = int(s[3:])
    except:
        return redirect('/')
    context = {
        'page': page,
        'image_url': image_url,
        'line_no': line_no,
        'char_no': char_no,
    }
    return render(request, 'tasks/sutra_page_detail.html', context)
Beispiel #10
0
 def obtain(self, request):
     staff = request.user
     task = retrieve_pagetask(staff)
     if not task:
         return Response({"status": -1, "msg": "All tasks have been done!"})
     pagerect = task.pagerect
     page_id = pagerect.page_id
     _rects = Rect.objects.filter(page_pid=page_id).all()
     rects = RectSerializer(data=_rects, many=True)
     rects.is_valid()
     page = pagerect.page
     image_url = get_image_url(page.reel, page.page_no)
     return Response({
         "status": task.status,
         "rects": rects.data,
         "image_url": image_url,
         "page_info": str(page),
         "current_x": task.current_x,
         "current_y": task.current_y,
         "task_id": task.pk
     })