Skip to content
Snippets Groups Projects
Commit a6f709f0 authored by Simon Oehrl's avatar Simon Oehrl
Browse files

Merge branch 'feature/add-multimeters' into 'develop'

Feature/add multimeters

See merge request VR-Group/in-situ-pipeline/info-node!1
parents 0584202f f0727462
Branches
No related tags found
1 merge request!1Feature/add multimeters
import connexion import connexion
import six import six
from info_node.models.multimeter_info import MultimeterInfo # noqa: E501
from info_node.models.neuron_properties import NeuronProperties # noqa: E501 from info_node.models.neuron_properties import NeuronProperties # noqa: E501
from info_node.models.simulation_time_info import SimulationTimeInfo # noqa: E501 from info_node.models.simulation_time_info import SimulationTimeInfo # noqa: E501
from info_node.models.status import Status # noqa: E501 from info_node.models.status import Status # noqa: E501
...@@ -8,6 +9,7 @@ from info_node import util ...@@ -8,6 +9,7 @@ from info_node import util
from info_node.models.storage import Node from info_node.models.storage import Node
from info_node.models.storage import nest_storage from info_node.models.storage import nest_storage
from info_node.models.multimeter_info_inner import MultimeterInfoInner
from flask import request from flask import request
ok_status = Status(code=200, message='OK') ok_status = Status(code=200, message='OK')
...@@ -36,6 +38,17 @@ def get_gids_in_population(population_id): # noqa: E501 ...@@ -36,6 +38,17 @@ def get_gids_in_population(population_id): # noqa: E501
return nest_storage.data[nest_storage.data["population"] == population_id].index.values.tolist() return nest_storage.data[nest_storage.data["population"] == population_id].index.values.tolist()
def get_multimeter_info(): # noqa: E501
"""Retreives the available multimeters and their properties
# noqa: E501
:rtype: MultimeterInfo
"""
return nest_storage.multimeters
def get_neuron_properties(gids=None): # noqa: E501 def get_neuron_properties(gids=None): # noqa: E501
"""Retrieves the properties of the specified neurons. """Retrieves the properties of the specified neurons.
...@@ -103,6 +116,45 @@ def put_gids(gids, address): # noqa: E501 ...@@ -103,6 +116,45 @@ def put_gids(gids, address): # noqa: E501
return ok_status return ok_status
def put_multimeter_info(id, attributes=None, gids=None): # noqa: E501
"""Puts the available multimeters and their properties
# noqa: E501
:param id:
:type id: int
:param attributes:
:type attributes: List[str]
:param gids:
:type gids: List[int]
:rtype: Status
"""
for gid in gids:
if gid not in nest_storage.data.index.values:
return Status(code=400, message="At least one gid has not been registered yet")
new_multimeter = True
for multimeter in nest_storage.multimeters:
if multimeter.id == id:
for attribute in attributes:
if attribute not in multimeter.attributes:
multimeter.attributes.append(attribute)
for gid in gids:
if gid not in multimeter.gids:
multimeter.gids.append(gid)
new_multimeter = False
break
if new_multimeter:
if gids == None:
gids = []
new_mult = MultimeterInfoInner(id, attributes, gids)
nest_storage.multimeters.append(new_mult)
return ok_status
def put_populations(gids): # noqa: E501 def put_populations(gids): # noqa: E501
"""Registers a new population with given gids. """Registers a new population with given gids.
...@@ -126,7 +178,7 @@ def put_populations(gids): # noqa: E501 ...@@ -126,7 +178,7 @@ def put_populations(gids): # noqa: E501
row["properties"].update({"population": nest_storage.num_populations + 1 }) row["properties"].update({"population": nest_storage.num_populations + 1 })
nest_storage.num_populations += 1 nest_storage.num_populations += 1
return ok_status return nest_storage.num_populations
def put_time(time, node_address): # noqa: E501 def put_time(time, node_address): # noqa: E501
...@@ -153,7 +205,7 @@ def set_neuron_properties(properties): # noqa: E501 ...@@ -153,7 +205,7 @@ def set_neuron_properties(properties): # noqa: E501
:param properties: A list of GIDs queried for properties. :param properties: A list of GIDs queried for properties.
:type properties: list | bytes :type properties: list | bytes
:rtype: None :rtype: Status
""" """
if connexion.request.is_json: if connexion.request.is_json:
properties = [NeuronProperties.from_dict(d) for d in connexion.request.get_json()] # noqa: E501 properties = [NeuronProperties.from_dict(d) for d in connexion.request.get_json()] # noqa: E501
...@@ -175,7 +227,7 @@ def set_simulation_time_info(simulation_time_info): # noqa: E501 ...@@ -175,7 +227,7 @@ def set_simulation_time_info(simulation_time_info): # noqa: E501
:param simulation_time_info: :param simulation_time_info:
:type simulation_time_info: dict | bytes :type simulation_time_info: dict | bytes
:rtype: None :rtype: Status
""" """
if connexion.request.is_json: if connexion.request.is_json:
simulation_time_info = SimulationTimeInfo.from_dict(connexion.request.get_json()) # noqa: E501 simulation_time_info = SimulationTimeInfo.from_dict(connexion.request.get_json()) # noqa: E501
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
# flake8: noqa # flake8: noqa
from __future__ import absolute_import from __future__ import absolute_import
# import models into model package # import models into model package
from info_node.models.multimeter_info import MultimeterInfo
from info_node.models.multimeter_info_inner import MultimeterInfoInner
from info_node.models.neuron_properties import NeuronProperties from info_node.models.neuron_properties import NeuronProperties
from info_node.models.simulation_time_info import SimulationTimeInfo from info_node.models.simulation_time_info import SimulationTimeInfo
from info_node.models.status import Status from info_node.models.status import Status
...@@ -6,7 +6,7 @@ from datetime import date, datetime # noqa: F401 ...@@ -6,7 +6,7 @@ from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401 from typing import List, Dict # noqa: F401
from info_node.models.base_model_ import Model from info_node.models.base_model_ import Model
from info_node.models.attribute import Attribute # noqa: F401,E501 from info_node.models.multimeter_info_inner import MultimeterInfoInner # noqa: F401,E501
from info_node import util from info_node import util
...@@ -16,32 +16,16 @@ class MultimeterInfo(Model): ...@@ -16,32 +16,16 @@ class MultimeterInfo(Model):
Do not edit the class manually. Do not edit the class manually.
""" """
def __init__(self, name: str=None, interval: float=None, attributes: List[Attribute]=None): # noqa: E501 def __init__(self): # noqa: E501
"""MultimeterInfo - a model defined in Swagger """MultimeterInfo - a model defined in Swagger
:param name: The name of this MultimeterInfo. # noqa: E501
:type name: str
:param interval: The interval of this MultimeterInfo. # noqa: E501
:type interval: float
:param attributes: The attributes of this MultimeterInfo. # noqa: E501
:type attributes: List[Attribute]
""" """
self.swagger_types = { self.swagger_types = {
'name': str,
'interval': float,
'attributes': List[Attribute]
} }
self.attribute_map = { self.attribute_map = {
'name': 'name',
'interval': 'interval',
'attributes': 'attributes'
} }
self._name = name
self._interval = interval
self._attributes = attributes
@classmethod @classmethod
def from_dict(cls, dikt) -> 'MultimeterInfo': def from_dict(cls, dikt) -> 'MultimeterInfo':
"""Returns the dict as a model """Returns the dict as a model
...@@ -52,66 +36,3 @@ class MultimeterInfo(Model): ...@@ -52,66 +36,3 @@ class MultimeterInfo(Model):
:rtype: MultimeterInfo :rtype: MultimeterInfo
""" """
return util.deserialize_model(dikt, cls) return util.deserialize_model(dikt, cls)
@property
def name(self) -> str:
"""Gets the name of this MultimeterInfo.
:return: The name of this MultimeterInfo.
:rtype: str
"""
return self._name
@name.setter
def name(self, name: str):
"""Sets the name of this MultimeterInfo.
:param name: The name of this MultimeterInfo.
:type name: str
"""
self._name = name
@property
def interval(self) -> float:
"""Gets the interval of this MultimeterInfo.
:return: The interval of this MultimeterInfo.
:rtype: float
"""
return self._interval
@interval.setter
def interval(self, interval: float):
"""Sets the interval of this MultimeterInfo.
:param interval: The interval of this MultimeterInfo.
:type interval: float
"""
self._interval = interval
@property
def attributes(self) -> List[Attribute]:
"""Gets the attributes of this MultimeterInfo.
:return: The attributes of this MultimeterInfo.
:rtype: List[Attribute]
"""
return self._attributes
@attributes.setter
def attributes(self, attributes: List[Attribute]):
"""Sets the attributes of this MultimeterInfo.
:param attributes: The attributes of this MultimeterInfo.
:type attributes: List[Attribute]
"""
self._attributes = attributes
# coding: utf-8
from __future__ import absolute_import
from datetime import date, datetime # noqa: F401
from typing import List, Dict # noqa: F401
from info_node.models.base_model_ import Model
from info_node import util
class MultimeterInfoInner(Model):
"""NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, id: int=None, attributes: List[str]=None, gids: List[int]=None): # noqa: E501
"""MultimeterInfoInner - a model defined in Swagger
:param id: The id of this MultimeterInfoInner. # noqa: E501
:type id: int
:param attributes: The attributes of this MultimeterInfoInner. # noqa: E501
:type attributes: List[str]
:param gids: The gids of this MultimeterInfoInner. # noqa: E501
:type gids: List[int]
"""
self.swagger_types = {
'id': int,
'attributes': List[str],
'gids': List[int]
}
self.attribute_map = {
'id': 'id',
'attributes': 'attributes',
'gids': 'gids'
}
self._id = id
self._attributes = attributes
self._gids = gids
@classmethod
def from_dict(cls, dikt) -> 'MultimeterInfoInner':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The MultimeterInfo_inner of this MultimeterInfoInner. # noqa: E501
:rtype: MultimeterInfoInner
"""
return util.deserialize_model(dikt, cls)
@property
def id(self) -> int:
"""Gets the id of this MultimeterInfoInner.
:return: The id of this MultimeterInfoInner.
:rtype: int
"""
return self._id
@id.setter
def id(self, id: int):
"""Sets the id of this MultimeterInfoInner.
:param id: The id of this MultimeterInfoInner.
:type id: int
"""
self._id = id
@property
def attributes(self) -> List[str]:
"""Gets the attributes of this MultimeterInfoInner.
:return: The attributes of this MultimeterInfoInner.
:rtype: List[str]
"""
return self._attributes
@attributes.setter
def attributes(self, attributes: List[str]):
"""Sets the attributes of this MultimeterInfoInner.
:param attributes: The attributes of this MultimeterInfoInner.
:type attributes: List[str]
"""
self._attributes = attributes
@property
def gids(self) -> List[int]:
"""Gets the gids of this MultimeterInfoInner.
:return: The gids of this MultimeterInfoInner.
:rtype: List[int]
"""
return self._gids
@gids.setter
def gids(self, gids: List[int]):
"""Sets the gids of this MultimeterInfoInner.
:param gids: The gids of this MultimeterInfoInner.
:type gids: List[int]
"""
self._gids = gids
...@@ -7,16 +7,18 @@ class Storage(object): ...@@ -7,16 +7,18 @@ class Storage(object):
time_info = SimulationTimeInfo(start=0.0, end=0.0, current=0.0) time_info = SimulationTimeInfo(start=0.0, end=0.0, current=0.0)
nodes = [] nodes = []
time_per_node = {} time_per_node = {}
multimeters = []
num_populations = 0 num_populations = 0
data = pd.DataFrame({ data = pd.DataFrame({
"gid": [], "gid": [1],
"node": [], "node": ["simulation node"],
"population": [], "population": [1],
"properties": [] "properties": [["example", "properties"]]
}) })
def __init__(self): def __init__(self):
self.data = self.data.set_index("gid") self.data = self.data.set_index("gid")
self.data = self.data.drop(1, axis=0)
def UpdateSimulationtime(self): def UpdateSimulationtime(self):
if len(self.time_per_node) == len(self.nodes) and len(self.time_per_node) > 0: if len(self.time_per_node) == len(self.nodes) and len(self.time_per_node) > 0:
......
...@@ -160,11 +160,12 @@ paths: ...@@ -160,11 +160,12 @@ paths:
responses: responses:
200: 200:
description: "Operation successful." description: "Operation successful."
schema:
$ref: "#/definitions/Status"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
type: "string" $ref: "#/definitions/Status"
example: "Error message"
x-swagger-router-controller: "info_node.controllers.nest_controller" x-swagger-router-controller: "info_node.controllers.nest_controller"
/current_time: /current_time:
put: put:
...@@ -297,8 +298,7 @@ paths: ...@@ -297,8 +298,7 @@ paths:
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
type: "string" $ref: "#/definitions/Status"
example: "Error message"
x-swagger-router-controller: "info_node.controllers.nest_controller" x-swagger-router-controller: "info_node.controllers.nest_controller"
/neuron_properties: /neuron_properties:
get: get:
...@@ -349,12 +349,73 @@ paths: ...@@ -349,12 +349,73 @@ paths:
responses: responses:
200: 200:
description: "Operation successful." description: "Operation successful."
schema:
$ref: "#/definitions/Status"
400:
description: "Operation failed."
schema:
$ref: "#/definitions/Status"
x-swagger-router-controller: "info_node.controllers.nest_controller"
/multimeter_info:
get:
tags:
- "nest"
summary: "Retreives the available multimeters and their properties"
operationId: "get_multimeter_info"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
200:
description: "Operation successful."
schema:
$ref: "#/definitions/MultimeterInfo"
400: 400:
description: "Operation failed." description: "Operation failed."
schema: schema:
type: "string" type: "string"
example: "Error message" example: "Error message"
x-swagger-router-controller: "info_node.controllers.nest_controller" x-swagger-router-controller: "info_node.controllers.nest_controller"
put:
tags:
- "nest"
summary: "Puts the available multimeters and their properties"
operationId: "put_multimeter_info"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- name: "id"
in: "query"
required: true
type: "integer"
format: "uint64"
- name: "attributes"
in: "query"
required: false
type: "array"
items:
type: "string"
- name: "gids"
in: "query"
required: false
type: "array"
items:
type: "integer"
format: "uint64"
responses:
200:
description: "Operation successful."
schema:
$ref: "#/definitions/Status"
400:
description: "Operation failed."
schema:
$ref: "#/definitions/Status"
x-swagger-router-controller: "info_node.controllers.nest_controller"
/population/${population_id}/gids: /population/${population_id}/gids:
get: get:
tags: tags:
...@@ -412,6 +473,18 @@ definitions: ...@@ -412,6 +473,18 @@ definitions:
- 1 - 1
- 2 - 2
- 3 - 3
MultimeterInfo:
type: "array"
items:
$ref: "#/definitions/MultimeterInfo_inner"
example:
- id: 0
attributes:
- "V_m"
gids:
- 1
- 2
- 3
SimulationTimeInfo: SimulationTimeInfo:
type: "object" type: "object"
properties: properties:
...@@ -428,3 +501,17 @@ definitions: ...@@ -428,3 +501,17 @@ definitions:
current: 63.1 current: 63.1
start: 0 start: 0
end: 100 end: 100
MultimeterInfo_inner:
properties:
id:
type: "integer"
format: "uint64"
attributes:
type: "array"
items:
type: "string"
gids:
type: "array"
items:
type: "integer"
format: "uint64"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment