コード例 #1
0
    def test_7_director_translation(self):
        panoid = "1234asdf4321fdsa"
        director_msg = GenericMessage()
        director_msg.type = 'json'
        director_msg.message = """
                {
                      "description":"",
                      "duration":30,
                      "name":"Browser service test",
                      "resource_uri":"/director_api/scene/browser-service-test/",
                      "slug":"browser-service-test",
                      "windows":[
                        {
                        "activity":"streetview",
                        "assets":["%s", "foo", "bar"],
                        "height":600,
                        "presentation_viewport":"center",
                        "width":800,
                        "x_coord":100,
                        "y_coord":100
                        }
                        ]
                    }
        """ % panoid

        # get existing asset
        asset = get_first_asset_from_activity(
            load_director_message(director_msg), "streetview")
        self.assertEqual(asset, panoid, 'Invalid asset returned')
        # get non existing asset
        asset = get_first_asset_from_activity(
            load_director_message(director_msg), "panoview")
        self.assertEqual(asset, None, 'No asset should have been returned')

        self.check_soft_relaunch()
コード例 #2
0
    def setUp(self):
        """
        - check whether bridge translates json with director message to proper message for 2 viewports
        - two messages should be sent:
            - bogus message - no director should catch that
            - message addressed to center viewport
        """
        self.message_bogus = GenericMessage()
        self.message_bogus.type = 'json'
        self.message_bogus.message = DIRECTOR_MESSAGE_BOGUS

        self.message_center = GenericMessage()
        self.message_center.type = 'json'
        self.message_center.message = DIRECTOR_MESSAGE_CENTER

        self.message_3 = GenericMessage()
        self.message_3.type = 'json'
        self.message_3.message = DIRECTOR_MESSAGE_CENTER_3

        self.mock_publisher_center = MockBrowserPoolPublisher()
        self.mock_publisher_right = MockBrowserPoolPublisher()
        self.mock_aggregate_publisher_center = MockAggregatePublisher()
        self.mock_aggregate_publisher_right = MockAggregatePublisher()
        self.bridge_center = AdhocBrowserDirectorBridge(
            self.mock_aggregate_publisher_center,
            self.mock_publisher_center,
            'center'
        )
        self.bridge_right = AdhocBrowserDirectorBridge(
            self.mock_aggregate_publisher_right,
            self.mock_publisher_right,
            'right'
        )
コード例 #3
0
    def test_7_director_translation(self):
        panoid = "1234asdf4321fdsa"
        director_msg = GenericMessage()
        director_msg.type = 'json'
        director_msg.message = """
                {
                      "description":"",
                      "duration":30,
                      "name":"Browser service test",
                      "resource_uri":"/director_api/scene/browser-service-test/",
                      "slug":"browser-service-test",
                      "windows":[
                        {
                        "activity":"streetview",
                        "assets":["%s", "foo", "bar"],
                        "height":600,
                        "presentation_viewport":"center",
                        "width":800,
                        "x_coord":100,
                        "y_coord":100
                        }
                        ]
                    }
        """ % panoid

        # get existing asset
        asset = get_first_asset_from_activity(
            load_director_message(director_msg), "streetview")
        self.assertEqual(asset, panoid, 'Invalid asset returned')
        # get non existing asset
        asset = get_first_asset_from_activity(
            load_director_message(director_msg), "panoview")
        self.assertEqual(asset, None, 'No asset should have been returned')

        self.check_soft_relaunch()
コード例 #4
0
ファイル: add_kml.py プロジェクト: EndPointCorp/lg_ros_nodes
    def handle_kml(self, msg):
        kml = msg.data

        filename = tempfile.mktemp(dir=self.serve_dir)
        with open(filename, 'w') as f:
            f.write(kml)
        
        kml_id = get_kml_id(kml)
        if kml_id not in self.id_to_file:
            self.id_to_file[kml_id] = list()
        
        # Keep track of files for easier remove by id
        self.id_to_file[kml_id].append(os.path.basename(filename))

        current_scene = self.uscs_service.call().message
        current_scene = json.loads(current_scene)
        self.add_earths(current_scene)
        for window in current_scene['windows']:
            if window['activity'] != 'earth':
                continue
            window['assets'].append(self.formatURL(filename))
        new_msg = GenericMessage()
        new_msg.type = 'json'
        new_msg.message = json.dumps(current_scene)
        self.director_pub.publish(new_msg)
        self.added_kml_pub.publish(StringArray(list(self.id_to_file.keys())))
