Skip to content

Local report generation

General sequence of actions needed to generate the report.

Initialization

Install all packages for the development environment you need to run following command:

pip install -e .[dev] -U --upgrade-strategy eager
1. External clients needed to get the report data. (SmartSensorAPIClient(), RawDataCollectorAPIClient(), ...) 2. Authenticate clients. (client.authenticate()) 3. Appropriate data reader with external clients. (APIAssetDataReader(clients...)) 4. Data object that will be subject of report with data reader and other params. (MotorAsset(data_reader, ..)) 5. Selected Report Output object that defines the format of report document. (WordReportOutput()) 6. Report object with ReportOutput and data object (MotorAssetReport(ro=report_output, asset=motor_asset))

Generation

Call .generate_report(**kwargs) method on report object.

Export

Call .export(file_path) method to save the generated report to a file path.

Example

import os

# Import clients from external packages
from reportconnectors import SmartSensorAPIClient, ConditionIndicesAPIClient, RawDataCollectorAPIClient, MccuAPIClient

# Import datastructures

from smartreport.datatypes.asset import MotorAsset
from smartreport.datatypes.reader.asset import APIAssetReader

# Import report

from smartreport.engine.outputs.word_document import WordReportOutput
from smartreport.report.asset import MotorAssetReport

# Prepare clients

# SmartSensor API

ss_client = SmartSensorAPIClient(url=os.getenv("SMART_SENSOR_API_URL"))
ss_client.authenticate(key=os.getenv("SMART_SENSOR_API_KEY"))

# RawData

raw_client = RawDataCollectorAPIClient(url=os.getenv("RAW_DATA_API_URL"))
raw_client.authenticate(username=os.getenv("RAW_DATA_USER"), password=os.getenv("RAW_DATA_PASS"))

# MCCU API

mccu_client = MccuAPIClient(url=os.getenv("MCCU_API_URL"))
mccu_client.authenticate(key=os.getenv("MCCU_API_KEY"))

# New Condition Indices API

ci_client = ConditionIndicesAPIClient(url=os.getenv("CONDITION_INDICES_API_URL"))
ci_client.authenticate(code=os.getenv("CONDITION_INDICES_API_CODE"))

# Initialize Data Reader

adr = APIAssetReader(
    ss_client=ss_client,
    raw_client=raw_client,
    mccu_client=mccu_client,
    ci_client=ci_client,
)

# Initialize Asset object

ASSET_ID = 7555
SD = "2022-01-01"
ED = "2022-02-01"

motor_asset = MotorAsset(
    asset_id=ASSET_ID,
    asset_data_reader=adr,
    start_date=SD,
    end_date=ED,
)

# Initialize report

word_ro = WordReportOutput()
report = MotorAssetReport(report_output=word_ro, asset=motor_asset)

# OPTIONAL
# Prefetch data and check the data availability
report.prefetch_data()
if not report.check_data_availability(threshold=0.5):
    # At least 50% of data is required to continue with report generation
    raise ValueError("Not enough data")

# Generate and export the report
report.generate_report(expert_mode=True, include_anomaly=False)
report.export(filepath=f"MotorAssetReport_A{ASSET_ID}_{SD}_{ED}.docx")

Environmental Variables

In order to use example files you need to provide the environmental variables. They are used to provide the links and credentials to external data connectors and to parametrize report generation process.

# General
# Default unit standard used when reading data SmartSensor API
UNIT_STANDARD=imperial
# Default logging level
LOGGING_LEVEL=DEBUG
# Proxy configuration (use it when you call scripts from inside ABB network)
HTTP_PROXY=
HTTPS_PROXY=

# Powertrain-based reports
POWERTRAIN_API_URL=https://api.powertrain.abb.com
CIAM_API_URL=https://api.accessmanagement.motion.abb.com
CIAM_TOKEN_URL=https://api.accessmanagement.motion.abb.com/polaris/oidc/token
CIAM_USERNAME=momg.analytics@pl.abb.com
CIAM_CLIENT_ID=*****************
CIAM_CLIENT_SECRET=**************
CIAM_PASSWORD=************

# SmartSensor API Client
SMART_SENSOR_URL=https://smartsensor.abb.com/
SMART_SENSOR_API_URL=https://api.smartsensor.abb.com/
# API key used for report generation
SMART_SENSOR_API_KEY=API1234API1234
# API key used for comunication tests
TEST_SMART_SENSOR_API_KEY=API1234API1234

# Drive DB Client - CosmosDBClient
DRIVE_COSMOS_URL=https://analytics-cosmos-stage.documents.azure.com:443/
DRIVE_COSMOS_CLIENT_TOKEN=sdasdasdasdasd
# Drive DB Client - Huawei DDS - Mongo
DRIVE_MONGODB_HOST=127.0.0.1
DRIVE_MONGODB_PORT=8635
DRIVE_MONGODB_USER=user
DRIVE_MONGODB_PASS=passssss
DRIVE_MONGODB_DB=test
# CMD API Client
CMD_API_URL=https://dev.monitoring.drives.abb.com
IAM_CLIENT_ID=XXXXXXXXX
IAM_CLIENT_SECRET=SSSSSSSSS
IAM_TOKEN_URL=https://stage.api.accessmanagement.motion.abb.com/polaris/oidc/token

Example files

You can find example scripts in the examples folder. Script names are rather self-explanatory, e.g. make_motor_asset_report.py creates a Motor Asset Report, while trigger_raw_data_from_collector.py triggers raw data collection process at remote Raw Data Collector.

Local Dash server

Local Dash server provides a developer server that can explore and visualize interactive (Dash) reports. You can start it by running examples/start_local_dash.py script. It will run a web service at 127.0.0.1:8050.

At the index page you will see a list of available report files. By default, it will search for them in examples/results/*.gz. To open the interactive report, simply click on the filename.