state = r.hgetall(source_ip)
representation = None
if state:
representation = json.loads(state[b"representation"].decode("ascii"))
prev_time = float(state[b"time"])
if representation is None:
prev_time = None
representation = np.zeros(representations.shape[1])
for i, rep in enumerate(representations):
time = timestamps[i].timestamp()
if prev_time is None:
representation = rep
prev_time = time
elif time > prev_time:
time_diff = time - prev_time
alpha = 1 - np.exp(-time_diff/time_const)
representation += alpha*(rep - representation)
prev_time = time
state = {"time": time, "representation": list(representation)}
r.hmset(source_ip, state)
if __name__ == "__main__":
// path to the pcap to get the update from