-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquerycalls.py
219 lines (172 loc) · 6.84 KB
/
querycalls.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import boto3
from boto3.dynamodb.conditions import Key
import time
import datetime
from collections import defaultdict
from collections import Counter
def trunkcalls(trunkid):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("calls")
# query a index
print ('Query a trunk calls start time :', time.strftime("%H:%M:%S"))
indexName='trunkid-calldate-index'
keyConditionExpression=Key('trunkid').eq(trunkid)
filterExpression = None
# querttuple =(indn,kc)
# querystr = "IndexName='trunkid-calldate-index',KeyConditionExpression=Key('trunkid').eq(TRK-Y456-7-ACC-1232),Limit=100000"
import pdb; pdb.set_trace()
response = table.query(IndexName= indexName,
KeyConditionExpression= keyConditionExpression,
FilterExpression=filterExpression)
# IndexName='trunkid-calldate-index',
# KeyConditionExpression=Key('trunkid').eq(trunkid),
# Limit=100000
# import pdb;pdb.set_trace()
print ('Query a trunk calls end time :', time.strftime("%H:%M:%S"), '(getting first 1M which is ', response['Count'], 'the limit')
# use the below code to scan the whole results and get the count
rowcount = response['Count']
while 'LastEvaluatedKey' in response:
response = table.query(
IndexName='trunkid-calldate-index',
KeyConditionExpression=Key('trunkid').eq("45692"),
ExclusiveStartKey=response['LastEvaluatedKey']
)
rowcount = response['Count'] + rowcount
#
print ("Query results item count: ", rowcount)
def trunkcallsbydatesort(trunkid,fromdate,todate):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("callstab2")
fd = datetime.datetime.fromtimestamp(fromdate).strftime('%Y-%m-%d %H:%M:%S')
td = datetime.datetime.fromtimestamp(todate).strftime('%Y-%m-%d %H:%M:%S')
# query a index
print ('Query a trunk calls start time :', time.strftime("%H:%M:%S"), ' (from ' , fd, ' to ', td,')')
response = table.query(
IndexName='trunkid-calldate-index',
KeyConditionExpression=Key('trunkid').eq(trunkid) & Key('calldate').between(fromdate, todate),
Limit=100000
)
print ('Query a trunk calls end time :', time.strftime("%H:%M:%S"), '(getting first 1M which is ', response['Count'], 'the limit')
def accountcalls(accountid):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("callstab2")
# query a index
print ('Query an account calls start time :', time.strftime("%H:%M:%S"))
response = table.query(
IndexName='accountid-calldate-index',
KeyConditionExpression=Key('accountid').eq(accountid),
Limit=100000
)
print ('Query an account calls end time :', time.strftime("%H:%M:%S"), '(getting first 1M which is ', response['Count'], 'the limit')
def accountcallsbydatesort(accountid,fromdate,todate):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("callstab2")
fd = datetime.datetime.fromtimestamp(fromdate).strftime('%Y-%m-%d %H:%M:%S')
td = datetime.datetime.fromtimestamp(todate).strftime('%Y-%m-%d %H:%M:%S')
# query a index
print ('Query an account calls start time :', time.strftime("%H:%M:%S"), ' (from ' , fd, ' to ', td,')')
response = table.query(
IndexName='accountid-calldate-index',
KeyConditionExpression=Key('accountid').eq(accountid) & Key('calldate').between(fromdate, todate),
Limit=100000
)
print ('Query an account calls end time :', time.strftime("%H:%M:%S"), '(getting first 1M which is ', response['Count'], 'the limit')
def locationcalls(location):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("callstab2")
# query a index
print ('Query a location calls start time :' + time.strftime("%H:%M:%S"))
response = table.query(
IndexName='location-calldate-index',
KeyConditionExpression=Key('location').eq(location),
Limit=100000
)
print ('Query a location calls end time :' + time.strftime("%H:%M:%S"), '(getting first 1M which is ', response['Count'], 'the limit')
def locationcallsbydatesort(location,fromdate,todate):
dynamodb=boto3.resource(service_name='dynamodb', region_name='eu-west-1')
table = dynamodb.Table("calls")
fd = datetime.datetime.fromtimestamp(fromdate).strftime('%Y-%m-%d %H:%M:%S')
td = datetime.datetime.fromtimestamp(todate).strftime('%Y-%m-%d %H:%M:%S')
# query a index
print ("Query a location and sort key calls start time: " + time.strftime("%H:%M:%S") + ' (from ' + fd + ' to ' + td +')')
response = table.query(
IndexName='location-calldate-index',
KeyConditionExpression=Key('location').eq(location) & Key('calldate').between(fromdate, todate),
Limit=100000
)
print ("Query a location and sort key calls end time: " + time.strftime("%H:%M:%S") + ' (Item count: ' + str(response['Count']) + ' . getting the first 1M (the limit) ')
if __name__ == '__main__':
var = ""
while not var == "x":
print ("")
print ("")
print ("Please select a query:")
print ("")
print ("------------------------------------------")
print("(a) trunk call query")
print("(b) trunk call and date sort key query")
print("(c) account call query")
print("(d) account call and date sort key query")
print("(e) location call query")
print("(f) location call and date sort key query")
print("(x) to exit")
print ("------------------------------------------")
print ("")
var = raw_input("")
# try:
if var == "a":
print("selected trunkid")
trk = raw_input()
trunkcalls(trk)
if var == "b":
print("selected trunkid")
trk = raw_input()
print("selected fromdate default 1480450008")
fd = raw_input()
if fd =="":
fd = 1480450008
print("selected todate default 1480450029")
td = raw_input()
if td =="":
td = 1480450029
trunkcallsbydatesort(trk,int(fd),int(td))
if var == "c":
print("selected accountid")
acc = raw_input()
accountcalls(acc)
if var == "d":
print("selected accountid")
acc = raw_input()
print("selected fromdate default 1480450008")
fd = raw_input()
if fd =="":
fd = 1480450008
print("selected todate default 1480450029")
td = raw_input()
if td =="":
td = 1480450029
accountcallsbydatesort(acc,int(fd),int(td))
if var == "e":
print("selected location default Port Kelsey")
loc = raw_input()
if loc == "":
loc = "Port Kelsey"
locationcalls(loc)
if var == "f":
print("selected location default Port Kelsey")
loc = raw_input()
if loc == "":
loc = "Port Kelsey"
print("selected fromdate default 1480447618")
fd = raw_input()
if fd =="":
fd = 1480447618
print("selected todate default 1480451001")
td = raw_input()
if td =="":
td = 1480451001
locationcallsbydatesort(loc,int(fd),int(td))
# except:
# print("")
# print("****** Problem with the report or report parameters. Please try again...")
# pass