-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
74 lines (51 loc) · 1.79 KB
/
user.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
71
72
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Library for defining a user. Each user should be defined with its identity, initial location and
speed, and virtual movement trajectory.
"""
__author__ = "Filip Lemic, Jakob Struye, Jeroen Famaey"
__copyright__ = "Copyright 2021, Internet Technology and Data Science Lab (IDLab), University of Antwerp - imec"
__version__ = "1.0.0"
__maintainer__ = "Filip Lemic"
__email__ = "filip.lemic@uantwerpen.be"
__status__ = "Development"
import numpy as np
import random
class User:
def __init__(self, initial_loc, initial_speed, identity):
if type(initial_loc) == list:
initial_loc = np.array(initial_loc)
self.identity = identity
self.initial_loc = initial_loc
self.speed = initial_speed
self.phy_locations = [initial_loc]
self.virt_locations = []
def get_phy_loc(self, offset=0):
return self.phy_locations[-1 + offset]
def get_virt_loc(self, offset=0):
return self.virt_locations[-1 + offset]
def fill_virtual_path(self, number_of_points, step, fixed_dir=None):
self.virt_locations.append(self.initial_loc)
# Filling the coordinates with random variables
for i in range(1, number_of_points):
val = random.randint(1, 4) if fixed_dir is None else fixed_dir # direction
newloc = np.array(self.virt_locations[-1])
if val == 1: #right
newloc[0] += step
elif val == 2: #left
newloc[0] -= step
elif val == 3: #up
newloc[1] += step
else: #down
newloc[1] -= step
self.virt_locations.append(newloc)
# The goal is to return a 1-dimensional list to be reshaped later on for short-term predictions
def get_phy_path(self):
dataset = {}
dataset['phy_x'] = []
dataset['phy_y'] = []
for i in self.phy_locations:
dataset['phy_x'].append(i[0])
dataset['phy_y'].append(i[1])
return dataset