# Path: server/localfinance/models.py
# SRID = 4326
# ADMIN_LEVEL_CITY = 5
# ADMIN_LEVEL_CITY_ARR = 6
# class AdminZone(Base):
# class AdminZoneFinance(Base):
# class Stats(Base):
#     def code_insee(self):


import os
import sys
import transaction
import pandas as pd
from sqlalchemy import engine_from_config
from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
from ..models import (
    DBSession,
    AdminZone,
    AdminZoneFinance,
    )






def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> <dirpath>\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)

def get_income_per_year(year, dirpath):
    short_year = str(year)[-2:]
    columns = ['RFPQ1%s'%short_year, 'RFPQ2%s'%short_year, 'RFPQ3%s'%short_year, 'RFPIQ%s'%short_year, 'RFPET%s'%short_year, 'RFPMO%s'%short_year]
    xls = pd.ExcelFile(os.path.join(dirpath, 'RFDP%sCOM.xls'%year))
    com = xls.parse('D_P', skiprows=6)[['COM'] + columns]
    com.set_index('COM', inplace=True)
    return com

def main(argv=sys.argv):
    if len(argv) < 3:
        usage(argv)
    config_uri = argv[1]
    dirpath = argv[2]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    az_id = pd.DataFrame(

# Path: server/localfinance/models.py
# SRID = 4326
# ADMIN_LEVEL_CITY = 5
# ADMIN_LEVEL_CITY_ARR = 6
# class AdminZone(Base):
# class AdminZoneFinance(Base):
# class Stats(Base):
#     def code_insee(self):


# Path: server/localfinance/scripts/addincome.py
import os
import sys
import transaction
import pandas as pd
from sqlalchemy import engine_from_config
from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
from ..models import (
    DBSession,
    AdminZone,
    AdminZoneFinance,
    )







def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri> <dirpath>\n'
          '(example: "%s development.ini")' % (cmd, cmd))
    sys.exit(1)

def get_income_per_year(year, dirpath):
    short_year = str(year)[-2:]
    columns = ['RFPQ1%s'%short_year, 'RFPQ2%s'%short_year, 'RFPQ3%s'%short_year, 'RFPIQ%s'%short_year, 'RFPET%s'%short_year, 'RFPMO%s'%short_year]
    xls = pd.ExcelFile(os.path.join(dirpath, 'RFDP%sCOM.xls'%year))
    com = xls.parse('D_P', skiprows=6)[['COM'] + columns]
    com.set_index('COM', inplace=True)
    return com

def main(argv=sys.argv):
    if len(argv) < 3:
        usage(argv)
    config_uri = argv[1]
    dirpath = argv[2]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    az_id = pd.DataFrame(

            (DBSession.query(AdminZone.code_insee, AdminZone.id).all()),