Utils¶
General¶
-
estuary.utils.general.
get_neo4j_node
(resource_name, uid)[source]¶ Get a Neo4j node based on a label and unique identifier.
-
estuary.utils.general.
inflate_node
(result)[source]¶ Inflate a Neo4j result to a neomodel model object.
- Parameters
result (neo4j.v1.types.Node) – a node from a cypher query result
- Returns
a model (EstuaryStructuredNode) object
-
estuary.utils.general.
login_required
(f)[source]¶ Decorate a Flask route to validate a token if authentication is enabled.
- Parameters
f (function) – the function to wrap
- Returns
the wrapper function
- Return type
function
-
estuary.utils.general.
str_to_bool
(item)[source]¶ Convert a string to a boolean.
- Parameters
item (str) – string to parse
- Returns
a boolean equivalent
- Return type
boolean
-
estuary.utils.general.
timestamp_to_date
(timestamp)[source]¶ Convert a string timestamp to a date object.
- Parameters
timestamp (str) – a generic or ISO-8601 timestamp
- Returns
date object of the timestamp
- Return type
- Raises
ValueError – if the timestamp is an unsupported or invalid format
-
estuary.utils.general.
timestamp_to_datetime
(timestamp)[source]¶ Convert a string timestamp to a datetime object.
- Parameters
timestamp (str) – a generic or ISO-8601 timestamp
- Returns
datetime object of the timestamp
- Return type
- Raises
ValueError – if the timestamp is an unsupported or invalid format
Story¶
-
class
estuary.utils.story.
BaseStoryManager
[source]¶ A class containing utility methods to create a story for an artifact.
-
format_story_results
(results, requested_item)[source]¶ Format story results from Neo4j to the API format.
- Parameters
results (list) – nodes in a story/path
requested_item (EstuaryStructuredNode) – item requested by the user
- Returns
results in API format
- Return type
-
get_sibling_nodes
(siblings_node_label, story_node, count=False)[source]¶ Return sibling nodes with the label siblings_node_label that are related to story_node.
- Parameters
siblings_node_label (str) – node label for which the siblings count is to be calculated
story_node (EstuaryStructuredNode) – node in the story that has the desired relationships with the siblings (specified with siblings_node_label)
count (bool) – determines if only count of sibling nodes should be returned or the nodes themselves
- Returns
siblings count of curr_node | sibling nodes
- Return type
int | EstuaryStructuredNode
-
get_sibling_nodes_count
(results, reverse=False)[source]¶ Iterate through the results and yield correlated nodes.
-
static
get_siblings_description
(story_node_display_name, story_node_story_flow, backward)[source]¶ Generate a description of the siblings.
- Parameters
- Returns
returns the appropriate siblings title
- Return type
string
-
static
get_story_manager
(item, config, limit=False)[source]¶ Select which story flow to follow.
- Parameters
item (node) – a Neo4j node whose story is requested by the user
config (flask.config.Config) – flask config
limit (bool) – specifies if LIMIT keyword should be added to the created cypher query
- Returns
instance of one of the story manager classes
- Return type
ModuleStoryManager/ContainerStoryManager
-
get_story_nodes
(item, reverse=False, limit=False)[source]¶ Create a raw cypher query for story of an artifact and query neo4j with it.
- Parameters
- Returns
story paths for a particular artifact
- Return type
-
get_total_lead_time
(results)[source]¶ Get the total lead time - the time from the start of a story until its current state.
-
get_wait_times
(results)[source]¶ Get the wait time between two artifacts for each pair of them, and the sum of these times.
- Parameters
results (list) – contains inflated results from Neo4j
- Returns
tuple with list of wait time ints in order of the story (oldest to newest), and a total wait time
- Return type
- Raises
RuntimeError – if results has less than 2 elements
-
-
class
estuary.utils.story.
ContainerStoryManager
[source]¶ A class containing utility methods to create a container story.