コード例 #5
0
ファイル: add_kml.py プロジェクト: EndPointCorp/lg_ros_nodes
    def clear_kmls(self, msg):
        current_scene = self.uscs_service.call().message
        current_scene = json.loads(current_scene)

        ids = msg.strings if msg.strings else None

        if ids:
            files = []
            for id in ids:
                if id in self.id_to_file:
                    for names in self.id_to_file.pop(id):
                        if type(names) == list:
                            for name in names:
                                files.append(name)
                        else:
                            files.append(names)
            
            urls_to_remove = [self.formatURL(filename) for filename in files]
            matcher = get_match_any_starts_with(urls_to_remove)
        else:
            # Remove all additional kmls
            self.id_to_file = dict()
            matcher = get_match_any_starts_with([self.formatURLPrefix()])
        
        for window in current_scene['windows']:
            if window['activity'] == 'earth':
                window['assets'] = [a for a in window['assets'] if not matcher(a)]
        
        new_msg = GenericMessage()
        new_msg.type = 'json'
        new_msg.message = json.dumps(current_scene)
        self.director_pub.publish(new_msg)
        self.added_kml_pub.publish(StringArray(list(self.id_to_file.keys())))
コード例 #6
0
 def _create_message(self, msg_string):
     message = GenericMessage()
     message.type = 'json'
     try:
         message_json = json.loads(msg_string)
         message.message = json.dumps(message_json)
         return message
     except ValueError:
         print "Could not decode json message from InteractiveSpacesMessagesFactory"
         sys.exit(1)
コード例 #7
0
 def make_director(self, uscs_message):
     # makes a generic message and returns it
     ret = GenericMessage()
     ret.type = 'json'
     try:
         ret.message = json.dumps(uscs_message)
     except:
         rospy.logerr('Could not dump state message into json...')
         ret.message = ''
     return ret
コード例 #8
0
 def make_director(self, uscs_message):
     # makes a generic message and returns it
     ret = GenericMessage()
     ret.type = 'json'
     try:
         ret.message = json.dumps(uscs_message)
     except:
         rospy.logerr('Could not dump state message into json...')
         ret.message = ''
     return ret
コード例 #9
0
 def _create_message(self, msg_string):
     message = GenericMessage()
     message.type = 'json'
     try:
         message_json = json.loads(msg_string)
         message.message = json.dumps(message_json)
         return message
     except ValueError:
         print "Could not decode json message from InteractiveSpacesMessagesFactory"
         sys.exit(1)
コード例 #10
0
 def _create_message(self, msg_string):
     message = GenericMessage()
     message.type = 'json'
     try:
         message_json = json.loads(msg_string)
         message.message = json.dumps(message_json)
         return message
     except ValueError:
         message = "Could not decode json message for msg_string: %s" % msg_string
         rospy.logerr(message)
         sys.exit(1)
コード例 #11
0
 def _create_message(self, msg_string):
     message = GenericMessage()
     message.type = 'json'
     try:
         message_json = json.loads(msg_string)
         message.message = json.dumps(message_json)
         return message
     except ValueError:
         message = "Could not decode json message for msg_string: %s" % msg_string
         rospy.logerr(message)
         sys.exit(1)
コード例 #12
0
 def test_get_slot_value(self):
     # prepare message for testing, as if it was received (incoming message)
     in_msg = GenericMessage(type="json", message="{}")
     p = Processor(watched_topic="/director/scene", msg_slot="message.slug")
     # test the same on a lower level
     # empty messages are fine - we just ignore them - dont make them raise exceptions
     # pytest.raises(EmptyIncomingMessage, p._get_slot_value, in_msg)
     subslot = json.loads(real_in_msg_director_scene)["message"]
     in_msg = GenericMessage(type="json", message=json.dumps(subslot))
     assert subslot['slug'] == p._get_slot_value(in_msg)
     in_msg = Session(application="someapplication1")
     p = Processor(watched_topic="loll", msg_slot="application")
     assert p._get_slot_value(in_msg) == "someapplication1"
