Skip to content
Snippets Groups Projects
Commit d2e5ba1d authored by Jan Müller's avatar Jan Müller
Browse files

Implement most of NEST Database functionallity (get_neuron_properties is stil missing)

parent aa80c938
No related branches found
No related tags found
1 merge request!4Feature/add arbor support
Pipeline #163320 failed
...@@ -18,22 +18,28 @@ def SetupDB(postgres_username, postgres_password, port): ...@@ -18,22 +18,28 @@ def SetupDB(postgres_username, postgres_password, port):
print("Database connection opened successfully!") print("Database connection opened successfully!")
cur = con.cursor() cur = con.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS SIMULATION_NODES ( cur.execute("DROP TABLE IF EXISTS SIMULATION_NODES CASCADE")
cur.execute("DROP TABLE IF EXISTS MULTIMETERS CASCADE")
cur.execute("DROP TABLE IF EXISTS GIDS CASCADE")
cur.execute("DROP TABLE IF EXISTS MULT_PER_GID CASCADE")
cur.execute('''CREATE TABLE SIMULATION_NODES (
NODE_ID INT PRIMARY KEY NOT NULL UNIQUE, NODE_ID INT PRIMARY KEY NOT NULL UNIQUE,
ADDRESS VARCHAR(25), ADDRESS VARCHAR(25),
CURRENT_SIM_TIME FLOAT);''') CURRENT_SIM_TIME FLOAT);''')
cur.execute('''CREATE TABLE IF NOT EXISTS MULTIMETERS ( cur.execute('''CREATE TABLE MULTIMETERS (
MULTIMETER_ID INT PRIMARY KEY NOT NULL UNIQUE, MULTIMETER_ID INT PRIMARY KEY NOT NULL UNIQUE,
ATTRIBUTE CHAR(50) );''') ATTRIBUTE CHAR(50) );''')
cur.execute('''CREATE TABLE IF NOT EXISTS GIDS ( cur.execute('''CREATE TABLE GIDS (
GID INT PRIMARY KEY NOT NULL UNIQUE, GID INT PRIMARY KEY NOT NULL UNIQUE,
NODE_ID INT, NODE_ID INT,
POPULATION_ID INT, POPULATION_ID INT,
FOREIGN KEY (NODE_ID) REFERENCES SIMULATION_NODES (NODE_ID));''') FOREIGN KEY (NODE_ID) REFERENCES SIMULATION_NODES (NODE_ID));''')
cur.execute('''CREATE TABLE IF NOT EXISTS MULT_PER_GID( cur.execute('''CREATE TABLE MULT_PER_GID(
GID INT NOT NULL, GID INT NOT NULL,
MULTIMETER_ID INT NOT NULL, MULTIMETER_ID INT NOT NULL,
PRIMARY KEY (GID,MULTIMETER_ID), PRIMARY KEY (GID,MULTIMETER_ID),
......
...@@ -10,6 +10,8 @@ from access_node import util ...@@ -10,6 +10,8 @@ from access_node import util
from access_node.models.nodes import nodes from access_node.models.nodes import nodes
import requests import requests
import psycopg2
import numpy as np
def nest_get_gids(): # noqa: E501 def nest_get_gids(): # noqa: E501
"""Retrieves the list of all GID. """Retrieves the list of all GID.
...@@ -19,7 +21,13 @@ def nest_get_gids(): # noqa: E501 ...@@ -19,7 +21,13 @@ def nest_get_gids(): # noqa: E501
:rtype: List[int] :rtype: List[int]
""" """
gids = requests.get(nodes.info_node+'/nest/gids').json() con = psycopg2.connect(database="postgres", user="postgres",
password="docker", host="database", port="5432")
cur = con.cursor()
cur.execute("SELECT GID FROM GIDS")
gids = [i[0] for i in cur.fetchall()]
con.close()
return gids return gids
...@@ -33,8 +41,13 @@ def nest_get_gids_in_population(population_id): # noqa: E501 ...@@ -33,8 +41,13 @@ def nest_get_gids_in_population(population_id): # noqa: E501
:rtype: List[int] :rtype: List[int]
""" """
gids = requests.get(nodes.info_node+'/nest/population/$' + con = psycopg2.connect(database="postgres", user="postgres",
str(population_id)+'/gids').json() password="docker", host="database", port="5432")
cur = con.cursor()
cur.execute("SELECT GID FROM GIDS WHERE GIDS.POPULATION_ID ="+str(population_id))
gids = [i[0] for i in cur.fetchall()]
con.close()
return gids return gids
...@@ -46,8 +59,24 @@ def nest_get_multimeter_info(): # noqa: E501 ...@@ -46,8 +59,24 @@ def nest_get_multimeter_info(): # noqa: E501
:rtype: MultimeterInfo :rtype: MultimeterInfo
""" """
multimeter_info = requests.get(nodes.info_node+'/nest/multimeter_info').json() con = psycopg2.connect(database="postgres", user="postgres",
return multimeter_info password="docker", host="database", port="5432")
cur = con.cursor()
cur.execute("SELECT MULTIMETER_ID FROM MULTIMETERS")
ids = cur.fetchall()
cur.execute("SELECT regexp_replace(ATTRIBUTE, '\s+$', '') FROM (SELECT * FROM MULTIMETERS) AS MULT_INFO;")
attributes = cur.fetchall()
mult_info = np.hstack((ids, attributes)).tolist()
gids = []
for id in ids:
cur.execute("SELECT GID FROM MULT_PER_GID WHERE MULTIMETER_ID = %s", (id,))
gids.append([i[0] for i in cur.fetchall()])
for i in range(len(gids)):
mult_info[i].append(gids[i])
con.close()
return mult_info.tolist()
def nest_get_multimeter_measurements(multimeter_id, attribute, _from=None, to=None, gids=None, offset=None, limit=None): # noqa: E501 def nest_get_multimeter_measurements(multimeter_id, attribute, _from=None, to=None, gids=None, offset=None, limit=None): # noqa: E501
...@@ -134,8 +163,16 @@ def nest_get_neuron_properties(gids=None): # noqa: E501 ...@@ -134,8 +163,16 @@ def nest_get_neuron_properties(gids=None): # noqa: E501
:rtype: List[NestNeuronProperties] :rtype: List[NestNeuronProperties]
""" """
properties = requests.get(nodes.info_node+'/nest/neuron_properties').json() con = psycopg2.connect(database="postgres", user="postgres",
return properties password="docker", host="database", port="5432")
cur = con.cursor()
# TODO HANDLE gids=None
con.close()
return "Not Implemented yet"
def nest_get_populations(): # noqa: E501 def nest_get_populations(): # noqa: E501
...@@ -146,7 +183,12 @@ def nest_get_populations(): # noqa: E501 ...@@ -146,7 +183,12 @@ def nest_get_populations(): # noqa: E501
:rtype: List[int] :rtype: List[int]
""" """
populations = requests.get(nodes.info_node+'/nest/populations').json() con = psycopg2.connect(database="postgres", user="postgres",
password="docker", host="database", port="5432")
cur = con.cursor()
cur.execute("SELECT DISTINCT (POPULATION_ID) FROM GIDS")
populations = populations = [i[0] for i in cur.fetchall()]
return populations return populations
...@@ -158,8 +200,13 @@ def nest_get_simulation_time_info(): # noqa: E501 ...@@ -158,8 +200,13 @@ def nest_get_simulation_time_info(): # noqa: E501
:rtype: SimulationTimeInfo :rtype: SimulationTimeInfo
""" """
time_info = requests.get(nodes.info_node+'/nest/simulation_time_info').json() con = psycopg2.connect(database="postgres", user="postgres",
return time_info password="docker", host="database", port="5432")
cur = con.cursor()
cur.execute("SELECT MAX(CURRENT_SIM_TIME) FROM SIMULATION_NODES")
time = cur.fetchall()[0][0]
return time
def nest_get_spikes(_from=None, to=None, gids=None, offset=None, limit=None): # noqa: E501 def nest_get_spikes(_from=None, to=None, gids=None, offset=None, limit=None): # noqa: E501
......
...@@ -4,3 +4,4 @@ setuptools >= 21.0.0 ...@@ -4,3 +4,4 @@ setuptools >= 21.0.0
requests requests
flask_cors flask_cors
psycopg2-binary psycopg2-binary
numpy
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment