Skip to content
Snippets Groups Projects

Remove redundant code and use existing functions

1 file
+ 2
55
Compare changes
  • Side-by-side
  • Inline
@@ -321,60 +321,7 @@ def nest_get_spikes_by_population(population_id, _from=None, to=None, offset=Non
:rtype: Spikes
"""
con = connect_to_database()
cur = con.cursor()
cur.execute("SELECT address FROM nest_simulation_node")
nodes.nest_simulation_nodes = [i[0] for i in cur.fetchall()]
con.close()
print("Updated simumlation nodes: " + str(nodes.nest_simulation_nodes))
gids = nest_get_gids_in_population(population_id)
return nest_get_spikes(_from, to, gids, offset, limit)
spikes = Spikes([], [])
for node in nodes.nest_simulation_nodes:
response = requests.get(
node+'/spikes', params={"from": _from, "to": to, "population": population_id})
try:
response_json = response.json()
spikes.simulation_times.extend(response_json['simulation_times'])
spikes.gids.extend(response_json['gids'])
except:
pass
# # sort
# sorted_ids = [x for _, x in sorted(
# zip(spikes.simulation_times, spikes.gids))]
# spikes.gids = sorted_ids
# spikes.simulation_times.sort()
# # offset and limit
# if (offset is None):
# offset = 0
# if (limit is None or (limit + offset) > len(spikes.gids)):
# limit = len(spikes.gids) - offset
# spikes.gids = spikes.gids[offset:offset+limit]
# spikes.simulation_times = spikes.simulation_times[offset:offset+limit]
return spikes
# spikes = Spikes([], [])
# for node in nodes.nest_simulation_nodes:
# response = requests.get(
# 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])
# # sort
# sorted_ids = [x for _, x in sorted(
# zip(spikes.simulation_times, spikes.gids))]
# spikes.gids = sorted_ids
# spikes.simulation_times.sort()
# # offset and limit
# if (offset is None):
# offset = 0
# if (limit is None or (limit + offset) > len(spikes.gids)):
# limit = len(spikes.gids) - offset
# spikes.gids = spikes.gids[offset:offset+limit]
# spikes.simulation_times = spikes.simulation_times[offset:offset+limit]
# return spikes
\ No newline at end of file
Loading