# Path: plenario/database.py
# def psql(path: str) -> None:
#     """Use psql to run a file at some path.
#     """
#     logger.info('[plenario] Psql file %s' % path)
#     command = 'psql {} -f {}'.format(DATABASE_CONN, path)
#     subprocess.check_call(command, shell=True)
# 
# Path: plenario/settings.py
# DB_USER = get('POSTGRES_USER', 'postgres')
# 
# DB_PASSWORD = get('POSTGRES_PASSWORD', 'password')
# 
# DB_HOST = get('POSTGRES_HOST', 'localhost')
# 
# DB_NAME = get('POSTGRES_DB', 'plenario_test')
# 
# DB_PORT = get('POSTGRES_PORT', 5432)


import os
import signal
import subprocess
from datetime import datetime
from random import randint, random
from sqlalchemy import create_engine
from sqlalchemy.exc import IntegrityError, ProgrammingError
from plenario.database import psql
from plenario.settings import DB_USER, DB_PASSWORD, DB_HOST, DB_NAME, DB_PORT
from plenario.models.SensorNetwork import *
            print(str(err))
        finally:
            conn.close()

    def _create_foi_table(self, table_schema):
        """A postgres friendly version of the redshift method that shares
        the same name.

        :param table_schema: (dict) {"name": "<name>", "properties": [ ... ]}
        :returns: None"""

        print("create table {}".format(table_schema["name"]))

        create_table = ("CREATE TABLE {} ("
                        "\"node_id\" VARCHAR NOT NULL,"
                        "datetime TIMESTAMP WITHOUT TIME ZONE NOT NULL,"
                        "\"meta_id\" DOUBLE PRECISION NOT NULL,"
                        "\"sensor\" VARCHAR NOT NULL,"
                        "").format(table_schema["name"])

        for i, prop in enumerate(table_schema["properties"]):
            create_table += '"{}" {} '.format(prop['name'], prop['type'])
            create_table += "," if i != len(table_schema["properties"]) - 1 else ""
        create_table += ')'
        self.rs_engine.execute(create_table)

    def __init__(self):
        os.environ["DB_NAME"] = "plenario_test"
        os.environ["RS_NAME"] = "plenario_test"


# Path: plenario/database.py
# def psql(path: str) -> None:
#     """Use psql to run a file at some path.
#     """
#     logger.info('[plenario] Psql file %s' % path)
#     command = 'psql {} -f {}'.format(DATABASE_CONN, path)
#     subprocess.check_call(command, shell=True)
# 
# Path: plenario/settings.py
# DB_USER = get('POSTGRES_USER', 'postgres')
# 
# DB_PASSWORD = get('POSTGRES_PASSWORD', 'password')
# 
# DB_HOST = get('POSTGRES_HOST', 'localhost')
# 
# DB_NAME = get('POSTGRES_DB', 'plenario_test')
# 
# DB_PORT = get('POSTGRES_PORT', 5432)


# Path: tests/test_sensor_network/fixtures.py
import os
import signal
import subprocess
from datetime import datetime
from random import randint, random
from sqlalchemy import create_engine
from sqlalchemy.exc import IntegrityError, ProgrammingError
from plenario.database import psql
from plenario.settings import DB_USER, DB_PASSWORD, DB_HOST, DB_NAME, DB_PORT
from plenario.models.SensorNetwork import *

            print(str(err))
        finally:
            conn.close()

    def _create_foi_table(self, table_schema):
        """A postgres friendly version of the redshift method that shares
        the same name.

        :param table_schema: (dict) {"name": "<name>", "properties": [ ... ]}
        :returns: None"""

        print("create table {}".format(table_schema["name"]))

        create_table = ("CREATE TABLE {} ("
                        "\"node_id\" VARCHAR NOT NULL,"
                        "datetime TIMESTAMP WITHOUT TIME ZONE NOT NULL,"
                        "\"meta_id\" DOUBLE PRECISION NOT NULL,"
                        "\"sensor\" VARCHAR NOT NULL,"
                        "").format(table_schema["name"])

        for i, prop in enumerate(table_schema["properties"]):
            create_table += '"{}" {} '.format(prop['name'], prop['type'])
            create_table += "," if i != len(table_schema["properties"]) - 1 else ""
        create_table += ')'
        self.rs_engine.execute(create_table)

    def __init__(self):
        os.environ["DB_NAME"] = "plenario_test"
        os.environ["RS_NAME"] = "plenario_test"


        self.user = DB_USER