-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerLogEntry.py
More file actions
executable file
·47 lines (42 loc) · 1.36 KB
/
ServerLogEntry.py
File metadata and controls
executable file
·47 lines (42 loc) · 1.36 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
#!/usr/bin/python
class ServerLogEntry:
''' class to encapsule data from webserver logs.
one object equates to one line of a text log.
'''
def __init__(self, t=None, line=None):
if line:
t = line.strip().split()
self.cookie_uid = int(t[0])
self.webpage_uid = int(t[1])
self.utc_time = int(t[2])
@staticmethod
def header_line():
row = ['cookie_uid', 'webpage_uid', 'utc_time']
return '\t'.join(row)
@property
def row(self):
return (self.cookie_uid, self.webpage_uid, self.utc_time)
def __repr__(self):
return str(self.row)
def __str__(self):
return '\t'.join(map(str, self.row))
def simulate_data():
''' simulate some entries from a web server log
'''
# set some simulation parameters
sample_size = 10**4
number_of_cookie_uids = 10**1
number_of_webpage_uids = 10**2
(min_time, max_time) = (0, 10**4)
# conditional import because of Jython errors
import random
def simulate_single_sample():
cookie_uid = random.randrange(number_of_cookie_uids)
webpage_uid = random.randrange(number_of_webpage_uids)
utc_time = random.randrange(min_time, max_time)
return ServerLogEntry(t=(cookie_uid, webpage_uid, utc_time))
# run the simulation
return [simulate_single_sample() for i in range(sample_size)]
if __name__ == '__main__':
for r in simulate_data():
print r