Using Data in our Report

Our code currently looks like this…

import ardi.util.mplreport

@mplreport.ardireport("Sample Report")
def CreateReport(report,args):    

   fig,ax = report.CreatePage(1)
   report.Title()

   thedata = report.FetchHistory("'Temperature' PROPERTYEX ALLPOINTS")

   report.Save()

First, we need the values. These can be found as a Pandas dataframe in thedata.data.

For instance, we could draw each channel as a line chart using the following code…

   frame = thedata.data
   for colname in frame.columns:
        ax.plot(frame[colname],label=colname)

This gives us a simple plot of every temperature in our ARDI system.

To make it prettier and easier to read, we can decorate our report with extra MatPlotLib code…

   ax.margins(x=0)
   ax.grid()
   ax.legend()
   ax.set_xlabel("Time")
   ax.set_ylabel("Temperature (Deg C)")

The mplreport object also has a function called TimeAxis which creates a sensible time format on an axis given the range of the report.

For example, a report that covers a few hours will use HH:MM format, while reports covering a week will include day and hour information, but omit seconds.

   report.TimeAxis(ax.xaxis)

We can now see the complete code of our simple report.