{ "cells": [ { "cell_type": "markdown", "id": "b443b10c-6c13-46ea-bb2a-cf8bc7b81121", "metadata": { "execution": { "iopub.execute_input": "2023-08-24T22:22:53.108211Z", "iopub.status.busy": "2023-08-24T22:22:53.107567Z", "iopub.status.idle": "2023-08-24T22:22:53.392087Z", "shell.execute_reply": "2023-08-24T22:22:53.389956Z", "shell.execute_reply.started": "2023-08-24T22:22:53.108137Z" } }, "source": [ "# Reporter" ] }, { "cell_type": "markdown", "id": "51afb035-8aac-448a-864c-dae8f7d42ac7", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 3, "id": "226a9fe1-3dcb-41f1-93ac-ebe6a767274f", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:01.997524Z", "iopub.status.busy": "2024-01-16T23:06:01.996894Z", "iopub.status.idle": "2024-01-16T23:06:02.021771Z", "shell.execute_reply": "2024-01-16T23:06:02.019219Z", "shell.execute_reply.started": "2024-01-16T23:06:01.997447Z" } }, "outputs": [], "source": [ "import productomator.lab as prolab\n", "import warnings\n", "warnings.simplefilter(\"ignore\")" ] }, { "cell_type": "markdown", "id": "ca7d91d1-a464-41c6-bf6b-d13eab83f3f5", "metadata": {}, "source": [ "For this example we define a class that represents a product that needs to be processed." ] }, { "cell_type": "code", "execution_count": 4, "id": "04fda014-f538-40d6-800d-d733b1c22a66", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:02.599320Z", "iopub.status.busy": "2024-01-16T23:06:02.598481Z", "iopub.status.idle": "2024-01-16T23:06:02.607527Z", "shell.execute_reply": "2024-01-16T23:06:02.605724Z", "shell.execute_reply.started": "2024-01-16T23:06:02.599263Z" } }, "outputs": [], "source": [ "class Test(object):\n", " def __init__(self, reporter):\n", " self.reporter = reporter\n", " def process(self):\n", " reporter.clean_increment()\n", " " ] }, { "cell_type": "markdown", "id": "1cbcc18c-e959-4d22-b005-56aeba67e595", "metadata": {}, "source": [ "Define a reporter:" ] }, { "cell_type": "code", "execution_count": 5, "id": "2610255f-2997-42b8-967f-0ed9a917d7bd", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:03.798066Z", "iopub.status.busy": "2024-01-16T23:06:03.797381Z", "iopub.status.idle": "2024-01-16T23:06:03.805235Z", "shell.execute_reply": "2024-01-16T23:06:03.803819Z", "shell.execute_reply.started": "2024-01-16T23:06:03.798015Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "start time: 2024-01-16 16:06:03.800410\n" ] } ], "source": [ "reporter = prolab.Reporter('test', log_folder='/export/htelg/tmp/', reporting_frequency=(1,'min'))" ] }, { "cell_type": "markdown", "id": "f9c3630c-aa71-4b37-b462-d36efd51348e", "metadata": {}, "source": [ "Feed the reporter to the Test class and play with changing reporting increments." ] }, { "cell_type": "code", "execution_count": 6, "id": "ca5d7c2a-e0e2-42bc-a6dd-3b19fd172f5f", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:05.816047Z", "iopub.status.busy": "2024-01-16T23:06:05.815405Z", "iopub.status.idle": "2024-01-16T23:06:05.825746Z", "shell.execute_reply": "2024-01-16T23:06:05.823998Z", "shell.execute_reply.started": "2024-01-16T23:06:05.815995Z" } }, "outputs": [], "source": [ "test = Test(reporter)\n", "test.process()\n", "\n", "test.reporter.clean_increment(10)\n", "test.reporter.warnings_increment(3)\n", "test.reporter.errors_increment(1)" ] }, { "cell_type": "markdown", "id": "cff80830-ee6a-4dcc-bb46-6af21531023b", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:00:44.824410Z", "iopub.status.busy": "2024-01-16T23:00:44.823675Z", "iopub.status.idle": "2024-01-16T23:00:44.834459Z", "shell.execute_reply": "2024-01-16T23:00:44.832053Z", "shell.execute_reply.started": "2024-01-16T23:00:44.824355Z" } }, "source": [ "Logging will append the log file, but only if time since last reporting is less than reporting frequency (overwrite possible)." ] }, { "cell_type": "code", "execution_count": 7, "id": "d73b291b-5e4f-4155-a13e-832daf7926ad", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:08.058793Z", "iopub.status.busy": "2024-01-16T23:06:08.057810Z", "iopub.status.idle": "2024-01-16T23:06:08.076317Z", "shell.execute_reply": "2024-01-16T23:06:08.074674Z", "shell.execute_reply.started": "2024-01-16T23:06:08.058734Z" } }, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test.reporter.log()" ] }, { "cell_type": "markdown", "id": "71a21258-6613-4fb9-a673-93acaa894301", "metadata": {}, "source": [ "## More usefull functions" ] }, { "cell_type": "markdown", "id": "7a301c5c-1faf-4a62-b733-94bde728e346", "metadata": {}, "source": [ "Wrapup is similar to log with reporting frequency overwrite. It also prints the time since reporter was first called." ] }, { "cell_type": "code", "execution_count": 8, "id": "2339db3a-b19e-48b3-ad83-9bf46eefdcee", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:10.583458Z", "iopub.status.busy": "2024-01-16T23:06:10.582821Z", "iopub.status.idle": "2024-01-16T23:06:10.593345Z", "shell.execute_reply": "2024-01-16T23:06:10.591679Z", "shell.execute_reply.started": "2024-01-16T23:06:10.583401Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "number of cleanes: 11\n", "number of errors: 1\n", "number of warnings: 3\n", "time finished: 2024-01-16 16:06:10.585969\n", "total processing time: 0.0018848775 hours\n" ] } ], "source": [ "test.reporter.wrapup()" ] }, { "cell_type": "markdown", "id": "350b7b99-c230-4281-830c-95ae51fc0f1a", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:04:16.424769Z", "iopub.status.busy": "2024-01-16T23:04:16.423428Z", "iopub.status.idle": "2024-01-16T23:04:16.434108Z", "shell.execute_reply": "2024-01-16T23:04:16.432276Z", "shell.execute_reply.started": "2024-01-16T23:04:16.424671Z" } }, "source": [ "This is how the new line will look like:m" ] }, { "cell_type": "code", "execution_count": 9, "id": "00255f7e-334a-41e2-8639-2b7846db6364", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:14.121704Z", "iopub.status.busy": "2024-01-16T23:06:14.120863Z", "iopub.status.idle": "2024-01-16T23:06:14.132613Z", "shell.execute_reply": "2024-01-16T23:06:14.130642Z", "shell.execute_reply.started": "2024-01-16T23:06:14.121649Z" } }, "outputs": [ { "data": { "text/plain": [ "'2024-01-16 16:06:14.123562,0,1,11,3,test,telg.cmdl.noaa.gov,\\n'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test.reporter.create_log_data()" ] }, { "cell_type": "markdown", "id": "6ae7d5b1-d199-40da-8c72-542dab5e7319", "metadata": {}, "source": [ "Nest time log will be possible (without reporting frequency overwrite)" ] }, { "cell_type": "code", "execution_count": 10, "id": "3dffa064-1168-43b2-ae5d-e2b2a6ed5fc8", "metadata": { "execution": { "iopub.execute_input": "2024-01-16T23:06:16.073056Z", "iopub.status.busy": "2024-01-16T23:06:16.072398Z", "iopub.status.idle": "2024-01-16T23:06:16.083737Z", "shell.execute_reply": "2024-01-16T23:06:16.082002Z", "shell.execute_reply.started": "2024-01-16T23:06:16.072999Z" } }, "outputs": [ { "data": { "text/plain": [ "Timestamp('2024-01-16 16:07:03.800204')" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test.reporter.next_report_due" ] }, { "cell_type": "code", "execution_count": null, "id": "14a95e46-48af-4c55-89c7-691597e26d09", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py310telg", "language": "python", "name": "py310telg" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }