# Path: lib/logger.py
# def get_logger(name):
#     '''
#     Obtain a logger outputing to stderr with specified name. Defaults to INFO
#     log level.
#     '''
#     logger = logging.getLogger(name)
#     if LUIGI_LOG_ARG in sys.argv:
#         index = sys.argv.index(LUIGI_LOG_ARG) + 1
#         if len(sys.argv) > index:
#             logger.setLevel(sys.argv[index])
# 
#     return logger


import os
import time
import re
import subprocess
import shutil
import zipfile
import requests
from lib.logger import get_logger
from itertools import zip_longest
from slugify import slugify
        SELECT '{table_id}', '{column_id}', er.id,
                 ST_SetValues(ST_SetValues(ST_SetValues(er.rast,
                 1, medians),
                 2, counts),
                 3, percents) geom
          FROM raster_empty_{tablename_ns} er, pixelspertile ppt
          WHERE er.id = ppt.id
       '''.format(tablename_ns=tablename_ns, tablename=tablename,
                  table_id=table_id, column_id=column_id)
    resp = session.execute(query)
    assert resp.rowcount > 0

    resp = session.execute('''
        UPDATE observatory.obs_column_table_tile
        SET tile = st_setvalues(st_setvalues(st_setvalues(tile,
                    1, geomvals, false),
                    2, geomvals, false),
                    3, geomvals, false)
        FROM (
            SELECT table_id, column_id, tile_id, array_agg(((geomval).geom, 0)::geomval) geomvals FROM (
                SELECT table_id, column_id, tile_id, st_dumpaspolygons(tile, 2, false) geomval
                FROM observatory.obs_column_table_tile
                WHERE column_id = '{column_id}'
                  AND table_id = '{table_id}'
            ) bar
            WHERE (geomval).val = -1
            GROUP BY table_id, column_id, tile_id
        ) foo
          WHERE obs_column_table_tile.table_id = foo.table_id
            AND obs_column_table_tile.column_id = foo.column_id

# Path: lib/logger.py
# def get_logger(name):
#     '''
#     Obtain a logger outputing to stderr with specified name. Defaults to INFO
#     log level.
#     '''
#     logger = logging.getLogger(name)
#     if LUIGI_LOG_ARG in sys.argv:
#         index = sys.argv.index(LUIGI_LOG_ARG) + 1
#         if len(sys.argv) > index:
#             logger.setLevel(sys.argv[index])
# 
#     return logger


# Path: tasks/util.py
import os
import time
import re
import subprocess
import shutil
import zipfile
import requests
from lib.logger import get_logger
from itertools import zip_longest
from slugify import slugify

        SELECT '{table_id}', '{column_id}', er.id,
                 ST_SetValues(ST_SetValues(ST_SetValues(er.rast,
                 1, medians),
                 2, counts),
                 3, percents) geom
          FROM raster_empty_{tablename_ns} er, pixelspertile ppt
          WHERE er.id = ppt.id
       '''.format(tablename_ns=tablename_ns, tablename=tablename,
                  table_id=table_id, column_id=column_id)
    resp = session.execute(query)
    assert resp.rowcount > 0

    resp = session.execute('''
        UPDATE observatory.obs_column_table_tile
        SET tile = st_setvalues(st_setvalues(st_setvalues(tile,
                    1, geomvals, false),
                    2, geomvals, false),
                    3, geomvals, false)
        FROM (
            SELECT table_id, column_id, tile_id, array_agg(((geomval).geom, 0)::geomval) geomvals FROM (
                SELECT table_id, column_id, tile_id, st_dumpaspolygons(tile, 2, false) geomval
                FROM observatory.obs_column_table_tile
                WHERE column_id = '{column_id}'
                  AND table_id = '{table_id}'
            ) bar
            WHERE (geomval).val = -1
            GROUP BY table_id, column_id, tile_id
        ) foo
          WHERE obs_column_table_tile.table_id = foo.table_id
            AND obs_column_table_tile.column_id = foo.column_id

            AND obs_column_table_tile.tile_id = foo.tile_id