<commit_before>// ==UserScript==
// @name                Calculate Hours
// @include     https://your-jira-domain.com/issues/*
// @namespace   http://toomasr.com/
// @version             0.1
// @description Shows the total of hours in the footer
// @copyright   2014+, <NAME>
// @author    <NAME>
// ==/UserScript==
"use strict";

jQuery(document).ready(function() {
    // Perform initial calculation on page load.
    addEstimatesFooter();

    // Monitor .navigator-content for changes.
    // When #issuetable is rewritten, recalculate estimates footer.
    var oldTable = jQuery("#issuetable").get(0);
    jQuery(".navigator-content").bind('DOMSubtreeModified', function(e) {
        var newTable = jQuery("#issuetable").get(0);
        if (newTable !== oldTable) {
            oldTable = newTable;
            addEstimatesFooter();
        }
    });
});

function addEstimatesFooter() {
    // Clone last row and clean it from content
    var resultRow = jQuery("#issuetable .issuerow:last").clone();
    resultRow.find("td").html("");
    // Calculate sums for the estimate columns
    resultRow.find(".timeoriginalestimate").html(formatEstimate(sumMinutes(".timeoriginalestimate")));
    resultRow.find(".timeestimate").html(formatEstimate(sumMinutes(".timeestimate")));

    var footer = jQuery("<tfoot></tfoot>").append(resultRow);
    jQuery("#issuetable").append(footer);
}

function formatEstimate(minutes) {
    if (minutes < 60) {
        return minutes + " minutes";
    }

    var hours = minutes / 60;
    if (hours < 8) {
        return roundTo(hours, 1) + " hours";
    }

    var days = hours / 8;
    if (days < 5) {
        return roundTo(days, 1) + " days";
    }

    var weeks = days / 5;
    return roundTo(weeks, 1) + " weeks";
}

function roundTo(number, decimals) {
    var pow = Math.pow(10, decimals);
    return Math.round(number*pow) / pow;
}

function sumMinutes(field) {
    var minutes = 0;
    jQuery(field).each(function(key,val) {
        var time = jQuery(val).text();
        if (time) {
            minutes += parseToMinutes(time);
        }
    });<commit_msg>Showing the totals in hours - easier to compare to other estimates<commit_after>// ==UserScript==
// @name                Calculate Hours
// @include     https://your-jira-domain.com/issues/*
// @namespace   http://toomasr.com/
// @version             0.1
// @description Shows the total of hours in the footer
// @copyright   2014+, <NAME>
// @author    <NAME>
// ==/UserScript==
"use strict";

jQuery(document).ready(function() {
    // Perform initial calculation on page load.
    addEstimatesFooter();

    // Monitor .navigator-content for changes.
    // When #issuetable is rewritten, recalculate estimates footer.
    var oldTable = jQuery("#issuetable").get(0);
    jQuery(".navigator-content").bind('DOMSubtreeModified', function(e) {
        var newTable = jQuery("#issuetable").get(0);
        if (newTable !== oldTable) {
            oldTable = newTable;
            addEstimatesFooter();
        }
    });
});

function addEstimatesFooter() {
    // Clone last row and clean it from content
    var resultRow = jQuery("#issuetable .issuerow:last").clone();
    resultRow.find("td").html("");
    // Calculate sums for the estimate columns
    resultRow.find(".timeoriginalestimate").html(formatEstimate(sumMinutes(".timeoriginalestimate")));
    resultRow.find(".timeestimate").html(formatEstimate(sumMinutes(".timeestimate")));

    var footer = jQuery("<tfoot></tfoot>").append(resultRow);
    jQuery("#issuetable").append(footer);
}

function formatEstimate(minutes) {
    if (minutes < 60) {
        return minutes + " minutes";
    }

    var hours = minutes / 60;
    return roundTo(hours, 1) + " hours";
}

function roundTo(number, decimals) {
    var pow = Math.pow(10, decimals);
    return Math.round(number*pow) / pow;
}

function sumMinutes(field) {
    var minutes = 0;
    jQuery(field).each(function(key,val) {
        var time = jQuery(val).text();
        if (time) {
            minutes += parseToMinutes(time);
        }
    });
{'fraction_non_alphanumeric': 0.15322183964584357, 'fraction_numerical': 0.009345794392523364, 'mean_word_length': 2.8404154863078377, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '81862', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1207, 'n_words': 286}