Package mosp :: Module monitors :: Class SocketPlayerMonitor
[hide private]
[frames] | no frames]

Class SocketPlayerMonitor

source code


Sends output of simulation to viewer via sockets.


Author: P. Tute

Instance Methods [hide private]
new empty list
__init__(self, name, sim, tick, kwargs)
Initialize the monitor.
source code
 
init(self)
Send coordinates to center camera on and start observing.
source code
 
end(self)
Send a signal to the viewer to announce simulation end.
source code
 
observe(self)
Send person coordinates and other data to draw them as points.
source code
 
center_on_lat_lon(self, lat, lon)
Center the connected viewer on specified coordinates.
source code
 
parse_color(self, color)
Determine the way color is defined and return an RGBA-tuple.
source code
 
draw_point(self, id, lat, lon, radius, color, ttl=0)
Send a point to be drawn to the viewer.
source code
 
draw_circle(self, id, center_lat, center_lon, radius, filled, color, ttl=0)
Send a circle to be drawn to the viewer.
source code
 
draw_rectangle(self, id, lat_bottom, lat_top, lon_left, lon_right, line_width, filled, color, ttl=0)
Send a rectangle to be drawn to the viewer.
source code
 
draw_triangle(self, id, lat1, lon1, lat2, lon2, lat3, lon3, filled, color, ttl=0)
Send a triangle to be drawn to the viewer.
source code
 
draw_text_to_screen(self, id, x, y, font_size, color, text, ttl=0)
Draw a text in the viewer.
source code
 
draw_text(self, id, lat, lon, offset_x, offset_y, font_size, color, text, ttl=0)
Draw a text in the viewer.
source code
 
add_heatmap_blip(self, lat, lon, radius, color)
Draw another heatmap-blip in the viewer.
source code
 
remove_object(self, type, id)
Remove a drawing object from the viewer.
source code

Inherited from SimPy.Lib.Process: acquired, active, cancel, interrupt, interruptReset, interrupted, passive, queuing, start, stored, terminated

Inherited from SimPy.Lib.Process (private): _hold, _passivate

Inherited from SimPy.Lister.Lister: __repr__, __str__, attrnames

Inherited from list: __add__, __contains__, __delitem__, __delslice__, __eq__, __ge__, __getattribute__, __getitem__, __getslice__, __gt__, __iadd__, __imul__, __iter__, __le__, __len__, __lt__, __mul__, __ne__, __new__, __reversed__, __rmul__, __setitem__, __setslice__, __sizeof__, append, count, extend, index, insert, pop, remove, reverse, sort

Inherited from object: __delattr__, __format__, __reduce__, __reduce_ex__, __setattr__, __subclasshook__

