View
36
Download
1
Category
Tags:
Preview:
DESCRIPTION
report designer wonderware
Citation preview
Wonderware Factelligence™
Report Designer
Invensys Systems, Inc.
Revision D
Last Revision: 3/6/08
Copyright© 2008 Invensys Systems, Inc. All Rights Reserved.
All rights reserved. No part of this documentation shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Invensys Systems, Inc. No copyright or patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this documentation, the publisher and the author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein.The information in this documentation is subject to change without notice and does not represent a commitment on the part of Invensys Systems, Inc. The software described in this documentation is furnished under a license or nondisclosure agreement. This software may be used or copied only in accordance with the terms of these agreements.
Invensys Systems, Inc.26561 Rancho Parkway SouthLake Forest, CA 92630 U.S.A.(949) 727-3200http://www.wonderware.comFor comments or suggestions about the product documentation, send an e-mail message to productdocs@wonderware.com.
TrademarksAll terms mentioned in this documentation that are known to be trademarks or service marks have been appropriately capitalized. Invensys Systems, Inc. cannot attest to the accuracy of this information. Use of a term in this documentation should not be regarded as affecting the validity of any trademark or service mark.Alarm Logger, ActiveFactory, ArchestrA, Avantis, DBDump, DBLoad, DT Analyst, Factelligence, FactoryFocus, FactoryOffice, FactorySuite, FactorySuite A2, InBatch, InControl, IndustrialRAD, IndustrialSQL Server, InTouch, MaintenanceSuite, MuniSuite, QI Analyst, SCADAlarm, SCADASuite, SuiteLink, SuiteVoyager, WindowMaker, WindowViewer, Wonderware, Wonderware Factelligence, and Wonderware Logger are trademarks of Invensys plc, its subsidiaries and affiliates. All other brands may be trademarks of their respective owners.
3
Wonderware Factelligence™ Report Designer
Contents
Chapter 1 Introduction ........................................ 5Aim .......................................................................................5Content.................................................................................5Assumptions ........................................................................5How to Use this Guide ........................................................5Reference Material ..............................................................6
Chapter 2 Overview............................................ 7
Chapter 3 Report Design ...................................... 9
Chapter 4 Reporting Mechanism........................... 13Report Designer.................................................................13Manager .............................................................................14Configuration.....................................................................15
Chapter 5 Report Preview .................................. 17
Chapter 6 Report Configuration ........................... 19
Chapter 7 Queries ............................................ 25Query Parameters .............................................................26
4 Contents
Wonderware Factelligence™ Report Designer
Chapter 8 Tutorial Exercise .................................31Overview ............................................................................32Specification ......................................................................32Query and Data Design ....................................................33Report Design and Data Validation .................................36
The Design Tab...............................................................36Using the Report Template............................................37Changing Properties ......................................................39The ADO Data Object and Data Fields.........................40Grouping .........................................................................42Formatting......................................................................44Adding Groups and Data Display Objects ....................46Complex Data Display Concepts ...................................47Creating Virtual Data Fields.........................................49Summation Objects ........................................................50Scripting Calculations....................................................52
Charting and Testing Using Manager .............................56Chart Data and Formatting...........................................56Configuring the Report for Manager.............................60Scripting Data to a Chart Using Global Arrays ...........62Adding a Table of Contents ...........................................64
Chapter 9 Scripting and Charts .............................67General ..............................................................................67Adding Script.....................................................................68Simple Report with Chart.................................................68
Virtual Fields..................................................................69Calculated Fields............................................................70Formatting Fields...........................................................71Simple Charting .............................................................71Displaying the Date .......................................................74Displaying the Filter Information and Custom
Parameters .................................................................74Report with Complex Graph.............................................75
Saving Data to Global Variables ...................................76Applying Global Data to the Chart ...............................77
Previewing Reports with Charts ......................................78
Appendix A Report Spec Sheet...............................79
5
Wonderware Factelligence™ Report Designer
Chapter 1
Introduction
Welcome to Factelligence Report Designer.
AimThis guide will teach you the basics involved in the creation and configuration of custom reports to run in the Factelligence MES system, specifically in the “Manager” browser reporting and analysis module.
ContentIt will cover the reporting mechanism and features of the Report Designer.
A number of tutorial exercises will help familiarize you with the functionality and provide the necessary skills to create powerful custom reports.
AssumptionsThe material in this course assumes that you know very little about Factelligence Report Designer and have not used the product before, but that you are familiar with the Microsoft Windows operating system and database concepts.
How to Use this GuideYou can use this guide as a self-paced training tool.
6 Chapter 1 Introduction
Wonderware Factelligence™ Report Designer
It is also a facilitation tool for your Factelligence instructor. The “Tutorial Exercise” is the same exercise used in the training course. All topics covered in the training course are in the guide.
Reference MaterialYou are encouraged to review the documentation and/or attend the training course on “Factelligence Manager”.
7
Wonderware Factelligence™ Report Designer
Chapter 2
Overview
Reports are designed using Factelligence Report Designer and typically viewed using Factelligence Manager, although reports can also be viewed using Factelligence Operator.
Over 75 pre-configured “System” reports have been provided with Factelligence in an attempt to cover most initial reporting requirements and to provide a base from which to build many more custom reports.
These reports are built on proven SQL queries designed to provide comprehensive data in the following areas:
• Production & Rejects• Consumption & Waste• Downtime & Utilization• Labor Usage• Traceability• Genealogy• Certification• Specifications• Performance & OEE• Cost• Data Log• Inventory• Yield & Quality• Audit Trail• Lean Manufacturing
8 Chapter 2 Overview
Wonderware Factelligence™ Report Designer
The user has many options when creating custom reports for their specific Factelligence application. These include:
1 Modifying an existing ‘System’ report2 Creating a new report based on an existing system report3 Creating a new report based on an existing system query4 Creating a new report from scratchThe next four sections will introduce you to the features of the Report Designer. The Tutorial Exercise will then take you through all the steps required to create a report.
9
Wonderware Factelligence™ Report Designer
Chapter 4
Report Design
The “Design” tab of the Report Designer contains the designer control and allows you to create and edit report layouts.
Figure 1 - Design Tab
10 Chapter 4 Report Design
Wonderware Factelligence™ Report Designer
The Designer has the following features:
Menu: (top left) for basic file and designer operations.Design Toolbars: (top) for use in the report design and formatting. Note in particular the “View Script” icon which we will use later.Object Toolbar: (far left side) used for placing all required graphical objects on the form “canvas”.Explorer Window: (left side - top) displays the groups and objects currently on the report canvas.Fields Window: (left side - bottom) displays all fields available from the database as a result of the query used by the report.Property Toolbox: used to set the properties of the report objects. If the toolbox is hidden then right click in blank section to the right of the Designer Toolbars and select “Property Toolbox” to open it.Clear Button: will clear the currently loaded report file and present the user with a blank sheet. This should be invoked before loading a new report for editing. If not then the application may crash due to a bug in the designer control which is yet to be sorted by the software supplier.
Exercise 1 - The Design Tab
Aim: To open a report and examine its features.
Method:
1 Launch Report Designer. If the application is licensed then you will be prompted with a login dialog requiring your user name and / or password.
2 If login is successful then the application will open to the Design tab. Note that you must have the required privilege to run the Report Designer.
3 From the menu select “File -> Open” and select the report layout file “Factelligence\Manager\Reports\System\Production\ProductionByPeriod.rpx”. The designer will appear as in Figure 1 above.
4 Note that the report consists of a series of sections containing graphic objects for the display of data and visual formatting.If you are familiar with Visual Basic and other visual programming languages you will note that the sections and objects exhibit a number of properties that affect
11
Wonderware Factelligence™ Report Designer
their behavior and appearance. These can be set via the Property Toolbox. Take some time to examine some of these.
12 Chapter 4 Report Design
Wonderware Factelligence™ Report Designer
13
Wonderware Factelligence™ Report Designer
Chapter 3
Reporting Mechanism
The reporting tool used with Factelligence is ‘Active Reports Professional Version 2.0’ (by Data Dynamics).
Active Reports provide royalty free components in the form of a “Designer” control, that allows the user to create and edit reports, and a “Viewer” control to view the report in an executable or browser based application.
The Report Designer application utilizes both components while the Manager application uses only the viewer.
A full version of this product may be purchased by the user if so desired or the help file downloaded from their website at www.datadynamics.com.
The mechanism for running a report works differently in the Report Designer and Manager browser applications for specific reasons as we shall see below.
Report DesignerAll report layouts are created with an ADO data object. This object is configured with the required connection string and SQL query to gather the data directly from the Factelligence database. When the report is previewed in Report Designer the designer runs it as a standalone report. The query configured in the report is run directly against the database (bypassing the Factelligence middleware), the retrieved dataset is applied to the report file for grouping and formatting, and the result displayed in the viewer.
14 Chapter 3 Reporting Mechanism
Wonderware Factelligence™ Report Designer
This mechanism requires the Report Designer application to have references to all the objects required to process the report and query the database. This is fine for a report design and configuration application and allows the user to quickly and efficiently design and test most reports outside of the Middleware/Manager structure. The exception is when the reports utilize the external global classes (see the section on “Scripting and Charts”).
ManagerManager uses a feature within the Active Reports framework that allows you to pass a recordset to a report layout at runtime. The recordset must include the same ‘fields’ and sort order as defined by the query configured in the report’s ADO object, but can be constrained and filtered prior to being applied to the report.
As a multi-client browser application, Manager makes use another feature called the Active Reports WebCache Server.
When a report is requested by a Manager client, the Factelligence Web Server processes the SQL query required by the report, modified with user selected time period and filters, via the Factelligence middleware, applies the resultant recordset to the report, and runs the report. The resultant formatted report complete with data is cached and then streamed to the client’s browser for viewing via the viewer object.
Why do we do it this way?
Firstly, the reporting workload of data gathering and report processing is now handled by the Web Server rather than the client. The client requires nothing more than the viewer to view the resultant report. This fits well with the Factelligence Manager architecture of n-tier and zero client install.
Secondly, the development effort in creating queries and report layouts is leveraged by this structure. A single report file created based on a given query can be used with any combination of data selection constraints and filters without alteration. The different record sets are simply generated and applied to the same report file.
Correspondingly, a number of different report files that display the data in different formats can be created based on a common query.
Configuration 15
Wonderware Factelligence™ Report Designer
ConfigurationThe trick with this approach is that Factelligence must be able to regenerate, complete with constraints and filters, the same SQL query that the report was designed with and run this via the middleware to create the data required.
So, when a user creates a report layout for running in Manager they must also configure, test and store in the database the query required by the report, and configure the relationship between the report and the query.
16 Chapter 3 Reporting Mechanism
Wonderware Factelligence™ Report Designer
17
Wonderware Factelligence™ Report Designer
Chapter 5
Report Preview
The “Preview” tab of the Report Designer contains the viewer control and allows you to preview the report you created in the designer.
Figure 2 - Preview Tab
The viewer contains a toolbar that allows you to perform the following functions:
Print: opens the standard printer dialogZoom: zoom in / out or select the desired scalingMulti-Page: View multiple pagesPage Select: Move back and forth between the pages or go to a specific page
18 Chapter 5 Report Preview
Wonderware Factelligence™ Report Designer
Exercise 2 - The Preview Tab
Aim: To preview a report.
Method:
1 In order to preview a report we must set the connection string for the embedded ADO object to point to a valid database. Carrying on from Exercise 1, have the “Production By Period” report layout open in the Design tab.
2 Find the “ADO” graphic object in the “Detail” section of the report. Right-click on this and select “Properties”. Edit the “Connection String” property to point to your Factelligence database.
Figure 2.1 - Setting the Connection String3 Click the “OK” button.4 Click the icon in the top right corner of the “Fields” list
(bottom left panel of Designer). If the connection string and query is valid then a list of the fields returned by the query will be displayed in the list. If there is an error, a message will be displayed.
5 Select the “Preview” tab to preview the report. It should appear as in Figure 2 above.
19
Wonderware Factelligence™ Report Designer
Chapter 6
Report Configuration
The “Configuration” tab of the Report Designer is where we configure the report to run in Factelligence.
Figure 3 - Configuration Tab
The Configuration tab consists of a number of controls to allow the setting / selection of the various aspects of a report’s configuration. You can modify an existing report configuration or create a new one.
In order to configure reports you must have the required privilege in Factelligence. If you do not then this tab is not available to you.
20 Chapter 6 Report Configuration
Wonderware Factelligence™ Report Designer
Important The tab will list all currently configured reports in the Factelligence database. Altering or deleting these will affect the way these reports operate. Ensure you are aware of all the ramifications before making changes.
A report’s configuration consists of the following:
Report Category: determines where the report will be placed in the report treeReport Name: determines the report name in the tree. Note that this name is different to the report filename. In fact you may have different named instances of the same report file configured differently.Report Description: for a brief description of the reportMax Pages: puts an upper limit on the number of pages that will be displayed for the report when it is run to prevent large reports from clogging the system. This will default to a preset value (usually 20) for a new report. If you have the required privilege you can alter the value.View Level: determines who can access this report at runtime. A user’s view level must be greater than or equal to the value set here to view the report. This will default to a preset value (usually 1) for a new report. If you have the required privilege you can alter the value.Report Type: will default to “Manager”. Reports may be run in the Manager client application or be scheduled to run in the background and the data be exported to files. This is achieved via the Factelligence Supply Chain Connector application (refer to the Supply Chain Connector documentation for further details.). When a report is run by Supply Chain Connector it cannot contain references to filters or sorts as there is no user interface available. Therefore all that need be configured is the report details and file path. By selecting the ‘SCC Export’ type the Query Details section will be hidden. File Path: must point to the report file that has been created. This must be the network filepath as required by the Manager application from the web server.
The path will default to:
%APP_PATH%Reports/System/<Category>/<Name>.rpxAt runtime the defined rootpath for the report files (set via the Factelligence Configurator application) will be substituted for ‘%APP_PATH%’.
By default the rootpath is installed as ‘C:\Factelligence\Manager\’.
21
Wonderware Factelligence™ Report Designer
The path can be left as is or an absolute path entered:
<drive>:\Factelligence\Manager\Reports\System\<Category>\<Name>.rpx
Data Query: specifies which query to run for this report.
Sort Fields: (optional) specifies the sort order for the data returned by the query for this report.
Filter: (optional) lists all the parameters available in the query. Selections here determine which filter options are displayed to the user at runtime to constrain the data.
Custom Filter: (optional) lists all the fields in the query. By setting descriptions for fields these will be available to the user at runtime to create a custom SQL filter to apply to the query.
Exercise 3 - The Configuration Tab
Aim: To examine report configuration.
Method:
1 Open the “Configuration” tab and in the “Report Details” tree select the “Production \ Production By Period” report. The controls on the form will display the current configuration settings for the report. It should appear as in Figure 3 above.
22 Chapter 6 Report Configuration
Wonderware Factelligence™ Report Designer
2 Select the “Set” button for “Sort Fields”. The dialog box is fairly straightforward. It presents a list of fields in the query for you to use as the sort criteria for the report.
Figure 3.1 - Sort Fields DialogNote that when the Sort dialog is opened the SQL query is examined and the fields are retrieved assuming a standard syntax of“SELECT tablename.fieldname …..FROM ….” The parsing of the SQL caters for most common SQL statements but it may be the case that the retrieved list of fields is nonsensical or incomplete. To cater for this a textbox for manual entry of available fields has been provided.
3 When the “Custom” filter option is selected for a report (as it is in this case) then when the report is selected in Manager a dialog is presented to you so you can construct a custom filter using the fields in the query. In order to
23
Wonderware Factelligence™ Report Designer
make this user friendly you assign alias descriptions for the fields and only include those fields that are relevant to what the report is trying to achieve.Select the “Set’ button for the “Custom Filter”’ table. Those fields that the user has access to at runtime have an associated alias.
Figure 3.2 - Custom Fields Dialog
24 Chapter 6 Report Configuration
Wonderware Factelligence™ Report Designer
25
Wonderware Factelligence™ Report Designer
Chapter 7
Queries
The “Query” tab in Report Designer allows you to design, test and configure SQL queries to run on Factelligence for use with your custom reports.
Figure 4 - Query Tab
The Query tab contains of a number of controls to allow the setting / selection of the various aspects of a query’s configuration. You can modify an existing query or create a new one.
26 Chapter 7 Queries
Wonderware Factelligence™ Report Designer
Important The tab will list all currently configured queries in the Factelligence database. These will be used by existing reports, status screens or SCC export functions. Altering these queries will affect the way these features operate. Ensure you are aware of all the ramifications before making changes.
A query definition consists of the following:
Query Description: the name that will appear in the queries tree.Query Type: you can use a SQL statement or an existing database stored procedure SQL Statement: type your SQL query here.Stored Procedure: enter the name of the stored procedure.Parameters: define the attributes of any runtime parameters that you included in your query.
Query ParametersParameters may be included in your SQL query or stored procedure. Those parameters which are then configured to be available for a given report will be made available for you to set when running the report in Manager.
Manager provides screens with controls such as calendars, tree views and text boxes to allow you to enter runtime parameters. As these screens are hard coded then there are only a limited number of parameters available to you to include in a query. These are:
• Start Time
• End Time
• Entity
• Item
• User
• Work Order
• Shift
• Custom
Query Parameters 27
Wonderware Factelligence™ Report Designer
Tip None, some or all of these parameters can be included in any given query and you are encouraged to include as many as possible to make the query generic. That way the same query may be used with many different report files. Remember that it is during the runtime configuration of each individual report that the parameters relevant to the report are selected from ALL those available in the query.
When using parameters in a query they must follow a strict syntax and then be setup correctly in the parameters list. Available parameter types for reports and their attributes are as follows:
Parameter Name Parameter TypeDefault ValueStart_Time Date TimeNULLEnd_Time Date TimeNULLEntity String ListNULLItem String ListNULLUser String ListNULLWork Order String ListNULLShift String ListNULLCustom CustomNULL
The syntax for parameters in the query is dependent on the parameter type as follows:
Parameter Type Typical Query EntryDate Time (<table>.<field> >= @Start_Time OR @Start_Time IS NULL)String List (<table>.<field> IN @Entity)Custom (@Custom)
Exercise 4 - The Query Tab
Aim: To examine query configuration and parameter usage and create a simple query.
Method:
1 Open the “Query” tab and in the tree, select the “Production Reports” query. The controls on the form will display the current configuration for the query. It should appear as in Figure 4 above.
28 Chapter 7 Queries
Wonderware Factelligence™ Report Designer
2 Click on the “Test” button to preview the results of the query.
Figure 4.1 - Query Test Results Dialog3 Note how the parameters are used in the query and
defined in the “Parameters” table. When the query was tested it used the default values for all these parameters ie: NULL. This will return all data, unconstrained.
4 Change the “Default Value” of the Entity parameter to reflect a list of “ent_id” values from the test data returned eg: ‘1211’,’1212’. Test the query again and it will return only those records for the entities listed.
Note Don’t forget the quotation marks around the entries.
5 Select the “Cancel” button to cancel the changes.
Query Parameters 29
Wonderware Factelligence™ Report Designer
6 Right-click on the root (topmost) node of the Queries tree and select “Add Query”. The controls are now ready to accept your new query details.
Figure 4.2 - Adding a New Query7 Change the “Query Description” to “My Query”.8 Enter the following SQL statement:
SELECT * FROM item9 Select the “Save” button then test your query.10 Alter the query to be:
SELECT * FROM item WHERE item.item_class_id IN @Item
11 Right-click on the Parameters table and select “Add”. Add the “Item” parameter as type “String List” to your query. Save the query and retest to ensure the syntax is correct.
30 Chapter 7 Queries
Wonderware Factelligence™ Report Designer
12 Set the default value for the Item parameter to something meaningful and retest.
Figure 4.3 - Sample Query
31
Wonderware Factelligence™ Report Designer
Chapter 8
Tutorial Exercise
This exercise will walk you through all the steps involved in producing a report for use in the Factelligence application.
The report chosen for the exercise is the ‘OEE By Shift Trend’ system report included with the Factelligence application.
This report was chosen as it includes all of the common report design concepts used in the Factelligence reports suite and those that will most commonly be used in the creation of custom reports.
Topics covered include:
• Preparing the report layout
• Creating a query and its parameters
• Using the report template to create the report
• Placing controls on the report
• Grouping of data
• Scripting for calculations
• Embedding an ActiveX chart control in the report and scripting to it
• Testing the report
• Configuring the report to run in Manager
It is impractical to try to cover all aspects of reporting in a single exercise and should you require a more thorough understanding of the reporting product then they are encouraged to either:
32 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
• Attend a training course on the “Active Reports” package. These are provided by Data Dynamics, the suppliers of the product and they can be contacted via their website at www.DataDynamics.com.
• Download the full documentation for the product free from the above website
OverviewThe creation of a report can be broken down into a number of phases:
• Specification (layout & requirements)
• Query & data design
• Design & data validation
• Charting & other features
• Configuration & final testing
We will cover each of these phases in order.
SpecificationIt is important to prepare a desired specification for the report with as much detail as possible re the layout, data content and how the user is to interact with the report.
The design of the report often is dependent on how the data needs to be displayed so it is a good idea to have as much of this done up front as possible.
The report we wish to prepare is described in the spec sheet ‘OEE By Shift Trend Report’ located in Appendix A. This spec sheet is a good template to use in the preparation of report requirements. Have a look at what is included here.
Tip Start with a basic description and a sketch of the layout of the report. As the phases of report creation are completed update the document.
In this report we wish to display the four KPIs associated with OEE on a per shift basis, in chronological order for the time period selected. This data will be tabular and grouped by entity with a chart after the data showing the trends for the KPIs.
Query and Data Design 33
Wonderware Factelligence™ Report Designer
Query and Data DesignNow that we know what we wish to display we need to create a query to get the required data.
Factelligence allows for the creation and use of parameterized SQL statements or Stored Procedures. The preferred method is to use a SQL statement as the stored procedures are more complicated to parameterize. However stored procedures are faster and more efficient so for very complex queries or for processing large amounts of data they may be a better option.
We must decide what data to retrieve and what parameter selections we wish to make available to the user. Our report requires the OEE data from the ‘tpm_stat’ database table and we wish the user to select the time period and entities.
34 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
In this case we will be using a standard SQL query that is included with the Factelligence application. Let us examine this query. The source for any of the standard queries can be found in the ‘Factelligence\Manager\SQL’ directory, in this case the file ‘OEE Reports.sql’.
SELECT tpm_stat.ent_id, ,ent.ent_name ,tpm_stat.wo_id ,wo.wo_desc ,tpm_stat.oper_id ,tpm_stat.seq_no ,job.act_start_time ,job.act_finish_time ,job.batch_size ,tpm_stat.shift_start ,tpm_stat.shift_id ,shift.shift_desc ,tpm_stat.item_id ,item.item_desc ,item.units ,tpm_stat.qty_good ,tpm_stat.qty_reject ,tpm_stat.std_prod_rate ,tpm_stat.runtime ,tpm_stat.downtime ,tpm_stat.idletime FROM tpm_stat tpm_stat with (nolock) INNER JOIN ent ent with (nolock) ON tpm_stat.ent_id = ent.ent_id LEFT OUTER JOIN wo wo with (nolock) ON tpm_stat.wo_id = wo.wo_id LEFT OUTER JOIN job job with (nolock) ON tpm_stat.wo_id = job.wo_id AND tpm_stat.oper_id = job.oper_id AND tpm_stat.seq_no = job.seq_no INNER JOIN shift shift with (nolock) ON tpm_stat.shift_id = shift.shift_id LEFT OUTER JOIN item item with (nolock) ON tpm_stat.item_id = item.item_idWHERE (tpm_stat.shift_start >= @Start_Time OR
Query and Data Design 35
Wonderware Factelligence™ Report Designer
@Start_Time IS NULL) AND (tpm_stat.shift_start < @End_Time OR @End_Time IS NULL) AND (tpm_stat.ent_id IN @Entity) AND (tpm_stat.item_id IN @Item) AND (tpm_stat.wo_id IN @Work_Order) AND (tpm_stat.shift_id IN @Shift) AND (@Custom)
This query retrieves all the data from the tpm_stat table together with some descriptive data from joined tables. Not a complicated query.
Take note of the WHERE section of the query. This is where any parameters are scripted. Parameters are those values that may be entered at runtime by the user to constrain the data returned. Please refer to the “Queries” section of this guide for more detail on query preparation and the use of parameters.
This is what we would term a “Generic” query. It retrieves all data fields from the table and the data is raw (unprocessed). Furthermore it includes all parameters that are available as report filters.
In our report we may not use some of these fields and we only wish the user to select the report period and the entities. However a generic query may be used by many different reports of an OEE theme eg: OEE by Work Order, Utilization By Entity, Performance By Shift, ….
Tip If the query is simple and it can be made generic then do so, thus leveraging your query development to multiple reports. If the query is complex and specific to one report or accesses large amounts of data then make it concise and more efficient.
Queries can be written, tested and saved to the database by using the Report Designer. Start Report Designer and go to the Query tab. Select the OEE Reports query and you will see the query text and parameters defined.
36 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Figure T1 - OEE Reports Query
Click on the “Test” button to see the result of the query (with no parameters applied).
We need do no more with the query so we will move on to designing the report.
Report Design and Data ValidationReport design should be an iterative process. Create the report in small steps, testing as you go. The Report Designer application caters for this by allowing the user to switch easily between design and preview mode.
The Design TabStart Report Designer. It defaults to the Design tab.
Report Design and Data Validation 37
Wonderware Factelligence™ Report Designer
Figure T2 - Design Tab
Using the Report TemplateFactelligence includes a report template to assist in the creation of custom reports. It is setup with some basic formatting and script to suit the running of reports in the Manager module. Alternately we could start with a completely blank sheet or use one of the existing reports as a starting point.
We will use the report template. From the menu select “File -> Open” and open the file “\Factelligence\ReportDesigner\Samples\ReportTemplate.rpx”.
38 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Figure T3 - The Report Template
Let us consider what is included in this template.
Firstly you will note that the report has a number of sections. Within those sections are placed the objects used to format the report and display the data. The use of these groups is the key to how the data is processed and displayed on the report.
Report Header/Footer: displayed once at the beginning and end of the reportPage Header/Footer: displayed at the beginning and end of each pageGeneral Group/Footer: displayed whenever the data field associated with the group changes.Detail: displayed for every database record processed.
Most of the objects that exist in the template will remain or be relocated and adjusted for a custom report. We will look at some of these in the process of designing the report.
Report Header/Footer: These sections contain objects and scripts used to display the details of report filters that are applied when the report is run in Manager.
If you open up the Report Header section you will find a hidden textbox “txtParameters”. This is included in all system reports as Manager has the capability of passing a text string to the report. The text string can contain anything but most commonly will contain variable values or text for display in the report. For example, entity ID’s are used in the query filter string in all reports. However it is more
Report Design and Data Validation 39
Wonderware Factelligence™ Report Designer
user-friendly to display the associated descriptions in the filter section so Manager uses the parameter feature to pass the descriptions.
The Report Footer section contains objects (and script) that will display the filters that were applied to the report query ie: entity IDs, item IDs, etc. Manager passes the filter string to the hidden “txtFilters” object in a standard syntax for all reports. If the user desires not to see this information then this section can be removed or hidden.
For your report nothing needs to be altered in these sections.
Page Header/Footer: The Page Header contains the logo, some labels, a colored box and text fields for start and end dates.
The date fields should not be altered as Factelligence will automatically populate them with the dates selected by the user when the report is run in Manager. If this particular report does not require the user to select start and end dates for the report then these objects and their labels can be deleted.
Changing PropertiesClick on the report title label. In the property toolbox change the “Caption” to reflect the title of your new report.
Figure T4 - Changing the Title by using the Property Toolbox
If the logo is to be changed then select it and in the property toolbox change the “Picture” property to reference the new bitmap file.
40 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Important The bitmap must be sized correctly for the report and the “SizeMode”’ property must be set to “Clip”. Using the SizeMode = Stretch or Zoom properties to resize a bitmap will cause the report to resize the graphic each time the report is rendered and can increase report processing time by a factor of 10+.
Using the “File -> Save” option in the designer menu, save the report file to it’s new location eg: “\Factelligence\Manager\Reports\Custom\MyOEEReport.rpx”
Figure T5 - File Save
Remember to save your work frequently.
The ADO Data Object and Data FieldsIn the “Detail” section we find the “ADO” object. This is used by the report to access the database for gathering data during design and preview operations. We need to set this object up to connect to our database and use the OEE query.
Right-click on the “ADO” object and select “Properties”.
Edit the “ConnectionString” to reflect the connection to your database
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=USER;Pwd=PWD;Initial Catalog=DBASE_NAME;Data Source=SERVER_NAME
Edit the “Source (SQL)” to be the OEE query above without the WHERE clause. We cannot include parameters at this point as we are not running the report within the Manager
Report Design and Data Validation 41
Wonderware Factelligence™ Report Designer
application and parameter selection is not available. The query embedded in the report is not used when the report is run in the Manager application. Rather the query configured in the Query tab together with its parameters is used (refer to the “Reporting Mechanism” section for further details).
Tip If you have a large amount of data to process then adding constraints to the ADO query (in a WHERE clause) to limit the data to a manageable and meaningful quantity will make the report design and testing process more efficient.
Figure T6 - Setting the Connection and Query
We can now do a quick test on the query.
By clicking on the icon in the “Fields” list (bottom left side of the Designer) the report will process the query entered in the ADO object and return a list of available database fields. If there is an error in either the query or the connection string then an error will be displayed.
42 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Figure T7 - Displaying Query Fields
GroupingNow it is time to start adding data fields and groups to the report.
Our primary grouping is to be by Entity. Select the “ghGroup” section (this is the group header) and in the property toolbox set:
Name: ghEntityData Field: ent_id Causes a new group header to be displayed eachtime this field changes.KeepTogether: TrueEnsures the section is not split over a pageboundary.
Select the ‘gfGroup’ section (this is the group footer) and in the property toolbox set:
Name: gfEntityKeepTogether: True
Note A certain standard for naming of objects as been employed here but this is entirely a user preference.
Report Design and Data Validation 43
Wonderware Factelligence™ Report Designer
Figure T8 - Data Field Selection for a Group
From the “Fields” window, drag the ent_name field into the ghEntity section. This creates a new Text Field object.
Edit the object properties:
Name: txtEntNameSet this object at the top of the section and make it cover the entire width of the section.
Tip The mouse can be used to size and move objects in the usual manner. For fine adjustments use SHIFT + ARROW KEYS for sizing and CTRL + ARROW KEYS for movement.
Increase the height of the section using the mouse or set it’s property:
Height: 615Now select the Preview tab to see how the report is processed. You may see something like that in Figure T9 below.
What is important to note here is how the grouping has worked. As the report processes the records retrieved by the query, each time it detects a change in the “ent_id” field a new ghEntity/gfEntity section is created. Because the query does not currently order the data we see repeats of the same entity. What we need to do is to ensure that the data retrieved by the query is ordered in the same way that we create groups on the report.
44 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Figure T9 - First Preview
Return to the Design tab and select the ADO object in the Detail section and right click to open its properties. Edit the SQL query to include “ORDER BY tpm_stat.ent_id” at the end of the query.
Preview the report again and you should now see only one entry per entity.
FormattingNow that we have achieved the first stage of the data processing we will do some formatting.
Firstly, this report will start a new page for each new entity so the ghEntity section is the logical place to have the column headers etc.
In the Page Header, delete the blue rectangle and cut and paste the column header labels into the ghEntity section.
Tip Hold the CTRL key down to select multiple objects. Use CTRL+X and CTRL+V to cut and paste in the usual manner.
Adjust the properties of the txtEntName:
BackStyle: NormalBackColor: R,G,B = 128,174,200Font: Bold
Report Design and Data Validation 45
Wonderware Factelligence™ Report Designer
Adjust the properties of the 6 column header label objects:
Caption: Date Shift % Util % Perf% Qual % OEEWidth: 2041 2778 1134 1134 1134 1134
Space them across the width of the report and use the formatting toolbar to set the text alignment to Centered.
Adjust the properties of the sections as follows:
PageHeader Height: 1300ghEntity Repeat: Every Page Include No Detail This causes the header to repeat if the data goes across a page boundary.gfEntity NewPage: After Starts a new page for each new entity.
Figure T10 - Entity Group formatting
There is one more small detail to take care of before we Preview our report again. Select the “PageHeader” section and then “View -> View Script” from the Designer menu (or click the View Script icon in the Designer toolbar). This will open the scripting window.
Delete the “Sub OnBeforePrint” section. This was used to hide the column headers that were in this section for the last report page which displays the filters. We will come back to discuss scripting later.
Save the report and Preview your results to date.
46 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Adding Groups and Data Display ObjectsThe next stage of the report will involve setting up the section to display the actual data. We wish to display the data per shift in descending chronological order so we first need to group the data by date and then by shift.
Right-click anywhere in the report and select “Insert -> Group Header/Footer”. This will create a new group outside the Detail section.
Set the properties as follows:
Name: ghShiftDataField: shift_startKeepTogether: TrueHeight: 900Name: gfShiftKeepTogether: TrueHeight: 0
Edit the SQL statement in the ADO object to read “ORDER BY tpm_stat.ent_id, tpm_stat.shift_start DESC”.
From the Fields window drag the shift_start, shift_id and shift_desc fields into the ghShift section and set the properties as follows:
Name: txtShiftStartOutputFormat: d-mmm-yyyyWidth: 2041Name: txtShiftIDLeft: 2098Width: 567Name: txtShiftDescLeft: 2778Width: 2041
Report Design and Data Validation 47
Wonderware Factelligence™ Report Designer
Figure T11 - Shift Grouping
Save the report and Preview. You should now see the shift groupings on the report.
Figure T12 - Preview of Shift Grouping
Complex Data Display ConceptsThese include:
• Using Virtual fields
• Creating Summation objects
• Scripting calculations
48 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
First let us review how OEE is calculated.
OEE = Utilization x Performance x Quality where all the values are expressed as a percentage figure.
Utilization = runtime vs available time
Performance = production vs (std rate x runtime)
Quality = good production vs total production
Looking at the fields returned by the query we can use the following calculations:
Utilization =runtime
----------------------------
runtime + downtime
Performance = (qty_good + qty_reject)
--------------------------------------------------------------
(batch_size / std_prod_rate) x (runtime / 3600)
Note All times are in seconds and the std_prod_rate is hours per batch.
Quality = qty_good
-----------------------------
qty_good + qty_reject
In our report we wish to do these calculations on a per shift basis. Easy enough for the Utilization and the Quality as they are simple summations of existing fields. Not so easy for the Performance. What would be nice is for there to be a performance field for each record in the table that we could then sum in the report over whatever grouping we chose (in this case by shift).
Mathematics tells us that all we need do is create a weighted performance field based on runtime and then if we sum the weighted performance over any timeframe as follows.
If
PW1 = P1 * RT1 PW = weighted perf, P = perf, RT = runtimePW2 = P2 * RT2
Then
Ptotal = (PW1 + PW2) / (RT1 + RT2)We could include a new calculated field in the query for weighted performance however we will do it in the report for two reasons. Firstly to demonstrate the concept of virtual
Report Design and Data Validation 49
Wonderware Factelligence™ Report Designer
report fields and more importantly it keeps the query generic so different reports may apply different versions of a performance calculation if required.
Our new field is now calculated as:
Weighted Performance =(qty_good + qty_reject) x std_prod_rate x 3600
--------------------------------------------------------------
batch_size
We will now start editing the report script. The user is encouraged to review the section on “Scripting” for a description on report processing and basic scripting principles.
Creating Virtual Data FieldsSelect the View Script icon in the Designer toolbar to open the Scripting Editor. From the “Object” drop down, select “Active Reports Document”.
Add the following script:Sub OnDataInitialize
'Create the required virtual fields rpt.Fields.Add "weighted_perf"
End Sub
Sub OnFetchData(eof) 'As data is read, populate the virtual fields 'Generate weighted performance field '
' = Performance * Runtime ' ' = (Qty Good + Qty Rej) * Std Prod Rate * Runtime
' ------------------------------------ ' Batch Size * (Runtime / 3600)
' ' = (Qty Good + Qty Rej) * Std Prod Rate * 3600
' ------------------------------------------- ' Batch Size
'
rpt.Fields("weighted_perf").Value =
(rpt.Fields("qty_good").Value + rpt.Fields("qty_reject").Value) *
rpt.Fields("std_prod_rate").Value * 3600 /rpt.Fields("batch_size").Value
End Sub
50 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
As the report processes the records returned by the query it will now add a new “virtual” field to each record with the value as calculated above. This field can now be accessed by report objects for processing and can be displayed like all the other fields.
Figure T13 - Creating a Virtual Data Field
Summation ObjectsWe will now add a number of invisible summation objects to calculate the values needed for the OEE KPIs. Note that summation objects are more efficient than using script.
Close the Scripting Editor. In the Object Toolbar select the “TextBox” icon and use the mouse to create a textbox in the lower part of the ghShift section. The size of the textbox is not important as it will be invisible. Set the properties as follows:
Name: txtShiftRTDatafield: runtimeSummaryGroup:ghShiftSummaryType: SubTotalText: RT
This object will now sum the runtime field values and reset itself at each change of shift.
Report Design and Data Validation 51
Wonderware Factelligence™ Report Designer
Repeat this procedure four more times as follows:
Name: txtShiftDTDatafield: downtimeSummaryGroup:ghShiftSummaryType: SubTotalText: DTName: txtShiftGoodDatafield: qty_goodSummaryGroup:ghShiftSummaryType: SubTotalText: GoodName: txtShiftRejectDatafield: qty_rejectSummaryGroup:ghShiftSummaryType: SubTotalText: RejectName: txtShiftWeightedPerfDatafield: weighted_perfSummaryGroup:ghShiftSummaryType: SubTotalText: Perf
Note You will not be able to select weighted_perf from the dropdown Datafield property. Simply type it in.
Figure T14 - Hidden Summation Objects
52 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Save the report and Preview to check that your data calculations are correct. Once the data has been validated then make all the summation objects invisible.
Tip Select all the objects by using the mouse to drag a box around them or hold the CTRL key down while clicking them. Then use the Property Toolbox to set their visibility to false.
Figure T14 - Preview Summation Data for Validation
Scripting CalculationsWe now have the summations of the fields we need to calculate our OEE KPIs on a per shift basis. Let us add the objects to display the data and the required scripting calculations.
Report Design and Data Validation 53
Wonderware Factelligence™ Report Designer
Add the following four TextBox objects to the ghShift section and then use the mouse to drag the bottom margin of the section up and thus reduce the height of the section to hide the summation objects.
Name: txtShiftUtilAlignment: RightOutputFormat: #,##0.0Text: UtilLeft: 4876Width: 850Name: txtShiftPerfAlignment: RightOutputFormat: #,##0.0Text: PerfLeft: 6066Width: 850Name: txtShiftQualAlignment: RightOutputFormat: #,##0.0Text: QualLeft: 7257Width: 850Name: txtShiftOEEAlignment: RightOutputFormat: #,##0.0Font: BoldText: OEELeft: 8447Width: 850
54 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Figure T15 - Final Data Display Objects
Select the “ghShift” section and open the Scripting Editor. Add the following script to calculate the OEE KPIs and populate the textboxes with the results.Sub OnBeforePrint
'Calculate the OEE KPIs 'Utilization If rpt.txtShiftRT.DataValue + rpt.txtShiftDT.DataValue <> 0 Then
rpt.txtShiftUtil.DataValue = rpt.txtShiftRT.DataValue /
(rpt.txtShiftRT.DataValue + rpt.txtShiftDT.DataValue) * 100
Else rpt.txtShiftUtil.DataValue = 0
End If 'Performance If rpt.txtShiftRT.DataValue <> 0 Then
rpt.txtShiftPerf.DataValue = rpt.txtShiftWeightPerf.DataValue /
rpt.txtShiftRT.DataValue * 100 Else
rpt.txtShiftPerf.DataValue = 0 End If 'Quality If rpt.txtShiftGood.DataValue + rpt.txtShiftReject.DataValue <> 0 Then
rpt.txtShiftQual.DataValue = rpt.txtShiftGood.DataValue /
(rpt.txtShiftGood.DataValue + rpt.txtShiftReject.DataValue) * 100
Else rpt.txtShiftQual.DataValue = 0
End If 'OEE rpt.txtShiftOEE.DataValue = rpt.txtShiftUtil.DataValue *
Report Design and Data Validation 55
Wonderware Factelligence™ Report Designer
rpt.txtShiftPerf.DataValue * rpt.txtShiftQual.DataValue / 10000
End Sub
All we are doing here is using the values in the hidden summation objects in the standard formula and applying the results to the textbox objects for formatting and display.
Figure T16 - Script for Calculating the KPIs
The data processing and display phase of the report is now complete. Save the report and Preview for further data validation.
Figure 17 - Preview OEE KPI Data
56 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Charting and Testing Using ManagerThe hard work has been done. Now we will add a chart to display the KPI trends. Refer to the “Scripting and Charts” section for more details on charting.
Increase the height of the gfEntity section to about 6500.
Select the “ActiveX Control” icon in the Object Toolbar and from the list of controls select the “Tidestone First Impression 6.0 Chart”. Place the chart in the section and size to suit by using mouse left click and drag. Set its properties to:
Name: chtOEE
Figure T18 - Inserting an ActiveX Chart Control
We use this chart in the Factelligence reports as it is simple to use and has very user-friendly design time editors built in that allow you to set the look and feel of the chart without having to run the report.
Chart Data and FormattingRight-click on the chart and select “Edit Chart Data”. Enter the data as shown below.
Charting and Testing Using Manager 57
Wonderware Factelligence™ Report Designer
Figure T19 - Sample Data to Test the Chart
Select ‘OK’ and you will see the data displayed in the chart.
58 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Right-click on the chart and select ‘Chart Designer’. Make the following settings from the options available:
ChartType LineBackdrop
FrameStyle = Single LineTitleLocation Visible = OnText “OEE Trend Chart”Font Arial Bold 12LegendLocation Visible = OnFont Arial Bold 10Category (X) AxisAxis TitleText “Date & Shift”Font Arial Bold 10
Axis LabelsDisplayAutomatic Rotation = OffLayoutAlignment = LeftOrientation = VerticalFontArial Regular 10
Value (Y) AxisAxis TitleText“Percent (%)”FontArial Bold 10Axis LabelsFontArial Regular 10
Value (2nd Y) AxisValue ScaleScaleShow = Off
SeriesUtilization / Performance / Quality /
OEELinesWidth = 1 PointColorChose a different line color if
desiredDataPoint
Charting and Testing Using Manager 59
Wonderware Factelligence™ Report Designer
MarkersShow Markers = OnStyle = Filled CircleSize = 4pt
Figure T20 - Chart Designer Dialog
Save the report and Preview. You will see the chart object displayed after each set of entity data. The charts will display the sample data as we have not scripted any real data to them yet.
Figure T21 - Formatted Chart
Scripting data to the chart is not a complex task once you understand how it works. Basically we must script the values for the OEE KPIs into the “DataGrid”’ of the chart where the rows represent the Shift and the columns represent the KPI values (one column per KPI). In short we replace the sample data we entered with actual data at runtime.
As we wish to graph the totals for each shift we need some way of storing the group totals as they are calculated (for an initially unknown number of groups) and then applying them
60 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
to the chart once the report has finished processing the data. This effectively requires the declaration and use of global variables (ie: variables that can span all sections).
Unfortunately, global variables cannot be defined inside the report’s scripting environment, however Active Reports provides a mechanism whereby the report processing engine can access an external object for use within the reports scripting. To this effect Factelligence provides a class containing a number of variant arrays that can be used by any report. These arrays are referenced by the Web Server when running the report and appear as global variables to the report script. The user need only know how to reference these arrays in the script and nothing more. These arrays should cater for any foreseeable charting or other requirements.
Now an important point.
When the Preview tab is selected the report that is in the Design tab runs directly against the database using the query in the ADO object to generate the recordset for the report. It does not access the Factelligence middleware or the Web Server so therefore the global variable arrays are not available to any reports previewed in the Report Designer application.
Important If you are designing a report using the global variables then you can only test that part of the scripting by using the Manager application.
Configuring the Report for ManagerSo we now need to configure the report to run in Manager in order to test the chart. Refer to the section on “Configuration” for more details on the Configuration tab.
Charting and Testing Using Manager 61
Wonderware Factelligence™ Report Designer
Select the “Configuration” tab in the Designer and set the following:
Report Category:OEEReport Name: My OEE ReportReport Description:Data and trend of OEE KPIs by shift for selected entities and shiftsReport Type: ManagerFile Path:C:\Factelligence\Manager\Reports\Custom\MyOEEReport.rpx
(or whatever path is relevant to your report)Data Query: From the dropdown list of queries select the “OEE Reports” query.Filter: In the “Filter”’ list select “Start_Time, End_Time, Entity, Shift”. These are the parameters that we wish the user to select at runtime.Sort Fields: Open the “Sort Fields” dialog by clicking the “Set” button and select the sort order for the data to suit the report ie: “ent_id, shift_start DESC”
Save the configuration.
Figure T22 - Report Configuration
Launch the Manager application and run the report. It should appear as it did in Report Designer with the charts showing the sample data.
62 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Tip Leave Manager open. Each time you make a change to the report in Report Designer simply save the report and then reselect the ‘View’ button in Manager to test this latest report file with the same parameters.
Scripting Data to a Chart Using Global ArraysNow we can add the scripting for the chart and test it.
The external object holding the arrays is always referenced in script as “objReport”. The available arrays for use are:
• DataArray1(1000,100,10)a 3D variant array
• DataArray2(1000,100,10)a 3D variant array
• DataArray3(10000,10,10)a 3D variant array
• DataIndex(10)a 1D variant array
We will use the last DataArray to store the Shift string, and KPI values. The DataIndex keeps track of the number of groups we end up with and maintains a pointer into the array.
First we need to populate the array.
Select the ghShift section and open the Scripting Editor. Add the following script to the end of the ‘OnBeforePrint’ subroutine:Dim i
Dim dDate 'Store the date, shift and % OEE to an array for graphing later 'The array and index are provided as global variables via an external class
' DataArray3(10000,10,10) use array #3 ' DataIndex(10) use index #0
i = objReport.DataIndex(0) dDate = FormatDateTime(rpt.txtShiftStart.Text) objReport.DataArray3(i,0,0) = Day(dDate) & MonthName(Month(dDate),True) & Right(Year(dDate),2) 'ddMmmYY objReport.DataArray3(i,1,0) = rpt.txtShiftID.DataValue 'Shift ID objReport.DataArray3(i,2,0) = rpt.txtShiftUtil.DataValue 'Utilization objReport.DataArray3(i,3,0) = rpt.txtShiftPerf.DataValue 'Performance objReport.DataArray3(i,4,0) = rpt.txtShiftQual.DataValue 'Quality objReport.DataArray3(i,5,0) = rpt.txtShiftOEE.DataValue 'OEE objReport.DataIndex(0) = i + 1
Charting and Testing Using Manager 63
Wonderware Factelligence™ Report Designer
We now have the data in the array and next we need to add script to extract this data into the chart.
Select the gfEntity section and open the Scripting Editor. Add the following script:Sub OnBeforePrint
Dim i, iSamples 'Process data to chart for display 'First determine how many data entries there are (X axis) iSamples = 0 Do While Not IsEmpty(objReport.DataArray3(iSamples,0,0))
iSamples = iSamples + 1 Loop
'Now setup the chart With rpt.Sections("gfEntity").Controls("chtOEE")
'Set the chart title to reflect the entity name .Title = rpt.txtEntName.Text & " OEE Trend Chart" 'Process the array into the graph data grid .RandomFill = False 'Redimension the data grid to reflect correct number of rows .RowCount = iSamples .ColumnCount = 4 'Add the data For i = 0 to iSamples - 1
.Row = i + 1 'Create string of shift and date for the X axis label .RowLabel = objReport.DataArray3(i,1,0) & " " &objReport.DataArray3(i,0,0) .Column = 1 'Utilization .Data = objReport.DataArray3(i,2,0) .Column = 2 'Performance .Data = objReport.DataArray3(i,3,0) .Column = 3 'Quality .Data = objReport.DataArray3(i,4,0) .Column = 4 'OEE .Data = objReport.DataArray3(i,5,0)
Next End With 'Clear the data array ready for the next chart If iSamples > 0 Then
iSamples = 0 Do While Not IsEmpty(objReport.DataArray3(iSamples,0,0))
objReport.DataArray3(iSamples,0,0) = EmptyobjReport.DataArray3(iSamples,1,0) = EmptyobjReport.DataArray3(iSamples,2,0) = EmptyobjReport.DataArray3(iSamples,3,0) = EmptyobjReport.DataArray3(iSamples,4,0) = EmptyobjReport.DataArray3(iSamples,5,0) = Empty iSamples = iSamples + 1
64 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
Loop objReport.DataIndex(0) = 0
End IfEnd Sub
We will not discuss the scripting contents in any detail as it is fairly straightforward.
Save the report and run it in Manager. You will now see that the charts will display the actual data for each entity.
Tip Scripting errors may or may not generate an error message when the report is run in Manager. Signs of scripting errors may include charts showing the message “Not Enough Data” or reports only displaying the first page (scripting errors can cause the report to stop processing). Ways to debug script include placing progress message prompts in the script or to comment out the script and uncomment sections progressively until the bug is found.
Adding a Table of ContentsAs a finishing touch we will add a Table Of Contents to the report to allow the user to easily page through the charts. The TOC is an inbuilt feature of the Active Reports environment and is easy to script to.
Select the gfEntity section and open the Script Editor. Add the following script to the end of the ‘OnBeforePrint’ subroutine.
'Add a Table of Contents entry for the chart rpt.TOC.Add "Charts" & "\" & rpt.txtEntName.Text
For each entity this will add a node to a TOC tree that will display with the report. The entry will have a root node of “Chart” and then a branch named after the entity.
The syntax for adding nodes is:
rpt.TOC.Add ROOTNODE & “\” (starts a child branch) & “NODENAME” & “\” (for another level) and so on
Save the final version of the report and run it in Manager.
Charting and Testing Using Manager 65
Wonderware Factelligence™ Report Designer
Figure T23 - Finished Report
66 Chapter 8 Tutorial Exercise
Wonderware Factelligence™ Report Designer
67
Wonderware Factelligence™ Report Designer
Chapter 9
Scripting and Charts
It is not within the scope of this document to provide an in depth discussion on scripting. Rather a number of examples of the use of scripting within the system reports will be explained here to provide a guide to the user.
You are encouraged to review the tutorials included in the Active Reports User Manual (downloadable from the website www.datadynamics.com).
GeneralVB Script is available for use within the report to provide for more complex data manipulation than is available using the standard properties of text field objects and section grouping.
Script is associated with each defined section within the report and will run as each section is processed.
During processing, a report will:
• Process the records in the applied/generated recordset one at a time in the order they appear in the recordset (ie: first to last).
• Start with the outermost group header defined in the report. If the defined group field has changed then create a new group header at this level.
• Populate section objects such as text fields with data.
• Run the associated script associated with the section.
• Work through the groups to the detail section as required.
68 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
• Format the pages for display.
• Display the report.
Adding ScriptWhen in the Report Designer and following the creation of the basic report (grouping, text fields, etc) you can select the “View Script” icon in the menu bar.
The script window that opens is very similar to a standard VB script window. You select the “Object” (report section) and then scripts within the appropriate “Event” within that section.
Tip It is always good practice to reuse code that you know works well. Use the scripting editor to cut and paste code from like reports.
Figure 5 - Script Editor
Simple Report with ChartWe will now look at examples of scripting and charting using the “Utilization Analysis” report. This report file can be found at
“\Factelligence\Manager\Reports\System\Utilization\UtilizationAnalysis.rpx”
Simple Report with Chart 69
Wonderware Factelligence™ Report Designer
Virtual FieldsUsed to create calculated fields in the records of the recordset as they are read by the report.
Object : ActiveReports DocumentThis section contains events for the report as a whole.Event : OnDataInitializeThis is triggered before the recordset is processed and in this case is used to define virtual fields that are created as the data is processed. This allows us to add extra calculated fields to each record for later display or grouping.Here we see the following code:'Create the virtual fieldsrpt.Fields.Add "run_time"rpt.Fields.Add "down_time"rpt.Fields.Add "stop_time"rpt.Fields.Add "total_time"
Event : OnFetchDataThis is triggered as each record in the recordset is processed and in this case is used to set the values of the virtual fields that were defined.Here we see the following code:'As data is read, populate the virtual fields'Generate runtime fieldIf rpt.Fields("runtime").Value Then
rpt.Fields("run_time").Value = rpt.Fields("duration").Value rpt.Fields("stop_time").Value = "0" rpt.Fields("down_time").Value = "0"
Else rpt.Fields("run_time").Value = "0" 'Generate downtime field If rpt.Fields("downtime").Value Then
rpt.Fields("down_time").Value = rpt.Fields("duration").Value rpt.Fields("stop_time").Value = "0"
Else rpt.Fields("down_time").Value = "0" 'Generate stoptime field rpt.Fields("stop_time").Value = rpt.Fields("duration").Value
End IfEnd If'Generate totaltime fieldrpt.Fields("total_time").Value = rpt.Fields("duration").Value
As we can see, the database includes the fields “duration”, “runtime” and “downtime”. The combination of runtime and downtime flags determines whether the duration is to be classed as runtime, downtime or stopped
70 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
time. It is easier for reporting to do this classification at this stage than to do it each time these values are required to be displayed in the report.
Calculated FieldsCalculating values prior to display using textboxes.
Object : ghTotalThis script executes for the “Total” group header section. This section will appear once at the start of the report.Event : OnBeforePrintThis event fires when all data objects in the section have been populated and section formatting is complete before the section is finalized for printing.The script here creates the report totals for display.Here we see the following code:'Calculate the % UtilizationIf rpt.txtTotRT.DataValue + rpt.txtTotDT.DataValue <> 0 Then
rpt.txtUtil.DataValue = rpt.txtTotRT.DataValue / _
(rpt.txtTotRT.DataValue + rpt.txtTotDT.DataValue)
Else rpt.txtUtil.DataValue = 0
End If
Here we calculate the “% Utilization” value as per the standard OEE formula.If you go to this report section and drag the section border down you will find 3 hidden text field objects which are responsible for summing the runtime, downtime and stoptime virtual fields for this group (ie: the totals of each field). These objects are then referenced by the script which calculates the % Utilization and applies it to the text field object for display.
Simple Report with Chart 71
Wonderware Factelligence™ Report Designer
Formatting FieldsChanging the format and / or visibility of data based on calculated values.
Object : ghStateCodeThis script executes for the “StateCode” group header section. This section will appear once for each unique state code that exists in the recordset.Event : OnBeforePrintThe script in this event is used to format values for displayHere we see the following code:'Convert times in seconds to hh:mm:ss formatrpt.txtStateRuntime.Text =
FormatTime(rpt.txtStateRuntime.DataValue)'Do not display zero valuesIf rpt.txtStateRuntime.DataValue = 0 Then
rpt.txtStateRuntime.Text = ""End If
The text field objects on the screen provide the group summing of the runtime, downtime, stoptime and totaltime fields for the state code. Here we use scripting to apply our own custom format to the displayed value. We take the objects raw data value and format it to HH:MM:SS and set the objects text value to this, while at the same time not displaying any zero values.
Simple ChartingThe chart object used in the reports was chosen based on ease of use. It is the “First Impressions” chart (by Tidestone Technologies). The user is free to use any charting ActiveX control in the reports.
To insert the chart control, or any other ActiveX control, simply click on the ActiveX Control icon on the toolbar on the left side of the designer, select the control from the list, and then drag a box in the appropriate report section.
72 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
Figure 6 - Inserting a Chart Control
Prior to writing any report script for the chart, the basic characteristics should be set up using the “Chart Designer” and “Set Chart Data” property boxes provided with the control. Simply right click on the chart to select either of these.
Figure 7 - Chart Designer Dialog
The “Chart Designer” allows the user to set the type and appearance of the chart. The chart draws its data from an internal data grid and this can also be populated at design time using “Set Chart Data” So by setting these at design time you can set what the chart will look like and test data values in the chart.
Simple Report with Chart 73
Wonderware Factelligence™ Report Designer
Figure 8 - Set Chart Data Dialog
At runtime the chart will, by default, display as it was setup at design time. Both the appearance and data can then be changed at runtime via script. Most commonly, as in this case, we change the data at runtime by re-populating the rows and columns of the chart’s data grid.
Object : gfTotalThis script executes for the “Total” group footer section where the chart is located. This section will only appear once at the end of the report.Event : OnBeforePrintThe script is used to pass the report totals to the chart for display. The chart could just have easily been put in the Report Footer section.Here we see the following code:'Pass data to the By Category chartintTotalTime = rpt.txtTotalRuntime.DataValue +
rpt.txtTotalDowntime.DataValue _ + rpt.txtTotalStoptime.DataValue
intPercRuntime = (rpt.txtTotalRuntime.DataValue/intTotalTime) * 100intPercDowntime = (rpt.txtTotalDowntime.DataValue/intTotalTime) * 100intPercStoptime = (rpt.txtTotalStoptime.DataValue/intTotalTime) * 100With rpt.Sections("gfTotal").Controls("graFIByCategory")
.DataGrid.SetData 1, 1, intPercRuntime, False .DataGrid.SetData 1, 2, intPercDowntime, False .DataGrid.SetData 1, 3, intPercStoptime, False
74 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
End With
Note the way that the graph object is referenced in the script:rpt.Sections(“SectionName”).Controls(“ControlName”)The required data for the chart is entered by populating the data grid rows and columns using the method:
.DataGrid.SetData <row>, <column>, <value>
Displaying the DateUsed in the Page Footer section of all system reports.
Object : PageFooterThis script executes for the ‘Page’ group footer section. This section will appear once at the end of each page.Event : OnBeforePrintThe script here will apply today’s date to a text field object for display.Here we see the following code:'Set the report daterpt.txtDate.DataValue = Date
Displaying the Filter Information and Custom Parameters
All the system reports supplied with Factelligence include this code in the Report Footer section. It is used to display the filters that were applied to the report when selected to run in the Manager module.
Each report that wants to display this information must include the following:
• This script as it appears in this section
• The display objects as they appear in this section
When the Manager client wishes to run a report is calls a URL on the Web Server with the required parameters for that report, including the selected filters. The syntax for this is:
http://…..&Filter=<filtername1>$<val1>,<val2>;<filtername2>$<val3>;…..
Report with Complex Graph 75
Wonderware Factelligence™ Report Designer
When the report is run by Factelligence it passes this filter string to the field ‘txtFilters’ which is a hidden text field in the Report Footer section. The script in this section then parses this string and extracts individual filter values for display by type.
All system reports also include a hidden text field labeled ‘txtParameters’ in the Report Header section. This is available for the user to pass any additional information they require to display in the report. The parameter string needs to be embedded in the call to the URL from the client in a similar way to the filters.
ie:http://……………..&Filter=……..&Parameter=<parameter string>…
When the report is run by Factelligence it passes this parameter string to the field which can then be processed using script.
This feature is used by some reports that wish to display descriptions for filter values rather than the IDs that are passed in the filter string. These descriptions are appended to any user specified parameter string with the syntax:
&Parameter=<user defined string>;Filter=<filtername1>$<desc1>,<desc2>;…
The script in the Report Footer section looks for this when it is displaying the filter information.
Object : ReportFooterThis script executes for the report footer section. This section will appear once at the end of the report.Event : OnBeforePrintThe script is used to display the filter information that was applied to the report.You are encouraged to inspect the code but as it is a large section of code it has not been included here.
Report with Complex GraphWe will now look at an example of a more complex graph using the “Downtime Analysis” report. Only the graphing component of this report will be discussed.
This report file can be found at:
“\Factelligence\Manager\Reports\System\Downtime\DowntimeAnalysis.rpx”
76 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
The graph example discussed in the previous section is fairly simple. All the required data can be totaled in the section where the graph is located and then applied to the graph.
If however we had wished to graph the totals for each state code ie “StateTotal” then we would need some way of storing the group totals as they are calculated (for an initially unknown number of groups) and then applying them to the chart once the report finished processing the data. This effectively requires the declaration and use of global variables (ie: variables that can span all sections).
Unfortunately, global variables cannot be defined inside the report’s scripting environment. However Active Reports provide a mechanism whereby the report processing engine can access an external object for use within the reports scripting. To this effect, Factelligence provides a class containing a number of variant arrays that can be used by any report. These arrays are referenced by the Web Server when running the report and appear as global variables to the report script. The user need only know how to reference these arrays in the script and nothing more. These arrays should cater for any foreseeable charting or other requirements but can be enhanced if required.
Saving Data to Global VariablesAs data is grouped and processed then save it away for later use.
Object : ghReasGrpThis script executes for the “ReasGrp” group header section. This section will appear once for each unique downtime reason group.Event : OnBeforePrintThe script in this section is used, among other tasks, to save the reason group description, duration and frequency to a global array variable.Here we see the following code:'Store the duration value for the reason group to an array for graphing later'The array and index are provided as global variables via an external class
' DataArray1(100,100,100) use array #1' DataIndex(10) use index #0
intIndex = objReport.DataIndex(0)objReport.DataArray1(intIndex,0,0) =
rpt.txtReasGrpDesc.DataValueobjReport.DataArray1(intIndex,1,0) =
rpt.txtReasGrpDowntime.DataValue
Report with Complex Graph 77
Wonderware Factelligence™ Report Designer
objReport.DataArray1(intIndex,2,0) = rpt.txtReasGrpFreq.DataValue
objReport.DataIndex(0) = intIndex + 1
The external object holding the arrays is always referenced as “objReport”. The available arrays for use are:• DataArray1(1000,100,10)a 3D variant array• DataArray2(1000,100,10)a 3D variant array• DataArray3(10000,10,10)a 3D variant array• DataIndex(10)a 1D variant arrayIn the code above we are using the first array and storing the reason group description, duration and freq values. The duration and freq values are summed for the group by text field objects. The index keeps track of the number of groups we end up with and maintains a pointer into the array.A similar process occurs in the “ghReas” section for reason related data. There we use the second data array and index.
Applying Global Data to the ChartWhen data processing is complete apply the saved data to the chart.
Object : gfTotalThis script executes for the “Total” group footer section. This section will only appear once at the end of the report.Event : OnBeforePrintThe script is used to pass the report totals to the chart for display. The chart could just have easily been put in the Report Footer section.Here we see the following code:'Process the reason groups data
'First sort the data in descending order of duration
'as we require a Pareto graphSortReasGroupData()'Apply the data to the graphWith rpt.Sections("gfTotal").Controls("graFIReasGrpDur")
.Column = 1 For i = 0 to 9 'Max of 10 groups
.Row = i + 1 If Not IsEmpty(objReport.DataArray1(i,0,0)) Then .RowLabel = objReport.DataArray1(i,0,0)
78 Chapter 9 Scripting and Charts
Wonderware Factelligence™ Report Designer
.Data = objReport.DataArray1(i,1,0) / 60 'Duration in minutes
intNumGrps = intNumGrps + 1 End If Next 'If less than 10 groups then delete unused bargraphs If intNumGrps < 10 Then
.DataGrid.DeleteRows intNumGrps + 1, 10 - intNumGrps
End IfEnd With
The concept of this script is similar to the simple chart example discussed previously. The data from the global array is used to re-populate the data grid for the chart. There are a few additional things to note here:• The row labels in the data grid are also populated
with the group descriptions • We are displaying a top ten pareto here so the data
must be sorted in descending order of duration. To achieve this we use a standard “Shell Sort” algorithm. Then we limit the graph to the first ten.
Previewing Reports with ChartsRemember from the “Reporting Mechanism” section that when the Preview tab is selected the report that is in the Design tab runs directly against the database using the query in the ADO object to generate the recordset for the report. It does not access the middleware or the Web Server so therefore the global variable arrays are not available to any reports previewed in the Report Designer application.
So, the chart in the Utilization Analysis will display correctly in the Report Designer preview as it does not use the global variables. However, the Downtime Analysis report chart will not run correctly. It will display the default data it was configured with and a script error will be displayed when previewed.
If you are designing a report using the global variables then you can only test it in the Manager application. So, build the basic report first and then configure the query and the report. Now use Manager to preview the report each time modifications are made.
This is not optimal and it is planned to put a “Test via Middleware” feature in a future release of Report Designer.
79
Industrial Application Server User’s Guide
Appendix A
Report Spec Sheet
Created by: Grant Kelly
Last Updated: 28 June 2004
Description
The report will retrieve all OEE data from the tpm_stat table where shift_start time falls in the selected period and for the selected entities or shifts (if any are selected else for all entities and shifts).
Data will be tabular with a section for each entity then grouped by date and shift. Each row (one row per date/shift) will show the following data:
• Date & shift
• % Utilization over the selected period
• % Performance over the selected period
• % Quality over the selected period
• % OEE over the selected period
There will be a chart for each entity of all OEE KPIs vs Date/shift. The chart will include a table of contents to allow easy scrolling through the charts.
The report is a generic report in that any time period, entities or shifts may be selected.
80 Appendix A Report Spec Sheet
Industrial Application Server User’s Guide
Configuration
Report Category:OEE
Report Name: OEE By Shift Trend
Report Description: Data and trend of OEE KPIs by shift for selected entities and shifts
Report Path: OEEByShiftTrend.rpx
Data Query: OEE Reports
Filter: Start_Time, End_Time, Entity, Shift, Custom
Sort Fields: ent_id, shift_start DESC
Custom Filter:
Query
Query Name: OEE Reports
Query:
SELECT tpm_stat.ent_id
,ent.ent_name
,tpm_stat.wo_id
,wo.wo_desc
,tpm_stat.oper_id
,tpm_stat.seq_no
,job.act_start_time
,job.act_finish_time
,job.batch_size
,tpm_stat.shift_start
81
Industrial Application Server User’s Guide
,tpm_stat.shift_id
,shift.shift_desc
,tpm_stat.item_id
,item.item_desc
,item.units
,tpm_stat.qty_good
,tpm_stat.qty_reject
,tpm_stat.std_prod_rate
,tpm_stat.runtime
,tpm_stat.downtime
,tpm_stat.idletime
FROM tpm_stat tpm_stat with (nolock)
INNER JOIN ent ent with (nolock) ON tpm_stat.ent_id = ent.ent_id
LEFT OUTER JOIN wo wo with (nolock) ON tpm_stat.wo_id = wo.wo_id
LEFT OUTER JOIN job job with (nolock) ON tpm_stat.wo_id = job.wo_id AND tpm_stat.oper_id = job.oper_id AND tpm_stat.seq_no = job.seq_no
INNER JOIN shift shift with (nolock) ON tpm_stat.shift_id = shift.shift_id
LEFT OUTER JOIN item item with (nolock) ON tpm_stat.item_id = item.item_id
WHERE (tpm_stat.shift_start >= @Start_Time OR @Start_Time IS NULL) AND
(tpm_stat.shift_start < @End_Time OR @End_Time IS NULL) AND
(tpm_stat.ent_id IN @Entity) AND
(tpm_stat.item_id IN @Item) AND
(tpm_stat.wo_id IN @Work_Order) AND
(tpm_stat.shift_id IN @Shift) AND
(@Custom)
Parameters:Start_Time(Datetime)
End_Time(Datetime)
Entity(String List)
Item(String List)
WorkOrder(String List)
82 Appendix A Report Spec Sheet
Industrial Application Server User’s Guide
Shift(String List)
Custom(Custom)
83
Wonderware Factelligence™ Report Designer
Index
AAdding Script 68Aim 5, 10, 18, 21, 27Assumptions 5
CCharting and Testing Using Manager 56
Adding a Table of Contents 64Chart Data and Formatting 56Scripting Data to a Chart Using Global Arrays 62
Configuration 15Content 5Custom Filter 21
DData Query 21
EExercise 1 - The Design Tab 10Exercise 2 - The Preview Tab 18Exercise 3 - The Configuration Tab 21Exercise 4 - The Query Tab 27
FFilter 21
GGeneral 67
HHow to Use this Guide 5
IIntroduction 5
MManager 14Method 10, 18, 21, 27
OOverview 32
PPreviewing Reports with Charts 78
QQueries 25Query and Data Design 33Query Parameters 26
RReference Material 6Report Configuration 19Report Design and Data Validation 36
84 Index
Wonderware Factelligence™ Report Designer
Adding Groups and Data Display Objects 46Changing Properties 39Complex Data Display Concepts 47Creating Virtual Data Fields 49Formatting 44Grouping 42Scripting Calculations 52Summation Objects 50The ADO Data Object and Data Fields 40The Design Tab 36Using the Report Template 37
Report Designer 13Report Design 9Report Preview 17Report with Complex Graph 75
Applying Global Data to the Chart 77
Saving Data to Global Variables 76Report with Complex Graph 75Reporting Mechanism 13
SScripting and Charts 67Simple Report with Chart 68
Calculated Fields 70Displaying the Date 74Displaying the Filter Information and Custom Parameters 74Simple Charting 71Virtual Fields 69
Sort Fields 21Specification 32
TTutorial Exercise 31
Recommended