# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


from collections import defaultdict
from sqlalchemy import create_engine, inspect
from sqlalchemy import event
from sqlalchemy import exc
from sqlalchemy.engine import reflection
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DDL
)
from sqlalchemy.sql.ddl import DropConstraint
from odpw.core.model import Dataset, Base, tab_datasets, tab_resourcesinfo, ResourceInfo, tab_resourcescrawllog
import os
import structlog
import time




log = structlog.get_logger()


def process_keyed_tuple(kt):
    for i in kt:
        if i is not None:
            inspect(i)  # discard result, just show that inspect() works


def process_object(o):
    inspect(o)  # discard result, just show that inspect() works


def dictate(r):
    # KeyedTuples are recognized by the real function dictate(), iterated over
    # and each item gets inspected
    if isinstance(r, tuple):
        return process_keyed_tuple(r)
    else:
        # This type is unknown, then treated as an object and inspected(),
        # which fails.
        process_object(r)


def to_dict(model_instance, query_instance=None):
    if hasattr(model_instance, '__table__'):

# Path: odpw/core/model.py
# class Portal(Base):
# class PortalSnapshot(Base):
# class Serializable(object):
# class PortalSnapshotDynamicity(Base,Serializable):
# class PortalSnapshotQuality(Base):
# class Dataset(Base):
# class DatasetData(Base):
# class DatasetQuality(Base):
# class MetaResource(Base):
# class ResourceInfo(Base):
# class ResourceCrawlLog(Base):
# class ResourceHistory(Base):
# class ResourceFreshness(Base):
# class FormatDist(Base):
#     def snapshot_count(self):
#     def snapshot_count(cls):
#     def first_snapshot(self):
#     def first_snapshot(cls):
#     def last_snapshot(self):
#     def last_snapshot(cls):
#     def datasetcount(self):
#     def datasetcount(cls):
#     def resourcecount(self):
#     def resourcecount(cls):
#     def __repr__(self):
#     def fetchtime(self):
#     def __repr__(self):
#     def to_dict(self):
#     def dyratio(self):
#     def adddelratio(self):
#     def addRatio(self):
#     def delRatio(self):
#     def updatedRatio(self):
#     def staticRatio(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def __repr__(self):
#     def info(cls):
#     def __repr__(self):


# Path: odpw/core/db.py
from collections import defaultdict
from sqlalchemy import create_engine, inspect
from sqlalchemy import event
from sqlalchemy import exc
from sqlalchemy.engine import reflection
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import (
    MetaData,
    Table,
    DropTable,
    ForeignKeyConstraint,
    DDL
)
from sqlalchemy.sql.ddl import DropConstraint
from odpw.core.model import Dataset, Base, tab_datasets, tab_resourcesinfo, ResourceInfo, tab_resourcescrawllog
import os
import structlog
import time





log = structlog.get_logger()


def process_keyed_tuple(kt):
    for i in kt:
        if i is not None:
            inspect(i)  # discard result, just show that inspect() works


def process_object(o):
    inspect(o)  # discard result, just show that inspect() works


def dictate(r):
    # KeyedTuples are recognized by the real function dictate(), iterated over
    # and each item gets inspected
    if isinstance(r, tuple):
        return process_keyed_tuple(r)
    else:
        # This type is unknown, then treated as an object and inspected(),
        # which fails.
        process_object(r)


def to_dict(model_instance, query_instance=None):
    if hasattr(model_instance, '__table__'):

        return {c.name: str(getattr(model_instance, c.name)) for c in model_instance.__table__.columns}