Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Oct 24, 2024
0 parents commit 2439bc5
Show file tree
Hide file tree
Showing 93 changed files with 16,638 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/create_all_workflows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: create-workflows
on:
push:
jobs:
create-all-workflows:
runs-on: ubuntu-20.04
steps:
- name: checkout simulation data
uses: actions/checkout@v4
with:
submodules: true
token: ${{ secrets.WRITE_WORKFLOW }}
- name: install prerequisites
run: |
npm install yaml --prefix ./workflow_utils
npm install ./workflow_utils/stmd-crud --prefix ./workflow_utils/stmd-crud
- name: create new workflow
env:
GithubBranch: ${{ github.ref_name }}
GithubRepoName: ${{ github.event.repository.name }}
GithubOwner: ${{ github.repository_owner }}
run: node ./workflow_utils/parse_to_yaml.js -f "./stmdtest.stmd" -o ./.github/workflows/
- name: push workflows
run: |
git config --global user.name "Automated Test Pipeline"
git config --global user.email "[email protected]"
git add ./.github/workflows
git commit -m "Generated new automated all workflow, based on STMD [actions skip]"
git push -f
- name: display result
run: |
echo "Successfully created new workflows" >> $GITHUB_STEP_SUMMARY
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

- Changed CDK Schema:
- MetricType: Deleted attribute `packageUri`, added attributes `module`, `interpreter`, `interpreterVersion`
- SimpleProcessingType: Deleted attribute `packageUri`, added attributes `module`, `interpreter`, `interpreterVersion`. Changed `id` from optional to required.
- ComplexProcessingType: Changed attribute name `method` to `interpreter`. Added `python` to selection for `interpreter`. Added attribute `interpreterVersion`. Changed `id` from optional to required.
- Prerequisites: Deleted attribute name `method` --> only bash scripts allowed

- json_to_yaml.js:
- added handling of python quality metrics and processing functions
- added version management for NodeJS
- added version management and virtual environments for python
- refactored and commented everything

- wrappers:
- added python wrapper
- added internal function to allow correct allocation from function arguments (so they can occur in arbitrary order in the STMD)

- parse_to_yaml.js:
- refactored
25 changes: 25 additions & 0 deletions data/cert_ahmann.crt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MIIENzCCAx+gAwIBAgIURfMlTJ+E8y+XBS3oudOk0z75+jQwDQYJKoZIhvcNAQEL
BQAwgaoxCzAJBgNVBAYTAkRFMRAwDgYDVQQIDAdCYXZhcmlhMQ8wDQYDVQQHDAZN
dW5pY2gxHjAcBgNVBAoMFVNFVExhYnMgUmVzZWFyY2ggR21iSDETMBEGA1UECwwK
QXV0b21vdGl2ZTEYMBYGA1UEAwwPTWF1cml6aW8gQWhtYW5uMSkwJwYJKoZIhvcN
AQkBFhptYXVyaXppby5haG1hbm5Ac2V0bGFicy5kZTAeFw0yMzAyMjMxNTMwNTla
Fw0yNDEyMzExNTMwNTlaMIGqMQswCQYDVQQGEwJERTEQMA4GA1UECAwHQmF2YXJp
YTEPMA0GA1UEBwwGTXVuaWNoMR4wHAYDVQQKDBVTRVRMYWJzIFJlc2VhcmNoIEdt
YkgxEzARBgNVBAsMCkF1dG9tb3RpdmUxGDAWBgNVBAMMD01hdXJpemlvIEFobWFu
bjEpMCcGCSqGSIb3DQEJARYabWF1cml6aW8uYWhtYW5uQHNldGxhYnMuZGUwggEi
MA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDSmUihmubtTl5DHeuo1xntCESm
hfZESRXVIgtKwQnHwcr4Y0KHB7No6MxEZN88f5Kdq9qa7yU1CmjlmBQvvFhLoyZE
Fciv2JH1lKPPY0hpa1aUMulygQrMBoWhI7C4DDg5GB8D2FmkMHKWvTzXqLIkQLpT
esKN64wTT44ElTjZaNLKpkH79sDbGzG8pxdtBE5abTainSBbpCFpt9or8Kc2PL74
smd24IfAcfCq+71arCQXFaW0cIAiXHWbSBvQGmAN5s+hcZ97P6VEQV5MMjRPESF4
toH1RahYLUYT18VICzWVnbo2eAxYZgAsgepCD/sAtAYBLbzxzip45oVIzUpfAgMB
AAGjUzBRMB0GA1UdDgQWBBQQjy3fPlVqebstqr2+s7s7MhorcjAfBgNVHSMEGDAW
gBQQjy3fPlVqebstqr2+s7s7MhorcjAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3
DQEBCwUAA4IBAQAShChBMOU89sy+cIElFgtd0gg33HgIWB3dTNqKS1tyKW95y0Hk
iTOSx31DVj+dT/bcqtrqNUqiad+iVp4QZLR5TlWTugxT958VTvm+KhPln7ovk+En
lvjWwFK3/wPEH9d+rTR7c20jlSl0MIfLXVTU7/8AkkbOZYHriH7AAoulldmc1s4n
L0e1sAhhL2AQBk6RR0FLLJTrXgKtdj3UxzYCnC/WTT6fj37KY9bVyXxQU46luumW
UMTNLhOOx1SILybhfkpMPff7VBP+9cN/qmk3dgT0LcBo9G/KyHpHs4TGWlpsPZTN
fsV1NFOtAz3c8ye83Pl98RkKn4uZi0Xdwy/D
-----END CERTIFICATE-----
1 change: 1 addition & 0 deletions data/expertStatement_req_m_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"content":{"result":true,"log":"The requirement with ID #req_m_01 is necessary, unambiguous, complete, singular, achievable, and verifiable."},"signature":"cd61a6dd9c56d7e4a14fdd2f590b8f45cb8bd18c4ba9fd67570f35b7729b6fbdabaae2f27d953d372064e7e8dcc5c67825393bf129838c31e2841aeb18786d2ea58800ac1209bc55d66406cc7b437471809e32866ecece40f3fe44422234182fec38379f38adafe1217ed50655e63421bded321fcb2f4cfaff36cf84df2f74ddace9c0a8375a11bec6e4dbefa84c50be591b6353dbfc3120716d2aca95b7ad28669bf2c82c8b1f40634793a9c967e1f7c610e76131712eee17d15844731fa3e7e55221f13fbf54a1d187c044796e8e3a035fa3a1631b100c9e3ab28bee569bacea9bfba7fc304757ee5623c3141070bfd0e688cc0a2ae78fd7d20113c714e97e","hash_algorithm":"SHA256","signature_encoding":"hex"}
1 change: 1 addition & 0 deletions data/my_testdata.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1, 4, 5, 7, 10]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# UTIL-COMMON
301 changes: 301 additions & 0 deletions processing_functions/node_functions/util/util-common/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
const Ajv = require("ajv");
const ajv = new Ajv({$data: true, allErrors: true})
require("ajv-keywords")(ajv);
const { XMLParser, XMLValidator } = require('fast-xml-parser');
const xsdValidator = require('libxmljs2-xsd');
const fileSync = require("fs");
const path = require('path');

