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

Rework Api and implement get_data

parent b0e6d484
No related branches found
No related tags found
No related merge requests found
import connexion import connexion
import six import six
from access_node.models.attribute import Attribute # noqa: E501
from access_node.models.data import Data # noqa: E501
from access_node.models.error import Error # noqa: E501 from access_node.models.error import Error # noqa: E501
from access_node.models.info import Info # noqa: E501
from access_node.models.multimeter import Multimeter # noqa: E501
from access_node.models.multimeter_info import MultimeterInfo # noqa: E501
from access_node.models.spikes import Spikes # noqa: E501 from access_node.models.spikes import Spikes # noqa: E501
from access_node import util from access_node import util
# My imports
import json
import requests
def get_current_simulation_time(): # noqa: E501
def get_attributes(): # noqa: E501 """Retrieves the current simulation time.
"""Retrieves the details of per-neuron attributes.
# noqa: E501 # noqa: E501
:rtype: List[Attribute] :rtype: float
""" """
with open('access_node//distribution_nodes.json', 'r') as f: return 'do some magic!'
dist_nodes = json.load(f)
information_node = dist_nodes['addresses'][0]
response = requests.get(information_node+'/attributes').json()
return response
def get_data(attribute, simulation_steps=None, neuron_ids=None): # noqa: E501 def get_data(multimeter, attribute, _from=None, to=None, neuron_ids=None): # noqa: E501
"""Retrieves the per-neuron attributes for the given attribute name, simulation steps (optional) and neuron IDs (optional). """Retrieves the per-neuron attributes for the given multimeter name, attribute name, duration (from - to) (optional) and neuron IDs (optional).
# noqa: E501 # noqa: E501
:param multimeter: Multimeter name.
:type multimeter: str
:param attribute: Attribute name. :param attribute: Attribute name.
:type attribute: str :type attribute: str
:param simulation_steps: Simulation steps (leave empty for all steps). :param _from: First timestep to retreive (leave empty for first step possible).
:type simulation_steps: List[] :type _from: float
:param to: Last timestep to retreive (leave empty for last step possible).
:type to: float
:param neuron_ids: Neuron IDs (leave empty for all neurons). :param neuron_ids: Neuron IDs (leave empty for all neurons).
:type neuron_ids: List[] :type neuron_ids: List[]
:rtype: Data :rtype: Multimeter
""" """
# Replace this with request to information_node
with open('access_node//distribution_nodes.json', 'r') as f: with open('access_node//distribution_nodes.json', 'r') as f:
dist_nodes = json.load(f) dist_nodes = json.load(f)
addresses = dist_nodes['addresses'] addresses = dist_nodes['addresses']
if simulation_steps != None:
num_ts = len(simulation_steps)
first_ts = simulation_steps[0]
else:
num_ts = get_simulation_step_count()
first_ts = get_timestep()
if neuron_ids != None: if neuron_ids != None:
ids = neuron_ids ids = neuron_ids
else: else:
ids = get_neuron_ids() ids = get_neuron_ids()
data = Data(first_ts, num_ts, ids, # TODO Query this
[[None]*num_ts for x in range(len(ids))]) interval = 0.1
num_values_per_neuron = (to-_from)/interval
mult_response = Multimeter(multimeter)
mult_response._from = _from
mult_response.to = to
mult_response.neuron_ids = ids
mult_response.interval = interval
mult_response.values = [[None]*num_values_per_neuron for x in range(len(ids))]
for address in addresses: for address in addresses:
response = requests.get(address+'/data', params={ response = requests.get(address+'/data', params={ "multimeter": multimeter,
"attribute": attribute, "simulation_steps": simulation_steps, "neuron_ids": neuron_ids}).json() "attribute": attribute, "from": _from, "to": to, "neuron_ids": neuron_ids}).json()
for x in range(len(response['neuron_ids'])): for x in range(len(response['neuron_ids'])):
data.values[data.neuron_ids.index( mult_response.values[mult_response.neuron_ids.index(
response['neuron_ids'][x])] = response['data'][x] response['neuron_ids'][x])] = response['values'][x]
return data return mult_response
def get_neuron_ids(): # noqa: E501 def get_info(): # noqa: E501
"""Retrieves the list of all neuron IDs. """Retrieves general simulation information.
# noqa: E501 # noqa: E501
:rtype: List[float] :rtype: Info
""" """
with open('access_node//distribution_nodes.json', 'r') as f: return 'do some magic!'
dist_nodes = json.load(f)
information_node = dist_nodes['addresses'][0]
response = requests.get(information_node+'/neuron_ids').json()
return response
def get_multimeters(): # noqa: E501
def get_simulation_step_count(): # noqa: E501 """Retrieves the details of all multimeters.
"""Retrieves the number of simulation steps.
# noqa: E501 # noqa: E501
:rtype: float :rtype: List[MultimeterInfo]
""" """
with open('access_node//distribution_nodes.json', 'r') as f: return 'do some magic!'
dist_nodes = json.load(f)
information_node = dist_nodes['addresses'][0]
def get_neuron_ids(): # noqa: E501
"""Retrieves the list of all neuron IDs.
# noqa: E501
response = requests.get(information_node+'/simulation_step_count').json() :rtype: List[float]
return response """
return 'do some magic!'
def get_spikes(simulation_steps=None, neuron_ids=None): # noqa: E501 def get_spikes(simulation_steps=None, neuron_ids=None): # noqa: E501
...@@ -114,34 +114,4 @@ def get_spikes(simulation_steps=None, neuron_ids=None): # noqa: E501 ...@@ -114,34 +114,4 @@ def get_spikes(simulation_steps=None, neuron_ids=None): # noqa: E501
:rtype: Spikes :rtype: Spikes
""" """
# Replace this with request to information_node return 'do some magic!'
with open('access_node//distribution_nodes.json', 'r') as f:
dist_nodes = json.load(f)
addresses = dist_nodes['addresses']
spikes = Spikes([], [])
for address in addresses:
response = requests.get(
address+'/spikes', params={"simulation_steps": simulation_steps, "neuron_ids": neuron_ids}).json()
for x in range(len(response['simulation_steps'])):
spikes.simulation_steps.append(response['simulation_steps'][x])
spikes.neuron_ids.append(response['neuron_ids'][x])
# Sort this?
return spikes
def get_timestep(): # noqa: E501
"""Retrieves the time between two simulation steps.
# noqa: E501
:rtype: float
"""
with open('access_node//distribution_nodes.json', 'r') as f:
dist_nodes = json.load(f)
information_node = dist_nodes['addresses'][0]
response = requests.get(information_node+'/timestep').json()
return response
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
from __future__ import absolute_import from __future__ import absolute_import
# import models into model package # import models into model package
from access_node.models.attribute import Attribute from access_node.models.attribute import Attribute
from access_node.models.data import Data
from access_node.models.error import Error from access_node.models.error import Error
from access_node.models.info import Info from access_node.models.info import Info
from access_node.models.multimeter import Multimeter from access_node.models.multimeter import Multimeter
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
swagger: "2.0" swagger: "2.0"
info: info:
description: "This is the REST API for the in-situ pipeline." description: "This is the REST API for the in-situ pipeline."
version: "1.0.0" version: "0.0.2"
title: "In-Situ Pipeline REST API" title: "In-Situ Pipeline REST API"
host: "localhost" host: "localhost"
basePath: "/" basePath: "/"
...@@ -23,12 +23,11 @@ paths: ...@@ -23,12 +23,11 @@ paths:
200: 200:
description: "Operation successful." description: "Operation successful."
schema: schema:
type: "number" $ref: "#/definitions/Info"
format: "double"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
$ref: "#/definitions/Info" $ref: "#/definitions/Error"
x-swagger-router-controller: "access_node.controllers.nest_controller" x-swagger-router-controller: "access_node.controllers.nest_controller"
/current_simulation_time: /current_simulation_time:
get: get:
...@@ -44,7 +43,7 @@ paths: ...@@ -44,7 +43,7 @@ paths:
description: "Operation successful." description: "Operation successful."
schema: schema:
type: "number" type: "number"
format: "int64" format: "double"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
...@@ -72,12 +71,12 @@ paths: ...@@ -72,12 +71,12 @@ paths:
schema: schema:
$ref: "#/definitions/Error" $ref: "#/definitions/Error"
x-swagger-router-controller: "access_node.controllers.nest_controller" x-swagger-router-controller: "access_node.controllers.nest_controller"
/attributes: /multimeters:
get: get:
tags: tags:
- "nest" - "nest"
summary: "Retrieves the details of per-neuron attributes." summary: "Retrieves the details of all multimeters."
operationId: "get_attributes" operationId: "get_multimeters"
produces: produces:
- "application/json" - "application/json"
parameters: [] parameters: []
...@@ -87,7 +86,7 @@ paths: ...@@ -87,7 +86,7 @@ paths:
schema: schema:
type: "array" type: "array"
items: items:
$ref: "#/definitions/Attribute" $ref: "#/definitions/MultimeterInfo"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
...@@ -142,7 +141,7 @@ paths: ...@@ -142,7 +141,7 @@ paths:
200: 200:
description: "Operation successful." description: "Operation successful."
schema: schema:
$ref: "#/definitions/Data" $ref: "#/definitions/Multimeter"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
...@@ -267,6 +266,14 @@ definitions: ...@@ -267,6 +266,14 @@ definitions:
type: "array" type: "array"
items: items:
$ref: "#/definitions/Attribute" $ref: "#/definitions/Attribute"
example:
name: "name"
interval: 0.1
attributes:
- precision: {}
name: "name"
- precision: {}
name: "name"
Info: Info:
type: "object" type: "object"
properties: properties:
...@@ -277,51 +284,23 @@ definitions: ...@@ -277,51 +284,23 @@ definitions:
type: "array" type: "array"
items: items:
$ref: "#/definitions/MultimeterInfo" $ref: "#/definitions/MultimeterInfo"
Data:
type: "object"
properties:
multimeters:
type: "array"
items:
$ref: "#/definitions/Multimeter"
example: example:
simulation_resolution: 0.01
multimeters: multimeters:
- name: "Multimeter_name" - name: "name"
interval: 0.2 interval: 0.1
attribute: attributes:
name: "voltage" - precision: {}
precission: "double" name: "name"
timesteps: - precision: {}
- 1.2 name: "name"
- 1.4 - name: "name"
from: 1.2
to: 1.4
neuron_ids:
- 1
- 2
values:
- - 61.48
- 45.23
- - 13.46
- 23.77
- name: "Multimeter_name"
interval: 0.2 interval: 0.2
attribute: attributes:
name: "voltage" - precision: {}
precission: "double" name: "name"
timesteps: - precision: {}
- 1.2 name: "name"
- 1.4
from: 1.2
to: 1.4
neuron_ids:
- 1
- 2
values:
- - 61.48
- 45.23
- - 13.46
- 23.77
Spikes: Spikes:
type: "object" type: "object"
properties: properties:
...@@ -337,11 +316,11 @@ definitions: ...@@ -337,11 +316,11 @@ definitions:
format: "int64" format: "int64"
example: example:
simulation_times: simulation_times:
- 0.80082819046101150206595775671303272247314453125 - 0.2
- 0.80082819046101150206595775671303272247314453125 - 0.3
neuron_ids: neuron_ids:
- 6.02745618307040320615897144307382404804229736328125 - 1
- 6.02745618307040320615897144307382404804229736328125 - 2
Error: Error:
type: "object" type: "object"
properties: properties:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment