forked from bitphy/customer-datathon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
78 lines (61 loc) · 1.83 KB
/
Copy pathclient.py
File metadata and controls
78 lines (61 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Gerardo Parrello"
__version__ = "0.0.1"
__status__ = "Prototype"
"""
client.py: Description of what client.py does.
"""
# import logging
# logging.basicConfig(level=logging.DEBUG)
# logger = logging.getLogger(__name__)
# Just add logger.debug('My message with %s', 'variable data') where you need data
import configparser as cfg
import pandas as pd
import requests as re
import datetime as dt
import json
def submit_predictions(config_file, df):
"""
"""
columns = [
'customer',
'date',
'billing',
]
for col in columns:
if col not in df.columns:
raise ValueError(
f"Column {col} is missing from dataframe."
)
if df.shape[1] != 3:
raise ValueError(
f"Wrong number of columns, should be 3."
)
if df.empty:
raise ValueError("you passed an empty dataframe")
total_customer = 1190 # total number of rows in the validation set
if len(df.customer) < total_customer:
raise ValueError("you have less customer than needed")
if len(df.customer) != len(df.customer.unique()):
raise ValueError("you have non-unique customer")
config = cfg.ConfigParser()
config.read(config_file)
protocol = 'http://'
host = config['DEFAULT']['host']
token = config['DEFAULT']['token']
# post predictions
endpoint = '/predictions'
url = protocol + host + endpoint
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer {}".format(token),
"Prefer": "return=representation",
}
payload = df[[
'customer',
'date',
'billing',
]].to_json(orient='records', date_format='iso')
r = re.post(url, data=payload, headers=headers)
return(r.status_code)