Skip to content

Event Analytics Client for Java

Introduction

The Event Analytics Java client allows you to analyze event data. It identifies significant dependencies and helps to get a better understanding of the system's internal processes using statistical analysis.

Further implementation of the EventAnalytics SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-java-sdk-examples

Hint

Placeholders in the following samples are indicated by angular brackets < >.

Event Operations

The event operations client statistically analyzes event data to identify the most frequent events.

Client name: EventOperationsClient

Find Top Events

This section shows two options for finding the N most frequently occurring events and returning them sorted by the number of occurrences in descending order.

// Construct the EventOperationsClient object
EventOperationsClient event_operations_client = EventOperationsClient.builder()
                                                  .mindsphereCredentials(<credentials>)
                                                  .restClientConfig(<config>)
                                                  .build();

// Create the EventsInputModelEventsMetadata object
EventsInputModelEventsMetadata events_metadata = new EventsInputModelEventsMetadata();
events_metadata.setEventTextPropertyName("text");

// Create a list of events to be analyzed
Event first_event = new Event();
first_event.setText("INTRODUCING FUEL");
first_event.setTextQc(0);
first_event.setTime("2017-10-01T12:00:00.001Z");

Event second_event = new Event();
second_event.setText("Status@Flame On");
second_event.setTextQc(0);
second_event.setTime("2017-10-01T12:02:01.001Z");

List<Event> events_list = new ArrayList<>();
events_list.add(first_event);
events_list.add(second_event);

// Create the TopEventsInputDataModel object that will be analyzed
TopEventsInputDataModel input_data_model = new TopEventsInputDataModel();
input_data_model.setNumberOfTopPositionsRequired(5);
input_data_model.setEventsMetadata(events_metadata);
input_data_model.setEvents(events_list);

TopEventOutput top_events_response = null;
try {
    top_events_response = event_operations_client.topEvents(input_data_model);
} catch (MindsphereException e) {
    // Exception handling
}

Alternatively, use the TopEventsRequest model.

// Create the EventOperationsClient object as shown above

TopEventsRequest request_object = new TopEventsRequest();
request_object.setData(<input_data>);

