Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
3,004


 

Introduction


Ever thought of empowering your customers to detect and diagnose potential defects before they call your customer service department? And if they already submitted the analysis results through their app to the helpdesk?

Here is an application that helps customers to make the AI-based decision to call customer service.

In this blog I will show you how to use SAP Build Apps to build a native app using your smartphone's sensors to capture sound or gyro data and use MS Azure, then call a maintenance request creation in SAP S/4HANA Cloud through Azure anomaly detector. Products we integrated with are SAP Build App, SAP BTP Kyma, SAP S/4HANA Cloud, Google Firebase, and MS Azure Anomaly Detector.

 

Steps to use



Application Flow


The image of the application flow can be listed below.

  1. Train your model of vibration or sound

  2. Use the trained model to detect anomaly

  3. If an anomaly is detected, create a maintenance request in SAP S/4HANA Cloud via SAP Build Apps


The flow of this application is straightforward.  Before getting in the main flow, you will face the login page, you can register your account using Google Firebase authenticator or just log in if you have already gotten account.

In the main flow, firstly you can train your own machine beforehand.

In 2nd step, once you find something wrong with your machine and wonder whether to call maintenance, you are now able to detect anomaly with the machine that you have already trained in 1st step.

Finally, if this app shows an anomaly, which has 4 anomaly levels, SAP S/4HANA Cloud maintenance request can be created by just inputting the required information. You can now check the maintenance notification that has been created on SAP S/4HANA Cloud as the image shows.


Maintenance Notification


Let's dive into the demonstration to see how it works and reflects on your S/4HANA page.

Demonstration



Technical Aspects


Architecture


For the front end, we use SAP Build Apps(aka AppGyver) which is Low-Code / No-Code service on SAP BTP.  As the middleware, we introduce Python container running upon SAP BTP Kyma which is a cloud-native application runtime that combines Kubernetes. This runtime gets the request from users to communicate with Maintenance Notification in S/4HANA Cloud using OData2, Azure Anomaly Detector, Azure Blob Storage, and Google Firebase.


Architecture


Most of all features of this application are handled by SAP BTP Kyma, so we will focus on how the data is taken and preprocessed and when the API call is triggered within SAP BTP Kyma.

Firstly let's dive into data handling parts.

This application has got two functionalities

  1. Vibration Anomaly Detection

  2. Sound Anomaly Detection


Both functionalities are able to be trained as you want from the main page as the image shows


Main page


 

Vibration Anomaly Detection


 We shall describe the background of vibration function such as how to make training data.
SAP Build Apps provides us with Accelerometer functions to measure acceleration as the image shows. It takes the x, y, and z axis values. For instance, If you tilt your phone left and right, the x-axis value changes from negative to positive and vice versa.


Build Apps Accelerometer Selection


 To procure a sufficient amount of data, collecting training data takes 5 mins more specifically we set a data collection interval as 10 ms, therefore the total number of training data sums up to 30000.
And calibration is also considered so that users are able to set their devices almost everywhere to deal with gradients.


Calibration Setting


The summarised way of data collection flow are

  1. Set calibration for 2 seconds, and get arrays of x, y, and z axis data

  2. Calculate their mean and let them be as calibration

  3. To train, collect data for 5 mins, and get 30000 x, y, and z axis data

  4. Set train data as the below equation



Vibration training data



Sound Anomaly Detection


For extracting sound features, we use Log-Mel spectrogram algorithms. We will not go into detail about that here.

SAP Build Apps has record audio functionality and posts the data as base64


Lo-Mel Spectrogram


 For the first data conversion to make the data shrink, we do not just use the output of Log-Mel spectrogram algorithms but generate an array of vectors and build a sliding window then make vector by concatenating the data as the code shows below.
def extract_signal_features(signal, sr, n_mels=64, frames=5, n_fft=1024, hop_length=64):
# Compute a spectrogram (using Mel scale):
mel_spectrogram = librosa.feature.melspectrogram(
y=signal,
sr=sr,
n_fft=n_fft,
hop_length=hop_length,
n_mels=n_mels
)
dims = frames * n_mels

