11 Replies Latest reply on Apr 13, 2018 9:29 PM by jsintilas

    How to inject timeProvider in PI Vision 4?

    Roger Palmen

      I'm a bit stuck here. I'm trying to get at the current time context (start- and endtime) of the display to insert into my PI Web API calls, but i can't find how to get that in.

      I expected that, just like migrating from PIV3 to PIV4, i just needed to add an import of timeProvider from @angular/core, and then include that in my constructor: private timeProv: timeProvider.

       

      But timeProvider nowhere to be found. Any clues?

        • Re: How to inject timeProvider in PI Vision 4?
          rschmitz

          Hey Roger,

           

          My initial inclination is to suggest working around this by reading the values out of the HTML elements via referencing their ID's and just doing a document.getElementById(), but it doesn't appear those time elements have ID's as they did in Vision 3.x. I believe the reason importing the TimeProvider isn't working is because it was developed for Vision 3.x and not part of the core angular modules. We're likely going to need to importing a differently named provider/service from a different location.

           

          I did some looking around myself and have been unsuccessful on finding how to get access to that information, but let me run the question by some of the developers and see what I can find out

           

          Cheers,

          Rob

          1 of 1 people found this helpful
            • Re: How to inject timeProvider in PI Vision 4?
              Roger Palmen

              Thanks, much appreciated!

              Normally i would have a look how the stock symbols do this, but for the Hackathon they reside on the public PI Vision server, so nothing to go on as the debug mode is off and the scripts are not readable client-side.

                • Re: How to inject timeProvider in PI Vision 4?
                  jsintilas

                  Hi Roger,

                   

                  We do not provide an angular service that keeps track of the display time in PI Vision 4. We need to provide a way to insert custom PI Web API queries into our data retrieval mechanism long term since we don't want out of band requests to be the norm since they don't scale well. As part of that we will likely provide access to the start and end time of the display during query generation, we will also discuss other possibilities in general for getting the time (possibilities include direct symbol inputs for start and end time, and a more formal display API for interacting with display at runtime). If you (or anyone else) have any questions, comments, or requests regarding this we would love to hear your feedback.

                   

                  Until then you only really have two options to get at the time, you can either go through the DOM to find the elements on the timebar using document.querySelector or querySelectorAll, or you set the shape for your symbol as trend and you should receive the start and end time for the display in your data input even if there are no data sources defined for the symbol.

                    • Re: How to inject timeProvider in PI Vision 4?
                      Roger Palmen

                      Hi John,

                       

                      First the good: thanks for giving some options how to get the time. Parsing the DOM is one way, was already looking into that, but of course not such a nice approach. Trend shape is the best option for now, so i'll pursue that.

                       

                      Then the bad: i strongly oppose that as a developer we don't have control over what we display. We should display the data the user needs, whether that is 1-month samples over 2 years, or millisecond samples over a the last minute, and all these combined, based on the needs. PI Vision is a framework for the custom symbols, and the extensibility is the one reason that has kept a number of our customers on the platform as the stock capabilities are nice for basics, but not what they need in the long run.

                      On the technical side, this blocks the upgrade path for a lot of functionality we currently build in custom symbols and would leave us stranded in that regard. We heavily use the PI Web API to retrieve the exact data we need for a symbol. And it's the task of the developer to make sure it performs. Customization cannot be without accepting the risk associated with the freedom it provides!

                      But let's leave that for a separate discussion.

                       

                      Wrt the best option: i liked the access to the time provider! That would enable custom symbols the same interaction with time as the stock symbols, like the scrolling behaviour on the trend changing the display time. Or nice features like the playback symbol. Just a readonly access or symbol input will be the minimum for any calls to the Web API to fit the concept of the time on the display. So my vote goes to the API, but for the time being just inputs would be OK too

                        • Re: How to inject timeProvider in PI Vision 4?
                          jsintilas

                          Absolutely Roger, and we want to give you the tools you need to get your job done. If we provide a way for you to define the queries you want to make from PI Web API I would expect that to give you the flexibility you need, if there are any concerns with that approach or you have specific use cases you'd like to discuss I'm happy to continue the conversation either here or in email. We want the framework to be powerful and easy to use for all developers and want your feedback.

                           

                          Another option that may work, but would require more work on your part would be to include an angular service of your own that could be injected into your symbols and be used to batch up all your calls so that you can minimize concurrent calls from your components. With regards to performance of PI Web API, the PI Web API team are dedicated to meeting the needs of both our internal developers and customers and are constantly working hard to make performance gains. They have already made some major strides in the past 6 months with more to come.

                            • Re: How to inject timeProvider in PI Vision 4?
                              Roger Palmen

                              Hi John,

                              Maybe my first understanding what you mentioned "out of band access" was a misunderstanding on my side, as i read it as that we would not have free access to the PI Web API anymore.

                               

                              I am already quite happy with the fully typed PI Web API we can use through the token. And PI Web API performance is also not a concern. The only thing that is missing is getting the time. We often either pull the time we need from attributes we link to the symbol, or use configuration to provide an offset to the display time.

                                • Re: How to inject timeProvider in PI Vision 4?
                                  jsintilas

                                  Hi Roger,

                                   

                                  I'm sorry for the misunderstanding, that's not what I meant at all. What I meant by out of band access was making web requests outside of PI Vision's own internal request mechanism. When this is done at the symbol level and if there are a lot of symbols on the page doing this it would start to hit the browser's concurrent connection max limit for the site and start queuing requests which would slow down the overall performance of the page. This is what I meant by it not scaling well. We are investigating ways to let symbol developers query for the data they need while still retaining some level of control of it on our end so we can optimize performance and keep display updates synchronized (so you don't end up with symbols updating at different intervals). With PI Vision 3 we added a way for symbols to generate PI Web API queries that would be picked up by our data pump and issued during the normal update cycle, XY Plot and the events table are examples of this. One of the limitations is that we often have queries that depend on values from previous queries and we cannot always chain these requests in a batch call in PI Web API, depending on query. Another limitation is that this request mechanism is tied to the update cycle so if you need a request to process immediately this is not a great approach and you will likely find yourself still going out of band. We are taking these factors into account and the final approach is still to be decided in PI Vision 4.

                                  1 of 1 people found this helpful
                            • Re: How to inject timeProvider in PI Vision 4?
                              gregor

                              Hello John,

                               

                              I am glad about the Virtual Hackathon allowing early access to PI Vision 4, resulting into discussions like this one to happen at an early stage.

                               

                              Extensibility is one of the key features of PI Vision 4. In that regards offering at least read access to the display start- and end-time also appears to be a key and I don't believe this should be available by analyzing the DOM but also to less advanced programmers.

                               

                              I am not sure if I properly understood the reason for "hiding". Is it an attempt to protect against expensive queries executed by a custom symbol and slowing down PI Vision? If so, isn't it that almost anything can be done in a custom PI Vision symbol e.g. querying a foreign data source, calculating prime numbers, a tetris game .. ?

                              1 of 1 people found this helpful
                                • Re: How to inject timeProvider in PI Vision 4?
                                  jsintilas

                                  Hi Gregor,

                                   

                                  It wasn't left out intentionally, more that we were/are focused on getting tool panes out and defining an API for display interaction that this could fall into. One of the things we like to see during these hackathons is how often developers need to break out of the box of our built in shapes so that we can use those use cases to either form new shapes (if we see common request patterns) or help define how we can optimize custom requests for developers. We absolutely want to see if you have expensive queries during the hackathon so that we can address these prior to general release.

                                   

                                  Since this is going to continue to be distributed via the cloud for the open preview we will regularly be pushing updates so you will be able to see things like access to the display times get added as we progress, we will make that a priority so look for it in the near future. For the purposes of the hackathon I've withheld updates to the application and seed project (other than documentation) since we are still going to have breaking changes during the open preview time frame and didn't want to jeopardize any entries by bringing the code base current.

                                   

                                  We will be looking to the PI Developer community here to continue to provide feedback into the open preview to help shape the API going into general release, so please keep posting with any questions or comments you may have as you use the product

                                  2 of 2 people found this helpful