|
|
|
@ -13,6 +13,8 @@ from django.core.cache import cache
|
|
|
|
from django.conf import settings
|
|
|
|
from django.conf import settings
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
|
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
|
|
|
|
|
|
|
from django.db.models import Avg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import psycopg2
|
|
|
|
import psycopg2
|
|
|
|
from postamates.settings import DB_URL
|
|
|
|
from postamates.settings import DB_URL
|
|
|
|
@ -93,6 +95,49 @@ def cached_func(key, func, timeout=settings.CACHE_TIMEOUT, *args, **kwargs):
|
|
|
|
return d
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_middle_bi_values():
|
|
|
|
|
|
|
|
fields_to_aggregate = [
|
|
|
|
|
|
|
|
'target_dist_shap',
|
|
|
|
|
|
|
|
'target_post_cnt_shap',
|
|
|
|
|
|
|
|
'target_cnt_ao_mean_shap',
|
|
|
|
|
|
|
|
'rival_pvz_cnt_shap',
|
|
|
|
|
|
|
|
'rival_post_cnt_shap',
|
|
|
|
|
|
|
|
'metro_dist_shap',
|
|
|
|
|
|
|
|
'property_price_bargains_shap',
|
|
|
|
|
|
|
|
'property_price_offers_shap',
|
|
|
|
|
|
|
|
'property_mean_floor_shap',
|
|
|
|
|
|
|
|
'property_era_shap',
|
|
|
|
|
|
|
|
'flats_cnt_shap',
|
|
|
|
|
|
|
|
'popul_home_shap',
|
|
|
|
|
|
|
|
'popul_job_shap',
|
|
|
|
|
|
|
|
'yndxfood_sum_shap',
|
|
|
|
|
|
|
|
'yndxfood_cnt_shap',
|
|
|
|
|
|
|
|
'school_cnt_shap',
|
|
|
|
|
|
|
|
'kindergar_cnt_shap',
|
|
|
|
|
|
|
|
'public_stop_cnt_shap',
|
|
|
|
|
|
|
|
'sport_center_cnt_shap',
|
|
|
|
|
|
|
|
'pharmacy_cnt_shap',
|
|
|
|
|
|
|
|
'supermarket_cnt_shap',
|
|
|
|
|
|
|
|
'supermarket_premium_cnt_shap',
|
|
|
|
|
|
|
|
'clinic_cnt_shap',
|
|
|
|
|
|
|
|
'bank_cnt_shap',
|
|
|
|
|
|
|
|
'reca_cnt_shap',
|
|
|
|
|
|
|
|
'lab_cnt_shap',
|
|
|
|
|
|
|
|
'culture_cnt_shap',
|
|
|
|
|
|
|
|
'attraction_cnt_shap',
|
|
|
|
|
|
|
|
'mfc_cnt_shap',
|
|
|
|
|
|
|
|
'bc_cnt_shap',
|
|
|
|
|
|
|
|
'tc_cnt_shap',
|
|
|
|
|
|
|
|
'business_activity_shap'
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
aggregations = {}
|
|
|
|
|
|
|
|
for field_name in fields_to_aggregate:
|
|
|
|
|
|
|
|
aggregations[f'avg_{field_name}'] = Avg(field_name)
|
|
|
|
|
|
|
|
result = models.PlacementPoint.objects.aggregate(**aggregations)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CustomReadOnlyModelViewSet(ReadOnlyModelViewSet):
|
|
|
|
class CustomReadOnlyModelViewSet(ReadOnlyModelViewSet):
|
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
|
def f():
|
|
|
|
def f():
|
|
|
|
|