-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataGenerator.py
70 lines (49 loc) · 1.69 KB
/
DataGenerator.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
import random
import time
from Caching import GetCacheKey,GetCacheData,SetCacheData
'''
===========================================================================================
'''
totalRecords = 1000000
def generateName():
namePrefixes = ["M","N","Z","Y","X"]
nameIds = range(1,10)
name = random.choice(namePrefixes) + str(random.choice(nameIds))
return name
def generateId():
ids = range(1,20)
return random.choice(ids)
def generateLevel():
levels = ["Architect","Developer","Sr Developer","Manager","Director","Ceo"]
return random.choice(levels)
def generateTraits():
traits = ["excellent","good","fair"]
return random.choices(traits,k=2)
'''
===========================================================================================
'''
'''
Generate the Cache Key (Using Selective Data)
'''
def generateData(primaryKeyDictionary:dict,cache_key:str):
print("Generate or Fetch Cached Data")
start = time.time() # time profiling
key = GetCacheKey(primaryKeyDictionary,cache_key)
cacheData = GetCacheData(key)
if cacheData is not None:
print("Data Generation Time (Cached) % s seconds" % (time.time() - start))
return cacheData
else:
cacheData = []
gdCounter = 1
while gdCounter <= 1000000:
d = dict()
d["id"] = generateId()
d["name"] = generateName()
d["level"] = generateLevel()
d["traits"] = generateTraits()
cacheData.append(d)
gdCounter = gdCounter + 1
SetCacheData(key,cacheData)
print("Data Generation Time (DB) % s seconds" % (time.time() - start))
return cacheData