metawards.Wards

class metawards.Wards(wards: Optional[List[metawards._ward.Ward]] = None)[source]

This class holds an entire network of Ward objects

__init__(wards: Optional[List[metawards._ward.Ward]] = None)[source]

Construct, optionally from a list of Ward objects

Methods

__add__(other)

__contains__(id)

Return whether or not the passed id - which can be an integer ID or WardInfo - is in this Wards object

__delattr__(name, /)

Implement delattr(self, name).

__dir__()

Default dir() implementation.

__eq__(other)

Return self==value.

__format__(format_spec, /)

Default object formatter.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__getitem__(id)

Return the ward with specified id - this can be the integer ID of the ward, or the WardInfo of the ward.

__gt__(value, /)

Return self>value.

__iadd__(other)

__imul__(scale)

In-place multiply the number of workers and players by ‘scale’

__init__([wards])

Construct, optionally from a list of Ward objects

__init_subclass__

This method is called when a class is subclassed.

__le__(value, /)

Return self<=value.

__len__()

__lt__(value, /)

Return self<value.

__mul__(scale)

Scale the number of workers and players by ‘scale’

__ne__(value, /)

Return self!=value.

__new__(**kwargs)

Create and return a new object.

__radd__(other)

__reduce__()

Helper for pickle.

__reduce_ex__(protocol, /)

Helper for pickle.

__repr__()

Return repr(self).

__rmul__(scale)

Scale the number of workers and players by ‘scale’

__setattr__(name, value, /)

Implement setattr(self, name, value).

__sizeof__()

Size of object in memory, in bytes.

__str__()

Return str(self).

__subclasshook__

Abstract classes can override this to customize issubclass().

_harmonise_links(other)

Make sure that the wards in this object has exactly the same links as the wards in ‘other’.

_harmonise_nodes(other)

Make sure that this set of Wards contains all of the wards in ‘other’, and that all have the same ID and info.

_resolve()

Try to resolve all of the links.

add(ward)

Synonym for insert

assert_sane()

Make sure that we don’t refer to any non-existent wards

contains(id)

Return whether or not the passed id - which can be an integer ID or WardInfo - is in this Wards object

from_data(data[, profiler])

Return the Wards constructed from a data represnetation, which may have come from deserialised JSON

from_json(s)

Return the Wards constructed from the passed json.

get(id[, dereference])

Return the ward with the specified id - this can eb the integer ID of the ward or the WardInfo of the ward.

getinfo(id)

Return the WardInfo matching the ward with the passed ID

harmonise(wardss)

Harmonise the passed list of wards, returning a tuple that contains the overall sum of all of these wards, plus a new list where all Wards use IDs that are correct and valid across the entire group

index(id)

Return the index of the ward that matches the passed id - which can be the integer ID or WardInfo - in this Wards object.

insert(wards[, overwrite, _need_deep_copy])

Insert the passed wards onto this list.

is_resolved()

