Example: Maximum Values Report

This example creates a report that shows the maximum values of a set of tags along with the time of those maximums within the start and end times.

( { Parameters }
  Reporter   { Object value for call-backs     };
  Start      { Starting time (local, not UTC!) };
  End        { Ending time                     };	

Tags { List of tag names in report }; ) [ { Variables } { Set this module to become a plug-in for the reports } [(POINTS) Shared Report; ] Constant TypeFilter = "Loggers" { Tag Type filter }; Constant ReportName = "Max Value Report" { Title }; Data { Array of data to output }; Formats { Array of formats to apply to the output }; Titles { Array of ODBC database field names }; Types { Array of ODBC column types }; TitleStrm { Title Stream }; StartTime { Start time in UTC }; EndTime { End time in UTC }; Result { Result from GetTagHistory }; LocalTime { Result timestamp converted to local }; Error { Error code from GetTagHistory }; Fields { Array of fields for GetTagHistory }; Modes { Array of modes for GetTagHistory }; TagObj { Current tag object }; TagIdx { Current index }; I { Counter }; ] Init [ If 1 Loop; [ { Set up the titles and prepare for the loop } { Create the titles array } Titles = New(3); Titles[0] = "Name"; Titles[1] = "Max Level"; Titles[2] = "Time of Max"; Formats = New(3); Formats[0] = "%-30s"; Formats[1] = "%-15s"; Formats[2] = "%-30s"; Types = New(3); ArrayOp1(Types[0], 0, 3, "TEXT", 0); Data = New(3); { Build the title lines } TitleStrm = BuffStream(""); SWrite(TitleStrm, "%s from %s %s to %s %s\r\n\r\n", ReportName { Title for the report }, Date(Start / 86400, "MMM d, yyyy"), Time(Start, "HH:mm:ss"), Date(End / 86400, "MMM d, yyyy"), Time(End , "HH:mm:ss")); { Add the headers to the title } I = 0; WhileLoop(I < ArraySize(Titles), SWrite(TitleStrm, Formats[I], Titles[I]); I++; ); { Output the titles } Reporter\ODBCColumns(Titles, Types); Reporter\TitleLine(TitleStrm); { Get ready to go } TagIdx = 0; StartTime = ConvertTimestamp(Start, 0, Invalid, Invalid); EndTime = ConvertTimestamp(End, 0, Invalid, Invalid); ] ] Loop [ { More tags to process } If TagIdx < ArraySize(Tags) GetTagData; { All done } If TagIdx >= ArraySize(Tags) Done; ] GetTagData [ If 1 ProcessLine; [ { Retrieve the data for the tag } { Set the current tag object } TagObj = Scope(VTSDB, Tags[TagIdx], TRUE); { Declare the arrays and initialize the error } { and result values } Fields = New(2); Fields[0] = "Value"; Fields[1] = "Value"; { Declare what retrieval modes will be used } Modes = New(2); Modes[0] = 2 { Max }; Modes[1] = 6 { Time of Max }; { Reset the error and results for the next query } Error = Result = Invalid; { Get the data for the Well } \HistorianManager\GetTagHistory(&Error, &Result { Return code, result }, TagObj { Tag Object }, Fields { Fields }, StartTime, 0 { Start, End (Ignored) }, End - Start, 1 { TPP, No intervals }, Modes { Modes }); ] ] ProcessLine [ If Valid(Error) Loop; [ { Save the tag data } Data[0] = PickValid(TagObj\Description, TagObj\Name); Data[1] = Format(6, 2, Result[0][0]); { Convert the UTC timestamp to local time } LocalTime = ConvertTimestamp(Result[1][0], Invalid, Invalid, 0); { Format for human consumption } Data[2] = concat(Date(LocalTime / 86400, 4), " - ", Time(LocalTime % 86400, 2)); { Output the results for this tag } Reporter\Dataline(Formats, Data); { Move to the next tag } TagIdx++; ] ] Done [ If 1; [ Slay(); ] ]