TopEventOutput top_events_response = null;
try {
    top_events_response = event_operations_client.topEvents(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

Filter Events

This section shows two options for simplifying the dataset by applying user defined filters.

// Create the EventOperationsClient object as shown above

// Create the EventsInputModelEventsMetadata object
EventsInputModelEventsMetadata events_metadata = new EventsInputModelEventsMetadata();
events_metadata.setEventTextPropertyName("text");

// Create a list of events to be analyzed
Event first_event = new Event();
first_event.setText("INTRODUCING FUEL");
first_event.setTextQc(0);
first_event.setTime("2017-10-01T12:00:00.001Z");

Event second_event = new Event();
second_event.setText("Status@Flame On");
second_event.setTextQc(0);
second_event.setTime("2017-10-01T12:02:01.001Z");

List<Event> events_list = new ArrayList<>();
events_list.add(first_event);
events_list.add(second_event);

// Create a list of filter criteria
List<String> filter_list = new ArrayList<>();
filter_list.add("Introduction fuel");

// Create the EventSearchInputDataModel object that will be analyzed
EventSearchInputDataModel input_data_model = new EventSearchInputDataModel();
input_data_model.setEvents(events_list);
input_data_model.setEventsMetadata(events_metadata);
input_data_model.setFilterList(filter_list);

EventArrayOutput filter_events_response = null;
try {
    filter_events_response = event_operations_client.filterEvents(input_data_model);
} catch (MindsphereException e) {
    // Exception handling
}

Alternatively, use the FilterEventsRequest model.

// Create the EventSearchInputDataModel object as shown above
FilterEventsRequest request_object = new FilterEventsRequest();
request_object.setData(input_data_model);

EventArrayOutput filter_events_response = null;
try {
    filter_events_response = event_operations_client.filterEvents(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

Count Events

This section shows two options for determining the number of events per time interval for a user defined interval length.

// Create the EventOperationsClient object as shown above
// Create the EventInputEventsMetadata object
EventInputEventsMetadata events_metadata = new EventInputEventsMetadata();
events_metadata.setEventTextPropertyName("text");
events_metadata.setSplitInterval(500);

// Create a list of events to be analyzed
Event first_event = new Event();
first_event.setText("INTRODUCING FUEL");
first_event.setTextQc(0);
first_event.setTime("2017-10-01T12:00:00.001Z");

Event second_event = new Event();
second_event.setText("Status@Flame On");
second_event.setTextQc(0);
second_event.setTime("2017-10-01T12:02:01.001Z");

List<Event> events_list = new ArrayList<>();
events_list.add(first_event);
events_list.add(second_event);

// Create the EventInput object that will be analyzed
EventInput event_input = new EventInput();
event_input.setEvents(events_list);
event_input.setEventsMetadata(events_metadata);

EventCountOutput count_events_response = null;
try {
    count_events_response = event_operations_client.countEvents(event_input);
} catch (MindsphereException e) {
    // Exception handling
}

Alternatively, use the CountEventsRequest model.

// Create the EventInput object as shown above
CountEventsRequest request_object = new CountEventsRequest();
request_object.setData(event_input);

EventCountOutput count_events_response = null;
try {
    count_events_response = event_operations_client.countEvents(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

Remove Duplicate Events

This section shows two options for removing duplicate events. The methods detect duplicate events within a sliding window of user defined width (example 5,000 ms) and reduce the data set by aggregating duplicate events.

// Create the EventOperationsClient object as shown above
// Create the EventInputEventsMetadata object
EventInputEventsMetadata events_metadata = new EventInputEventsMetadata();
events_metadata.setEventTextPropertyName("text");
events_metadata.setSplitInterval(500);

// Create a list of events to be analyzed
Event first_event = new Event();
first_event.setText("INTRODUCING FUEL");
first_event.setTextQc(0);
first_event.setTime("2017-10-01T12:00:00.001Z");

Event second_event = new Event();
second_event.setText("Status@Flame On");
second_event.setTextQc(0);
second_event.setTime("2017-10-01T12:02:01.001Z");

List<Event> eventsList = new ArrayList<>();
eventsList.add(first_event);
eventsList.add(second_event);

// Create a list of filter criteria
List<String> filter_list = new ArrayList<>();
filter_list.add("Introduction fuel");

// Create the EventInput object that will be analyzed
EventInput event_input = new EventInput();
event_input.setEvents(eventsList);
event_input.setEventsMetadata(events_metadata);

DuplicateEventArrayOutput remove_duplicate_response = null;
try {
    remove_duplicate_response = event_operations_client.removeDuplicateEvents(event_input);
} catch (MindsphereException e) {
    // Exception handling
}

Alternatively, use the RemoveDuplicateEventsRequest model.

// Create the EventInput object as shown above
RemoveDuplicateEventsRequest request_object = new RemoveDuplicateEventsRequest();
request_object.setData(event_input);

DuplicateEventArrayOutput remove_duplicate_response = null;
try {
    remove_duplicate_response = event_operations_client.removeDuplicateEvents(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

Pattern Operations

The Pattern Operations client statistically analyzes the event data to identify the most frequent events.

Client name: PatternOperationsClient

Find Event Patterns

This section shows two options for searching for user defined patterns in a list of events. The response lists all events which match the specified pattern(s).

// Construct the PatternOperationsClient object
PatternOperationsClient pattern_operations_client = PatternOperationsClient.builder()
                                                      .mindsphereCredentials(credentials)
                                                      .restClientConfig(config)
                                                      .build();

// Construct the EventsInputModelEventsMetadata object
EventsInputModelEventsMetadata events_metadata = new EventsInputModelEventsMetadata();
events_metadata.setEventTextPropertyName("text");

// Create a list of events to be analyzed
Event first_event = new Event();
first_event.setText("INTRODUCING FUEL");
first_event.setTextQc(0);
first_event.setTime("2017-10-01T12:00:00.001Z");

Event second_event = new Event();
second_event.setText("Status@Flame On");
second_event.setTextQc(0);
second_event.setTime("2017-10-01T12:02:01.001Z");

List<Event> events_list = new ArrayList<>();
events_list.add(first_event);
events_list.add(second_event);

// Construct the EventsInputModel object
EventsInputModel events_input = new EventsInputModel();
events_input.setEvents(events);
events_input.setEventsMetadata(events_metadata);

// Construct MatchingPattern object
MatchingPattern matching_pattern_1 = new MatchingPattern();
matching_pattern_1.setEventText("INTRODUCING FUEL");
matching_pattern_1.setMaxRepetitions(2);
matching_pattern_1.setMinRepetitions(1);

MatchingPattern matching_pattern_2 = new MatchingPattern();
matching_pattern_2.setEventText("Status@Flame On");
matching_pattern_2.setMaxRepetitions(1);
matching_pattern_2.setMinRepetitions(0);

// Create a list of matching patterns
List<MatchingPattern> pattern = new ArrayList<>();
pattern.add(matching_pattern_1);
pattern.add(matching_pattern_2);

// Construct PatternDefinition object
PatternDefinition pattern_definition = new PatternDefinition();
pattern_definition.setPattern(pattern);

// Create a list of pattern definitions
List<PatternDefinition> pattern_definition_list = new ArrayList<>();
pattern_definition_list.add(pattern_definition);

// Create a list of non event strings
List<String> non_events = new ArrayList<>();
non_events.add("Error 2.. occurred");
non_events.add("STOPPING ENGINE");

// Construct the PatternMatchingInputDataModel object that will be analyzed
PatternMatchingInputDataModel input_data_model = new PatternMatchingInputDataModel();
input_data_model.setEventsInput(events_input);
input_data_model.setNonEvents(non_events);
input_data_model.setPatternsList(pattern_definition_list);
input_data_model.setMaxPatternInterval(200000);

PatternMatchingOutput match_pattern_response = null;
try {
    match_pattern_response = pattern_operations_client.matchPatternsOverEvents(input_data_model);
} catch (MindsphereException e) {
    // Exception handling
}

Alternatively, use the MatchPatternsOverEventsRequest model.

// Construct the PatternMatchingInputDataModel object as shown above

MatchPatternsOverEventsRequest request_object = new MatchPatternsOverEventsRequest();
request_object.setData(input_data_model);

PatternMatchingOutput match_pattern_response = null;
try {
    match_pattern_response = pattern_operations_client.matchPatternsOverEvents(request_object);
} catch (MindsphereException e) {
    // Exception handling
}

Last update: April 2, 2024

Except where otherwise noted, content on this site is licensed under the Development License Agreement.