<commit_before>""" NOTE: below there are queries that are specific to TriMet's geo database (PostGIS), and a street intersection table.
"""
import os

from sqlalchemy.orm import Session
from sqlalchemy import text
from geoalchemy2.shape import to_shape

from ott.utils import file_utils
from ott.utils import geo_utils
from .db_exporter import DbExporter

import logging
log = logging.getLogger(__file__)


class Intersections(DbExporter):
    """ export Transit data from
    """
    def __init__(self):
        super(Intersections, self).__init__()
        self.schema = 'prod'
        csv_output = self.config.get('intersections_csv', section='geocoder', def_val="intersections.csv")
        self.file_path = os.path.join(self.cache_dir, csv_output)

    def query_and_output(self):
        IntersectionsOrm = self.get_table_orm('geocode')
        session = Session(self.engine)
        fp = open(self.file_path, 'w')
        csv_writer = file_utils.make_csv_writer(fp, ['name', 'lon', 'lat'])

        intersections = session.query(IntersectionsOrm).filter(text('type = 2')).all()
        for i, a in enumerate(intersections):
            x = to_shape(a.geom).x
            y = to_shape(a.geom).y
            lon, lat = geo_utils.to_lon_lat(x, y)<commit_msg>refactor out most of slack to a lib<commit_after>""" NOTE: below there are queries that are specific to TriMet's geo database (PostGIS), and a street intersection table.
"""
import os

from sqlalchemy.orm import Session
from sqlalchemy import text
from geoalchemy2.shape import to_shape

from ott.utils import file_utils
from ott.utils import geo_utils
from .db_exporter import DbExporter

import logging
log = logging.getLogger(__file__)


class Intersections(DbExporter):
    """ export Transit data from
    """

    def __init__(self):
        super(Intersections, self).__init__()
        self.schema = 'prod'
        csv_output = self.config.get('intersections_csv', section='geocoder', def_val="intersections.csv")
        self.file_path = os.path.join(self.cache_dir, csv_output)

    def query_and_output(self):
        IntersectionsOrm = self.get_table_orm('geocode')
        session = Session(self.engine)
        fp = open(self.file_path, 'w')
        csv_writer = file_utils.make_csv_writer(fp, ['name', 'lon', 'lat'])

        intersections = session.query(IntersectionsOrm).filter(text('type = 2')).all()
        for i, a in enumerate(intersections):
            x = to_shape(a.geom).x
            y = to_shape(a.geom).y
            lon, lat = geo_utils.to_lon_lat(x, y)
{'fraction_non_alphanumeric': 0.1099332548095799, 'fraction_numerical': 0.0015704750687082843, 'mean_word_length': 3.4780316344463973, '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': '4930942', 'n_tokens_mistral': 817, 'n_tokens_neox': 781, 'n_words': 202}