-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweighted_average.py
More file actions
65 lines (50 loc) · 1.83 KB
/
weighted_average.py
File metadata and controls
65 lines (50 loc) · 1.83 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
Accepts a heatmap and generates a single point that represents the average
location of the occupant over a certain period of time.
"""
# language imports
import sys
import string
import math
# library imports
import matplotlib.pyplot as plt
import numpy as np
# Constants
ARBITRARY_LARGE_NUMBER = 9999
from heatmap import Heatmap
class WeightedAverage():
"""
Given a heatmap, returns a point on the grid corresponding to the
average location of the occupant over a certain period of time
"""
def __init__(self, heatmap):
# constants
self.map_width = 9.0 # in meters
self.map_height = 6.0 # in meters
self.map_resolution = 0.125
self.number_of_sensors = 0
self.heatmap = heatmap
self.result = (0, 0)
def get_weighted_average_point(self):
x_average = 0
y_average = 0
# self.heatmap = self.heatmap.get_heatmap_array()
self.heatmap = self.heatmap.get_normalized_heatmap()
for x_index in range(len(self.heatmap)):
for y_index in range(len(self.heatmap[0])):
if (self.heatmap[x_index][y_index] != 0):
x_average += (x_index * self.heatmap[x_index][y_index])
y_average += (y_index * self.heatmap[x_index][y_index])
weighted_average_point = (x_average, y_average)
self.result = weighted_average_point
return weighted_average_point
def display_all(self):
heatmap_array = self.heatmap.get_heatmap_array()
np_heatmap = np.array(heatmap_array)
plt.plot(self.result[0], self.result[1], 'go')
axis = plt.gca()
plt.imshow(np.transpose(np_heatmap),
cmap='hot', interpolation='nearest')
axis.set_ylim(axis.get_ylim()[::-1])
plt.show()