<commit_before>// ========================================================================
// viewModel class
// ========================================================================
function viewModel(){
    var self = this;

    // ========================================================================
    // Controls subpage
    // ========================================================================
    // | Section  | Option  |  Function |  Comment  |
    // | -------- | ------- | --------- | --------- |
    // | design   |  exp    |  exp_old  |           |
    // |          |         |  exp_new  |           |
    // |          |  lay    |  lay_old  |           |
    // |          |         |  lay_new  |           |
    // |          |  imp    |  imp_file |           |
    // |          |         |  imp_manu |           |
    // | vis      |  plate  |           |           |
    // |          |  genes  |           |           |
    // | analysis |  norm   |           |           |
    // |          |  expt   |           |           |
    //
    self.sec = ko.observable('design');  // Active section
    self.opt = ko.observable('exp');     // Active option
    self.fun = ko.observable('exp_old'); // Active function

    // Experiment subpage
    self.exp = new ExpVM();

    // ========================================================================
    // Layout subpage
    // ========================================================================
    //
    // Factor (independent variables)
    self.exp_fact = ko.observableArray([new ExpVar()]);
    self.layouts = ko.observableArray(['AAA', 'BBB']);
    self.layout_exps = ko.observableArray(['AAA','AAA']);

    // ========================================================================
    // Plates
    // ========================================================================

    // Visualize plate
    self.vis_plate = ko.observable(false);

    // ========================================================================
    // Genes Vis: Factor selection and query
    // ========================================================================
    // Available factor for visualization
    self.factors = getFactors();

    // Factor chosen to be added
    self.factor_chosen = ko.observable();

    // Factor selected
    self.factor_panels = ko.observableArray();

    // Add a factor selection panel
    self.add_panel = function() {
        if (self.factor_chosen()){
            self.factor_panels.push(self.factor_chosen());
            self.factors.remove(self.factor_chosen());
            self.factor_chosen();
        }
    };

    // Remove a factor
    self.del_panel = function(fact) {
        self.factor_panels.remove(fact);
        self.factors.push(fact);
        self.factors.sort(function(left, right) {
            return left.name == right.name ? 0 :
            (left.name < right.name ? -1 : 1)
        });
        self.factor_chosen();

        // console.log(fact);
        // self.factor_panels.remove(fact)
        // fact._destroy = false;
        // self.factors.valueHasMutated();
    };

    // ========================================================================
    // Genes Vis: Time series curve vis
    // ========================================================================
    // vis row
    self.row = ko.observableArray([ ['a', 'b'], ['c', 'd'] ]);

}

// ========================================================================
// Experiment viewModel class
// ========================================================================
function ExpVM() {
    var self = this;

    // Possible values: old, new
    self.fun = ko.observable('old');
    // Reset current_exp every time fun changes
    self.fun.subscribe(function(){self.current_exp(null);})

    self.experiments = ko.observableArray();
    self.current_exp = ko.observable();

    self.current_exp.subscribe(function(new_exp){
        self.exp_chnl(null);
        for (c in new_exp.channels){
            self.exp_chnl.push(new_exp.channels[c]);
        }
    })

    // General information
    self.name = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().name;
        }
    });

    self.user = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().user;
        }
    });

    // Well numbers
    self.well_types = [96, 384];
    self.well = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().well;
        }
    })

    // TODO: refresh button
    $.ajax({
        url: "/api/v2/experiment",
        type: "GET",
        success: function(data){
            for (e in data.experiment){
                self.experiments.push(data.experiment[e]);
            }
        }
    });

    // Factor (independent variables)
    self.exp_fact = ko.observableArray([new ExpVar()]);

    // Channels (dependent variables)
    self.exp_chnl = ko.observableArray();

    self.var_types = ['Category', 'Integer', 'Decimal'];

    // Add a new dependent
    self.add_chnl = function() { self.exp_chnl.push(new ExpVar()) };<commit_msg>Update knockout <-> API interaction<commit_after>// ========================================================================
