Writing Custom Reports¶
Overview
The platform comes with built-in reports that summarize the results of a specific job run. Custom Reports are non-standard reports that the user has specified and added to the standard report package.
Where is this done
The reports seen in the dashboards of the platform can be configured as needed. To add a new report, we expose an API that can be used to create an additional report. This is a class-based API where various components can be extended and defined. The main portion of the reporting API is:
-
run_computation()- Which defines the logic on computing the metrics for the report. For example, logic to compute quantiles, method of binning, histogram calculations, etc. -
get_visualization()- This defines how the report should be visualized. For example Scatter plot, bar chart, etc.
Example: Model Report
from corridor_api.tasks.reporting_task import BaseModelReport
class ModelExampleReport(BaseModelReport):
supported_lang_specs = ('pyspark-dataframe',)
name = 'model_example_report'
def run_computation(self, metadata, data):
# Logic to use the metadata information to process the data
score_col = metadata['scoreinfo']['colname']
actual_col = metadata['actualinfo']['colname']
df_avg = data.agg(
F.mean(data[score_col]).alias('score'),
F.mean(data[actual_col]).alias('actual'),
).toPandas()
return df_avg
def get_visualization(self, metadata, df_avg):
import plotly.graph_objs as go
return go.Figure(
data=go.Scatter(x=df_avg['score'],
y=df_avg['actual'],
name='Actual vs Pred',
),
layout=go.Layout(title={'text': 'Actual vs Pred'},
xaxis={'title': {'text': 'Score'}},
yaxis={'title': {'text': 'Actual'}},
),
)