Skip to content

Commit

Permalink
add matrix api
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Jan 19, 2020
1 parent 4e2920f commit 4a32181
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
37 changes: 37 additions & 0 deletions octobot_evaluators/api/matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Drakkar-Software OctoBot-Evaluators
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_evaluators.data.matrix import Matrix
from octobot_evaluators.matrices.matrices import Matrices


def get_matrix(matrix_id) -> Matrix:
return Matrices.instance().get_matrix(matrix_id)


def get_node_children_by_names(matrix) -> dict:
return matrix.get_node_children_by_names_at_path([])


def get_children_list(matrix_node) -> list:
return matrix_node.children


def has_children(matrix_node) -> bool:
return bool(matrix_node.children)


def get_value(matrix_node) -> object:
return matrix_node.node_value
1 change: 1 addition & 0 deletions octobot_evaluators/data/matrix.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cdef class Matrix:

cpdef void set_tentacle_value(self, object value, object value_type, list value_path)
cpdef list get_node_children_at_path(self, list node_path, EventTreeNode starting_node=*)
cpdef dict get_node_children_by_names_at_path(self, list node_path, EventTreeNode starting_node=*)
cpdef EventTreeNode get_node_at_path(self, list node_path, EventTreeNode starting_node=*)
cpdef list get_tentacle_nodes(self, str exchange_name=*, object tentacle_type=*, str tentacle_name=*)
cpdef list get_tentacles_value_nodes(self, list tentacle_nodes, str cryptocurrency=*, str symbol=*, str time_frame=*)
Expand Down
7 changes: 7 additions & 0 deletions octobot_evaluators/data/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def get_node_children_at_path(self, node_path, starting_node=None):
except NodeExistsError:
return []

def get_node_children_by_names_at_path(self, node_path, starting_node=None):
try:
return {key: val
for key, val in self.matrix.get_node(node_path, starting_node=starting_node).children.items()}
except NodeExistsError:
return {}

def get_node_at_path(self, node_path, starting_node=None):
try:
return self.matrix.get_node(node_path, starting_node=starting_node)
Expand Down

0 comments on commit 4a32181

Please sign in to comment.