-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion1.py
More file actions
112 lines (83 loc) · 3.69 KB
/
Copy pathversion1.py
File metadata and controls
112 lines (83 loc) · 3.69 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
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
from cassandra.cluster import Cluster
from tabulate import tabulate
from cassandra.query import dict_factory
from colorama import Fore ,Style
from datetime import datetime
import distutils
from distutils import util
import time
import pandas as pd
def retrieveOneIndicator(content):
session = cluster.connect('fdc_treateddata_cass')
session.execute('USE fdc_treateddata_cass')
ps = session.prepare('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid=? LIMIT 1')
futures = []
time_1 = time.time()
for fdc in content:
futures.append(session.execute_async(ps.bind([int(fdc)])))
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
i = 0
for future in futures:
rows = future.result()
for row in rows:
i += 1
print("i = "+str(i)+"\n")
print(row)
session.shutdown()
def retrieveAllIndicators(content):
session = cluster.connect('fdc_treateddata_cass')
session.execute('USE fdc_treateddata_cass')
ps = session.prepare('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where fdccontextid=?')
futures = []
time_1 = time.time()
for fdc in content:
futures.append(session.execute_async(ps.bind([int(fdc)])))
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
i = 0
for future in futures:
rows = future.result()
for row in rows:
i += 1
print("i = "+str(i)+"\n")
print(row)
session.shutdown()
def retrievefdcs(ind):
session = cluster.connect('fdc_treateddata_cass')
session.execute('USE fdc_treateddata_cass')
ps = session.prepare('select fdccontextid,indicatorid from fdc_treateddata_cass.treateddata where indicatorid=? ALLOW FILTERING')
time_1 = time.time()
fdcs = session.execute(ps.bind([int(ind)]))
time_2 = time.time()
time_interval = time_2 - time_1
print(Fore.RED+"time to execute the query : "+ str(time_interval) +" seconds"+Style.RESET_ALL)
print(tabulate(fdcs,tablefmt='pretty',headers='keys',showindex=True))
for fdc in fdcs:
print(fdc)
session.shutdown()
if __name__ == "__main__":
cluster = Cluster(['rio.pdf.com'],port=9042)
data= pd.read_csv("Treateddata.csv")
fdcs = (data.fdccontextid).tolist()
#print(fdcs)
f = open("fdccontextids.txt", "r")
content = f.read().splitlines()
#print(len(content))
ch = ''
while ch != 'e':
ch = input('''1. Retrieve One indicator for list of fdccontextids. Using bind (one indicator).
\n2. Retrieve list of indicators for list of fdccontextids. Using bind (all indicators).
\n3. Retrieve Fdccontextids for a specific Indicatorid.
\ne. exit.\n''')
if ch == '1':
retrieveOneIndicator(content)
elif ch == '2':
retrieveAllIndicators(content)
elif ch == '3':
Indicatorid = input("Enter Indicatorid ... ")
retrievefdcs(Indicatorid)
elif ch == 'e':
break