27 Replies Latest reply on Nov 20, 2012 11:46 AM by Asle Frantzen

    A better regression line visualization?

    Asle Frantzen

      For a ProcessBook project we recently did, we had to provide a way to see the regression line for some trends / traces. We looked at the built in functionality in the trend definition window, and also at the regression line addin (devnet legacy).

       

      The addin gives more options, and is also visualized as a new trace in the trend (meaning it has its own color, linestyle, etc). The built in regression line is always the same color as the trace, and is always a dashed line - sometimes making it difficult to separate from the tag you're adding it to.

       

       

       

      Our client were more satisfied with the addin, but since we're now using ERD we can't use it since it uses a custom dataset - and this doesn't support ERD. I've tried to modify the custom dataset defined by the addin using VBA code, but it doesn't seem like I can edit the tag defined. If I could, I'd change the tag in my ContextHandlerChanged method.

       

       

       

      Any ideas on what we could try here?

       

      It would suffice if I could edit the color and linestyle of the regression line functionality built in to ProcessBook, but to me it doesn't seem possible.

          • Re: A better regression line visualization?
            andreas

            I'll see if I can find the developer of the devnet addin.

              • Re: A better regression line visualization?

                Asle, on the face of it wouldn't take much to recreate the regression addin if Andreas cannot contact the developer for the source.  Community project?

                    • Re: A better regression line visualization?
                      andreas

                      A brief update - the add in is VB6 :-( and I have the source code :-)

                        • Re: A better regression line visualization?

                          You going to add the source code to the library?

                            • Re: A better regression line visualization?
                              Asle Frantzen

                              Andreas, how about that source code?

                               

                              My client is still waiting for a regression line with red color, the built-in functionality is so confusing (being that is has the same color as the trend) that they've disabled it.

                                • Re: A better regression line visualization?
                                  andreas

                                  Asle, the source code is sitting on my desktop and waiting to be transfered into a .NET add in - most likely after vCampus Live! 2012 :-(

                                    • Re: A better regression line visualization?
                                      Asle Frantzen

                                      Rhys, I got the code from Andreas, as one of my clients are eager to get this implemented in their displays.

                                       

                                      I'm well on my way to converting this to a .NET addin. I've based this on the .NET AddIn template for custom datasets, and in the GUI I've created three tabs to represent PI tag data, AF data, and ERD data.

                                       

                                      With the PI tag tab I can use all standards dialogs and controls, same thing with AF tab. But the ERD form in ProcessBook seems to be custom made, and I'll have to recreate it manually (unless someone knows something something?)

                                       

                                      So a couple of related questions:

                                       

                                      1. How do I get the currently selected element of interest from ProcessBook?

                                       

                                      2. What is the correct behaviour of the ERD functionality? You only load the template based attributes for the element of interest, right?

                                       

                                      When I'm done with the first edition we can put this up as a community project.

                                        • Re: A better regression line visualization?
                                          andreas

                                          @Asle - are we going to see the .NET add in in your Blog or as a community project?

                                          • Re: A better regression line visualization?

                                            For 1) you would use Application.ContextHandlers("E")

                                             

                                            On 2) I would need to double check, but I thought it was possible to use non-template based Elements as EOI.

                                              • Re: A better regression line visualization?
                                                Asle Frantzen

                                                1. OK, that should be pretty similar to what I've used before, in VBA

                                                 

                                                2. I think you're right. Any attribute or element can be used, I just tried it.

                                                 

                                                I'll probably have more questions later. Thanks!

                                                  • Re: A better regression line visualization?
                                                    andreas

                                                    to 1):

                                                     
                                                                this.app.DisplayActivate +=new EApplication_DisplayActivateEventHandler(app_DisplayActivate);
                                                                this.app.DisplayDeactivate += new EApplication_DisplayDeactivateEventHandler(app_DisplayDeactivate);
                                                    
                                                            }
                                                    
                                                            public void app_DisplayActivate(PBObjLib.Display myDisplay)
                                                            {
                                                                PBObjLib.ContextHandler eContextHandler;
                                                                eContextHandler = myDisplay.ContextHandlers.Item("E");
                                                                eContextHandler.ContextChanged +=new EContextHandlerEvents_ContextChangedEventHandler(eContextHandler_ContextChanged);
                                                            }
                                                    
                                                            public void app_DisplayDeactivate(PBObjLib.Display myDisplay)
                                                            {
                                                                PBObjLib.ContextHandler eContextHandler;
                                                                eContextHandler = myDisplay.ContextHandlers.Item("E");
                                                                eContextHandler.ContextChanged -= eContextHandler_ContextChanged;
                                                    
                                                            }
                                                    
                                                            public void eContextHandler_ContextChanged(out PBObjLib.Display myDisplay, out PBObjLib.ContextHandler myContextHandler)
                                                            {
                                                                myContextHandler = this.app.ContextHandlers.Item("E"); ;
                                                                myDisplay = this.app.ActiveDisplay;
                                                                MessageBox.Show(myContextHandler.get_CurrentContext(myDisplay));
                                                            }
                                                    

                                                     

                                                      • Re: A better regression line visualization?
                                                        Asle Frantzen

                                                        Hmm... I get this error message trying to assign the ContextChanged event handler:

                                                         

                                                        'PBObjLib.ContextHandler' does not contain a definition for 'ContextChanged' and no extension method 'ContextChanged' accepting a first argument of type 'PBObjLib.ContextHandler' could be found (are you missing a using directive or an assembly reference?)

                                                         

                                                         

                                                         

                                                        And this one with the event handler I'm assigning it to:

                                                         

                                                        The type or namespace name 'EContextHandlerEvents_ContextChangedEventHandler' could not be found (are you missing a using directive or an assembly reference?)

                                                         

                                                         

                                                         

                                                        I have included references and using statements for the PBObjLib and PBSymLib assemblies, but I'm just not finding any of the above mentioned handlers and types. My project is .NET 3.5 (as I remember that is the newest recommended .NET version to use with ProcessBook). Any ideas?

                                                          • Re: A better regression line visualization?
                                                            dhollebeek

                                                            Well, just as a guess, you might be having problems with the exact method argument types (they are 'out' parameters in C# even thought they shouldn't be).  Other than that, I'd need to see the code to guess at what's wrong.  You can email the code to me at dhollebeek@osisoft.com if you don't want to post it (or if it's way too long) for the forums.

                                                            • Re: A better regression line visualization?
                                                              Asle Frantzen

                                                              That's strange... I looked at the example project for custom datasets (from a learning lab, or similar) and there the two OSIsoft.PBObjLib.dll and OSIsoft.PBSymLib.dll files have runtime version v2.0.50727 - while they have v1.1 in my project. And when clicking "Go to definition" for the PBObjLib.ContextHandler I see that my project's PBObjLib.ContextHandler interface only inherits from IDualContextHandler, while the example project's PBObjLib.ContextHandler also inherits from EContextHandlerEvents_Event.

                                                               

                                                              Both projects are similar in setups, but while looking at the *.csproj files of both projects I see a difference in the way the references are set up...

                                                               

                                                              My project:

                                                               

                                                              <Project....>
                                                                <ItemGroup>
                                                                  <Reference Include="OSIsoft.PBObjLib, Version=1.0.0.0, Culture=neutral">
                                                                    <HintPath>..\..\..\..\Program Files (x86)\PIPC\Procbook\PublicAssemblies\OSIsoft.PBObjLib.dll</HintPath>
                                                                    <Private>False</Private>
                                                                    <EmbedInteropTypes>True</EmbedInteropTypes>
                                                                  </Reference>
                                                                  <Reference Include="OSIsoft.PBSymLib">
                                                                    <Name>OSIsoft.PBSymLib</Name>
                                                                    <HintPath>..\..\..\..\Program Files\PIPC\Procbook\OSIsoft.PBSymLib.dll</HintPath>
                                                                    <Private>False</Private>
                                                                  </Reference>
                                                                </ItemGroup>
                                                              </Project>

                                                              And the example project:

                                                               

                                                              <Project....>
                                                                <ItemGroup>
                                                                  <Reference Include="OSIsoft.PBObjLib, Version=3.1.0.0, Culture=neutral, PublicKeyToken=c3309f0734ba2805, processorArchitecture=MSIL" />
                                                                  <Reference Include="OSIsoft.PBSymLib, Version=3.1.0.0, Culture=neutral, PublicKeyToken=c3309f0734ba2805, processorArchitecture=MSIL" />
                                                                </ItemGroup>
                                                              </Project>

                                                               

                                                              After manually editing my .csproj file, the references changed to v2.0 and the missing lines of code could be resolved.

                                                               

                                                              Why did the two dll file references have version 1.1 when I added them to a .NET 3.5 project? I had to browse for the files, since they weren't available in the .NET tab of the 'add references' dialog in Visual Studio. So I browsed to PIPC\ProcessBook\Public Assemblies and selected them. I see they are GAC'ed with version 3.1.0.0...

                                                                • Re: A better regression line visualization?
                                                                  dhollebeek

                                                                  Short answer:  Visual Studio is really bad about how it handles references, especially if a project is moved from one dev enviroment to another.  It tries to be entirely too smart about how it tries to find a reference, and it usually ends up getting it wrong.  You'd be surprised how many times after loading a project, I delete the references and re-add them.

                                                                   

                                                                  The PBObjLib and PBSimLib libraries have what I think are old versions in the same directory as ProcBook.exe for backward compatibility (take a look at where PbSymLib was loading from in it's HintPath).  Anyway, loading them from Public Assemblies of the GAC is always preferable.  As a best practice, we always review Visual Studio project files before we check them in and get rid of versions, guids, etc.  Here's an example of what we use to load PBSymLib:

                                                                   

                                                                     <Reference Include="OSIsoft.PBSymLib">

                                                                   

                                                                       <HintPath>..\..\EXE\$(Configuration)\OSIsoft.PBSymLib.dll</HintPath>

                                                                   

                                                                       <Private>True</Private>

                                                                   

                                                                     </Reference>

                                                                   

                                                                  (of course we use hintpath to direct it to the latest compiled version rather than whatever PB (if any) is installed, but you could get rid of hintpath and it should then always chose the GAC version first).

                                                                   

                                                                  Other than those observations, I can't really provide any input unless I know the history of how the project got created.

                                                                    • Re: A better regression line visualization?
                                                                      Asle Frantzen

                                                                      Ok, I see. But do you have those two available in the .NET tab of the 'add references' dialog in your computer?

                                                                       

                                                                      I see now that the hint paths of the two assemblies were different as well. PBObjLib is pointing to the correct, new version in the ProcessBook\Public assemblies folder, and PBSymLib is pointing to the older version directly in the ProcessBook folder.

                                                                       

                                                                      I did make sure (several times) that my project referenced the new dll files in the Public assemblies directory. Both have the version 3.3.0.949 there, but somehow the older 1.0.0.0 versions were used instead.

                                                                       

                                                                      Strange things...

                                                                        • Re: A better regression line visualization?
                                                                          dhollebeek

                                                                          Our configuration is a little bit special for our add-ins because PB gets recompiled at the same time, so we pull from an odd spot and they are not registered.

                                                                           

                                                                          If you have a machine which is consistantly picking the wrong references from the .Net 'add reference', find the correct directory for the assembly and do 'regasm /codebase' on it.  The /codebase directive tells regasm to register the assembly in that specific directory (however what is in the GAC will usually win - to get around this, we don't keep assemblies in the GAC on dev PC's).  However, you don't have the issues with using pre-released versions of the PB libs like we do.

                                                                           

                                                                          Microsoft's handling of this stuff is bad enough that we have just gotten in the habit of always reviewing and editting project files by hand before checking them in ...