|
|
|
|
@ -24,7 +24,8 @@ import base64
|
|
|
|
|
from io import StringIO
|
|
|
|
|
from django.core.cache import cache
|
|
|
|
|
from service.layer_service import LayerService
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
from postamates.settings import GEOCODER_API_KEY
|
|
|
|
|
|
|
|
|
|
@shared_task()
|
|
|
|
|
def raschet():
|
|
|
|
|
@ -245,6 +246,7 @@ def raschet():
|
|
|
|
|
except:
|
|
|
|
|
conn2 = None
|
|
|
|
|
log_to_telegram('Не удалось подключиться к базе данных')
|
|
|
|
|
|
|
|
|
|
# prediction_current
|
|
|
|
|
if conn2 is not None:
|
|
|
|
|
update_records1 = []
|
|
|
|
|
@ -442,6 +444,28 @@ def load_data(obj_id: int):
|
|
|
|
|
models.TempFiles.objects.all().delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task()
|
|
|
|
|
def start_matching(obj_id: int):
|
|
|
|
|
file = models.TempFiles.objects.get(id=obj_id)
|
|
|
|
|
status, _ = models.TaskStatus.objects.get_or_create(task_name='Мэтчинг точек')
|
|
|
|
|
excel_file = base64.b64decode(file.data)
|
|
|
|
|
df = pd.read_excel(excel_file)
|
|
|
|
|
total = df.shape[0]
|
|
|
|
|
matched = 0
|
|
|
|
|
for _i, row in df.iterrows():
|
|
|
|
|
status.status = f'Мэтчинг: {_i} из {total}'
|
|
|
|
|
status.save()
|
|
|
|
|
addr = row['Адрес']
|
|
|
|
|
cat = row['Категория объекта']
|
|
|
|
|
req_url = f"https://geocode.search.hereapi.com/v1/geocode?q={addr}&apiKey={GEOCODER_API_KEY}"
|
|
|
|
|
response = requests.get(req_url).json()['items'][0]['address']
|
|
|
|
|
obj = models.PlacementPoint.objects.filter(street=response['street'], house_number=response['houseNumber'], category=cat).first()
|
|
|
|
|
if obj:
|
|
|
|
|
matched += 1
|
|
|
|
|
status.status = f"Мэтчинг завершен. Смэтчилось {matched}, несмэтчилось {total-matched}"
|
|
|
|
|
status.save()
|
|
|
|
|
models.TempFiles.objects.all().delete()
|
|
|
|
|
|
|
|
|
|
@shared_task()
|
|
|
|
|
def start_pvz_group_count(instance_id: int):
|
|
|
|
|
instance = models.Post_and_pvzGroup.objects.filter(id=instance_id).first()
|
|
|
|
|
|