# Path: openaddr/ci/objects.py
# import logging; _L = logging.getLogger('openaddr.ci.objects')
# class Job:
# class Set:
# class Run:
# class RunState:
# class Zip:
#     def __init__(self, id, status, task_files, states, file_results,
#                  github_owner, github_repository, github_status_url,
#                  github_comments_url, datetime_start, datetime_end):
#     def __init__(self, id, commit_sha, datetime_start, datetime_end,
#                  render_world, render_europe, render_usa, render_geojson,
#                  owner, repository):
#     def __init__(self, id, source_path, source_id, source_data, datetime_tz,
#                  state, status, copy_of, code_version, worker_id, job_id,
#                  set_id, commit_sha, is_merged):
#     def __init__(self, json_blob):
#     def get(self, json_key):
#     def to_dict(self):
#     def to_json(self):
#     def __init__(self, url, content_length):
# def _result_runstate2dictionary(result):
# def result_dictionary2runstate(result):
# def add_job(db, job_id, status, task_files, file_states, file_results, owner, repo, status_url, comments_url):
# def write_job(db, job_id, status, task_files, file_states, file_results, owner, repo, status_url, comments_url):
# def read_job(db, job_id):
# def read_jobs(db, past_id):
# def add_set(db, owner, repository):
# def complete_set(db, set_id, commit_sha):
# def update_set_renders(db, set_id, render_world, render_usa, render_europe, render_geojson):
# def read_set(db, set_id):
# def read_sets(db, past_id):
# def read_latest_set(db, owner, repository):
# def add_run(db):
# def set_run(db, run_id, filename, file_id, content_b64, run_state, run_status,
#             job_id, worker_id, commit_sha, is_merged, set_id):
# def copy_run(db, run_id, job_id, commit_sha, set_id):
# def read_run(db, run_id):
# def get_completed_file_run(db, file_id, interval):
# def get_completed_run(db, run_id, min_dtz):
# def old_read_completed_set_runs(db, set_id):
# def read_completed_set_runs(db, set_id):
# def read_completed_set_runs_count(db, set_id):
# def read_completed_source_runs(db, source_path):
# def read_completed_runs_to_date_cheaply(db):
# def read_completed_runs_to_date(db, starting_set_id):
# def mark_runs_for_index_page(db, runs):
# def read_latest_run(db, source_path):
# def load_collection_zips_dict(db):


import logging; _L = logging.getLogger('openaddr.render')
import json, csv, io, os
import requests
    import cairo
    import cairocffi as cairo
from glob import glob
from unicodedata import normalize
from collections import defaultdict
from argparse import ArgumentParser
from itertools import combinations, chain
from os.path import join, dirname, splitext, relpath
from urllib.parse import urljoin
from osgeo import ogr, osr
from .ci import objects
    elif area == EUROPE:
        left, top = -2700000, 8700000
        right, bottom = 5800000, 3600000
    else:
        raise RuntimeError('Unknown area "{}"'.format(area))

    aspect = (right - left) / (top - bottom)

    hsize = int(resolution * width)
    vsize = int(hsize / aspect)

    hscale = hsize / (right - left)
    vscale = (hsize / aspect) / (bottom - top)

    hoffset = -left
    voffset = -top

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, hsize, vsize)
    context = cairo.Context(surface)
    context.scale(hscale, vscale)
    context.translate(hoffset, voffset)

    return surface, context, hscale

def load_live_state():
    '''
    '''
    got = requests.get('https://results.openaddresses.io/state.txt')
    state = csv.DictReader(io.StringIO(got.text), dialect='excel-tab')


# Path: openaddr/ci/objects.py
# import logging; _L = logging.getLogger('openaddr.ci.objects')
# class Job:
# class Set:
# class Run:
# class RunState:
# class Zip:
#     def __init__(self, id, status, task_files, states, file_results,
#                  github_owner, github_repository, github_status_url,
#                  github_comments_url, datetime_start, datetime_end):
#     def __init__(self, id, commit_sha, datetime_start, datetime_end,
#                  render_world, render_europe, render_usa, render_geojson,
#                  owner, repository):
#     def __init__(self, id, source_path, source_id, source_data, datetime_tz,
#                  state, status, copy_of, code_version, worker_id, job_id,
#                  set_id, commit_sha, is_merged):
#     def __init__(self, json_blob):
#     def get(self, json_key):
#     def to_dict(self):
#     def to_json(self):
#     def __init__(self, url, content_length):
# def _result_runstate2dictionary(result):
# def result_dictionary2runstate(result):
# def add_job(db, job_id, status, task_files, file_states, file_results, owner, repo, status_url, comments_url):
# def write_job(db, job_id, status, task_files, file_states, file_results, owner, repo, status_url, comments_url):
# def read_job(db, job_id):
# def read_jobs(db, past_id):
# def add_set(db, owner, repository):
# def complete_set(db, set_id, commit_sha):
# def update_set_renders(db, set_id, render_world, render_usa, render_europe, render_geojson):
# def read_set(db, set_id):
# def read_sets(db, past_id):
# def read_latest_set(db, owner, repository):
# def add_run(db):
# def set_run(db, run_id, filename, file_id, content_b64, run_state, run_status,
#             job_id, worker_id, commit_sha, is_merged, set_id):
# def copy_run(db, run_id, job_id, commit_sha, set_id):
# def read_run(db, run_id):
# def get_completed_file_run(db, file_id, interval):
# def get_completed_run(db, run_id, min_dtz):
# def old_read_completed_set_runs(db, set_id):
# def read_completed_set_runs(db, set_id):
# def read_completed_set_runs_count(db, set_id):
# def read_completed_source_runs(db, source_path):
# def read_completed_runs_to_date_cheaply(db):
# def read_completed_runs_to_date(db, starting_set_id):
# def mark_runs_for_index_page(db, runs):
# def read_latest_run(db, source_path):
# def load_collection_zips_dict(db):


# Path: openaddr/render.py
import logging; _L = logging.getLogger('openaddr.render')
import json, csv, io, os
import requests
    import cairo
    import cairocffi as cairo
from glob import glob
from unicodedata import normalize
from collections import defaultdict
from argparse import ArgumentParser
from itertools import combinations, chain
from os.path import join, dirname, splitext, relpath
from urllib.parse import urljoin
from osgeo import ogr, osr
from .ci import objects

    elif area == EUROPE:
        left, top = -2700000, 8700000
        right, bottom = 5800000, 3600000
    else:
        raise RuntimeError('Unknown area "{}"'.format(area))

    aspect = (right - left) / (top - bottom)

    hsize = int(resolution * width)
    vsize = int(hsize / aspect)

    hscale = hsize / (right - left)
    vscale = (hsize / aspect) / (bottom - top)

    hoffset = -left
    voffset = -top

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, hsize, vsize)
    context = cairo.Context(surface)
    context.scale(hscale, vscale)
    context.translate(hoffset, voffset)

    return surface, context, hscale

def load_live_state():
    '''
    '''
    got = requests.get('https://results.openaddresses.io/state.txt')
    state = csv.DictReader(io.StringIO(got.text), dialect='excel-tab')


    return {s['source']: RunPartial(objects.RunState(s))