<commit_before>/* 
 * This class is used to retrive data from webservice, mutaton and cna servlets
 * including all date and date attributes
 */


var StudyViewProxy = (function() {
    
    var parObject = {},
        caseIdStr = '',
        ajaxParameters = {},
        obtainDataObject = [];
        
    obtainDataObject['attr'] = [];
    obtainDataObject['arr'] = [];
    
    function initLocalParameters(){
        parObject = jQuery.extend(true, {}, StudyViewParams.params);
        caseIdStr = parObject.caseIds.join(' ');
    }
    
    function initAjaxParameters(){
        ajaxParameters = {
            webserviceData: {
                cmd: "getClinicalData",
                format: "json",
                cancer_study_id: parObject.studyId,
                case_set_id: parObject.caseSetId
            },
            clinicalAttributesData: {
                cancer_study_id: parObject.studyId,
                case_list: caseIdStr
            },
            mutationsData: {
                cmd: "count_mutations",
                cases_ids: caseIdStr,
                mutation_profile: parObject.mutationProfileId
            },
            cnaData: {
                cmd: "get_cna_fraction",
                case_ids: caseIdStr,
                cancer_study_id: parObject.studyId
            },
            mutatedGenesData: {
                cmd: 'get_smg',
                case_list: caseIdStr,
                mutation_profile: parObject.mutationProfileId
            },
            gisticData: {
                selected_cancer_type: parObject.studyId
            }
        };
    }
    
    function getDataFunc(callbackFunc){
         $.when(  
                $.ajax({type: "POST", url: "webservice.do", data: ajaxParameters.webserviceData}), 
                $.ajax({type: "POST", url: "mutations.json", data: ajaxParameters.mutationsData}),
                $.ajax({type: "POST", url: "cna.json", data: ajaxParameters.cnaData}),
                $.ajax({type: "POST", url: "mutations.json", data: ajaxParameters.mutatedGenesData}),
                $.ajax({type: "POST", url: "Gistic.json", data: ajaxParameters.gisticData}))
            .done(function(a1, a2, a3, a4, a5){
                var _dataAttrMapArr = {}, //Map attrbute value with attribute name for each datum
                    _keyNumMapping = {},
                    _data = a1[0]['data'],
                    _dataAttrOfa1 = a1[0]['attributes'],
                    _dataLength = _data.length,
                    _globalCaseIdsLength = parObject.caseIds.length;

                //Reorganize data into wanted format datum[ caseID ][ Attribute Name ] = Attribute Value
                //The original data structure is { attr_id: , attr_va: , sample}
                for(var i = 0; i < _dataLength; i++){
                    if(_data[i]["sample"] in _dataAttrMapArr){
                        _dataAttrMapArr[_data[i]["sample"]][_data[i]["attr_id"]] = _data[i]["attr_val"];
                    }
                    else{
                        _dataAttrMapArr[_data[i]["sample"]] = [];
                        _dataAttrMapArr[_data[i]["sample"]][_data[i]["attr_id"]] = _data[i]["attr_val"];
                    }
                }
                
                //Initial data array, not all of cases has MUTAION COUND OR COPY NUMBER ALTERATIONS.
                for(var j = 0; j <  _globalCaseIdsLength; j++){
                    var _caseDatum = {};
                    _caseDatum["CASE_ID"] = parObject.caseIds[j];
                    _caseDatum["MUTATION_COUNT"] = "NA";
                    _caseDatum["COPY_NUMBER_ALTERATIONS"] = "NA";
                    _keyNumMapping[parObject.caseIds[j]] = j;
                    $.each(_dataAttrOfa1,function(key,value){
                        if(value['attr_id'] !== 'CASE_ID'){
                            _caseDatum[value['attr_id']] = "NA";
                        }
                    });
                    obtainDataObject['arr'].push(_caseDatum);
                }
                
                $.each(_dataAttrOfa1,function(key,value){
                    if(!value['display_name']){
                        value['display_name'] = value['attr_id'];
                    }
                    
                    value['display_name'] = toPascalCase(value['display_name']);
                });
                <commit_msg>Make sure always convert attr_id to upper case<commit_after>/* 
 * This class is used to retrive data from webservice, mutaton and cna servlets
 * including all date and date attributes
 */


var StudyViewProxy = (function() {
    
    var parObject = {},
        caseIdStr = '',
        ajaxParameters = {},
        obtainDataObject = [];
        
    obtainDataObject['attr'] = [];
    obtainDataObject['arr'] = [];
    
    function initLocalParameters(){
        parObject = jQuery.extend(true, {}, StudyViewParams.params);
        caseIdStr = parObject.caseIds.join(' ');
    }
    
    function initAjaxParameters(){
        ajaxParameters = {
            webserviceData: {
                cmd: "getClinicalData",
                format: "json",
                cancer_study_id: parObject.studyId,
                case_set_id: parObject.caseSetId
            },
            clinicalAttributesData: {
                cancer_study_id: parObject.studyId,
                case_list: caseIdStr
            },
            mutationsData: {
                cmd: "count_mutations",
                cases_ids: caseIdStr,
                mutation_profile: parObject.mutationProfileId
            },
            cnaData: {
                cmd: "get_cna_fraction",
                case_ids: caseIdStr,
                cancer_study_id: parObject.studyId
            },
            mutatedGenesData: {
                cmd: 'get_smg',
                case_list: caseIdStr,
                mutation_profile: parObject.mutationProfileId
            },
            gisticData: {
                selected_cancer_type: parObject.studyId
            }
        };
    }
    
    function getDataFunc(callbackFunc){
         $.when(  
                $.ajax({type: "POST", url: "webservice.do", data: ajaxParameters.webserviceData}), 
                $.ajax({type: "POST", url: "mutations.json", data: ajaxParameters.mutationsData}),
                $.ajax({type: "POST", url: "cna.json", data: ajaxParameters.cnaData}),
                $.ajax({type: "POST", url: "mutations.json", data: ajaxParameters.mutatedGenesData}),
                $.ajax({type: "POST", url: "Gistic.json", data: ajaxParameters.gisticData}))
            .done(function(a1, a2, a3, a4, a5){
                var _dataAttrMapArr = {}, //Map attrbute value with attribute name for each datum
                    _keyNumMapping = {},
                    _data = a1[0]['data'],
                    _dataAttrOfa1 = a1[0]['attributes'],
                    _dataLength = _data.length,
                    _globalCaseIdsLength = parObject.caseIds.length;

                //Reorganize data into wanted format datum[ caseID ][ Attribute Name ] = Attribute Value
                //The original data structure is { attr_id: , attr_va: , sample}
                for(var i = 0; i < _dataLength; i++){
                    if(_data[i]["sample"] in _dataAttrMapArr){
                        _dataAttrMapArr[_data[i]["sample"]][_data[i]["attr_id"].toString().toUpperCase()] = _data[i]["attr_val"];
                    }
                    else{
                        _dataAttrMapArr[_data[i]["sample"]] = [];
                        _dataAttrMapArr[_data[i]["sample"]][_data[i]["attr_id"].toString().toUpperCase()] = _data[i]["attr_val"];
                    }
                }
                
                //Initial data array, not all of cases has MUTAION COUND OR COPY NUMBER ALTERATIONS.
                for(var j = 0; j <  _globalCaseIdsLength; j++){
                    var _caseDatum = {};
                    _caseDatum["CASE_ID"] = parObject.caseIds[j];
                    _caseDatum["MUTATION_COUNT"] = "NA";
                    _caseDatum["COPY_NUMBER_ALTERATIONS"] = "NA";
                    _keyNumMapping[parObject.caseIds[j]] = j;
                    $.each(_dataAttrOfa1,function(key,value){
                        value['attr_id'] = value['attr_id'].toUpperCase();
                        _dataAttrOfa1[key]['attr_id'] = value['attr_id'];
                        if(value['attr_id'] !== 'CASE_ID'){
                            _caseDatum[value['attr_id']] = "NA";
                        }
                    });
                    obtainDataObject['arr'].push(_caseDatum);
                }
                
                $.each(_dataAttrOfa1,function(key,value){
                    if(!value['display_name']){
                        value['display_name'] = value['attr_id'];
                    }
                    
                    value['display_name'] = toPascalCase(value['display_name']);
                });
                
{'fraction_non_alphanumeric': 0.11807255731137324, 'fraction_numerical': 0.003227242377030937, 'mean_word_length': 1.4929264909847435, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1791502', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2364, 'n_words': 435}