Module trase.tools.pcs.traders.retrieve

Functions

def find_group_by_name(group_name, cur=None)
def find_groups_by_name(group_name, cur=None)

Find the trader group (level 0) with name group_name

def find_label(name, cur=None)

Retrieve nodes.id of trader labels.

def find_labels(names, cur=None)

Retrieve nodes.id of trader labels.

def find_trader_by_name(trader_name, country_id=None, cur=None)

Find the trader (level 1) with name trader_name

def find_traders_by_name(trader_name, country_id=None, cur=None)

Find the trader(s) (level 1) with name trader_name

def get_all_group_trader_ids(group_id, cur=None)

Return node_id of all traders that are part of group at any given time.

def get_group_label_ids(group_id, year=None, month=None, day=None, time_start=None, time_end=None, cur=None)
def get_group_trader_ids(group_id, year=None, month=None, day=None, time_start=None, time_end=None, cur=None)
def get_label_trader_id(label_id, country_id=None, trase_id=None, strict=False, random=False, cur=None) ‑> int
def get_label_trader_ids(label_id, cur=None)
def get_trader_activities(node_id, year=None, cur=None) ‑> List[TraderActivity]

Recompute trader countries for trader.

Find all instances of trader or corresponding label acting as an exporter or importer, and add countries of export and import to trader countries.

def get_trader_commodities(trader_id, cur=None)
def get_trader_countries(trader_id, cur=None)
def get_trader_datasets(trader_id, cur=None)

Return ref_id of datasets the trader is part of.

def get_trader_details(node_id, countries=True, cur=None)
def get_trader_group_id(node_id, country_id=None, year=None, month=None, day=None, time_start=None, time_end=None, cur=None)

Get group for trader at specified time.

def get_trader_group_membership(trader_id, cur=None)
def get_trader_label_ids(trader_id, cur=None)
def get_trader_qual_dict(qual_id, year=None, cur=None)

Returns all node ids, values and years of nodes that have a qualitative attribute value for the qual id and (if valid) year entered. This function assumes that the nodes with this qual are traders.

qual_id – 'quals.qual_id' in main database

Keyword arguments: year – year cur – Main database cursor object

def get_trader_relatives(trader_id, year=None, month=None, day=None, time_start=None, time_end=None, cur=None)

Return list of node ids for all traders and their labels belonging to the same group.

def get_trader_tree_data(node_id, year=None, month=None, day=None, all_years=False, only_traders=None, cur=None)
def get_traders_from_labels(trader_labels: Iterable[str], cur=None) ‑> Dict[str, List[Tuple[str, Optional[str], int]]]

Given a list of trader labels returns all of the associated traders: in particular, their name, node ID, and any trase ID. It is possible that there are no traders (likely because the label is not in the database) and also possible that there are more than one.

Example

traders = get_traders_from_labels(["NIDERA SA"])
traders["NIDERA SA"][0].name      # 'NIDERA ARGENTINA'
traders["NIDERA SA"][0].trase_id  # 'AR-TRADER-33506737449'
traders["NIDERA SA"][0].node_id   # 2530809

Labels are de-duplicated by this function. It is guaranteed that all labels passed to the function appear as keys in the returned dictionary.

def seek_labels(partial_name, cur=None)

Return node ids of all trader labels that have partial_name in their name.

Classes

class TraderActivity (role, com_id, country_of_production_id, country_of_import_id)

TraderActivity(role, com_id, country_of_production_id, country_of_import_id)

Ancestors

  • builtins.tuple

Instance variables

var com_id

Alias for field number 1

var country_of_import_id

Alias for field number 3

var country_of_production_id

Alias for field number 2

var role

Alias for field number 0