[kepler-users] Parsing JSON data; advice on collaboration

Elizabeth Ann Latronico beth at berkeley.edu
Tue Dec 16 15:17:20 PST 2014


Hi Brandon,

If the JSON data follows the typical format of name : value pairs, then
JSONToToken can be used to convert the data into a record in Kepler or
Ptolemy.

I've attached a sample model.  I created it in Ptolemy and tried it out in
Kepler, it works OK!  It doesn't pop up any output windows, but if you
double-click on each "Test" actor, this will show the output produced.

This example uses an energy data feed sample from the Berkeley sMAP campus
energy monitoring service.  The JSON starts out as a string containing a
record with a "uuid' field (value: a string) and a "Readings" field (value:
an array of arrays of doubles - here, an array of [timestamp, reading]
pairs).

For your model, you'll need to manually annotate the type on the output
port of the JSONToToken actor.  There are notes in the example.  The Kepler
actor options menu is a bit different than Ptolemy, try:
Right click -> Configure Ports

Curly braces {} indicate a record type and arrayType() indicates an array
type.

You are right - this is not a well documented feature!  The only Ptolemy
models that happen to use it involve the web server, which isn't needed if
you're just receiving data.  Plus a couple really basic test cases.

Edward and Christopher - I added this example as a test case in the Ptolemy
repository at:
$PTII/ptolemy/actor/data/lib/conversions/json/test/auto/JSONEnergyExample.xml

Best,
Beth



On Mon, Dec 15, 2014 at 9:44 PM, Christopher Brooks <cxh at eecs.berkeley.edu>
wrote:
>
>  Hi Brandon,
>
> Backward type inference can help with these JSONToToken models, see
>
> http://chess.eecs.berkeley.edu/pubs/1035.html - a poster
>
> http://ptolemy.eecs.berkeley.edu/books/Systems/chapters/TheTypeSystem.pdf
>
> In Ptolemy II, to enable backward type conversion in Vergil, right click
> on  the canvas, select Customize, then Configure, then check the
> enableBackwardTypeInference box.
>
> In Kepler, it might be necessary to do something different, see
> http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/2013-October/002542.html
>
> For the JSON actor and Backward Type Conversion, see Marten's poster at
> http://chess.eecs.berkeley.edu/pubs/1035.html
>
> See also
> http://sisyphus.eecs.berkeley.edu:8079/hudson/job/ptII/javadoc/ptolemy/actor/lib/conversions/json/JSONToToken.html
> and
> http://sisyphus.eecs.berkeley.edu:8079/hudson/job/ptII/javadoc/ptolemy/actor/lib/conversions/json/TokenToJSON.html
> though there is not much there.
>
> Martin's tech report "Maximally Permissive Composition of Actors in
> Ptolemy II" at
> http://www.eecs.berkeley.edu/Pubs/TechRpts/2013/EECS-2013-19.html also
> has some info about JSONToToken.
>
>
>
> In a multicontributor environment, I suggest the following:
>
> - Where you can, use actor oriented classes to define models.  This means
> that people can "own" blocks of functionality and others can instantiate
> them.  If the original definition changes, then the users will see those
> changes.
>
> - A nightly build with a test suite goes a long way to helping find
> problems early.  There is a Test actor that can be used in models to create
> regression tests. $PTII/doc/coding/testing.htm has details.
>
> - In your version control system, always work at the head, branching can
> consume resources when doing a merge.
>
> _Christopher
>
>
> On 12/10/14 7:58 PM, Edward A. Lee wrote:
>
>
> In the underlying Ptolemy system, we have a JavaScript actor that would be
> ideal for this...
> Not sure whether this is exposed in the Kepler libraries...
>
> Edward
>
> On 12/10/14, 2:16 PM, Brandon Kuczenski wrote:
>
> Hi all,
>
> I'm new to Kepler and I'm trying to build a minimal demo to show my
> research group how the tool works.  I have two questions, and the first
> is a two-parter.
>
> 1a- My first application is to pull down data from a web service (using
> RESTService) and display it.  In the WebService demo (Getting Started
> 06) I see the XMLDisassembler actor is used.  However, my data come back
> in JSON format- It does not appear that there is a JSON analog for
> XMLDisassembler.  Any recommendations on how I could parse the data?
>
> 1b- One thing I tried was JSONToToken, thinking that a token was
> something that might be more easily manipulated; it did not turn out to
> be.  In fact, I can't really find anything that I can connect to the
> output of a JSONToToken actor.  Is there a way for me to find actorsI
> with input ports that are valid terminals for a given output port, or
> vice-versa?
>
> 2- The team I'm working with includes about 14 people across several
> academic departments.  Are there any documents or helpful resources that
> give practical advice on working with Kepler in a multi-contributor
> environment?  None of us has used the tool before.
>
> BTW it seems some actors (RESTService and JSON-anything, for instance)
> are missing from the Actor Reference.
>
> Thanks in advance,
> Brandon
>
>
>
> _______________________________________________
> Kepler-users mailing list
> Kepler-users at kepler-project.org
> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users
>
>
>
> --
> Christopher Brooks, PMP                       University of California
> Academic Program Manager & Software Engineer  US Mail: 337 Cory Hall
> CHESS/iCyPhy/Ptolemy/TerraSwarm               Berkeley, CA 94720-1774cxh at eecs.berkeley.edu, 707.332.0670           (Office: 545Q Cory)
>
>
> _______________________________________________
> Kepler-users mailing list
> Kepler-users at kepler-project.org
> http://lists.nceas.ucsb.edu/kepler/mailman/listinfo/kepler-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20141216/d6987522/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: JSONEnergyExample.xml
Type: text/xml
Size: 18794 bytes
Desc: not available
URL: <http://lists.nceas.ucsb.edu/kepler/pipermail/kepler-users/attachments/20141216/d6987522/attachment-0001.xml>


More information about the Kepler-users mailing list