-
Notifications
You must be signed in to change notification settings - Fork 1
/
topCoupons.py
60 lines (35 loc) · 1.56 KB
/
topCoupons.py
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
#!/usr/bin/Python
# Top Customers
#Arranging based on household_key not SALES_VALUE
import requests
import json
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
coupon_json_id = []
coupon_json_product = []
product_json_id = []
rank = 0
coupon_redempt = requests.post('http://localhost:9200/_sql', data = 'SELECT COUPON_UPC, household_key FROM coupon_redempt').json()
#print 'name, quantity, value'
for coupon in coupon_redempt['hits']['hits']:
coupon_id = coupon['_source']['COUPON_UPC']
household_key = coupon['_source']['household_key']
coupon_json = requests.post('http://localhost:9200/_sql', data = 'SELECT COUPON_UPC, PRODUCT_ID FROM coupon WHERE COUPON_UPC=' + str(coupon_id)).json()
if len(coupon_json['hits']['hits']):
print coupon_json['hits']['hits']
rank += 1
coupon_json_id.append(coupon_json_id['hits']['hits']['_source']['COUPON_UPC'])
coupon_json_product.append(coupon_json_product['hits']['hits']['_source']['PRODUCT_ID'])
print coupon_json_id
"""
print coupon_json
for row in coupon_json['hits']['hits']:
coupon_json_id.append(row['_source']['COUPON_UPC'])
coupon_json_product.append(row['_source']['PRODUCT_ID'])
product_json = requests.post('http://localhost:9200/_sql', data = 'SELECT PRODUCT_ID, SUB_COMMODITY_DESC, DEPARTMENT FROM products').json()
for row in product_json['hits']['hits']:
product_json_id.append(row['_source']['PRODUCT_ID'])
#for row in product_json['hits']['hits']:
#print row
"""