[ANSWERED] JSON Parser Beta and nested square brackets
-
@mark I love this, something I have ben waiting for. I have one issue, a lot of sites will return time in unix timestamps. I have made a javascript actor to parse the timestamps and output a human readable date time string. However the timestamps I am getting are in milliseconds and are truncated by the limitation of the type I am guessing (I think they should be int64?).
Is it possible to allow these types to be passed from the json parser? Or if it is already possible, is there a trick to it?
Fred
-
@fred said:
I have made a javascript actor to parse the timestamps and output a human readable date time string. However the timestamps I am getting are in milliseconds and are truncated by the limitation of the type I am guessing (I think they should be int64?).
According to this article about Javascript integers:
JavaScript, by specification, does not know about integers (with the exception of recently introduced BigInts). It only knows IEEE doubles. But many operations are based on integers, just think of
for
loops. All JavaScript engines have a special representation for integers. V8 has so calledSmis
, small integers.Now, I just tried using a BigInt in our Javascript actor -- but it ended up crashing Isadora. :-(
(Apparently our version of v8 knows about BigInts because I didn't get a syntax error, but something else went wrong. I'll have to look into that.)
Let me get clear on what you mean by "unix timestamps" -- do you mean the number of seconds since midnight Jan 1, 1970? I guess not since these do not include milliseconds. What do you mean?
But what if you simply divided your millisecond integer values by 1000.0 to get seconds instead? Does that address the problem?
Well, I think I need an example patch or something to answer this more effectively.
Best Wishes,
Mark -
@mark yes, I am talking about unix timestamps - the number of seconds since midnight Jan 1, 1970, this is how pretty much every web api deals with dates and times. The problem I am having is not getting the timestamp into the Javascript actor but getting it out of the JSON parser.
For example when I check the web api I am using I get the first timestamp as : 1585207161600, but this element is output from the JSON parser as 364071376, if I use another method to see the results and search them there is nowhere that I find 364071376 (just to check if I made a mistake parsing).
I have made a very simple sample patch based on the example above, if I change any of the values of a JSON attribute to 1585207161600, it will output 364071376 from the parser.JSON Parse timestamp error.izz
-
@mark Any word on this or should I put it in a bug report- I understand this might not be high priority.
-
I've confirmed the issue, and have added it to the issue tracker.
Thanks -
@dusx cheers
-
I believe JSON Parser v0.9.3 addressees your problem. Please give it a try. (Note: you'll need to change the text inputs to see the correct results; simply opening a patch will not generate a new output because the input string will not have changed.)
Best Wishes,
Mark -
@mark works like a charm thanks.
-
@mark here is what I was trying to do, it now works great, and I made a little javascript to get human readable dates and times from timestamps. This will get earthquake data from a selected time period and read out timestamps locations magnitude and latitude and longitude and display it on screen. I am a bit busy now but I was hoping to find a way to rotate a globe map to the latitude and longitude of each earthquake if anyone knows how..
The data comes from the US government and this site: https://www.usgs.gov/products/data-and-tools/real-time-data/earthquakes
Patch attached
Fred
-
I was hoping to find a way to rotate a globe map to the latitude and longitude of each earthquake if anyone knows how..
Download the files from the Gurusession #3 (https://support.troikatronix.c...). @mark has a scene there that does exactly that.
Best Michel
-
@fred said:
a way to rotate a globe map to the latitude and longitude of each earthquake if anyone knows how..
@Michel is right you will find a javascript actor in the demo patch from @mark. It transforms latitude and longitude to quaternion angles that can be applied to move a sphere. I have used it in a patch with open source data from World Bank that indicates poverty levels / relative wealth in 180 countries. Interestingly, Marks example demos states in the USA. But I applied the effect on global positions. I guess in controlled visual simulations motion paths might be more like actual flight paths rather than direct and uncanny routes. When we see the earth move/spin it is usually constrained by the magnetic poles. I haven’t yet built in any constraints to simulate this.
Kind Regards
Russell
-
Here is the demonstration patch I am working on - not even close to completed. I have reduced the resolution of the texture maps to fit into under 3mb download .zip.
You will see the javascript actor from @mark that rotates the sphere (it references an external three.js file that needs to be accessible in the project folder). I haven't yet completed calibrating the rotation to be absolutely accurate with the texture map, but it is in the general location of cities that are referenced through the World Bank API.
It uses API data sources from VirusTracker and the WorldBank. I am also looking at accessing earth texture maps from NASA API to associate with times of day. but at the moment just have two texture maps that swap out including an example of average temperature and night. The data updates every day based on the availability of current Covid19 statistics through VirusTracker. It is set to minus 3 days because of the uncertainty of availability of daily data over weekends etc. The WorldBank API data provides, country broad individual wealth position, world coordinates and capital city.
I would say the patch system needs a way to capture the data with a single pass of the API URL's rather than continuously using the TCP GET method over and over. I haven't yet got the single pass TCP GET method into a Data Array configured, but I think that would be best practice.
Kind Regards
Russell