added paragraph score, inited word api

This commit is contained in:
Alexander Karpov 2022-08-27 11:13:36 +03:00
parent f06651d1a9
commit cdf082415c
4 changed files with 45 additions and 11 deletions

View File

@ -24,8 +24,8 @@ class RetireDocxSerializer(APIView):
def get(self, request, uuid):
doc = get_object_or_404(Docx, uuid=uuid)
res = {}
paragraphs = ParagraphType.objects.filter(paragraphs__docx=doc)
paragraphs = ParagraphType.objects.all()
for p in paragraphs:
res[p.name] = [x.text for x in p.paragraphs.filter(docx=doc)]
res[p.name] = [(x.text, x.score) for x in p.paragraphs.filter(docx=doc)]
return Response(res)

View File

@ -1,4 +1,6 @@
import uuid as uuid
from django.core.validators import MinValueValidator, MaxValueValidator
from django.db import models
# Create your models here.
@ -30,6 +32,7 @@ class ParagraphType(models.Model):
class Paragraph(models.Model):
score = models.IntegerField(default=0, validators=[MinValueValidator(0), MaxValueValidator(100)])
text = models.TextField()
type = models.ForeignKey(
ParagraphType, related_name="paragraphs", on_delete=models.CASCADE

View File

@ -25,12 +25,18 @@ def process_file(pk: int):
dct = {x: vals[x] for x in range(len(vals))}
x = requests.post("http://109.248.175.223:5000/api", json=dct)
for el_id, type_id in x.json().items():
Paragraph.objects.create(type_id=type_id, docx=file, text=dct[int(el_id)])
if x.status_code == 200:
for el_id, dat in x.json().items():
type_id, score = dat
Paragraph.objects.create(
type_id=type_id, docx=file, text=dct[int(el_id)], score=score
)
counter += len(vals)
print(f"processing {uuid}, {counter}/{len_c}")
file.paragraphs_processed = counter
file.save(update_fields=["paragraphs_processed"])
counter += len(vals)
print(f"processing {uuid}, {counter}/{len_c}")
file.paragraphs_processed = counter
file.save(update_fields=["paragraphs_processed"])
else:
print(f"AI server error, {x.status_code}")
return f"ok, {pk}"

View File

@ -4,7 +4,32 @@ from checker.api.views import ListCreateDocxApiView, RetireDocxSerializer, GetDo
urlpatterns = [
path("health/", include("health_check.urls")),
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_docx"),
path("docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_docx"),
path("state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_docx"),
path(
"site/",
include(
[
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_docx"),
path(
"docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_docx"
),
path(
"state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_docx"
),
]
),
),
path(
"word/",
include(
[
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_word"),
path(
"docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_word"
),
path(
"state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_word"
),
]
),
),
]