9
9
10
10
# Define the mapping for the index
11
11
mapping = {
12
+
12
13
"mappings" : {
13
14
"properties" : {
14
15
"deviceId" : {"type" : "text" },
19
20
"store" : True
20
21
},
21
22
"message" : {"type" : "text" }
22
- }
23
- },
24
- "settings" : {
25
- "index.mapping.total_fields.limit" : 2000 ,
26
- "date_detection" : True ,
23
+ },
27
24
"dynamic_templates" : [
28
25
{
29
26
"timestamps" : {
35
32
}
36
33
}
37
34
}
38
- ]
35
+ ],
36
+ "date_detection" : True
37
+ },
38
+ "settings" : {
39
+ "index.mapping.total_fields.limit" : 2000
39
40
}
40
41
}
41
42
43
+
42
44
# Delete index if it exists
43
- if es .indices .exists (index = "test_time " ):
44
- es .indices .delete (index = "test_time " )
45
+ if es .indices .exists (index = "tes_time " ):
46
+ es .indices .delete (index = "tes_time " )
45
47
46
48
# Create the index with the defined mapping
47
- es .indices .create (index = "test_time " , body = mapping )
49
+ es .indices .create (index = "tes_time " , body = mapping )
48
50
49
51
# Define the STB devices and user profiles
50
52
deviceIds = [f'ZX98763{ i :02d} ' for i in range (1 , 10 )]
55
57
channel_suffixes = ["Network" , "Channel" , "Central" , "World" , "Planet" , "Hub" ]
56
58
57
59
channels = {}
58
- for i in range (100 ):
60
+ for i in range (80 ):
59
61
channel_name = f"{ random .choice (channel_prefixes )} { random .choice (channel_suffixes )} { i + 1 } "
60
62
channels [i + 1 ] = {'lcn' : f'LCN{ i + 1 :03d} ' , 'channel_name' : channel_name }
61
63
@@ -127,7 +129,7 @@ def simulate_device(device_id):
127
129
current_user_age = random .choice (user_profiles [device_id ])
128
130
129
131
# STB is powered on
130
- es .index (index = "test_time " ,
132
+ es .index (index = "tes_time " ,
131
133
id = f'{ device_id } _powered_on_{ session_id } ' ,
132
134
document = generate_log (device_id , current_user_age , "Powered On" , channel = device_channels [device_id ],
133
135
volume = device_volumes [device_id ]))
@@ -136,7 +138,7 @@ def simulate_device(device_id):
136
138
# Generate heartbeat events for 1-2 hours
137
139
end_time = time .time () + 60 * 60 * random .randint (1 , 2 )
138
140
while time .time () < end_time :
139
- es .index (index = "test_time " ,
141
+ es .index (index = "tes_time " ,
140
142
id = f'{ device_id } _heartbeat_{ session_id } ' ,
141
143
document = generate_log (device_id , current_user_age , "Heartbeat" , channel = device_channels [device_id ],
142
144
volume = device_volumes [device_id ]))
@@ -148,20 +150,20 @@ def simulate_device(device_id):
148
150
if event_type == "Channel Zap" :
149
151
channel = select_channel_based_on_age (current_user_age )
150
152
device_channels [device_id ] = channel
151
- es .index (index = "test_time " ,
153
+ es .index (index = "tes_time " ,
152
154
id = str (uuid .uuid4 ()), # Random Elasticsearch ID
153
155
document = generate_log (device_id , current_user_age , event_type , channel = channel ))
154
156
elif event_type == "Volume change" :
155
157
old_volume = device_volumes [device_id ]
156
158
new_volume = random .randint (0 , 100 ) # Assuming STB volume range is 0-100
157
159
device_volumes [device_id ] = new_volume
158
- es .index (index = "test_time " ,
160
+ es .index (index = "tes_time " ,
159
161
id = str (uuid .uuid4 ()), # Random Elasticsearch ID
160
162
document = generate_log (device_id , current_user_age , event_type , volume = new_volume ,
161
163
old_volume = old_volume ))
162
164
elif event_type == "Profile Change" :
163
165
current_user_age = random .choice (user_profiles [device_id ])
164
- es .index (index = "test_time " ,
166
+ es .index (index = "tes_time " ,
165
167
id = str (uuid .uuid4 ()), # Random Elasticsearch ID
166
168
document = generate_log (device_id , current_user_age , event_type ))
167
169
0 commit comments