Module trase.tools.pcs.traders.transform
Functions
def add_label_trader(label_id, trader_id, autocommit=True, cnx=None, cur=None)-
Add trader to label
def attach_label_to_trader(label_id, trader_id, autocommit=True, cnx=None, cur=None)-
TODO: check what happens when more than 1 label under trader
Move label under new trader and move old parent trader under group of same name, outside of the original trader hierarchy.
Example:
attach_trader_label(X, Z)transforms this[V] BUNGE [GROUP] | |– [W] BUNGE IBRICA [TRADER] | | | |– [X] BUNGE IBRICA | |– [Z] BUNGE IBERICA [TRADER] | | | |– [Y] BUNGE IBERICA
into this
[V] BUNGE [GROUP] | |– [Z] BUNGE IBERICA [TRADER] | | | |– [Y] BUNGE IBERICA | |– [X] BUNGE IBRICA
[U] BUNGE IBRICA [GROUP] | |– [W] BUNGE IBRICA [TRADER] | |
def change_group_name(group_id, new_group_id, interactive=False, autocommit=True, cnx=None, cur=None)-
Move all traders under group to new group.
def change_label_trader(label_id, new_trader_id, old_trader_id=None, country_id=None, interactive=False, autocommit=True, cnx=None, cur=None)-
Move label to new trader. If label is attached to more than 1 trader, the trader that needs to be changed has to be specified as optional argument, or selected interactively.
def change_trader_group(trader_id, new_group_id, year_start=None, month_start=None, day_start=None, year_end=None, month_end=None, day_end=None, interactive=False, autocommit=True, cnx=None, cur=None)-
Move trader to new group for specified time period.
def change_trader_name(label_id, country_id=None, trader_id=None, interactive=False, autocommit=True, cnx=None, cur=None)-
Set name of trader as name of one of its labels.
def copy_trader_group_membership(from_trader_id, to_trader_id, autocommit=True, cnx=None, cur=None)-
Copy trader group membership from one trader to another.
def detach_trader_by_pattern(pattern, clean_name, autocommit=True, cnx=None, cur=None)def detach_trader_label(label_id, autocommit=True, cnx=None, cur=None)-
Move label under trader of same name, keeping the original group. Returns the new
trader_id.Example:
detach_trader_label()(Y)transforms this[V] BUNGE [GROUP] | |– [W] BUNGE [TRADER] | | | |– [X] BUNGE | |– [Y] BUNGE IBERICA
into this
[V] BUNGE [GROUP] | |– [W] BUNGE [TRADER] | | | |– [X] BUNGE | |– [Z] BUNGE IBERICA [TRADER] | | | |– [Y] BUNGE IBERICA
def extract_trader_label(label_id, autocommit=True, cnx=None, cur=None)-
Move label under group of same name.
Example:
extract_trader(Y)transforms this[V] CARGILL [GROUP] | |– [W] CARGILL [TRADER] | | | |– [X] CARGILL | |– [Y] BUNGE IBERICA
into this
[V] CARGILL [GROUP] | |– [W] CARGILL [TRADER] | | | |– [X] CARGILL
[U] BUNGE IBERICA [GROUP] | |– [Z] BUNGE IBERICA [TRADER] | | | |– [Y] BUNGE IBERICA
def insert_new_trader(name, trase_id, country_id=None, autocommit=True, cnx=None, cur=None)-
When trader with same name but different trase_id already exists, insert new trader under same group, and with same labels.
Example:
insert_new_trader('BUNGE', AA-TRADER-ABC)transforms this[V] BUNGE [GROUP] | |– [W] BUNGE [TRADER | AA-TRADER-XYZ] | | | |– [X] BUNGE
into this
[V] BUNGE [GROUP] | |– [W] BUNGE [TRADER | AA-TRADER-XYZ] | | | |– [X] BUNGE | |– [Y] BUNGE [TRADER | AA-TRADER-ABC] | | | |– [X] BUNGE
def remove_trader_duplicates(keep_trader_id, autocommit=True, cnx=None, cur=None)