diff --git a/access_node/__main__.py b/access_node/__main__.py index b701c9fd1784a4b2b5746d6d2637d087e4d12fe1..39dfd78630800656f150cabfcd7b98e173cd13b2 100644 --- a/access_node/__main__.py +++ b/access_node/__main__.py @@ -16,126 +16,20 @@ def ConnectToDatabase(postgres_username, postgres_password, port): return psycopg2.connect(database="postgres", user=postgres_username, password=postgres_password, host="database", port=str(port)) -def SetupNestTables(postgres_username, postgres_password, port): - con = ConnectToDatabase(postgres_username, postgres_password, port) - print("Database connection opened successfully!") - - cur = con.cursor() - cur.execute("DROP TABLE IF EXISTS nest_simulation_node CASCADE") - cur.execute("DROP TABLE IF EXISTS nest_multimeter CASCADE") - cur.execute("DROP TABLE IF EXISTS nest_neuron CASCADE") - cur.execute("DROP TABLE IF EXISTS nest_neuron_multimeter CASCADE") - - - cur.execute(''' - CREATE TABLE nest_simulation_node ( - id SERIAL PRIMARY KEY NOT NULL UNIQUE, - address VARCHAR(50), - current_simulation_time FLOAT - );''') - - cur.execute(''' - CREATE TABLE nest_multimeter ( - id INT PRIMARY KEY NOT NULL UNIQUE, - attributes VARCHAR(50) ARRAY - );''') - - cur.execute(''' - CREATE TABLE nest_neuron ( - id INT PRIMARY KEY NOT NULL UNIQUE, - simulation_node_id INT, - population_id INT, - position FLOAT[], - FOREIGN KEY (simulation_node_id) REFERENCES nest_simulation_node (id) - );''') - - cur.execute(''' - CREATE TABLE nest_neuron_multimeter ( - neuron_id INT NOT NULL, - multimeter_id INT NOT NULL, - PRIMARY KEY (neuron_id,multimeter_id), - FOREIGN KEY (neuron_id) REFERENCES nest_neuron (id), - FOREIGN KEY (multimeter_id) REFERENCES nest_multimeter (id) - );''') - - con.commit() - con.close() - print("Nest tables created successfully!\n") - -def SetupArborTables(postgres_username, postgres_password, port): - con = ConnectToDatabase(postgres_username, postgres_password, port) - print("Database connection opened successfully!") - cur = con.cursor() - cur.execute("DROP TABLE IF EXISTS arbor_probe CASCADE") - cur.execute("DROP TABLE IF EXISTS arbor_cell CASCADE") - cur.execute("DROP TABLE IF EXISTS arbor_simulation_node CASCADE") - cur.execute("DROP TABLE IF EXISTS arbor_attribute CASCADE") - - cur.execute(''' - CREATE TABLE arbor_simulation_node ( - id INT PRIMARY KEY NOT NULL UNIQUE, - address VARCHAR(50), - current_simulation_time FLOAT - );''') - - cur.execute(''' - CREATE TABLE arbor_cell ( - id INT PRIMARY KEY NOT NULL UNIQUE - ); - ''') - - cur.execute(''' - CREATE TABLE cell_property ( - cell_id INT NOT NULL, - property VARCHAR(50) NOT NULL, - PRIMARY KEY (cell_id, property), - FOREIGN KEY (cell_id) REFERENCES arbor_cell (id), - );''') - - cur.execute(''' - CREATE TABLE arbor_attribute ( - id INT PRIMARY KEY NOT NULL UNIQUE, - name VARCHAR(50) NOT NULL, - );''') - - cur.execute(''' - CREATE TABLE arbor_probe ( - id INT PRIMARY KEY NOT NULL UNIQUE, - cell_id INT NOT NULL, - segment_id INT NOT NULL, - position FLOAT, - attribute_id INT NOT NULL, - simulation_node_id INT, - FOREIGN KEY (simulation_node_id) REFERENCES arbor_simulation_node (id), - FOREIGN KEY (cell_id) REFERENCES arbor_cell (id), - FOREIGN KEY (attribute_id) REFERENCES arbor_attribute (id) - );''') - - - - con.commit() - con.close() - print("Arbor tables created successfully!\n") - def main(): - # Connect to the Database and initalize basic Table structure - SetupNestTables('postgres', 'docker', 5432) - #SetupArborTables('postgres', 'docker', 5432) - # Wait for simulation nodes to post to database time.sleep(5) - # get simulation nodes - con = ConnectToDatabase('postgres', 'docker', 5432) + con = ConnectToDatabase('postgres', 'postgres', 5432) cur = con.cursor() # NEST cur.execute("SELECT address FROM nest_simulation_node") nodes.nest_simulation_nodes = [i[0] for i in cur.fetchall()] # Arbor - #cur.execute("SELECT address FROM nest_simulation_node") - #nodes.nest_simulation_nodes = [i[0] for i in cur.fetchall()] + cur.execute("SELECT address FROM nest_simulation_node") + nodes.arbor_simulation_nodes = [i[0] for i in cur.fetchall()] con.close() diff --git a/access_node/controllers/arbor_controller.py b/access_node/controllers/arbor_controller.py index 4b8115a2c70cbc7f269f31510a1b33ee4e1086e1..00a4ac4273c0d12a9f829bac53b3cb61d930e19a 100644 --- a/access_node/controllers/arbor_controller.py +++ b/access_node/controllers/arbor_controller.py @@ -16,7 +16,7 @@ import numpy as np def connect_to_database(): return psycopg2.connect(database="postgres", user="postgres", - password="docker", host="database", port="5432") + password="postgres", host="database", port="5432") def arbor_get_attributes(): # noqa: E501 diff --git a/access_node/controllers/nest_controller.py b/access_node/controllers/nest_controller.py index c183e09d07f6a4e42f0b3015895ce44fec5ea9c6..ffd4aa0e8f52a0839f13f043f09597eef52261c1 100644 --- a/access_node/controllers/nest_controller.py +++ b/access_node/controllers/nest_controller.py @@ -16,7 +16,7 @@ import numpy as np def connect_to_database(): return psycopg2.connect(database="postgres", user="postgres", - password="docker", host="database", port="5432") + password="postgres", host="database", port="5432") def nest_get_gids(): # noqa: E501 @@ -304,7 +304,7 @@ def nest_get_spikes_by_population(population_id, _from=None, to=None, offset=Non spikes = Spikes([], []) for node in nodes.nest_simulation_nodes: response = requests.get( - node+'/population/'+population_id+'/spikes', params={"from": _from, "to": to}).json() + node+'/population/$'+str(population_id)+'/spikes', params={"from": _from, "to": to}).json() for x in range(len(response['simulation_times'])): spikes.simulation_times.append(response['simulation_times'][x]) spikes.gids.append(response['gids'][x])