Class Variables [hide private]
  MESSAGES = {'circle': '\x03', 'coords': '\x00', 'delete': '\xf...
  FORMATS = {'circle': '!iddi?4dd', 'coords': '!dd', 'delete': '...
  start_tick = 0

Inherited from SimPy.Lister.Lister: indent

Inherited from list: __hash__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name, sim, tick, kwargs)
(Constructor)

source code 

Initialize the monitor.

Parameters:
  • name - unique string name of monitor
  • sim - reference to simulation
  • tick - monitoring is done every tick ticks
  • kwargs - additional keyword arguments for monitor
Returns: new empty list
Overrides: object.__init__

init(self)

source code 

Send coordinates to center camera on and start observing.

Overrides: EmptyMonitor.init

end(self)

source code 

Send a signal to the viewer to announce simulation end.

Overrides: EmptyMonitor.end

observe(self)

source code 

Send person coordinates and other data to draw them as points.

Overrides: EmptyMonitor.observe

center_on_lat_lon(self, lat, lon)

source code 

Center the connected viewer on specified coordinates.

Parameters:
  • lat (float) - Latitude to center on
  • lon (float) - Longitude to center on
Overrides: EmptyMonitor.center_on_lat_lon

parse_color(self, color)

source code 

Determine the way color is defined and return an RGBA-tuple.

Parameters:
  • color (string containing the name of a color, or tuple with 4 floats in range [0,1]) - The color that is to be parsed

draw_point(self, id, lat, lon, radius, color, ttl=0)

source code 

Send a point to be drawn to the viewer.

Parameters:
  • id (int) - ID of the drawn point. Should be unique or another point will be replaced.
  • lat (float) - Latitude to draw point at.
  • lon (float) - Longitude to draw point at.
  • radius (int) - A radius of 0 means a size of one pixel. A radius of n means n pixels will be drawn in each direction around the center-pixel.
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the point in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.
Overrides: EmptyMonitor.draw_point

draw_circle(self, id, center_lat, center_lon, radius, filled, color, ttl=0)

source code 

Send a circle to be drawn to the viewer.

Parameters:
  • id (int) - ID of the drawn circle. Should be unique or another circle will be replaced.
  • center_lat (float) - Latitude to center circle at.
  • center_lon (float) - Longitude to center circle at.
  • radius (int) - Radius of the circle, in meter
  • filled (boolean) - Signals whether the circle should be filled or hollow.
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the circle in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.
Overrides: EmptyMonitor.draw_circle

draw_rectangle(self, id, lat_bottom, lat_top, lon_left, lon_right, line_width, filled, color, ttl=0)

source code 

Send a rectangle to be drawn to the viewer.

Parameters:
  • id (int) - ID of the drawn rectangle. Should be unique or another rectangle will be replaced.
  • lat_top (float) - Latitude of top of the rectangle.
  • lat_bottom (float) - Latitude of bottom of the rectangle.
  • lon_left (float) - Longitude of left side of rectangle.
  • lon_right (float) - Longitude of right side of rectangle.
  • line_width (int) - thickness of the lines of the rectangle, if it is not filled
  • filled (boolean) - Signals whether the rectangle should be filled or hollow.
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the rectangle in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.
Overrides: EmptyMonitor.draw_rectangle

draw_triangle(self, id, lat1, lon1, lat2, lon2, lat3, lon3, filled, color, ttl=0)

source code 

Send a triangle to be drawn to the viewer.

Parameters:
  • id (int) - ID of the drawn triangle. Should be unique or another triangle will be replaced.
  • lat1 (float) - Latitude of the first corner of the triangle.
  • lon1 (float) - Longitude of first corner of triangle.
  • lat2 (float) - Latitude of the second corner of the triangle.
  • lon2 (float) - Longitude of second corner of triangle.
  • lat3 (float) - Latitude of the third corner of the triangle.
  • lon3 (float) - Longitude of third corner of triangle.
  • filled (boolean) - Signals whether the triangle should be filled or hollow.
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the triangle in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.

draw_text_to_screen(self, id, x, y, font_size, color, text, ttl=0)

source code 

Draw a text in the viewer.

This method uses x, y coordinates of the player instead of lat/lon. It can be used to permanently draw something on the viewer window. IDs are no shared with normal text-IDs.

Parameters:
  • id (int) - Should be unique or another text will be replaced.
  • x (int) - x-coordinate of left side of the text, negative value means 'from right' instead of 'from left' (positive value) of screen
  • y (int) - y-coordinate of bottom side of text, negative value means 'from top' instead of 'from bottom' (positive value) of screen
  • font_size (int) - Fontsize in points
  • text (string) - The actual text to display in the viewer
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the rectangle in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.

draw_text(self, id, lat, lon, offset_x, offset_y, font_size, color, text, ttl=0)

source code 

Draw a text in the viewer.

Parameters:
  • id (int) - Should be unique or another text will be replaced.
  • lat (float) - Latitude of bottom of the text
  • lon (float) - Longitude of left side of text
  • offset_x (int) - An offset added to the given coordinates, specified in meters
  • offset_y (int) - An offset added to the given coordinates, specified in meters
  • font_size (int) - Fontsize in points
  • text (string) - The actual text to display in the viewer
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.
  • ttl (int) - Specifies a time to live for the rectangle in seconds. 0 means infinite lifetime (default). After the given time, the point will be removed.
Overrides: EmptyMonitor.draw_text

add_heatmap_blip(self, lat, lon, radius, color)

source code 

Draw another heatmap-blip in the viewer.

Parameters:
  • lat (float) - Latitude to draw point at.
  • lon (float) - Longitude to draw point at.
  • radius (int) - A radius of 0 means a size of one pixel. A radius of n means n pixels will be drawn in each direction around the center-pixel.
  • color (4-tuple containing RGBA-colors as floats in range [0, 1] or string) - Has to be a tupel with 4 floats in the range of 0 to 1, representing rgba-color; or can be a string containing the name of a color.

remove_object(self, type, id)

source code 

Remove a drawing object from the viewer.

Parameters:
  • type (string) - The type of the object to be removed (e. g. 'rectangle')
  • id (int) - ID of the object to be removed
Overrides: EmptyMonitor.remove_object

Class Variable Details [hide private]

MESSAGES

Value:
{'circle': '\x03',
 'coords': '\x00',
 'delete': '\xfd',
 'direct-text': '\x07',
 'draw': '\xfe',
 'heatmap': '\x06',
 'point': '\x01',
 'rectangle': '\x02',
...

FORMATS

Value:
{'circle': '!iddi?4dd',
 'coords': '!dd',
 'delete': '!i',
 'direct-text': '!iiii4did',
 'heatmap': '!ddi4d',
 'point': '!iddi4dd',
 'rectangle': '!i4di?4dd',
 'text': '!iddiii4did',
...