コード例 #13
0
    def test_get_data_for_influx(self):
        # prepare message for testing, as if it was received (incoming message)
        slot = json.loads(real_in_msg_director_scene)["message"]
        in_msg = GenericMessage(type="json", message=json.dumps(slot))

        # get outgoing message (to /lg_stats/debug) - via Processor instance
        p = Processor(watched_topic="/director/scene",
                      msg_slot="message.slug",
                      strategy="default")

        out_msg = p._get_outbound_message(in_msg)
        whole_field_name = "message.slug"  # depends on the particular message type above

        # now finally test the method of submitters:
        influx = InfluxDirect.get_data_for_influx(out_msg, 'test')
        assert isinstance(influx, dict)
        assert influx["tags"]["topic"] == p.watched_topic
        assert influx["tags"]["field_name"] == whole_field_name
        assert influx["tags"][
            "metadata"] == "bbb94866-2216-41a2-83b4-13ba35a3e9dc__scene-3-1"
        # real InfluxTelegraf.get_timestamp requires ROS init_node, this is a work-around
        InfluxTelegraf.get_timestamp = staticmethod(InfluxMock.get_timestamp)
        influx = InfluxTelegraf.get_data_for_influx(out_msg, 'test')
        assert isinstance(influx, str)
        assert p.watched_topic in influx
        assert influx.find("field_name=\"%s\"" % whole_field_name) > -1
        assert influx.find("metadata=\"%s\"" % out_msg.metadata) > -1
        # this mock just calls InfluxTelegraf - do the same assertions
        influx = InfluxMock.get_data_for_influx(out_msg, 'test')
        assert isinstance(influx, str)
        assert p.watched_topic in influx
        assert influx.find("field_name=\"%s\"" % whole_field_name) > -1
        assert influx.find("metadata=\"%s\"" % out_msg.metadata) > -1
コード例 #14
0
    def send_director_scene(self):
        """
        Check stats handling of /director/scene messages.
        By sending this kind of message, trigger the stats message on /lg_stats/debug.

        """
        rospy.init_node(ROS_NODE_NAME, anonymous=True)
        msg = GenericMessage(type="json", message="""{"slug": "something"}""")
        pub = rospy.Publisher("/director/scene", GenericMessage, queue_size=3)
        self.checker(pub, msg, "something")
        # test with another (real) message
        RESULT.value = "UNDEFINED"
        slot = json.loads(real_in_msg_director_scene)["message"]
        msg = GenericMessage(type="json", message=json.dumps(slot))
        self.checker(pub, msg,
                     "bbb94866-2216-41a2-83b4-13ba35a3e9dc__scene-3-1")
コード例 #15
0
 def test_background_submission_thread(self):
     msg = GenericMessage(type="json",
                          message="""{"slug": "something1234"}""")
     pub = MockTopicPublisher()
     influx = InfluxMock()
     p = Processor(watched_topic="/director/scene",
                   msg_slot="message.slug",
                   inactivity_resubmission=1,
                   influxdb_client=influx,
                   debug_pub=pub)
     # do the thread testing without ROS intervening
     # without rospy.init_node ... and without threading too ...
     # just invoke the thread worker method
     # nothing has been processed by the processor
     assert p.time_of_last_in_msg is None
     assert p.last_in_msg is None
     # as if the message was received on the ROS topic
     p.process(msg)
     # check that it was correctly processed
     assert len(p.debug_pub.messages) == 1
     assert len(p.influxdb_client.messages) == 1
     assert p.debug_pub.messages[0].field_name == "message.slug"
     assert p.debug_pub.messages[0].metadata == "something1234"
     assert "/director/scene" in p.influxdb_client.messages[0]
     # how run the thread worker - directly, wait before - there is a time check
     time.sleep(2)
     p._resubmit_worker()
     assert len(p.debug_pub.messages) == 2
     assert len(p.influxdb_client.messages) == 2
     assert p.debug_pub.messages[1].field_name == "message.slug"
     assert p.debug_pub.messages[1].metadata == "something1234"
     assert "/director/scene" in p.influxdb_client.messages[1]
