Changeset 53
- Timestamp:
- 25/06/08 08:11:38 (7 months ago)
- Location:
- wirelessheatmap/trunk
- Files:
-
- 2 added
- 1 modified
-
ap.py (added)
-
dump2pickle.py (added)
-
heat.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wirelessheatmap/trunk/heat.py
r52 r53 12 12 13 13 from pyglet.window import key 14 from pyglet.window import mouse 14 15 from pyglet import window 15 16 from pyglet import image … … 17 18 from pyglet.gl import * 18 19 19 class AccessPoint(object): 20 21 def __init__(self, *bits): 22 bits = map(lambda a: a.strip(), bits) 23 self.bssid = bits[0] 24 self.first_seen = bits[1] 25 self.last_seen = bits[2] 26 self.channel = int(bits[3]) 27 self.speed = int(bits[4]) 28 self.privacy = bits[5] 29 self.cipher = bits[6] 30 self.auth = bits[7] 31 self.power = float(bits[8]) 32 self.beacons = int(bits[9]) 33 self.iv = bits[10] 34 self.ip = bits[11] 35 self.id_length = int(bits[12]) 36 self.essid = bits[13] 37 self.key = bits[14] 38 39 def __hash__(self): 40 return hash(self.bssid) 41 42 def __repr__(self): 43 return self.essid 44 20 from ap import AccessPoint 45 21 46 22 class Heat(object): … … 51 27 52 28 self.window = window.Window( 53 640, 580, 54 caption='Heat', \ 29 # 640, 480, 30 1024, 768, 31 # caption='Heat', \ 32 # fullscreen=True, 55 33 ) 56 34 self.window.on_mouse_press = self.on_mouse_press 35 self.window.on_mouse_drag = self.on_mouse_drag 36 self.window.on_mouse_scroll = self.on_mouse_scroll 57 37 self.window.on_key_release = self.on_key_release 58 38 59 39 self.current_ap = '' 40 41 # defaults before image loads 42 self.cellsize = 12 43 self.img_zoom = 1. 60 44 61 45 if self.cfg.image_file: 62 46 self.img = image.load(self.cfg.image_file) 47 self.img_zoom = float(self.window.width) / self.img.width 48 zoomier = float(self.window.height) / self.img.height 49 if zoomier < self.img_zoom: 50 self.img_zoom = zoomier 51 52 self.cellsize = self.img.width / 100 53 63 54 else: 64 55 self.img = None 65 56 66 self.img_pos = 0, 0 67 self.img_zoom = 1. 57 self.img_pos = [0., 0.] 68 58 69 59 self.font_size = 20 … … 74 64 self.last_dump_read = 0 75 65 76 self.cellsize = 1277 66 self.samples = 10 78 67 self.grid = {} 79 68 69 self.grid_margin = 100 # pixels surrounding the image 70 80 71 def parse_config(self): 81 72 self.cfg = ConfigParser() 82 self.opt = OptionParser( \ 83 usage='usage: %prog [options]') 73 self.opt = OptionParser(usage='usage: %prog [options]') 84 74 85 75 # Configuration loading and saving … … 163 153 self.window.clear() 164 154 165 glLoadIdentity()166 155 if self.current_ap: 167 156 self.calc_heat() 157 158 self.map_matrix() 168 159 self.draw_heat() 169 160 self.draw_strength() 170 161 162 glLoadIdentity() 171 163 self.draw_text('%s %s %f' % (self.current_ap, 172 164 self.ap[self.current_ap].essid, … … 174 166 175 167 if self.img: 168 self.map_matrix() 176 169 glEnable(GL_BLEND) 177 170 glBlendFunc(GL_SRC_ALPHA, GL_ONE) 178 glLoadIdentity() 179 glScalef(0.5, 0.5, 1) 180 glColor3f(1, 1, 1) 171 glColor4f(1, 1, 1, 0.5) 181 172 self.img.blit(0, 0) 182 173 glDisable(GL_BLEND) … … 185 176 self.window.dispatch_events() 186 177 # time.sleep(0.5) 187 178 179 def map_matrix(self): 180 glLoadIdentity() 181 glTranslatef(self.img_pos[0], self.img_pos[1], 0) 182 glScalef(self.img_zoom, self.img_zoom, 1) 183 184 def screen2map(self, x, y): 185 x -= self.img_pos[0] 186 y -= self.img_pos[1] 187 x /= self.img_zoom 188 y /= self.img_zoom 189 return x, y 190 188 191 def draw_strength(self): 189 192 if not self.current_ap: … … 205 208 glBegin(GL_POINTS) 206 209 for pos, strength in self.store[self.current_ap].items(): 207 s = (strength - min_str) / (max_str - min_str)210 s = 0.5 + (strength - min_str) / (max_str - min_str) 208 211 glColor3f(s, s, s) 209 212 glVertex2f(pos[0], pos[1], 0) … … 218 221 self.grid = {} 219 222 220 print 'calc' 221 222 for x in xrange(0, 400, self.cellsize): 223 224 for y in xrange(0, 800, self.cellsize): 223 gmin = -self.grid_margin 224 gmaxx = self.img.width + self.grid_margin 225 gmaxy = self.img.height + self.grid_margin 226 227 for x in range(gmin, gmaxx, self.cellsize): 228 for y in range(gmin, gmaxy, self.cellsize): 225 229 226 230 distance_strengths = [] … … 241 245 heat /= self.samples 242 246 self.grid[x, y] = heat 243 print 'calc done'244 247 245 248 def draw_heat(self): … … 248 251 max_heat = max(self.grid.values()) 249 252 min_heat = min(self.grid.values()) 250 251 253 if not max_heat: 252 254 return 253 if max_heat - min_heat == 0:255 if max_heat == min_heat: 254 256 return 255 257 … … 276 278 return colorsys.hsv_to_rgb((1 - val) * 2. / 3, 1, val * 0.6) 277 279 278 def on_mouse_press(self, x, y, buttons, modifiers): 279 for ap in self.ap.values(): 280 self.store[ap.bssid][x, y] = ap.power 281 self.save_data() 282 280 def on_mouse_press(self, x, y, button, modifiers): 281 if button == mouse.LEFT: 282 x, y = self.screen2map(x, y) 283 for ap in self.ap.values(): 284 self.store[ap.bssid][x, y] = ap.power 285 self.save_data() 286 287 def on_mouse_drag(self, x, y, dx, dy, button, modifiers): 288 if button == mouse.RIGHT: 289 self.img_pos[0] += dx 290 self.img_pos[1] += dy 291 292 def on_mouse_scroll(self, x, y, scroll_x, scroll_y): 293 if scroll_y > 0: 294 self.img_zoom /= 0.8 * scroll_y 295 if scroll_y < 0: 296 self.img_zoom *= 0.8 * -scroll_y 297 283 298 def on_key_release(self, symbol, mods): 284 299 self.grid = {}