Return whether or not this is a fully resolved set of Wards (i.e.

num_play_links()

Return the total number of play links

num_players()

Return the total number of players in this network

num_work_links()

Return the total number of work links

num_workers()

Return the total number of workers in this network

population()

Return the total population in this network

scale([work_ratio, play_ratio, _inplace])

Return a copy of these wards where the number of workers and players have been scaled by ‘work_ratios’ and ‘play_ratios’ respectively.

to_data([profiler])

Return a data representation of these wards that can be serialised to JSON

to_json([filename, indent, auto_bzip])

Serialise the wards to JSON.

unresolved_wards()

Return the list of IDs of unresolved wards

Attributes

__dict__

__doc__

__hash__

__module__

__weakref__

list of weak references to the object (if defined)

__contains__(id: Union[int, str, metawards._wardinfo.WardInfo, metawards._ward.Ward])bool[source]

Return whether or not the passed id - which can be an integer ID or WardInfo - is in this Wards object

__eq__(other)[source]

Return self==value.

__getitem__(id: Union[int, str, metawards._wardinfo.WardInfo])metawards._ward.Ward[source]

Return the ward with specified id - this can be the integer ID of the ward, or the WardInfo of the ward. Note that this returns a copy of the Ward

__imul__(scale: float)metawards._wards.Wards[source]

In-place multiply the number of workers and players by ‘scale’

__init__(wards: Optional[List[metawards._ward.Ward]] = None)[source]

Construct, optionally from a list of Ward objects

__mul__(scale: float)metawards._wards.Wards[source]

Scale the number of workers and players by ‘scale’

__repr__()[source]

Return repr(self).

__rmul__(scale: float)metawards._wards.Wards[source]

Scale the number of workers and players by ‘scale’

__str__()[source]

Return str(self).

add(ward: metawards._ward.Ward)None[source]

Synonym for insert

assert_sane()[source]

Make sure that we don’t refer to any non-existent wards

contains(id: Union[int, str, metawards._wardinfo.WardInfo])bool[source]

Return whether or not the passed id - which can be an integer ID or WardInfo - is in this Wards object

static from_data(data, profiler: Optional[metawards.utils._profiler.Profiler] = None)[source]

Return the Wards constructed from a data represnetation, which may have come from deserialised JSON

static from_json(s: str)[source]

Return the Wards constructed from the passed json. This will either load from a passed json string, or from json loaded from the passed file

get(id: Union[int, metawards._wardinfo.WardInfo], dereference: bool = True)metawards._ward.Ward[source]

Return the ward with the specified id - this can eb the integer ID of the ward or the WardInfo of the ward. If ‘dereference’ is True then this will dereference all of the IDs into WardInfo objects. This is useful if you want to use the resulting Ward with other Wards collections

getinfo(id: Union[int, str, metawards._wardinfo.WardInfo])metawards._wardinfo.WardInfo[source]

Return the WardInfo matching the ward with the passed ID

static harmonise(wardss: List[Wards])Tuple[Wards, List[Wards]][source]

Harmonise the passed list of wards, returning a tuple that contains the overall sum of all of these wards, plus a new list where all Wards use IDs that are correct and valid across the entire group

index(id: Union[int, str, metawards._wardinfo.WardInfo, metawards._ward.Ward])int[source]

Return the index of the ward that matches the passed id - which can be the integer ID or WardInfo - in this Wards object. This raises a ValueError if the ward doens’t exist

insert(wards: List[metawards._ward.Ward], overwrite: bool = True, _need_deep_copy: bool = True)None[source]

Insert the passed wards onto this list. This will overwrite the existing ward if ‘overwrite’ is true, otherwise it will add the ward’s data to the existing ward

is_resolved()bool[source]

Return whether or not this is a fully resolved set of Wards (i.e. each ward only links to other wards in this set)

Return the total number of play links

num_players()[source]

Return the total number of players in this network

Return the total number of work links

num_workers()[source]

Return the total number of workers in this network

population()[source]

Return the total population in this network

scale(work_ratio: float = 1.0, play_ratio: float = 1.0, _inplace: bool = False)metawards._wards.Wards[source]

Return a copy of these wards where the number of workers and players have been scaled by ‘work_ratios’ and ‘play_ratios’ respectively. These can be greater than 1.0, e.g. if you want to scale up the number of workers and players

Parameters
  • work_ratio (float) – The scaling ratio for workers

  • play_ratio (float) – The scaling ratio for players

Returns

Wards

Return type

A copy of this Wards scaled by the requested amount

to_data(profiler: Optional[metawards.utils._profiler.Profiler] = None)[source]

Return a data representation of these wards that can be serialised to JSON

to_json(filename: Optional[str] = None, indent: Optional[int] = None, auto_bzip: bool = True)str[source]

Serialise the wards to JSON. This will write to a file if filename is set, otherwise it will return a JSON string.

Parameters
  • filename (str) – The name of the file to write the JSON to. The absolute path to the written file will be returned. If filename is None then this will serialise to a JSON string which will be returned.

  • indent (int) – The number of spaces of indent to use when writing the json

  • auto_bzip (bool) – Whether or not to automatically bzip2 the written json file

Returns

Returns either the absolute path to the written file, or the json-serialised string

Return type

str

unresolved_wards()List[int][source]

Return the list of IDs of unresolved wards