exports.factorialize = factorialize;
exports.makeDeepCopy = makeDeepCopy;
exports.isStructureValid = isStructureValid
exports.roundToDigit = roundToDigit;
exports.getLsd = getLsd;
exports.roundToInterval = roundToInterval;
exports.floorToInterval = floorToInterval;
exports.ceilToInterval = ceilToInterval;
exports.mod = mod;

exports.validateXMLAgainstXSD = validateXMLAgainstXSD;
exports.validateXML = validateXML;
exports.parseXMLToJson = parseXMLToJson;


const PRECISION = 15;

/**
* Calculates the faculty of an integer
*
* If the number is smaller than 0 or not an integer, -1 will be returned
*
* @param {number} num
* @returns
*/
function factorialize(num) {
if (!Number.isInteger(num) || num < 0)
return -1;
else if (num == 0)
return 1;
else
return (num * factorialize(num - 1));
}

/**
* Makes a deep copy of the input object
*
* @param {any[], Object} obj
* @returns
*/
function makeDeepCopy(obj) {
return JSON.parse(JSON.stringify(obj));
}

/**
* Validates if the passed object fulfills the given JSON schema
*
* @author localhorst87
* @function
* @param {Object} obj The object to be validated
* @param {Object} schema The schema the object is validated against
* @return {Boolean} returns true if the object fulfills the schema
*/
function isStructureValid(obj, schema) {
const validate = ajv.compile(schema);
return validate(obj);
}

/**
* Applies the given significant digits to the number
*
* @author localhorst87
* @function
* @param {number} value value to apply precision to
* @param {number} precision significant digits
* @returns {number} value with given significant digits
*/
function precise(value, precision) {
return parseFloat(value.toPrecision(precision));
}

/**
* Rounds a value to a given digit.
* The function is valid for fast floating point arithmetic,
* up to a precision of 15 digits.
*
* digit > 0: digit after decimal point
*
* digit == 0: round to integer
*
* digit < 0: digit before decimal point
*
* @author localhorst87
* @function
* @param {number} value value to round
* @param {number} digit the digit to round to
* @param {Function} [roundFn=Math.round] round function, Math.round by default
* @returns {number} rounded value
*/
function roundToDigit(value, digit, roundFn = Math.round) {
if (typeof(value) !== "number")
throw("value must be numerical");
if (typeof(digit) !== "number")
throw("digit must be numerical");
if (!Number.isInteger(digit))
throw("digit must be an integer");
if (roundFn !== Math.round && roundFn !== Math.ceil && roundFn !== Math.floor)
throw("only Math.round, Math.ceil and Math.floor allowed as roundFn");

const tenPower = Math.pow(10, digit);
const roundedValue = roundFn(value * tenPower) / tenPower;

return precise(roundedValue, PRECISION);
}