コード例 #16
0
ファイル: attract_loop.py プロジェクト: johnjsb/lg_ros_nodes
    def _publish_blank_scene(self):
        """
        Emits a scene with empty windows to clean up all assets from screens
        """
        rospy.loginfo("Playing blank scene")

        viewports = [viewport.split('/')[2] for viewport in params.get_param_names() if '/viewport/' in viewport]

        scene = {
            "description": "attract loop blank scene",
            "duration": 666,
            "name": "attract loop blank scene",
            "resource_uri": "no uri",
            "slug": "attract-loop-break",
            "windows": []
        }

        for viewport_name in viewports:
            window = {
                "assets": [],
                "y_coord": 666,
                "x_coord": 666,
                "height": 666,
                "width": 666,
                "activity": "no_activity",
                "presentation_viewport": viewport_name
            }
            scene['windows'].append(window)

        scene_msg = GenericMessage(type='json', message=json.dumps(scene))
        self.director_scene_publisher.publish(scene_msg)
コード例 #17
0
 def test_1_sending_messages_work(self):
     msg = GenericMessage(type='json', message='{}')
     self.director_publisher.publish(msg)
     time.sleep(1)
     self.visibility_publisher.publish(Bool(data=True))
     time.sleep(1)
     self.active_wait('{}', SCENE.value)
     self.active_wait('True', VISIBILITY.value)
     self.active_wait("['kiosk']", ACTIVATE.value)
コード例 #18
0
ファイル: attract_loop.py プロジェクト: johnjsb/lg_ros_nodes
    def _play_scene(self, lazy_scene, lazy_presentation):
        """
        Accepts lazy scene object and lazy presentation object
        Fetches full, non-lazy versions of objects
        Emits a /director/scene and /director/presentation message
        """
        full_presentation = self._fetch_presentation_by_slug(lazy_presentation['slug'])
        full_scene = self._fetch_by_resource_uri(lazy_scene['resource_uri'])
        duration = full_scene['duration']
        if duration <= 0:
            duration = self.default_duration
        rospy.logdebug("Playing scene %s from presentation %s with duration %s" % (full_scene, full_presentation, duration))

        scene_msg = GenericMessage(type='json', message=json.dumps(full_scene))
        presentation_msg = GenericMessage(type='json', message=json.dumps(full_presentation))

        self.director_scene_publisher.publish(scene_msg)
        self.director_presentation_publisher.publish(presentation_msg)

        self.scene_timer = duration
コード例 #19
0
 def _scene_gen(self, slug, activity):
     director_msg = GenericMessage()
     director_msg.type = 'json'
     director_msg.message = """
             {
                   "description":"",
                   "duration":30,
                   "name":"lg_nav_to_device test",
                   "resource_uri":"/director_api/scene/lg_nav_to_device-test/",
                   "slug":"%s",
                   "windows":[
                     {
                     "activity":"%s",
                     "assets":["foo", "bar"],
                     "height":600,
                     "presentation_viewport":"center",
                     "width":800,
                     "x_coord":100,
                     "y_coord":100
                     }
                     ]
                 }
     """ % (slug, activity)
     return director_msg
コード例 #20
0
 def _scene_gen(self, slug, activity):
     director_msg = GenericMessage()
     director_msg.type = 'json'
     director_msg.message = """
             {
                   "description":"",
                   "duration":30,
                   "name":"lg_nav_to_device test",
                   "resource_uri":"/director_api/scene/lg_nav_to_device-test/",
                   "slug":"%s",
                   "windows":[
                     {
                     "activity":"%s",
                     "assets":["foo", "bar"],
                     "height":600,
                     "presentation_viewport":"center",
                     "width":800,
                     "x_coord":100,
                     "y_coord":100
                     }
                     ]
                 }
     """ % (slug, activity)
     return director_msg
