<commit_before>'''
update_sgid.py

handles updating data in SGID from the app database
'''
import logging
from os import path

import arcpy
import settings


utm = arcpy.SpatialReference(26912)
period_replacement = '___'
logger = logging.getLogger('forklift')


def update_sgid_data(source, destination):
    logger.debug('updating: %s', destination)

    arcpy.DeleteRows_management(destination)
    arcpy.Append_management(source, destination, 'NO_TEST')


def update_sgid_for_crates(crates_from_slip):
    updated_crates = [crate for crate in crates_from_slip if crate['was_updated'] and not crate['name'].startswith('DirectFrom')]

    for crate_slip in updated_crates:
        sgid_name = path.basename(crate_slip['destination']).replace(period_replacement, '.')
        destination = path.join(settings.sgid[sgid_name.split('.')[1]], sgid_name)

        if sgid_name.startswith('SGID10'):
            update_sgid_data(crate_slip['destination'], destination)<commit_msg>fix: make SGID update work on unqualified feature class names<commit_after>'''
update_sgid.py

handles updating data in SGID from the app database
'''
import logging
from os import path

import arcpy
import settings


utm = arcpy.SpatialReference(26912)
period_replacement = '___'
logger = logging.getLogger('forklift')


def update_sgid_data(source, destination):
    logger.debug('updating: %s', destination)

    arcpy.DeleteRows_management(destination)
    arcpy.Append_management(source, destination, 'NO_TEST')


def update_sgid_for_crates(crates_from_slip):
    logger.info('getting SGID names lookup')
    sgid_lookup = {}
    arcpy.env.workspace = path.join(settings.dbConnects, 'SGID10.sde')
    for dataset in arcpy.ListTables() + arcpy.ListFeatureClasses():
        sgid_lookup[dataset.split('.')[-1]] = dataset
    arcpy.env.workspace = None
        
    updated_crates = [crate for crate in crates_from_slip if crate['was_updated'] and not crate['name'].startswith('DirectFrom')]

    for crate_slip in updated_crates:
        sgid_name = sgid_lookup[crate_slip['name']]
        destination = path.join(settings.sgid[sgid_name.split('.')[1]], sgid_name)

        if sgid_name.startswith('SGID10'):
            update_sgid_data(crate_slip['destination'], destination)
{'fraction_non_alphanumeric': 0.11219512195121951, 'fraction_numerical': 0.008425720620842573, 'mean_word_length': 4.8903394255874675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '100400', 'n_tokens_mistral': 755, 'n_tokens_neox': 721, 'n_words': 149}