# Convert to decibel
log_mel_spectrogram = librosa.power_to_db(mel_spectrogram, ref=np.max)

features_vector_size = log_mel_spectrogram.shape[1] - frames + 1

# concatenate with N slides
features = np.zeros((features_vector_size, dims), np.float32)
for t in range(frames):
features[:, n_mels*t:n_mels*(t+1)] = log_mel_spectrogram[:, t:t+features_vector_size].T

return log_mel_spectrogram

On top of that, in order to reduce the train time for the user, we additionally set a function to meaningful feature from the output of the above code to 8 vectors as the code shows below.
for i in range(0, 63, 8):
sound_list.append(np.average(df[:][i:i+8], axis=0)

Finally, we can use 8 vectors as input for Azure Anomaly Detector

SAP S/4HANA Cloud Maintenance Request


We shall explain how to create a maintenance request in SAP S/4HANA  Cloud. Before calling maintenance notification API, the prerequisite steps that must have been done are

  1. Train your vibration or sound model on the Training page

  2. Choose the model from the Model list page

  3. Set your device and detect anomaly at the Anomaly detection page


Then Azure Anomaly Detector outputs the anomaly level. If an anomaly is detected, the page is automatically transferred to the Maintenance Request page

As a 4th step, you can call a maintenance request. To set a payload to make a POST request, there are minimum requirements to fill out and these three values below are automatically filled based upon the output from Azure Anomaly Detector.

  1. MainNotificationCode: based on the model types, VIB(vibration) or NOI(noise sound)

  2. MaintPriority: based on Azure Anomaly Detector severity and score values

  3. MaintenanceObjectIsDown: based on MalfunctionEffect that user can select


The other requirements where you input are mainly at Maintenance Request page as the image shows below


Maintenance Request page


By pressing "Create in S/4HANA" button, the runtime receives filled requirements and maps these values to the request payload as the below python code shows.
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-csrf-token': x_csrf_token,
'Authorization': auth,
'Cookie': 'SAP_SESSIONID_E5Z_100=' + cookie + '; sap-usercontext=sap-client=100'
}
payload = {
"TechnicalObject": payload_contents["payload"].get("Technical_id"),
"NotificationText": payload_contents["payload"].get("NotificationText"),
"MaintNotificationCode": payload_contents["payload"].get("MaintNotificationCode"),
"MalfunctionEffect": payload_contents["payload"].get("MalfunctionEffect"),
"MaintenanceObjectIsDown": is_down,
"MalfunctionStartDate": payload_contents["date_dict"].get("MalfunctionStartDate"),
"MaintNotificationLongText": payload_contents["payload"].get("NotificationText"),
"MaintNotifLongTextForEdit": payload_contents["payload"].get("NotificationText"),
"MaintPriority": payload_contents["date_dict"].get("MaintPriority"),
"ReporterFullName": payload_contents["date_dict"].get("ReporterFullName"),
"NotificationType": "Y1",
"TechObjIsEquipOrFuncnlLoc": "EAMS_EQUI",
"LocationDescription": payload_contents["date_dict"].get("Location"),
"MaintNotificationCodeGroup":"YB-PMGNL",
"RequiredStartDate": payload_contents["date_dict"].get("RequiredStartDate"),
"RequiredEndDate": payload_contents["date_dict"].get("RequiredEndDate"),
"NotificationReferenceDate": payload_contents["date_dict"].get("NotificationReferenceDate"),
"ReporterFullName": payload_contents["date_dict"].get("ReporterFullName")
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))

The application notifies you of "Maintenance <notification ID> is created", then you can check the created maintenance request in S/4HANA Cloud.

Wrap up


We have gone through how this SAP Build Apps application works to create maintenance request in S/4HANA Cloud combined with Azure Anomaly Detector. Using SAP Build Apps and integrating other not only SAP services but also other powerful services have a great impact on your business processes.

Using the architecture and pattern outlined above, you can now quickly create mobile apps to digitize and make an AI-based decision to create maintenance request.

Product references are below:

Credits


gunteralbrecht, lsm1401, sam.yu.puay

I sincerely appreciate your support.
4 Comments