-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.py
128 lines (120 loc) · 3.8 KB
/
worker.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# vim: set fileencoding=utf-8 :
from __future__ import print_function, unicode_literals, division
import pymongo, bson
db = pymongo.MongoClient("mongodb://localhost:27017/").assistantDb
db.branches.insert([
{
"location": {"type": "Point", "coordinates": [29.011896, 41.024065]},
"chainName": "BİM",
"branchName": "UNCULAR/ÜSKÜDAR",
"priceList_id": "1"
},
{
"location": {"type": "Point", "coordinates": [29.016949, 41.025344]},
"chainName": "BİM",
"branchName": "ÇARŞI/ÜSKÜDAR",
"priceList_id": "1"
},
{
"location": {"type": "Point", "coordinates": [29.014056, 41.020141]},
"chainName": "Şok",
"branchName": "Doğancılar Üsküdar İstanbul",
"priceList_id": "2"
},
{
"location": {"type": "Point", "coordinates": [29.010941, 41.022537]},
"chainName": "Şok",
"branchName": "ŞEMSİPAŞA Üsküdar İstanbul",
"priceList_id": "3"
},
{
"location": {"type": "Point", "coordinates": [29.02265642, 41.02036627]},
"chainName": "A101",
"branchName": "Çavuşdere Üsküdar İstanbul",
"priceList_id": "4"
},
{
"location": {"type": "Point", "coordinates": [29.07688379, 41.01901575]},
"chainName": "A101",
"branchName": "Bulgurlu Üsküdar İstanbul",
"priceList_id": "4"
},
{
"location": {"type": "Point", "coordinates": [29.025385, 41.023184]},
"chainName": "Çağrı",
"branchName": "Selam-i Ali",
"priceList_id": "5"
},
{
"location": {"type": "Point", "coordinates": [29.081132, 41.019218]},
"chainName": "Çağrı",
"branchName": "Bulgurlu",
"priceList_id": "6"
}
])
db.products.insert([
{
"barcode": "1",
"name": "ÜLKER ÇİKOLATALI GOFRET 38 GR",
"imageSrc": "images/1.jpg",
"prices": [
{"priceList_id": "1", "price": 1.3 },
{"priceList_id": "2", "price": 0.43},
{"priceList_id": "3", "price": 0.63},
{"priceList_id": "4", "price": 2.33},
{"priceList_id": "5", "price": 4.55},
{"priceList_id": "6", "price": 0.22}
]
},
{
"barcode": "2",
"name": "Ülker Biskrem Kakaolu Krema Dolgulu Poşet",
"imageSrc": "images/2.jpg",
"prices": [
{"priceList_id": "1", "price": 23},
{"priceList_id": "2", "price": 44.3},
{"priceList_id": "3", "price": 16.3},
{"priceList_id": "4", "price": 13.3},
{"priceList_id": "6", "price": 22.2}
]
},
{
"barcode": "3",
"name": "Ülker Bistik Fındıklı",
"imageSrc": "images/3.jpg",
"prices": [
{"priceList_id": "1", "price": 0.13},
{"priceList_id": "2", "price": 0.43},
{"priceList_id": "3", "price": 0.63},
{"priceList_id": "4", "price": 1.33},
{"priceList_id": "5", "price": 2.55}
]
},
{
"barcode": "4",
"name": "Ülker Çubuk Kraker",
"imageSrc": "images/4.jpg",
"prices": [
{"priceList_id": "3", "price": 0.53},
{"priceList_id": "5", "price": 0.75},
{"priceList_id": "6", "price": 0.62}
]
}
])
db.branches.ensure_index([("location", pymongo.GEOSPHERE)])
db.products.ensure_index([("barcode", pymongo.ASCENDING),
("prices.price", pymongo.ASCENDING)])
# for fast sorting price,
# order of indexes are important.
# first use important search field
# then narrow index by the other search field,
# where the final component of the index is the sort field to
# maximize index efficiency.
# TODO: bson.ObjectId() for uuid
# in the future:
# * read priceList_id from branches collection for each branch or chain only once:
# # TODO: create new collection for just checking priceList_ids easily
# * insert new product if there is a new barcode in the products
# * push priceList_id - price pair OR update price in the prices array of each product for given barcode.
# * sort each prices array
# * create indexes