This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathteacherperformance-noindex.py
77 lines (67 loc) · 2.85 KB
/
teacherperformance-noindex.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
# Find students within a country
# A Cloud Guru - Dynamo DB Course\
# USES V3 DATA MODEL
import boto3, botocore, tqdm, random, time
from time import gmtime, strftime
from boto3.dynamodb.conditions import Attr
from botocore.exceptions import ClientError
from sys import version_info
py3 = version_info[0] > 2 #creates boolean value for test that Python major version > 2
lesson = '4-014' ## UDPATE ME
loadmin_session = boto3.Session(profile_name='loadmin')
db_c = loadmin_session.client('dynamodb')
db_r = loadmin_session.resource('dynamodb')
## PREREQS - images/ folder in same directory as this scripts
## configured AWS tools
## installed python2.7+
## installed boto3 (pip install boto3)
## Installed faker module
## Installed tqdm module
## 'loadmin' AWS configuration profile - with admin rights
## Data Model v2 loaded.
## _retry.json file from lesson files - adjusted for 1mil+ auto retries
## for retryable operations
if __name__ == "__main__":
teacher_id = ""
capacityconsumed = 0
scannedcount = 0
while True:
if py3:
teacher_id = str(input('Enter a teacher ID: '))
else:
teacher_id = str(raw_input('Enter a teacher ID: '))
if teacher_id !="":
break
## END WHILE LOOP
starttime = time.time()
response=db_r.Table("lo_exams").scan(\
ReturnConsumedCapacity='TOTAL', \
ExpressionAttributeValues={':teacher_id' : teacher_id}, \
FilterExpression="t_id = :teacher_id" \
)
capacityconsumed = response['ConsumedCapacity']['CapacityUnits']
scannedcount = response['ScannedCount']
data=response['Items']
while 'LastEvaluatedKey' in response:
#print "hi"
response=db_r.Table("lo_exams").scan(\
ReturnConsumedCapacity='TOTAL', \
ExpressionAttributeValues={':teacher_id' : teacher_id}, \
ExclusiveStartKey=response['LastEvaluatedKey'], \
FilterExpression="t_id = :teacher_id" \
)
#print response
capacityconsumed = capacityconsumed + response['ConsumedCapacity']['CapacityUnits']
scannedcount = scannedcount + response['ScannedCount']
data.extend(response['Items'])
totalgrade=0
for d in data:
totalgrade = totalgrade + int(d['grade'])
average=totalgrade / int(len(data)+1)
finishtime=time.time()
timetocomplete = finishtime - starttime
print "Script Started on %s, finished on %s, took %0.2fs to complete without indexes" % (time.ctime(starttime),\
time.ctime(finishtime), timetocomplete)
print "Operation required %i capacity units to complete" % capacityconsumed
print "Total number of items scanned [%i]" % scannedcount
print "Average performance for teacher [%s] is %.2f percent over %i exams " % (teacher_id, average, int(len(data)))