/**
* Returns the least significant digit of the number.
*
* This function is valid for numbers up to a precision
* of 15 (numbers with 15 digits without leading or trailing
* zeroes)
*
* lsd > 0: digit after decimal point
*
* lsd <= 0: digit before decimal point
*
* @author localhorst87
* @function
* @param {number} value
* @returns {number} least significant digit
*/
function getLsd(value) {
if (typeof(value) !== "number")
throw("value must be numeric");

if (value === 0)
return 0;

value = precise(value, PRECISION);

let lsd = 0;

if (Number.isInteger(value)) {
while(value - roundToDigit(value, --lsd, Math.round) == 0) continue;
lsd += 1;
}
else
while(value - roundToDigit(value, ++lsd, Math.round) !== 0) continue;

return lsd;
}

/**
* Rounds a number to the nearest number that
* can be divided by the given interval
*
* @author localhorst87
* @function
* @param {number} value raw numeric value
* @param {number} interval interval to round to
* @returns {number} number with applied interval
*/
function roundToInterval(value, interval) {
if (typeof(value) !== "number")
throw("value must be a number");
if (typeof(interval) !== "number")
throw("interval must be a number");
if (interval <= 0)
throw("interval must be > 0");

const lsd = Math.max(getLsd(interval), getLsd(value));
const remainder = roundToDigit(mod(value, interval), lsd); // use round to digit to avoid floating point errors

if (value >= 0)
return remainder < interval/2 ? roundToDigit(value - remainder, lsd) : roundToDigit(value - remainder + interval, lsd);
else
return Math.abs(remainder) <= interval/2 ? roundToDigit(value - remainder, lsd) : roundToDigit(value - remainder - interval, lsd);
}

/**
* Floors a number to the nearest number that
* can be divided by the given interval
*
* @author localhorst87
* @function
* @param {number} value raw numeric value
* @param {number} interval interval to round to
* @returns {number} number with applied interval
*/
function floorToInterval(value, interval) {
if (typeof(value) !== "number")
throw("value must be a number");
if (typeof(interval) !== "number")
throw("interval must be a number");
if (interval <= 0)
throw("interval must be > 0");

const lsd = Math.max(getLsd(interval), getLsd(value));
const remainder = roundToDigit(mod(value, interval), lsd); // use round to digit to avoid floating point errors

if (value >= 0)
return roundToDigit(value - remainder, lsd);
else
return Math.abs(remainder) > 0 ? roundToDigit(value - remainder - interval, lsd) : value;
}

/**
* Ceils a number to the nearest number that
* can be divided by the given interval
*
* @author localhorst87
* @function
* @param {number} value raw numeric value
* @param {number} interval interval to round to
* @returns {number} number with applied interval
*/
function ceilToInterval(value, interval) {
if (typeof(value) !== "number")
throw("value must be a number");
if (typeof(interval) !== "number")
throw("interval must be a number");
if (interval <= 0)
throw("interval must be > 0");

const lsd = Math.max(getLsd(interval), getLsd(value));
const remainder = roundToDigit(mod(value, interval), lsd); // use round to digit to avoid floating point errors

if (value >= 0)
return remainder > 0 ? roundToDigit(value - remainder + interval, lsd) : value;
else
return roundToDigit(value - remainder, lsd);
}

/**
* floating-point safe modulo operator
*
* @author localhorst87
* @function
* @param {number} value
* @param {number} divisor
* @returns {number} remainder of value / divisor
*/
function mod(value, divisor) {
if (typeof(value) !== "number")
throw("value must be numeric");
if (typeof(divisor) !== "number")
throw("divisor must be numeric");

const lsd = Math.max(getLsd(value), getLsd(divisor));
const remainderPower = (value * Math.pow(10, lsd)) % (divisor * Math.pow(10, lsd));

return remainderPower / Math.pow(10, lsd);
}

/**
* Checks if the XML model description file fulfills the given XSD scheme
* @author lvtan
* @function
* @param {String} xmlString XML-validated model description
* @param {String} xsdFilePath path of xsd file that is used to validate
* @return {Boolean} returns true/false upon valid/invalid scheme
*/
function validateXMLAgainstXSD(xmlString, xsdFilePath) {
var xsdString = fileSync.readFileSync(xsdFilePath, 'utf8');
var modelDescXsdBasePath = path.dirname(path.resolve(xsdFilePath))+"/"
let parsedXsd = xsdValidator.parse(xsdString, { baseUrl: modelDescXsdBasePath });
let validationErrors = parsedXsd.validate(xmlString);
return validationErrors == null;
}

/**
* Checks if the XML structure of the given XML string is valid
* @author lvtan
* @function
* @param {String} xmlString XML as plain text
* @return {Boolean} returns true/false upon valid/invalid XML format
*/

function validateXML(xmlString) {
const validationOptions = {
allowBooleanAttributes: true
};
const validationResult = XMLValidator.validate(xmlString, validationOptions);

return validationResult == true;
}

/**
* Convert XML string to JSON
*
* @author lvtan3005
* @function
* @param {string} xmlString the xml at the string format
* @returns {object} json object after parsing
*/

function parseXMLToJson(xmlString) {
const parserOptions = {
ignoreAttributes : false
};
const xmlParser = new XMLParser(parserOptions);
return xmlParser.parse(xmlString);
}
Loading

0 comments on commit 2439bc5

Please sign in to comment.