コード例 #21
0
    def test_empty_message_not_ignored(self):
        """
        Empty message - consider just empty slot of of the slotted incoming message.
        Such shall be ignored.

        """
        # prepare message for testing, as if it was received (incoming message)
        influx = InfluxMock()
        pub = MockTopicPublisher()
        in_msg = GenericMessage(type="json", message="{}")
        p = Processor(watched_topic="/director/scene",
                      influxdb_client=influx,
                      debug_pub=pub,
                      msg_slot="message.slug")
        p.process(in_msg)
        # we want to submit empty messages
        assert p.last_in_msg is not None
        assert p.time_of_last_in_msg is not None
コード例 #22
0
try:
    json_file = open(sys.argv[1], 'r')
except IOError:
    print "Could not open file"

try:
    message = json_file.read()
except IOError:
    print "Could not read file"

try:
    message = json.loads(message)
    DIRECTOR_MESSAGE = json.dumps(message)
except ValueError:
    print "Could not parse json file"


msg = GenericMessage()
msg.type = 'json'
msg.message = DIRECTOR_MESSAGE

try:
    rospy.init_node('director_messager')
    rospy.sleep(1)
    rospy.Publisher('/director/scene', GenericMessage, queue_size=10, latch=True).publish(msg)
    rospy.sleep(1)
except KeyboardInterrupt:
    print "Exiting cleanly"
    rospy.signal_shutdown("Ctrl+c used on send_director.py")
コード例 #23
0
ファイル: test_helpers.py プロジェクト: johnjsb/lg_ros_nodes
def gen_scene_msg(scene):
    return GenericMessage(type='json', message=scene)
コード例 #24
0
ファイル: test_helpers.py プロジェクト: johnjsb/lg_ros_nodes
 def setup_method(self, method):
     self.msg = GenericMessage()
     self.msg.type = "json"
コード例 #25
0
    json_file = open(sys.argv[1], 'r')
except IOError:
    print "Could not open file"

try:
    message = json_file.read()
except IOError:
    print "Could not read file"

try:
    message = json.loads(message)
    DIRECTOR_MESSAGE = json.dumps(message)
except ValueError:
    print "Could not parse json file"

msg = GenericMessage()
msg.type = 'json'
msg.message = DIRECTOR_MESSAGE

try:
    rospy.init_node('director_messager')
    rospy.sleep(1)
    rospy.Publisher('/director/scene',
                    GenericMessage,
                    queue_size=10,
                    latch=True).publish(msg)
    rospy.sleep(1)
except KeyboardInterrupt:
    print "Exiting cleanly"
    rospy.signal_shutdown("Ctrl+c used on send_director.py")
コード例 #26
0
 def publish_event(self, event):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = str(event)
     self.publisher.publish(msg)
コード例 #27
0
 def get_empty_director_msg(self):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = EMPTY_MESSAGE
     return msg
コード例 #28
0
 def get_director_msg(self):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = DIRECTOR_MESSAGE
     return msg
コード例 #29
0
 def get_empty_director_msg(self):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = EMPTY_MESSAGE
     return msg
コード例 #30
0
#!/usr/bin/env python
import rospy
from interactivespaces_msgs.msg import GenericMessage

if __name__ == '__main__':
    scene_msg = GenericMessage()
    scene_msg.type = 'json'
    scene_msg.message = '{"slug":"blank"}'

    rospy.init_node('director_messager')
    scene_pub = rospy.Publisher('/director/scene', GenericMessage, queue_size=100)

    rospy.sleep(2)
    scene_pub.publish(scene_msg)
    rospy.sleep(2)
コード例 #31
0
ファイル: repub.py プロジェクト: EndPointCorp/lg_ros_nodes
import rospy
import sys
import json
from interactivespaces_msgs.msg import GenericMessage
from lg_common.srv import USCSMessage, USCSMessageResponse, InitialUSCS, InitialUSCSResponse


