<commit_before>const biomPromise = require('../details/biom');
const _ = require('lodash');
const $ = require('jquery');
const addTraitToProject = require('../helpers/addTraitToProject');

$('document').ready(async () => {
    let biom = await biomPromise;
    let projectData = $('#project-data');
    let internalProjectId = projectData.data('internal-project-id');
    let traitFormat = projectData.data('trait-format');
    let traitValues = projectData.data('trait-values');
    let traitName = projectData.data('trait-name');
    let traitCitations = projectData.data('trait-citations');
    let dimension = projectData.data('dimension');
    let dbversion = $('#globals').data('dbversion');
    let attribute = projectData.data('attribute');

    $('#add-trait-to-project-button').on('click', function () {
        addTraitToProject(traitName, traitValues, traitCitations, biom, dimension, dbversion, internalProjectId, () => showMessageDialog('Successfully added ' + traitName + ' to metadata.', 'success'));
    });

    let projectUrl = Routing.generate('project_details', {'dbversion': dbversion, 'project_id': internalProjectId, 'attribute': attribute})+"#traits";
    let pageTitle = $('#page-title');
    pageTitle.html(
        `<a href="${projectUrl}"><i class="fa fa-arrow-circle-left" style="padding-right: 10px"></i></a>`+pageTitle.html()
    );

    if(traitFormat === 'categorical_free'){
        traitValues = condenseCategoricalTraitValues(traitValues);
        let counts = _.countBy(traitValues);
        counts['NA'] = biom.shape[0] - _.sum(Object.values(counts));<commit_msg>Fix proportion in pie chart (absence/presence)<commit_after>const biomPromise = require('../details/biom');
const _ = require('lodash');
const $ = require('jquery');
const addTraitToProject = require('../helpers/addTraitToProject');

$('document').ready(async () => {
    let biom = await biomPromise;
    let projectData = $('#project-data');
    let internalProjectId = projectData.data('internal-project-id');
    let traitFormat = projectData.data('trait-format');
    let traitValues = projectData.data('trait-values');
    let traitName = projectData.data('trait-name');
    let traitCitations = projectData.data('trait-citations');
    let dimension = projectData.data('dimension');
    let dbversion = $('#globals').data('dbversion');
    let attribute = projectData.data('attribute');

    $('#add-trait-to-project-button').on('click', function () {
        addTraitToProject(traitName, traitValues, traitCitations, biom, dimension, dbversion, internalProjectId, () => showMessageDialog('Successfully added ' + traitName + ' to metadata.', 'success'));
    });

    let projectUrl = Routing.generate('project_details', {'dbversion': dbversion, 'project_id': internalProjectId, 'attribute': attribute})+"#traits";
    let pageTitle = $('#page-title');
    pageTitle.html(
        `<a href="${projectUrl}"><i class="fa fa-arrow-circle-left" style="padding-right: 10px"></i></a>`+pageTitle.html()
    );

    let fennecIDs = biom.getMetadata({dimension: dimension, attribute: ['fennec', dbversion, 'fennec_id']});
    if(traitFormat === 'categorical_free'){
        traitValues = condenseCategoricalTraitValues(traitValues);
        let traitForID = fennecIDs.map(x => traitValues[x] || 'NA');
        let counts = _.countBy(traitForID);
        counts['NA'] = biom.shape[0] - _.sum(Object.values(counts));
{'fraction_non_alphanumeric': 0.17281780902167546, 'fraction_numerical': 0.0017574692442882249, 'mean_word_length': 4.749158249158249, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '1692325', 'n_tokens_mistral': 1005, 'n_tokens_neox': 995, 'n_words': 189}