yawning_titan.networks.network_db#

Provides an API for the network.json TinyDB file, and a Schema class that defines the network DB fields.

Functions

dcbo_base_network

Creates the same network used to generated DCBO data.

default_18_node_network

The standard 18-node network found in the Ridley, A.

Classes

NetworkDB

The NetworkDB class extends YawningTitanDB.

NetworkQuery

NetworkSchema

A schema-like class that defines the network DB fields.

class yawning_titan.networks.network_db.NetworkDB[source]#

The NetworkDB class extends YawningTitanDB.

The below code blocks demonstrate how to use the NetworkDB class.

  • Instantiate the Network DB:

    >>> from yawning_titan.networks.network_db import NetworkDB, NetworkSchema
    >>> db = NetworkDB()
    
  • Search for all network that have set_random_entry_nodes == True.

    >>> db.search(NetworkSchema.SET_RANDOM_ENTRY_NODES == True)
    
__init__()[source]#
insert(network, name=None, description=None, author=None)[source]#

Insert a Network into the DB as .json.

Parameters:
  • network – An instance of Network DocMetadata. DocMetadata. DocMetadata.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The inserted Network.

all()[source]#

Get all Network from the network DB.

Returns:

A list of Network.

show(verbose=False)[source]#

Show details of all entries in the db.

Parameters:

verbose – If True, all doc metadata details are shown, otherwise just the name is shown.

get(uuid)[source]#

Get a network config document from its uuid.

Parameters:

uuid – A target document uuid.

Returns:

The network config document as an instance of Network if the uuid exists, otherwise None.

search(query)[source]#

Searches the Network with a NetworkSchema query.

Parameters:

query – A YawningTitanQuery.

Returns:

A list of Network.

count(cond=None)[source]#

Count how many docs are in the db. Extends tinydb.table.Table.count.

A YawningTitanQuery can be used to filter the count.

Parameters:

cond – An optional YawningTitanQuery. Has a default value of None.

Returns:

The number of docs counted.

update(network, name=None, description=None, author=None)[source]#

Update a Network. in the db.

Parameters:
  • network – An instance of Network.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The updated Network.

upsert(network, name=None, description=None, author=None)[source]#

Upsert a Network. in the db.

Parameters:
  • network – An instance of Network.

  • name – The config name.

  • description – The config description.

  • author – The config author.

Returns:

The upserted Network.

remove(network)[source]#

Remove a Network. from the db.

Parameters:

network – An instance of Network.

Returns:

The uuid of the removed Network.

remove_by_cond(cond)[source]#

Remove Network. from the db that match the query.

Parameters:

cond – A YawningTitanQuery.

Returns:

The list of uuids of the removed Network.

reset_default_networks_in_db(force=False)[source]#

Reset the default network in the db.

Achieves this by loading the default yawning_titan/networks/_package_data/network.json db file into TinyDB, then iterating over all docs and forcing an update of each one in the main networks db from its uuid if they do not match.

Parameters:

force – Forces a reset without checking for equality when True. Has a default value of False.

rebuild_db()[source]#

Rebuild the db.

Actions taken:

Warning

This function completely rebuilds the database. Any custom networks saved in the db will be lost. The default networks can be reset using the reset_default_networks_in_db() function.

class yawning_titan.networks.network_db.NetworkSchema[source]#

A schema-like class that defines the network DB fields.

Fields are defined using the YawningTitanQuery class so that schema paths can be used directly within tinydb.table.Table.search() function calls. All fields are mapped to a property in the Network class.

Example:

>>> from yawning_titan.networks.network_db import NetworkDB, NetworkSchema
>>> db = NetworkDB()
>>> network_configs = db.search(NetworkSchema.SET_RANDOM_ENTRY_NODES == True)
yawning_titan.networks.network_db.default_18_node_network()[source]#

The standard 18-node network found in the Ridley, A. (2017) research paper.

Returns:

An instance of Network.