try:
    rospy.init_node('director_messager')
    rospy.sleep(1)
    service = rospy.ServiceProxy('/uscs/message', USCSMessage)	
    current_scene = service ()
    clear_scene = stop_scene = " { \"description\": \"STOP the presentation\", \"duration\": 0, \"name\": \"stop the presentations\", \"resource_uri\": \"/director_api/scene/stop-the-presentations/\", \"slug\": \"stop-the-presentations\", \"windows\": [] } "
    clear_scene = json.loads(clear_scene)
    clear_msg = GenericMessage()
    clear_msg.type = 'json'
    clear_msg.message = json.dumps(clear_scene)
    rospy.Publisher('/director/scene', GenericMessage, queue_size=10, latch=True).publish(clear_msg)
    rospy.sleep(1)
    current_scene = str(current_scene)
    current_scene = current_scene.strip('type: json')
    current_scene = current_scene.strip('\n')
    current_scene = current_scene.strip('message:')
    current_scene = json.loads(current_scene)
    DIRECTOR_MESSAGE = json.dumps(current_scene)
    msg = GenericMessage()
    msg.type = 'json'
    msg.message = DIRECTOR_MESSAGE
    rospy.Publisher('/director/scene', GenericMessage, queue_size=10, latch=True).publish(msg)
    rospy.sleep(1)
except KeyboardInterrupt:
コード例 #32
0
#!/usr/bin/env python
import rospy
from interactivespaces_msgs.msg import GenericMessage

if __name__ == '__main__':
    scene_msg = GenericMessage()
    scene_msg.type = 'json'
    scene_msg.message = '{"slug":"blank"}'

    rospy.init_node('director_messager')
    scene_pub = rospy.Publisher('/director/scene',
                                GenericMessage,
                                queue_size=100)

    rospy.sleep(2)
    scene_pub.publish(scene_msg)
    rospy.sleep(2)
コード例 #33
0
import rospy
from lg_common import ManagedWindow
from appctl_support import ProcController
from interactivespaces_msgs.msg import GenericMessage
from sensor_msgs.msg import CompressedImage
from lg_mirror.utils import get_viewport_image_topic

CAPTURE_VIEWPORT = os.environ.get('CAPTURE_VIEWPORT')
CAPTURE_DISPLAY = os.environ.get('DISPLAY')
CAPTURE_WIDTH = int(os.environ.get('CAPTURE_WIDTH'))
CAPTURE_HEIGHT = int(os.environ.get('CAPTURE_HEIGHT'))
CAPTURE_TOPIC = get_viewport_image_topic(CAPTURE_VIEWPORT)

BLANK_SCENE = GenericMessage(
    type='json',
    message='{"slug":"blank"}'
)

SCENE_TEMPLATE = """
{
  "description": "bogus",
  "duration": 0,
  "name": "test whatever",
  "resource_uri": "bogus",
  "slug": "test message",
  "windows": [
    {
      "activity": "mirror",
      "activity_config": {
        "viewport": "%s"
      },
コード例 #34
0
 def get_director_msg(self):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = DIRECTOR_MESSAGE
     return msg
コード例 #35
0
ファイル: replay.py プロジェクト: EndPointCorp/lg_ros_nodes
 def publish_event(self, event):
     msg = GenericMessage()
     msg.type = 'json'
     msg.message = str(event)
     self.publisher.publish(msg)
コード例 #36
0
ファイル: test_scene.py プロジェクト: johnjsb/lg_ros_nodes
    {
      "activity": "panovideo",
      "assets": [
        "%s"
      ],
      "activity_config": {
        "projection": "equirectangular",
        "expandCoef": 1.025,
        "loop": true
      },
      "presentation_viewport": "right",
      "width": 800,
      "height": 600,
      "x_coord": 800,
      "y_coord": 0
    }
  ]
}
""" % (video_url, video_url)

scene_msg = GenericMessage()
scene_msg.type = 'json'
scene_msg.message = DIRECTOR_MESSAGE

rospy.init_node('sv_messager')
scene_pub = rospy.Publisher('/director/scene', GenericMessage, queue_size=100)

rospy.sleep(2)
scene_pub.publish(scene_msg)
rospy.sleep(2)
コード例 #37
0
 def setup_method(self, metdhod):
     self.publisher = MockActivatePublisher()
     self.msg = GenericMessage()
     self.msg.type = "json"
     self.router = OnboardRouter(default_viewport=["wall"],
                                 onboard_activate_publisher=self.publisher)