-
The pacing algorithm is located in the folder Pacing_project
-
All steps to construct the algorithm are notebooks situated in the folder Pacing_notebooks
-
The Report folder contains the internship report and slides
-
The Miscellaneous folder contains miscellaneous things such as work on auction theory
This is the main folder of the project. It contains all useful scripts about the pacing algorithm.
pacing_class_tz.py is the script that contains the final algorithm.
external_functions_tz.pyis the script that contains functions used to simulate the algorithm.
execution_tz.py allows to simulate the algorithm on a dataframe (give any dataframe on the data folder).
api_rest.py is the script to generate the API of the algorithm. It allows to launch a local server.
exec_api.py is the script that simulates the API (with a dataframe of br situated in the data folder).
test_basics.py is basic unit tests on the API.
Note: pacing_class.py, external_functions.py and execution.py are the same that those with the suffix tz, but the algorithm doesn't allow multiple time zones.
To start a local server in order to use the API, launch on a terminal the following command:
python api_rest.pyPOST method
- Initialise a campaign:
curl --request POST \
--url http://127.0.0.1:8000/campaign \
--header 'content-type: application/json' \
--data '{
"cpid": String ID
}'- Initialise a line item:
curl --request POST \
--url http://127.0.0.1:8000/campaign/1/init \
--header 'content-type: application/json' \
--data '{
"budget": Budget,
"start": String date,
"end": String date,
"liid": String ID
}'- Send a bid request
curl --request POST \
--url http://127.0.0.1:8000/li/1/br \
--header 'content-type: application/json' \
--data '{
"tz": String time zone,
"brid": ID of BR,
"imps": Number of impressions,
"cpm": CPM
}'- Send notification
curl --request POST \
--url http://127.0.0.1:8000/li/1/notif \
--header 'content-type: application/json' \
--data '{
"status": Status: must be 'win' or 'lose',
"brid": ID of BR
}'GET method
Note that all output are in JSON format.
- Get campaigns list
curl --request GET \
--url http://127.0.0.1:8000/campaignFor example the if there is a campaign with the ID "1" and 3 line items for this campaign:
{
"campaigns": {
"1": 3
}
}- Get line items list
curl --request GET \
--url http://127.0.0.1:8000/liThe output for 3 line items would be the following:
{
"status": "ok",
"LineItems": [
"1",
"2",
"3"
]
}- Get general status
curl --request GET \
--url http://127.0.0.1:8000/li/1/statusThe general status of a line item returns the sum of expenditures and the total remaining budget:
{
"spent": 0,
"remaining": 10000
}- Get status detailed by time zone
curl --request GET \
--url http://127.0.0.1:8000/li/1/status/tzThe output is the expenditure per time zone. Assuming that we have spent $1 in the time zone America/New_York, the output would be:
{
"spent": {
"Europe/Paris": 0,
"America/New_york": 1.0
},
"remaining": {
"Europe/Paris": 5000.0,
"America/New_york": 4999.0
}
}- Get status of a precised time zone
curl --request GET \
--url http://127.0.0.1:8000/li/1/status/tz/STRING_TIMEZONENote: The / of the timezone in the URL should be replaced by --. For example if you want the time zone America/New_York:
curl --request GET \
--url http://127.0.0.1:8000/li/1/status/tz/America--New_YorkThe output would be then:
{
"spent": 1.0,
"remaining": 4999.0
}Test the API
You can launch unit tests on the API by starting the local server and then execute the following command:
py.test .To test the API in "real" conditions, you can start the local server, and if you have a br dataframe, just launch the exec_api.py script.
python exec_api.py