18 Replies Latest reply on Aug 29, 2018 5:14 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
                                • Re: How to inject timeProvider in PI Vision 4?
                                  Roger Palmen

                                  Just wanted to follow-up on this, and prepare for PI Vision 4 in our current decisions.

                                  We now have a few symbols that interact with the timeprovider to set the display time, or to request details (like checking if it is updating / set to Now). Will those options be available in PI Vision 4 in some way?

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

                                      Roger,

                                       

                                      I suggest you take a look at the latest extensibility guide for PI Vision 4 on the OSIsoft github (pi-vision-extensions/extensibility-guide.md at master · osisoft/pi-vision-extensions · GitHub ).

                                       

                                      With the addition of an experimental Display API you can now read the display startTime/endTime and they have added a function to change the display time range: setTimeRange(start: string, end: string);

                                       

                                      Although note the warning provided:

                                       

                                      Warning The Display and Symbol APIs are currently experimental and subject to change. They are provided here for preview purposes and feedback only. If you have any comments, suggestions, or requests please contact PIVisionFeedback@osisoft.com

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

                                          Ah, a display API, nice! That gives us a better way to interact with PI Vision, instead of digging out data from the underlying objects, big step forward!

                                           

                                          There are a few things i currently read/manipulate that i don't see in the API

                                          • reading the current state of the display provider (has the user scrolled or not) using timeProvider.model.props.isUpdating. I use this to drive different behaviours of a custom symbol. I need to know if a user is looking at a display at a specific time range, or is currently updating
                                          • access the logger object to add errors from the custom symbols to the display errors
                                          • a pointer to the HTTP element, to manipulate the DOM, e.g overriding the styling (one thing i use is to allow a symbol to draw outside the 'box')

                                           

                                          So if you still have room on your backlog, having these would be great!

                                            • Re: How to inject timeProvider in PI Vision 4?
                                              nicka
                                              • To the best of my knowledge the display is always updating as long as it is in view mode and in play mode. While in edit mode the display only updates on changes or when the refresh button is pressed, so to detect if the display is updating you would check the current display mode and you could check to see if the display is currently paused. You can confirm that the display is always updating in play mode (even if looking at historical data) by opening up the networking panel within your browsers developer tools.
                                              • Seeing as the logger is a new addition with the latest update I imagine that they're working on incorporating it into the API but haven't finished yet (that or just not documented, at least I didn't see it).
                                              • If you can get the symbol name (which may be possible now) you could do this by iterating over the DOM. However it's likely there's another way you can do what you want using symbol configuration/data to toggle overflow:visible through the use of Angular directives like NgClass or NgStyle on the symbol to allow to draw outside it's box
                                              • Re: How to inject timeProvider in PI Vision 4?
                                                jsintilas

                                                Hi Roger,

                                                 

                                                As Nicholas mentioned, there's been a lot of work done on the logger recently and we've heard requests for access to it so we will have an item in our backlog to provide an interface for it (priority TBD). Can you give some examples of how you would use it? Are there features that are missing from the current logger that you would need to meet your use cases?

                                                 

                                                For DOM manipulation it sounds like you want to change the symbol host so that it doesn't clip your symbol. In general we don't want symbols to go past their boundaries, can you describe your symbol and why it needs to draw past it's boundaries? With the SymbolAPI you can change your size to fit using the resize function, though that is also something we would recommend against doing since it may overlap other symbols on your display. Maybe there is another solution we can suggest based on your use case.

                                                 

                                                For receiving updates on time changes we've been going over several ways of handling this: automatically including a time object as part of the data that is sent to a symbol (including things like UTC seconds, PI time, and formatted time), having an input for symbols that can receive their evaluated time, and providing access to an observable for the display's time via the developer API. Do you need access to the display's time or the time your symbol would be evaluated at (which can be the display's time if the user hasn't configured the symbol or any of it's series with a specific time range or offset)? Also, what are you using it for? Is it primarily for creating your own data requests via PI Web API? If so, we're also going to look into making our client data access library extensible so that you can provide your own requests and data shapes without having to make out of band data access calls. Would something like that meet your needs?

                                                 

                                                Thanks for the great feedback!

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

                                                    Hi John, Nicholas,

                                                     

                                                    • Wrt to the logger, i use it mainly to log exceptions in my symbols, or errors received in PI Web API (batch) calls. The purpose is that the user can relay the specific error details to application support.
                                                    • The symbol we've built is a dropdown menu, which while dropping down flows over the boundaries of the symbol. To make that work, we manipulate the overflow setting of the HTML element containing the symbol. Otherwise you need a symbol that is larger than the initial size AND is on top of / over other symbols to ensure the dropdown is over the symbols below. Which in turn makes editing or interaction with symbols below that symbol impossible. Basically we run all displays in kiosk mode, and provide navigation etc through custom symbols. By the element that we currently inject, it's a matter of navigating upward in the DOM, so no looping needed to find the symbol element (or it's parent) in the DOM.
                                                    • Wrt to the time, i need some way (maybe my current way is not correct), to detect if the display is set to "Now", thus continuously scrolling forward in time. We have a symbol that needs to behave differently when the user has changed the time to any other endtime than the current time. Or simply said: if the "Now" button is green, it does something different (retrieves data through PIWebAPI in a different way), then when the Now button is not green

                                                     

                                                    Too bad i won't be at the EMEA UC this year, we could have a chat and i could show how we currently use PI Vision

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

                                                        Hi Roger,

                                                         

                                                        Thanks for the use cases. I can see how a dropdown widget would need to turn off clipping. We'll record these in our user voice for prioritization. I've also mentioned these to our product manager Alicia Coppock. Since we won't be able to connect at the UC we could always connect over Webex instead. If that would be good, contact me with some times you'd be available and I'll get something set up.