|
|
|
@ -27,7 +27,7 @@ from service.layer_service import LayerService
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task()
|
|
|
|
@shared_task()
|
|
|
|
def raschet():
|
|
|
|
def raschet(table_name='service_placementpoint'):
|
|
|
|
LastMLCall.objects.all().delete()
|
|
|
|
LastMLCall.objects.all().delete()
|
|
|
|
LastMLCall.objects.create()
|
|
|
|
LastMLCall.objects.create()
|
|
|
|
log_to_telegram('start raschet')
|
|
|
|
log_to_telegram('start raschet')
|
|
|
|
@ -46,23 +46,17 @@ def raschet():
|
|
|
|
pts['geometry'] = pts['geometry'].apply(wkb.loads, hex=True)
|
|
|
|
pts['geometry'] = pts['geometry'].apply(wkb.loads, hex=True)
|
|
|
|
pts = gpd.GeoDataFrame(pts, geometry='geometry', crs='epsg:4326')
|
|
|
|
pts = gpd.GeoDataFrame(pts, geometry='geometry', crs='epsg:4326')
|
|
|
|
pts = pts.to_crs('epsg:32637')
|
|
|
|
pts = pts.to_crs('epsg:32637')
|
|
|
|
pts = pts.rename(
|
|
|
|
|
|
|
|
columns={
|
|
|
|
|
|
|
|
'target_cnt_nearby_mean': 'target_dist1',
|
|
|
|
|
|
|
|
'target_age_nearby_mean': 'target_dist2',
|
|
|
|
|
|
|
|
'yndxfood_cnt_cst': 'target_dist3',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
feats = [
|
|
|
|
feats = [
|
|
|
|
'id', 'metro_dist', 'target_dist', 'property_price_bargains', 'property_price_offers',
|
|
|
|
'id', 'metro_dist', 'target_dist', 'property_price_bargains', 'property_price_offers',
|
|
|
|
'property_mean_floor',
|
|
|
|
'property_mean_floor',
|
|
|
|
'property_era', 'flats_cnt_2', 'flats_cnt', 'popul_home', 'popul_job', 'other_post_cnt', 'yndxfood_sum',
|
|
|
|
'property_era', 'flats_cnt', 'popul_home', 'popul_job', 'yndxfood_sum',
|
|
|
|
'yndxfood_cnt', 'school_cnt', 'kindergar_cnt', 'target_post_cnt', 'public_stop_cnt', 'sport_center_cnt',
|
|
|
|
'yndxfood_cnt', 'school_cnt', 'kindergar_cnt', 'target_post_cnt', 'public_stop_cnt', 'sport_center_cnt',
|
|
|
|
'pharmacy_cnt', 'supermarket_cnt', 'supermarket_premium_cnt', 'clinic_cnt', 'bank_cnt', 'reca_cnt',
|
|
|
|
'pharmacy_cnt', 'supermarket_cnt', 'supermarket_premium_cnt', 'clinic_cnt', 'bank_cnt', 'reca_cnt',
|
|
|
|
'lab_cnt', 'culture_cnt', 'attraction_cnt', 'mfc_cnt', 'bc_cnt', 'tc_cnt', 'rival_pvz_cnt',
|
|
|
|
'lab_cnt', 'culture_cnt', 'attraction_cnt', 'mfc_cnt', 'bc_cnt', 'tc_cnt', 'rival_pvz_cnt',
|
|
|
|
'rival_post_cnt',
|
|
|
|
'rival_post_cnt',
|
|
|
|
'business_activity', 'age_day', 'target_cnt_ao_mean', 'target_dist1', 'target_dist2', 'target_dist3',
|
|
|
|
'business_activity', 'age_day', 'target_cnt_ao_mean'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
# Записи для обучения
|
|
|
|
# Записи для обучения
|
|
|
|
@ -83,23 +77,6 @@ def raschet():
|
|
|
|
)
|
|
|
|
)
|
|
|
|
pts_trn.loc[pts_trn.target_dist > 700, 'target_dist'] = 700
|
|
|
|
pts_trn.loc[pts_trn.target_dist > 700, 'target_dist'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
pts_trn['target_dist1'] = pts_trn.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[2])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_trn.loc[pts_trn.target_dist1 > 700, 'target_dist1'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_trn['target_dist2'] = pts_trn.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[3])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_trn.loc[pts_trn.target_dist2 > 700, 'target_dist2'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_trn['target_dist3'] = pts_trn.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[4])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_trn.loc[pts_trn.target_dist3 > 700, 'target_dist3'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_trn['buf'] = pts_trn.buffer(500)
|
|
|
|
pts_trn['buf'] = pts_trn.buffer(500)
|
|
|
|
pts_trn = gpd.GeoDataFrame(pts_trn, geometry='buf', crs='epsg:32637')
|
|
|
|
pts_trn = gpd.GeoDataFrame(pts_trn, geometry='buf', crs='epsg:32637')
|
|
|
|
@ -113,11 +90,17 @@ def raschet():
|
|
|
|
Y_trn = pts_trn[['fact']]
|
|
|
|
Y_trn = pts_trn[['fact']]
|
|
|
|
|
|
|
|
|
|
|
|
# Записи для инференса
|
|
|
|
# Записи для инференса
|
|
|
|
pts_inf = pts.loc[(pts.status == 'Pending') |
|
|
|
|
if table_name == 'service_placementpoint':
|
|
|
|
(pts.status == 'Installation') |
|
|
|
|
pts_inf = pts.loc[(pts.status == 'Pending') |
|
|
|
|
(pts.status == 'Cancelled') |
|
|
|
|
(pts.status == 'Installation') |
|
|
|
|
((pts.status == 'Working') & (pts.sample_trn == False))].reset_index(drop=True)
|
|
|
|
(pts.status == 'Cancelled') |
|
|
|
|
pts_inf = gpd.GeoDataFrame(pts_inf, geometry='geometry', crs='epsg:32637')
|
|
|
|
((pts.status == 'Working') & (pts.sample_trn == False))].reset_index(drop=True)
|
|
|
|
|
|
|
|
elif table_name == 'service_preplacementpoint':
|
|
|
|
|
|
|
|
pts_inf = pd.read_sql(f"select * from {table_name}", conn)
|
|
|
|
|
|
|
|
pts_inf = pts_inf.loc[pts_inf.matching_status == 'New'].reset_index(drop=True)
|
|
|
|
|
|
|
|
pts_inf['geometry'] = pts_inf['geometry'].apply(wkb.loads, hex=True)
|
|
|
|
|
|
|
|
pts_inf = gpd.GeoDataFrame(pts_inf, geometry='geometry', crs='epsg:4326')
|
|
|
|
|
|
|
|
pts_inf = pts_inf.to_crs('epsg:32637')
|
|
|
|
|
|
|
|
|
|
|
|
pts_inf['buf'] = pts_inf.buffer(500)
|
|
|
|
pts_inf['buf'] = pts_inf.buffer(500)
|
|
|
|
pts_inf = gpd.GeoDataFrame(pts_inf, geometry='buf', crs='epsg:32637')
|
|
|
|
pts_inf = gpd.GeoDataFrame(pts_inf, geometry='buf', crs='epsg:32637')
|
|
|
|
@ -139,24 +122,6 @@ def raschet():
|
|
|
|
)
|
|
|
|
)
|
|
|
|
pts_inf.loc[pts_inf.target_dist > 700, 'target_dist'] = 700
|
|
|
|
pts_inf.loc[pts_inf.target_dist > 700, 'target_dist'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
pts_inf['target_dist1'] = pts_inf.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[1])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_inf.loc[pts_inf.target_dist1 > 700, 'target_dist1'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_inf['target_dist2'] = pts_inf.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[2])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_inf.loc[pts_inf.target_dist2 > 700, 'target_dist2'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_inf['target_dist3'] = pts_inf.apply(
|
|
|
|
|
|
|
|
lambda x: ((sorted(distance.cdist([[x['geometry'].x, x['geometry'].y]], target_feature_coords)[0])[3])),
|
|
|
|
|
|
|
|
axis=1,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
pts_inf.loc[pts_inf.target_dist3 > 700, 'target_dist3'] = 700
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pts_inf = pts_inf.sort_values(by='id').reset_index(drop=True)
|
|
|
|
pts_inf = pts_inf.sort_values(by='id').reset_index(drop=True)
|
|
|
|
target_post = gpd.sjoin(pts_inf, pts_target, op='contains').groupby('id', as_index=False).agg({'cnt': 'count'})
|
|
|
|
target_post = gpd.sjoin(pts_inf, pts_target, op='contains').groupby('id', as_index=False).agg({'cnt': 'count'})
|
|
|
|
target_post = target_post.rename(columns={'cnt': 'target_post_cnt'})
|
|
|
|
target_post = target_post.rename(columns={'cnt': 'target_post_cnt'})
|
|
|
|
@ -251,7 +216,7 @@ def raschet():
|
|
|
|
update_records1 = []
|
|
|
|
update_records1 = []
|
|
|
|
for i in range(0, len(update_fields)):
|
|
|
|
for i in range(0, len(update_fields)):
|
|
|
|
update_records1.append((int(update_fields.prediction_current[i]), int(update_fields.id[i])))
|
|
|
|
update_records1.append((int(update_fields.prediction_current[i]), int(update_fields.id[i])))
|
|
|
|
sql_update_query = """Update service_placementpoint set prediction_current = %s where id = %s"""
|
|
|
|
sql_update_query = f"""Update {table_name} set prediction_current = %s where id = %s"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records1)
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records1)
|
|
|
|
conn2.commit()
|
|
|
|
conn2.commit()
|
|
|
|
@ -264,7 +229,7 @@ def raschet():
|
|
|
|
update_records2 = []
|
|
|
|
update_records2 = []
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
update_records2.append((int(update_fields_working.plan_first[i]), int(update_fields_working.id[i])))
|
|
|
|
update_records2.append((int(update_fields_working.plan_first[i]), int(update_fields_working.id[i])))
|
|
|
|
sql_update_query = """Update service_placementpoint set plan_first = %s where id = %s"""
|
|
|
|
sql_update_query = f"""Update {table_name} set plan_first = %s where id = %s"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records2)
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records2)
|
|
|
|
conn2.commit()
|
|
|
|
conn2.commit()
|
|
|
|
@ -277,7 +242,7 @@ def raschet():
|
|
|
|
update_records3 = []
|
|
|
|
update_records3 = []
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
update_records3.append((int(update_fields_working.plan_current[i]), int(update_fields_working.id[i])))
|
|
|
|
update_records3.append((int(update_fields_working.plan_current[i]), int(update_fields_working.id[i])))
|
|
|
|
sql_update_query = """Update service_placementpoint set plan_current = %s where id = %s"""
|
|
|
|
sql_update_query = f"""Update {table_name} set plan_current = %s where id = %s"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records3)
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records3)
|
|
|
|
conn2.commit()
|
|
|
|
conn2.commit()
|
|
|
|
@ -290,7 +255,7 @@ def raschet():
|
|
|
|
update_records4 = []
|
|
|
|
update_records4 = []
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
update_records4.append((int(update_fields_working.delta_first[i]), int(update_fields_working.id[i])))
|
|
|
|
update_records4.append((int(update_fields_working.delta_first[i]), int(update_fields_working.id[i])))
|
|
|
|
sql_update_query = """Update service_placementpoint set delta_first = %s where id = %s"""
|
|
|
|
sql_update_query = f"""Update {table_name} set delta_first = %s where id = %s"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records4)
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records4)
|
|
|
|
conn2.commit()
|
|
|
|
conn2.commit()
|
|
|
|
@ -303,7 +268,7 @@ def raschet():
|
|
|
|
update_records5 = []
|
|
|
|
update_records5 = []
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
for i in range(0, len(update_fields_working)):
|
|
|
|
update_records5.append((int(update_fields_working.delta_current[i]), int(update_fields_working.id[i])))
|
|
|
|
update_records5.append((int(update_fields_working.delta_current[i]), int(update_fields_working.id[i])))
|
|
|
|
sql_update_query = """Update service_placementpoint set delta_current = %s where id = %s"""
|
|
|
|
sql_update_query = f"""Update {table_name} set delta_current = %s where id = %s"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records5)
|
|
|
|
psycopg2.extras.execute_batch(cursor, sql_update_query, update_records5)
|
|
|
|
conn2.commit()
|
|
|
|
conn2.commit()
|
|
|
|
@ -316,6 +281,7 @@ def raschet():
|
|
|
|
log_to_telegram('end raschet')
|
|
|
|
log_to_telegram('end raschet')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
@shared_task
|
|
|
|
def load_post_and_pvz(obj_id: int):
|
|
|
|
def load_post_and_pvz(obj_id: int):
|
|
|
|
file = models.TempFiles.objects.get(id=obj_id)
|
|
|
|
file = models.TempFiles.objects.get(id=obj_id)
|
|
|
|
|