-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedup_data.py
More file actions
49 lines (43 loc) · 1.71 KB
/
dedup_data.py
File metadata and controls
49 lines (43 loc) · 1.71 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
import json
import redis
def print_data(data):
for key, value in data.items():
print(key, value)
def merge_data(key, item, old_item):
counter = 0
dedup_queue = redis.StrictRedis('localhost', 6380)
if item['grades'] == ['A', 'A', 'A', 'A', 'A', 'A']:
item['status'] = 1
old_item['status'] = -1
item['historyData'].append(old_item['historyData'])
del old_item['historyData']
del old_item['grades']
item['historyData'].append(old_item)
dedup_queue.execute_command('JSON.SET', key, '.', json.dumps(item))
return
for i in range(len(item['grades'])):
if item['grades'][i] > old_item['grades'][i]:
counter += 1
key_ = 'String' + str(i)
item[key_] = old_item[key_]
item['grades'][i] = old_item['grades'][i]
if counter > 0:
old_item['status'] = -1
item['historyData'] += (old_item['historyData'])
del old_item['historyData']
del old_item['grades']
item['historyData'].append(old_item)
if item['grades'] == ['A', 'A', 'A', 'A', 'A', 'A']:
item['status'] = 1
dedup_queue.execute_command('JSON.SET', key, '.', json.dumps(item))
print(item)
def deduplicate_data(key, item):
dedup_queue = redis.StrictRedis('localhost', 6380)
exists = dedup_queue.execute_command('EXISTS', key)
if exists > 0:
print('Extracting item from queue. De-duplicating..')
old_item = json.loads(dedup_queue.execute_command('JSON.GET', key))
merge_data(key, item, old_item)
else:
print('Item not found in queue. Placing it now.')
dedup_queue.execute_command('JSON.SET', key, '.', json.dumps(item))