Skip to content

MarshallChiang/GroupSchedule

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

Manipulate events composed of group object, activate and deactive by shifting time window and event priority.

Environment setup

Database schema

Field Type Null Key Default Extra
id int(10) unsigned NO PRI NULL auto_increment
cashflow_group_id varchar(10) YES NULL
offer_id varchar(10) NO NULL
affiliates varchar(100) YES NULL
name varchar(100) YES NULL
description text YES NULL
percent decimal(4,2) YES 0.00
rate decimal(10,2) YES 0.00
default_value text NO NULL
actived_from datetime NO NULL
actived_to datetime NO NULL
created_at datetime NO NULL
rules text YES NULL
status varchar(20) NO NULL
group_type varchar(5) NO NULL
follow tinyint(3) unsigned NO NULL
sub_1 text YES NULL

Install libraries

$ cd path/to/project
$ pip install -r requirements.txt -t .

Available Methods

class OfferGroupCursor(offer_id, **kwargs)

Parameters :

Parameter Type Required Description
offer_id int Required id of the offer to initialize the object
branch_at datetime string Optional fetch specific configuration from given datetime (YYYY-mm-dd HH:MM:SS), if None is given, configuration in the current will be used
from GroupSchedule import OfferGroupCursor

# get offer 1544 current setting.
cursor = OfferGroupCursor(1544)

# get offer 1544 setting at 2019-01-01 18:00:00
cursor = OfferGroupCursor(1544, branch_at='2019-01-01 18:00:00')

Return :

None

Instance Attributes

Attributes Type Description
offer_id int id of the initialized offer
actived_from string datetime of this configuration start
actived_to string datetime of this configuration end
default_value JSON string default percentage and rate value of this configuration
groups list list with groups object
branch_at datetime string datetime specified for fetching specific configuration
created_at datetime string datetime when this configuration was created
ptype string payout type of this object as following 'cpa_percentage', 'cpa_rate', 'cpa_both'

function group_display(**kwargs)

search groups inside the cursor by filtering name or value.

Parameters :

Parameter Type Required Description
text_filter string Optional key for group name search
value_filter string Optional key for group value search
return_object string Optional return list with eligible groups
groups = cursor.group_display(text_filter='AU')

Return :

# dictionary in list
[{'name': 'AU',
  'description': 'AU Group',
  'affiliates': [],
  'rules': [{'id': '1234',
    'cashflow_group_id': '2345',
    'field': 'field7',
    'operator': 'IN',
    'value': ['rule_value_1'],
    'negate': '0'},
   {'id': '4567',
    'cashflow_group_id': '2345',
    'field': 'field8',
    'operator': 'IN',
    'value': ['rule_value_2'],
    'negate': '1'}],
  'cashflow_group_id': '2345',
  'offer_id': 1544,
  'percent': '10',
  'rate': None,
  'follow': 1}]
  
  # group object in list if return_object=True
  [GroupSchedule.Group]

function group_append(cashflow_group_id, **kwargs)

append new group into cursor with either one of percent or rate assigned at least.

Parameters :

Parameter Type Required Description
cashflow_group_id int Required id of cashflowgroup object
percent float Optional percent(%) type value
rate float Optional rate($) type value
cursor.group_append(2000, percent=5.5, rate=30)

Return :

None

function group_remove(cashflow_group_id)

remove group from cursor object.

Parameters :

Parameter Type Required Description
cashflow_group_id int Required id of cashflowgroup object
cursor.group_remove(2000)

Return :

None

function setup_default_value(**kwargs)

assign default percent or rate for object

Parameters

Parameter Type Required Description
percent float Optional percent(%) value, default as 0
rate float Optional rate($) value, default as 0
cursor.setup_default_value(percent=10, rate=5.5)

Return :

#JSON format string
'{
  "max_payout": 5.5, 
  "default_payout": 5.5, 
  "max_percent_payout": 10, 
  "percent_payout": 10
  }'

function setup_period(**kwargs)

specify start and end datetime for the ready-to-push configuration.

Parameters

Parameter Type Required Description
actived_from datetime string Required start date of this configuration
actived_to datetime string Required end date of this configuration
is_base Boolean Optional _setup eternal configuration of this cursor, groups of this _
# set specific time range for this configure
cursor.setup_period(actived_from='2019-01-01 00:00:00', actived_to='2019-01-31 23:59:59')

# set baseline for this object to have every configure fallback to
cursor.setup_period(is_base=True)

Return :

None

fuction push_cursor(**kwargs)

push the configuration into database

Parameters

Parameter Type Required Description
utc int Optional push the configuration into database and wait for activation
cursor.push_cursor()

Return :

None

function deploy_cursor()

deploy configuration loaded on cursor object to server.

cursor.deploy_cursor()

Return :

None

class Group(offer_id, cashflow_group_id, percent, rate, **kwargs)

# group object will be initialized along with cursor object.

group = cursor.groups[0]

Instance Attributes

Attributes Type Description
cashflow_group_id int id of group
offer_id int id of the initialized offer with group included
percent decimal(4,2) percent value of this group
rate decimal(10,2) decimal value of this group
db_id int auto increment number in database if cursor is fetched from database
follow tiny int a binary number to determine whether this group is created by branch as a copy (1) or has been assigned value that need to be prioritized (0)

setup_value(**kwargs)

assign percent of rate value to the group object, group with value assigned by this function will be prioritized and always be fetched when this cashflow_group_id is also existed in the cursor configuration.

Parameters

Parameter Type Required Description
percent float Optional percent(%) value, default as 0
rate float Optional rate($) value, default as 0

Return :

None

About

manage scheduling tasks by internal API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages