debug temp

This commit is contained in:
2024-07-31 00:56:23 +00:00
parent 26e8e68dbd
commit 49b3ee7342
9 changed files with 383 additions and 100 deletions

View File

@ -26,6 +26,8 @@ from django.contrib.postgres.indexes import GistIndex
from django.utils import timezone
from datetime import timedelta,date
from django.contrib.gis.geos import Point,MultiPoint
#from django.db import models
from django.core.exceptions import ValidationError
@ -886,17 +888,17 @@ def publish_data(sender, instance, created, **kwargs):
os.remove(file)
try:
logger.debug("Attempting to read shape file")
#logger.debug("Attempting to read shape file")
# print("before reading the file")
shp = glob.glob(r'{}/**/*.shp'.format(file_path), recursive=True)[0]
logger.info(f"Shape file read: {shp}")
#logger.info(f"Shape file read: {shp}")
# print("this is the read file",shp)
gdf = gpd.read_file(shp)
crs_name = str(gdf.crs.srs)
logger.debug(f"CRS name: {crs_name}")
#logger.debug(f"CRS name: {crs_name}")
# print(crs_name, 'crs - name')
epsg = int(crs_name.replace('epsg:',''))
@ -904,11 +906,11 @@ def publish_data(sender, instance, created, **kwargs):
epsg=4326
lm2 = getTempMappingforModel(instance.layerof, shp)
logger.info("Saving to temporary table")
#logger.info("Saving to temporary table")
# print("### shape file is ###")
lm2.save(strict=True, verbose=True)
logger.info("Save to temporary table completed")
#logger.info("Save to temporary table completed")
os.remove(shp)
except Exception as e:
@ -922,9 +924,9 @@ def publish_data(sender, instance, created, **kwargs):
remove_bom_inplace(csv_f)
mdl = apps.get_model(app_label="rog", model_name=LAYER_CHOICES[instance.layerof -1][1])
# print(mdl)
# print(f"#### instance.layerof - {instance.layerof}")
logger.debug(f"Model for layer: {mdl}")
print(mdl)
print(f"#### instance.layerof - {instance.layerof}")
#logger.debug(f"Model for layer: {mdl}")
with open(csv_f, mode="r", encoding="utf-8") as txt_file:
#heading = next(txt_file)
@ -936,7 +938,8 @@ def publish_data(sender, instance, created, **kwargs):
print("@@@@@@@@@@@@")
if instance.layerof == 1:
#insertShapeLayerLocation(instance.name, fields)
updateLocation(mdl, fields)
#updateLocation(mdl, fields)
update_or_create_location(mdl, fields)
if instance.layerof == 2:
updateLineTable(mdl, fields)
if instance.layerof == 3:
@ -975,6 +978,72 @@ def insertUserUploadUser(name, fields):
except Exception as e:
logger.error(f"Error updating TempLocation: {e}", exc_info=True)
def update_or_create_location(mdl, fields):
try:
with transaction.atomic():
latitude = float(fields[11]) if fields[11] and len(fields[11]) > 0 else None
longitude = float(fields[12]) if fields[12] and len(fields[12]) > 0 else None
geom = MultiPoint(Point(longitude, latitude)) if latitude is not None and longitude is not None else None
defaults={
'sub_loc_id': fields[1] if len(fields[1]) > 0 else '',
'cp': fields[2] if len(fields[2]) > 0 else 0,
# その他のフィールド...
'location_name': fields[3] if len(fields[3]) > 0 else '',
'category': fields[4] if len(fields[4]) > 0 else '',
'subcategory': fields[5] if len(fields[5]) > 0 else '',
'zip': fields[6] if len(fields[6]) > 0 else '',
'address': fields[7] if len(fields[7]) > 0 else '',
'prefecture': fields[8] if len(fields[8]) > 0 else '',
'area': fields[9] if len(fields[9]) > 0 else '',
'city': fields[10] if len(fields[10]) > 0 else '',
'latitude': latitude,
'longitude': longitude,
'photos': fields[13] if len(fields[13]) > 0 else '',
'videos': fields[14] if len(fields[14]) > 0 else '',
'webcontents': fields[15] if len(fields[15]) > 0 else '',
'status': fields[16] if len(fields[16]) > 0 else '',
'portal': fields[17] if len(fields[17]) > 0 else '',
'group': fields[18] if len(fields[18]) > 0 else '',
'phone': fields[19] if len(fields[19]) > 0 else '',
'fax': fields[20] if len(fields[20]) > 0 else '',
'email': fields[21] if len(fields[21]) > 0 else '',
'facility': fields[22] if len(fields[22]) > 0 else '',
'remark': fields[23] if len(fields[23]) > 0 else '',
'tags': fields[24] if len(fields[24]) > 0 else '',
'hidden_location': fields[25] if len(fields[25]) > 0 else False,
'auto_checkin': fields[26] if len(fields[26]) > 0 else False,
'checkin_radius': fields[27] if len(fields[27]) > 0 else 15,
'checkin_point': fields[28] if len(fields[28]) > 0 else 10,
'buy_point': fields[29] if len(fields[29]) > 0 else 0,
'evaluation_value': fields[30] if len(fields[30]) > 0 else '',
'shop_closed': fields[31] if len(fields[31]) > 0 else False,
'shop_shutdown': fields[32] if len(fields[32]) > 0 else False,
'opening_hours_mon': fields[33] if len(fields[33]) > 0 else '',
'opening_hours_tue': fields[34] if len(fields[34]) > 0 else '',
'opening_hours_wed': fields[35] if len(fields[35]) > 0 else '',
'opening_hours_thu': fields[36] if len(fields[36]) > 0 else '',
'opening_hours_fri': fields[37] if len(fields[37]) > 0 else '',
'opening_hours_sat': fields[38] if len(fields[38]) > 0 else '',
'opening_hours_sun': fields[39] if len(fields[39]) > 0 else ''
}
if geom:
defaults['geom'] = geom
obj, created = mdl.objects.update_or_create(
location_id=int(fields[0]),
defaults=defaults
)
if created:
logger.info(f"New location created with id: {obj.location_id}")
else:
logger.info(f"Location updated with id: {obj.location_id}")
except Exception as e:
logger.error(f"Error updating or creating location: {e}", exc_info=True)
def updateLocation(mdl, fields):