// viewModel class
// ========================================================================
function viewModel(){
    var self = this;

    // ========================================================================
    // Controls subpage
    // ========================================================================
    // | Section  | Option  |  Function |  Comment  |
    // | -------- | ------- | --------- | --------- |
    // | design   |  exp    |  exp_old  |           |
    // |          |         |  exp_new  |           |
    // |          |  lay    |  lay_old  |           |
    // |          |         |  lay_new  |           |
    // |          |  imp    |  imp_file |           |
    // |          |         |  imp_manu |           |
    // | vis      |  plate  |           |           |
    // |          |  genes  |           |           |
    // | analysis |  norm   |           |           |
    // |          |  expt   |           |           |
    //
    self.sec = ko.observable('design');  // Active section
    self.opt = ko.observable('exp');     // Active option
    self.fun = ko.observable('exp_old'); // Active function

    // Experiment subpage
    self.exp = new ExpVM();

    // ========================================================================
    // Layout subpage
    // ========================================================================
    //
    // Factor (independent variables)
    self.exp_fact = ko.observableArray([new ExpVar()]);
    self.layouts = ko.observableArray(['AAA', 'BBB']);
    self.layout_exps = ko.observableArray(['AAA','AAA']);

    // ========================================================================
    // Plates
    // ========================================================================

    // Visualize plate
    self.vis_plate = ko.observable(false);

    // ========================================================================
    // Genes Vis: Factor selection and query
    // ========================================================================
    // Available factor for visualization
    self.factors = getFactors();

    // Factor chosen to be added
    self.factor_chosen = ko.observable();

    // Factor selected
    self.factor_panels = ko.observableArray();

    // Add a factor selection panel
    self.add_panel = function() {
        if (self.factor_chosen()){
            self.factor_panels.push(self.factor_chosen());
            self.factors.remove(self.factor_chosen());
            self.factor_chosen();
        }
    };

    // Remove a factor
    self.del_panel = function(fact) {
        self.factor_panels.remove(fact);
        self.factors.push(fact);
        self.factors.sort(function(left, right) {
            return left.name == right.name ? 0 :
            (left.name < right.name ? -1 : 1)
        });
        self.factor_chosen();

        // console.log(fact);
        // self.factor_panels.remove(fact)
        // fact._destroy = false;
        // self.factors.valueHasMutated();
    };

    // ========================================================================
    // Genes Vis: Time series curve vis
    // ========================================================================
    // vis row
    self.row = ko.observableArray([ ['a', 'b'], ['c', 'd'] ]);

}

// ========================================================================
// Experiment viewModel class
// ========================================================================
function ExpVM() {
    var self = this;

    // =====================
    // Current functionality
    // =====================
    // Possible values: old, new
    self.fun = ko.observable('old');

    // Reset current_exp every time fun changes
    self.fun.subscribe(function(){self.current_exp(null);})

    // =====================
    // Experiment objs
    // =====================
    self.experiments = ko.observableArray();
    self.current_exp = ko.observable();
    // Factor (independent variables)
    self.exp_fact = ko.observableArray([new ExpVar()]);
    // Channels (dependent variables)
    self.exp_chnl = ko.observableArray();

    // Reset exp_fact everytime the current_exp is reset
    self.current_exp.subscribe(function(exp){
        self.exp_fact([]);
        if (exp) {
            for (f in exp.factors){
                self.exp_fact.push(exp.factors[f]);
            }
        }
    })

    // Reset exp_chnl everytime the current_exp is reset
    self.current_exp.subscribe(function(exp){
        self.exp_chnl([]);
        if (exp) {
            for (c in exp.channels){
                self.exp_chnl.push(exp.channels[c]);
            }
        }
    })

    // General information
    self.name = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().name;
        }
    });

    self.user = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().user;
        }
    });

    // Well numbers
    self.well_types = [96, 384];
    self.well = ko.computed(function(){
        if (self.current_exp()){
            return self.current_exp().well;
        }
    })

    // TODO: refresh button
    $.ajax({
        url: "/api/v2/experiment",
        type: "GET",
        success: function(data){
            for (e in data.experiment){
                self.experiments.push(data.experiment[e]);
            }
        }
    });

    // TODO disable update button if there is no change
    self.update_exp = function() {
        $.ajax({
            url: "/api/v2/experiment",
            type: "PUT",
            dataType: "json",
            data: JSON.stringify({experiment: [self.current_exp()]}),
            contentType: "application/json; charset=utf-8",
            success: function(data){
                self.current_exp(data);
            }
        });
    };


    self.var_types = ['Category', 'Integer', 'Decimal'];

    // Add a new dependent
    self.add_chnl = function() { self.exp_chnl.push(new ExpVar()) };
{'fraction_non_alphanumeric': 0.3102808691043985, 'fraction_numerical': 0.0017664723547076487, 'mean_word_length': 2.0810884353741494, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2235148', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2810, 'n_words': 523}