11 Replies Latest reply on Jul 27, 2016 10:18 AM by meghan RSS
    msakshi-2 Explorer

    Multiple player data using single Thing/Template

    Currently i am working on a project, where i need to display information of multiple player on a dashboard.

    I tried with repeater widget, but problem with that widget is that i need to create multiple things. For each user we need to create seperate things.

    what i am looking for is that :

    1) Is it possible to have multiple player data on a single dashboard using a single thing/template?

    2) From a single EMS(Edge Micro Server) we need to send the data to ThingWorx. (JSON format looks good to me)

    3) Do we need to write any service for it? If yes what is it?

     

    All that i require is Multiple Player Data on a Dashboard using a single Thing and single EMS.

    On clicking the player name or id, the mashup should redirect to the specified player name/id dashboard(it should display the name, age, height or weight of only that particular player).

     

    I am struggling with this problem from a very long time. Kindly, give some input so that i can proceed.

      • Re: Multiple player data using single Thing/Template
        meghan Communicator

        Mayur,

         

        Typically you should be using one Thing to represent each player and it's properties.

         

        If you want to push a bunch of data to one Thing on the platform from an Edge device I recommend sending it all in one InfoTable property. You would then bind the Edge InfoTable property to an InfoTable property in ThingWorx. This is assuming that you are binding a Remote device and not just sending REST requests.

        You can then call "GetPropertyValues", in a Mashup, for the Thing with the InfoTable property that is storing all of your player data. From that point you would drag and drop the InfoTable property from "All Data" onto a List Widget that can display all of the player names. Upon someone selecting a player name you would bind any other data you want to show for that player from"Selected Rows" on the "GetPropertyValues" service.

         

        Hope that makes sense. You shouldn't need to write any services if you follow this.

         

        Meghan

          • Re: Multiple player data using single Thing/Template
            msakshi-2 Explorer

            Thank you so much Meghan.

            I will look into the solution and try to implement that and if i am stuck again, then again i will ping.

            • Re: Multiple player data using single Thing/Template
              msakshi-2 Explorer

              Hello Meghan,

               

              Wanted to know few more things,

              1) Do you have any sample code to create infotable from the Edge micro server side, as whatever code i had i tried to implement that but it is not able to      push the data in the info table ?

              2) Do we need to bind the property from template level or thing level?

                • Re: Multiple player data using single Thing/Template
                  meghan Communicator

                  Mayur,

                   

                  1) The code will need to be written in Lua, as the Edge MicroServer what handles any property updates from the Lua Script Resources running on the devices.

                   

                  If you take a look at the "example.lua" file in the "microserver\etc\custom\templates\" directory, you can see an example of how an InfoTable is being populated with data, and then a service is defined that can be bound to the Thing on the ThingWorx server to populate the property.

                   

                  If you want the property to be automatically pushed you will need to look at the "generator.lua" file in the "microserver\etc\thingworx\lua\handlers\ directory". Properties are given a "functionType" and in the "read" function in the "generator.lua" file the different function types are being handled. The property definition for this would look like so:

                  properties.Random_Number   = { baseType="NUMBER",   pushType="NEVER", handler="generator", functionType="random", minValue=0, maxValue=100, qualityPercent=90, errorQualityStatus="BAD" }

                   

                   

                  To build an InfoTable with a custom service that can be bound and invoked from the RemoteThing in ThingWorx, review the following:

                  • You will need to define the InfoTable property:

                  properties.Pushed_InMemory_InfoTable =  { baseType="INFOTABLE", pushType="VALUE", dataShape="AllPropertyBaseTypes" }

                   

                  • You will need to define a DataShape:

                  dataShapes.AllPropertyBaseTypes (

                    { name = "Boolean", baseType = "BOOLEAN" },

                    { name = "Datetime", baseType = "DATETIME" },

                    { name = "GroupName", baseType = "GROUPNAME" },

                    { name = "HTML", baseType = "HTML" },

                    { name = "Hyperlink", baseType = "HYPERLINK" },

                    { name = "Image", baseType = "IMAGE" },

                    { name = "Imagelink", baseType = "IMAGELINK" },

                    { name = "Integer", baseType = "INTEGER" },

                    { name = "Json", baseType = "JSON" },

                    { name = "Location", baseType = "LOCATION" },

                    { name = "MashupName", baseType = "MASHUPNAME" },

                    { name = "MenuName", baseType = "MENUNAME" },

                    { name = "Number", baseType = "NUMBER" },

                    { name = "Query", baseType = "QUERY" },

                    { name = "String", baseType = "STRING" },

                    { name = "Text", baseType = "TEXT" },

                    { name = "ThingName", baseType = "THINGNAME" },

                    { name = "UserName", baseType = "USERNAME" },

                    { name = "XML", baseType = "XML" }

                  )


                  • Define a service handler for the service to populate the InfoTable property:

                  serviceDefinitions.Push_InfoTable (

                    input { name="value", baseType="INFOTABLE", description="", aspects={dataShape="AllPropertyBaseTypes" } },

                    output { baseType="INFOTABLE", description="", aspects={dataShape="AllPropertyBaseTypes"} },

                    description { "Used to push a value to platform." }

                  )

                   

                  • The final step is to define a service that will populate the property:

                  services.Push_InfoTable = function(me, headers, query, data)

                    if not data.value then

                      return 400, "You must provide the 'value' parameter"

                    end

                   

                    local success, error

                   

                    -- Have to create an InfoTable for property that we want to set

                    tw_mutex.lock()

                    local ds = DataShape.AllPropertyBaseTypes:clone()

                    tw_mutex.unlock()

                   

                   

                    local propIt = tw_infotable.createInfoTable(ds)

                    for _,row in pairs(data.value.rows) do

                      success, err = propIt:addRow(row)

                      if err then return 400, err end

                    end

                   

                    -- Now, place the prop InfoTable into a container InfoTable

                   

                    local ds = tw_datashape.createDataShape("Pushed_InMemory_InfoTable", "INFOTABLE", nil, {dataShape="AllPropertyBaseTypes"})

                    local it = tw_infotable.createInfoTable(ds)

                    success, err = it:addRow({Pushed_InMemory_InfoTable = propIt})

                   

                   

                    if err then return 400, err end

                   

                   

                    me:setProperty("Pushed_InMemory_InfoTable", nil, nil, it:toTable())

                    return 200, propIt

                  end

                   

                  2) You need to bind the properties at the Thing level

                    • Re: Multiple player data using single Thing/Template
                      msakshi-2 Explorer

                      Thank you Meghan for your help that was really helpful.

                      Now i am able to create an infotable from the Edge microserver(EMS) side and able to push bunch of data at once.

                      The infotable created on the EMS side is received by a property on ThingWorx with base type as infotable.

                      That infotable data i am binding with a list widget over the mashup, but

                      i am stuck here

                      I am pushing the infotable in the list widget with value field and display field as "name" of the player.

                      Upon selection of any name their respective age and weight should be displayed.

                      i mapped the age value display field with selected rows >infotable name > selected rows > age, i know i am missing out some thing but i don't know what is it.

                       

                      Can you please help in getting the respective player age and weight upon selecting their name?

                      your help is important

                        • Re: Multiple player data using single Thing/Template
                          meghan Communicator

                          I'm assuming your are calling getPropertyValues in the Mashup, but instead you will need to write a custom service that has one line in it:

                           

                          var result = me.infoTablePropertyName;

                          The Output result of the service should be an InfoTable, using the DataShape defined for it, and in your Mashup you can use this service to manage what values you see upon the Selected Row changing.

                           

                          Meghan

                            • Re: Multiple player data using single Thing/Template
                              msakshi-2 Explorer

                              Thanks a lot Meghan,

                               

                              with your help I am almost able to do this.

                              I am writing a service

                              var result = me.info; //info is my property name whose base type is infotable and has datashape (has field name,age and weight).

                               

                              on testing this service I am getting a table which has list of name, age and weight.

                               

                              i am using this service to map the data, i am taking this service(name : test_service) > all data > age to a value widget, where i am able to display the age of player but only 1st row player age is being displayed, on selecting different name from the list the age is not changing it is still taking the age from 1st row.

                               

                              from "getPropertyValues" i am taking "SelectedRowsChanged" service and mapping it with the service "test_service", still the data is not changing.

                               

                              can you please help me with step to step mapping of it, i am really confused with it

                               

                              Kindly give your input so that i can proceed it as soon as possible.

                    • Re: Multiple player data using single Thing/Template
                      Sajid Patel Apprentice

                      You can refer to these 2 response:

                      Re: Multiple User Data

                      Re: How to map data coming from EMS to multiple users?

                       

                      Disclaimer: This response contains my views and opinions expressed and not R&D's or company's.

                       

                      1) Is it possible to have multiple player data on a single dashboard using a single thing/template?

                          Yes, it is possible. The simplest option is to display it in a grid. However it might be possible to display it other ways too.

                       

                      2) From a single EMS(Edge Micro Server) we need to send the data to ThingWorx. (JSON format looks good to me)

                          JSON or InfoTable may be used. You will need service code on platform end to consume this data and set appropriate properties.

                       

                      3) Do we need to write any service for it? If yes what is it?

                           You will need a service to breakdown the data into properties that may be displayed into the dashboard, please see the above referenced answers.