|
@@ -0,0 +1,48 @@
|
|
1
|
+from threading import Timer
|
|
2
|
+
|
|
3
|
+#Once an hour has passed, this function erases the hash table of
|
|
4
|
+#event ids
|
|
5
|
+def prevent_overflow():
|
|
6
|
+ global hash_EventID
|
|
7
|
+ hash_EventID = {}
|
|
8
|
+ #Starts the timer once again. (First argument is time in seconds)
|
|
9
|
+ Timer(60*60, prevent_overflow).start()
|
|
10
|
+
|
|
11
|
+#This function recieves from an Event, its ID and Data payload;
|
|
12
|
+#If that id has not been received before, it calles the Function
|
|
13
|
+# processEventsWithoutDuplicates
|
|
14
|
+def processEvents(EventId, EventData):
|
|
15
|
+ if EventID not in hash_EventID:
|
|
16
|
+ processEventsWithoutDuplicates(EventID, EventData)
|
|
17
|
+ hash_EventID[EventID] = 1
|
|
18
|
+
|
|
19
|
+#This function does something with the events that are not duplicated
|
|
20
|
+def processEventsWithoutDuplicates(EventId, EventData):
|
|
21
|
+ pass
|
|
22
|
+
|
|
23
|
+def main():
|
|
24
|
+ #hash structure to record the event ids
|
|
25
|
+ hash_EventID = {}
|
|
26
|
+ #create a thread of a timer.
|
|
27
|
+ #once it ends, it will call the function prevent_overflow
|
|
28
|
+ Timer(60*60, prevent_overflow).start()
|
|
29
|
+
|
|
30
|
+ #iterator receiving the data and calling the processEvents function
|
|
31
|
+ for elem in data_stream:
|
|
32
|
+ #take the event id and data payload
|
|
33
|
+ data = data_object(elem)
|
|
34
|
+ processEvents(data.eventid, data.eventdata)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+processEvents 1 , data
|
|
40
|
+processEvents 2 , data
|
|
41
|
+processEvents 3 , data
|
|
42
|
+processEvents 1 , data
|
|
43
|
+processEvents 1 , data
|
|
44
|
+
|
|
45
|
+expectation
|
|
46
|
+processEventsWithoutDuplicates 1 , data
|
|
47
|
+processEventsWithoutDuplicates 2 , data
|
|
48
|
+processEventsWithoutDuplicates 3 , data
|