Reporter

The reporter class is the newer of the two reporting classes and is most likely what you need. It can be passed to a function, class, etc. In certain events increments of clean, error, or warning can be changed. The reporter will report the results either in regular intervals or at termination. Reporting currently works only by saving in a log file. Other means of reporting, e.g. email, exist but are not currently working … fix it if you want it.

[3]:
import productomator.lab as prolab
import warnings
warnings.simplefilter("ignore")

For this example we define a class that represents a product that needs to be processed.

[4]:
class Test(object):
    def __init__(self, reporter):
        self.reporter = reporter
    def process(self):
        reporter.clean_increment()

Define a reporter:

[5]:
reporter = prolab.Reporter('test', log_folder='/export/htelg/tmp/', reporting_frequency=(1,'min'))
start time: 2024-01-16 16:06:03.800410

Feed the reporter to the Test class and play with changing reporting increments.

[6]:
test = Test(reporter)
test.process()

test.reporter.clean_increment(10)
test.reporter.warnings_increment(3)
test.reporter.errors_increment(1)

Logging will append the log file, but only if time since last reporting is less than reporting frequency (overwrite possible).

[7]:
test.reporter.log()
[7]:
False

More usefull functions

Wrapup is similar to log with reporting frequency overwrite. It also prints the time since reporter was first called.

[8]:
test.reporter.wrapup()
number of cleanes: 11
number of errors: 1
number of warnings: 3
time finished: 2024-01-16 16:06:10.585969
total processing time: 0.0018848775 hours

This is how the new line will look like:m

[9]:
test.reporter.create_log_data()
[9]:
'2024-01-16 16:06:14.123562,0,1,11,3,test,telg.cmdl.noaa.gov,\n'

Nest time log will be possible (without reporting frequency overwrite)

[10]:
test.reporter.next_report_due
[10]:
Timestamp('2024-01-16 16:07:03.800204')
[ ]: