<commit_before>import zipfile
import os

import sqlalchemy as sa

import config
import sa_common
from csv_util import make_csv

engine = sa.create_engine(config.CONNECTION_USER, echo=False)
conn = engine.connect()


def run_sql(*args, **kw):
    return sa_common.run_sql(engine, *args, **kw)


def make_zip(file_path, files):
    zf = zipfile.ZipFile(file_path, mode='w')
    for f in files:
        arcname = os.path.basename(f)
        zf.write(f, compress_type=zipfile.ZIP_DEFLATED, arcname=arcname)
        os.remove(f)
    zf.close()


TEMP_PATH = '/tmp'

data = [

    {
        # c_ct
        'file_name': 'consumer_trend_codes.csv',
        'sql': 'select * from c_ct',
    },
    {
        # scat_group_codes
        'file_name': 'scat_group_codes.csv',
        'sql': 'select code, "desc" from c_scat_group',
    },
    {
        # premises
        'file_name': 'premises.csv',
        'sql': 'select * from v_download_premises_data where la_code IN :la_codes',
    },
#    {
#        # market size
#        'file_name': 'market_size.csv',
#        'sql': 'select * from s_la_spending_by_ct where la_code IN :la_codes',
#    },
]


def zoopla_downloads():
    sql = '''<commit_msg>no ct download<commit_after>import zipfile
import os

import sqlalchemy as sa

import config
import sa_common
from csv_util import make_csv

engine = sa.create_engine(config.CONNECTION_USER, echo=False)
conn = engine.connect()


def run_sql(*args, **kw):
    return sa_common.run_sql(engine, *args, **kw)


def make_zip(file_path, files):
    zf = zipfile.ZipFile(file_path, mode='w')
    for f in files:
        arcname = os.path.basename(f)
        zf.write(f, compress_type=zipfile.ZIP_DEFLATED, arcname=arcname)
        os.remove(f)
    zf.close()


TEMP_PATH = '/tmp'

data = [

#    {
#        # c_ct
#        'file_name': 'consumer_trend_codes.csv',
#        'sql': 'select * from c_ct',
#    },
    {
        # scat_group_codes
        'file_name': 'scat_group_codes.csv',
        'sql': 'select code, "desc" from c_scat_group',
    },
    {
        # premises
        'file_name': 'premises.csv',
        'sql': 'select * from v_download_premises_data where la_code IN :la_codes',
    },
#    {
#        # market size
#        'file_name': 'market_size.csv',
#        'sql': 'select * from s_la_spending_by_ct where la_code IN :la_codes',
#    },
]


def zoopla_downloads():
    sql = '''
{'fraction_non_alphanumeric': 0.13274706867671693, 'fraction_numerical': 0.0, 'mean_word_length': 2.774091627172196, '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': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '722096', 'n_tokens_mistral': 893, 'n_tokens_neox': 870, 'n_words': 182}