Skip to content
Snippets Groups Projects
Commit de53f4ee authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: finished initial implementation of data analysis extension

parent 81a4a21f
No related branches found
No related tags found
No related merge requests found
/*
* ** header with license infoc
* ...
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Alexander Schlemmer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
'use strict';
/**
* description of the module ...
* Module that adds data analysis buttons to records of a specified record type.
* These record types are configured in a file called data_analysis.json. The record type
* usually has Dataset as Parent and contains references to multiple datasets that are used
* as input for the data analysis script.
*
* @module ext_flight_preview
* Currently this module supports only one analysis script. It is planned to expand this for
* multiple configured analysis scripts.
*
* @module ext_data_analysis
* @version 0.1
*
* @requires somelibrary
* (pass the dependencies as arguments)
*/
var ext_flight_preview = function (somelibrary) {
var ext_data_analysis = function (somelibrary) {
var init = function (toolbox) {
/* initialization of the module */
this.add_ui();
}
/**
* doc string
* Add the analysis buttons to the correct records.
*/
var add_ui = async function() {
// load configuration for data analysis module
var config = await load_config("data_analysis.json");
var ents = getEntities();
for (ent of ents) {
// Check parents for configured parent:
var parents = getParents(ent);
var found = false;
for (parent of parents) {
if (parents[0].name == config["supported_dataset_parent"]) {
found = true;
break;
}
}
if (found == true) {
var button = $("<button>" + config["data_analysis_title"] + "</button>");
let entity_id = getEntityID(ent);
let analysis_script = config["analysis_script_file"];
button.click(_=>runCorrAnalysis(entity_id, analysis_script));
$(ent).find(".caosdb-v-entity-header-buttons-list").prepend(button);
}
}
}
/**
* Run the analysis script. This function is run by the
* analysis button and runs the configured python script in the background.
* The current entity id (which is usually a sub record type of a dataset is passed
* as argument "--entity" to the script file.
*/
var some_function = function (arg1, arg2) {
function runAnalysis(entity_id, analysis_script) {
connection.runScript(analysis_script, {"-Oentity": entity_id});
}
/* the main function must return the initialization of the module */
......@@ -38,29 +92,7 @@ $(document).ready(function() {
// use a variable starting with `BUILD_MODULE_` to enable your module
// the build variable has to be enabled in the `build.properties.d/` directory.
// Otherwise the module will not be activated.
if ("${BUILD_MODULE_EXT_BOTTOM_LINE}" === "ENABLED") {
caosdb_modules.register(ext_flight_preview);
if ("${BUILD_MODULE_EXT_DATA_ANALYSIS}" === "ENABLED") {
caosdb_modules.register(ext_data_analysis);
}
});
// -------------------------
function runCorrAnalysis(entity_id) {
console.log(entity_id);
connection.runScript("", {"-Oentity": entity_id});
}
var ents = getEntities();
for (ent of ents) {
var parents = getParents(ent);
if (parents.length > 0 && parents[0].name == "") {
var button = $("<button>Data Analysis</button>");
button.click((function(entity_id){return()=>runCorrAnalysis(entity_id);})(getEntityID(ent)));
$(ent).find(".caosdb-v-entity-header-buttons-list").prepend(button);
}
}
// load configuration for data analysis module
var config = await load_config("data_analysis.json");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment