Merge branch 'fix_ml-2' into 'dev'

fixes

See merge request spatial/postamates!126
dev
Aleksandr Popov 2 years ago
commit 0d61a86630

@ -67,6 +67,7 @@ class CategoryAdmin(admin.ModelAdmin):
class PostPvzCategoryAdmin(CategoryAdmin): class PostPvzCategoryAdmin(CategoryAdmin):
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
obj.save() obj.save()
run_psql_command()
if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data:
LayerService.update_categories(obj) LayerService.update_categories(obj)
cache.clear() cache.clear()
@ -92,9 +93,8 @@ class GroupAdmin(admin.ModelAdmin):
class PostPvzGroupAdmin(GroupAdmin): class PostPvzGroupAdmin(GroupAdmin):
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
if not obj.pk:
run_psql_command()
obj.save() obj.save()
run_psql_command()
if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data: if 'include_in_ml' in form.changed_data or 'visible' in form.changed_data:
LayerService.update_groups(obj) LayerService.update_groups(obj)
cache.clear() cache.clear()

@ -25,10 +25,11 @@ from io import StringIO
from django.core.cache import cache from django.core.cache import cache
from service.layer_service import LayerService from service.layer_service import LayerService
from service.service import PointService from service.service import PointService
from service.utils import run_psql_command
@shared_task() @shared_task()
def raschet(table_name='service_placementpoint'): def raschet(table_name='service_placementpoint', need_time=True):
print('start raschet') print('start raschet')
status, _ = models.TaskStatus.objects.get_or_create(task_name=STATUS_TASK_NAME) status, _ = models.TaskStatus.objects.get_or_create(task_name=STATUS_TASK_NAME)
raschet_objs = models.RaschetObjects.objects.all() raschet_objs = models.RaschetObjects.objects.all()
@ -319,10 +320,13 @@ def raschet(table_name='service_placementpoint'):
conn2.close() conn2.close()
cache.clear() cache.clear()
log_to_telegram('end raschet') log_to_telegram('end raschet')
status.status = 'Перерасчет ML завершен' run_psql_command()
status.save() status.status = 'Перерасчет ML завершен'
LastMLCall.objects.all().delete() status.save()
LastMLCall.objects.create() if need_time:
LastMLCall.objects.all().delete()
LastMLCall.objects.create()
@shared_task @shared_task

@ -24,7 +24,7 @@ def run_psql_command():
) )
try: try:
cursor = connection.cursor() cursor = connection.cursor()
command = "CALL public.pivot_dist();" command = "CALL public.pivot_dist();CALL public.prepivot_dist();"
cursor.execute(command) cursor.execute(command)
connection.commit() connection.commit()
except psycopg2.Error as e: except psycopg2.Error as e:

@ -367,7 +367,7 @@ class PrePlacementPointViewSet(PlacementPointViewSet):
file_id = request.POST['id'] file_id = request.POST['id']
total, matched, problem = PointService().start_mathing(file_id) total, matched, problem = PointService().start_mathing(file_id)
PointService().make_enrichment() PointService().make_enrichment()
raschet('service_preplacementpoint') raschet('service_preplacementpoint', need_time=False)
return Response( return Response(
{'message': {'total': total, 'matched': matched, 'error': problem, 'unmatched': total - matched - problem}}, {'message': {'total': total, 'matched': matched, 'error': problem, 'unmatched': total - matched - problem}},
status=HTTPStatus.OK, status=HTTPStatus.OK,

Loading…
Cancel
Save