Idea

Chris Smith avatar image
3 Likes"
Chris Smith suggested Ben Wilson edited

Function to sample a value from a webpage

I think this is actually something that would be extremely useful for a lot of users, and also fairly easy to implement due to development in the software in the last few years. The idea would be something like webvalue(String - website url, String - HTML element id, Boolean - on Reset). The first parameter would be for the url of the site with the value. The second would be for the id of the element that contains the string. The third would be a value that determines if the value is obtained from the website on reset only and stored in a label to be used for future calls (if the function is called during the model run it would just reference the value in the label) or if a request is done each time it is called (this could really slow down a model, but if the value is changing on the web page frequently it may be worth it to the user). This would basically make it easier to maintain models whose values can be linked to web dashboards. It would also make it easier to create an emulation like simulation of a running production line.

Additionally, a built in browser with a sample tool that the user could use to auto-populate this function would be great...

A quick example of when this might be useful. A certain station on a production line might have a web dashboard that gives the weekly yield of the station. That value could be referenced from the webpage into the model, so that the model accurately reflects what is happening in the current week.

web communicationsampler
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image
1 Like"
Ben Wilson commented Ben Wilson edited

FlexSim Native (FlexScript and/or attached DLLs)

The functionality you're asking for is already available in the software, albeit from a lower level with more coding required than a single, simple function. However, the power is there, so if you wanted to wrap the existing functionality within a simple user command, you could do it today (minus the sampler idea). This could be a bridge between today, and some future date when FlexSim may include an easy web query command right out of the box.

For an overview of FlexSim's current web communication functionality, see these previous Q&As:

https://answers.flexsim.com/questions/29348/is-it-possible-to-use-the-server-sent-events-with.html

https://answers.flexsim.com/questions/21092/web-communication-within-flexsim.html

Ideally the site you're querying would have a nice API you could request against that would return just the data you're interested, preferably in some sort of well structured format like JSON, which you could then easily interpret within FlexSim.

Assuming the site you're querying lacks an easy API, you would then be in web scraping territory. The example model in one of my previous answers does just that using FlexScript's stringsearch command to drill down within the returned HTML to the data I'm interested in. Using FlexSim 2017's new dot-syntax, you'd have better, more power string commands (hello Regex :) with which to parse the HTML.

To really take this all the way, you'd want to find/build a CSS selector engine (probably like a C++ or other language program that you could compile to a DLL to attach to FlexSim). This would allow you to traverse a HTML DOM as you would within JavaScript. Or, better yet, do CSS-based DOM selection using FlexSim's built in WebKit web renderer, using jQuery. This method is outlined in another response to this idea.

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ben Wilson avatar image
1 Like"
Ben Wilson commented Ben Wilson edited

FlexSim's Integrated Webkit

FlexSim includes Webkit, a fully featured web renderer. This gives you all the power of JavaScript and other web technologies, right from within FlexSim.

There are helper functions that allow a webpage running in FlexSim's Webkit to call a FlexScript function (fireFlexSimEvent()), and vice versa, a way for FlexScript to call JavaScript functions on the webpage (callwebscriptmethod()). In this manner you can bridge the two worlds.

So, using raw JavaScript, or JQuery or any other library of choice you could create a web application that gives you the power you want as far as querying external sites, parsing the data returned, etc. Then pass that data to your FlexSim model for whatever you need it for. This could be on demand (ie user must press a button, on the web page or within FlexSim proper, the query is made, and the data passed back to FlexSim), or tied to a trigger or other event.

I'll see about putting together an example and post it here.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Michael Machado avatar image
0 Likes"
Michael Machado commented
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Your Opinion Counts

Share your great idea, or help out by voting for other people's ideas.