<commit_before>from ..default import default
from ..pg import format
from ..pg import ident

class db(default):
    def tag_type(self, key):
        if key[0:4] == 'osm:':
            if key == 'osm:id':
                return ( 'column', 'id', self.compile_modify_id )
            elif key == 'osm:user':
                return None
            elif key == 'osm:user_id':
                return ( 'column', 'user_id' )
            elif key == 'osm:version':
                return ( 'column', 'version' )
            elif key == 'osm:timestamp':
                return ( 'column', 'tstamp' )
            elif key == 'osm:changeset':
                return ( 'column', 'changeset_id' )
            else:
                return None

        return ( 'hstore-value', key, 'tags' )

    def compile_modify_id(self, key, value):
        return format(value[1:])<commit_msg>DB/Osmosis: convert osm:user to user_id<commit_after>from ..default import default
from ..pg import format
from ..pg import ident

class db(default):
    def tag_type(self, key):
        if key[0:4] == 'osm:':
            if key == 'osm:id':
                return ( 'column', 'id', self.compile_modify_id )
            elif key == 'osm:user':
                return ( 'column', 'user_id', self.compile_user_id )
            elif key == 'osm:user_id':
                return ( 'column', 'user_id' )
            elif key == 'osm:version':
                return ( 'column', 'version' )
            elif key == 'osm:timestamp':
                return ( 'column', 'tstamp' )
            elif key == 'osm:changeset':
                return ( 'column', 'changeset_id' )
            else:
                return None

        return ( 'hstore-value', key, 'tags' )

    def compile_modify_id(self, key, value):
        return format(value[1:])

    def compile_user_id(self, key, value):
        plan = self.conn.prepare('select * from users where name=$1')
        res = plan(value)

        if(len(res)):
            return str(res[0][0])

        print("Warning compiling tag 'osm:user': User '{1}' not found.".format(key, value))
        return None
{'fraction_non_alphanumeric': 0.13887576759565423, 'fraction_numerical': 0.004723665564478035, 'mean_word_length': 1.8052980132450331, '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': '4195242', 'n_tokens_mistral': 647, 'n_tokens_neox': 623, 'n_words': 169}