Skip to content

Commit

Permalink
adding sample block
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Mar 19, 2024
1 parent 4d521b4 commit eae49c7
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
7 changes: 7 additions & 0 deletions analytics-ui/src/shared/analytics.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export const REPO_SAMPLES_BLOCKSDK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}
export const REPO_SAMPLES_CONTRIB_BLOCK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/blocks`;
export const REPO_SAMPLES_CONTRIB_CUMULOCITY = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/cumulocity-blocks`;
export const REPO_SAMPLES_CONTRIB_SIMULATION = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/simulation-blocks`;
export const REPO_SAMPLES_ANALYTICS_MANAGEMENT = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}//cumulocity-analytics-management/contents/repository/blocks`;
export const REPO_SAMPLES = [
{
id: uuidCustom(),
name: 'Block SDK Quick Start Samples',
url: REPO_SAMPLES_ANALYTICS_MANAGEMENT,
enabled: true
},
{
id: uuidCustom(),
name: 'Block SDK Samples',
Expand Down
79 changes: 79 additions & 0 deletions repository/blocks/MathOperation.mon
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* $Copyright (c) 2020-2021 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.$
* Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
*/
package apamax.analyticsbuilder.blocks;

using apama.analyticsbuilder.BlockBase;
using apama.analyticsbuilder.Activation;

event MathOperation_$Parameters {

/**
* Operation.
*
* The mathematical operation to perform.
**/
string operation;

/** Addition */
constant string operation_add := "add";
/** Substraction */

Check warning on line 21 in repository/blocks/MathOperation.mon

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"Substraction" should be "Subtraction".
constant string operation_sub := "substraction";

Check warning on line 22 in repository/blocks/MathOperation.mon

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"substraction" should be "subtraction".
/** Multiplication */
constant string operation_mul := "multiplication";
/** Division */
constant string operation_div := "division";
/** Modulo */
constant string operation_mod := "modulo";


}

/**
* Mathematical Operation.
*
* Combine two inputs using a mathematical operation.
* Supported operations are addition, substraction, multiplication, divison, and modulo.

Check warning on line 37 in repository/blocks/MathOperation.mon

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"substraction" should be "subtraction".

Check warning on line 37 in repository/blocks/MathOperation.mon

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"divison" should be "division".
*
* @$blockCategory Calculations
* @$derivedName $operation
*/
event MathOperation {

BlockBase $base;
MathOperation_$Parameters $parameters;

/**
* @param $input_value1 The first input value.
* @param $input_value2 The second input value.
*
* @$inputName value1 Value1
* @$inputName value2 Value2
*/
action $process(Activation $activation, float $input_value1, float $input_value2) {
if($parameters.operation = MathOperation_$Parameters.operation_add) {
$setOutput_output($activation, $input_value1 + $input_value2);
} else if($parameters.operation = MathOperation_$Parameters.operation_sub) {
$setOutput_output($activation, $input_value1 - $input_value2);
} else if($parameters.operation = MathOperation_$Parameters.operation_mul) {
$setOutput_output($activation, $input_value1 * $input_value2);
} else if($parameters.operation = MathOperation_$Parameters.operation_div) {
if($input_value2 != 0.0) {
$setOutput_output($activation, $input_value1 / $input_value2);
}
} else if($parameters.operation = MathOperation_$Parameters.operation_mod) {
if($input_value2 != 0.0) {
$setOutput_output($activation, $input_value1.fmod($input_value2));
}
}
}

/**
* Result.
*
* The result of the mathematical operation.
*/
action<Activation, float> $setOutput_output;

}

0 comments on commit eae49c7

Please sign in to comment.