<commit_before>function loadTimelines(userId, containerId, detailsContainer, detailDesc) {
    var url = '/api/v1/timelines/' + userId;

    $.getJSON(url, function(collections) {

        /* convert collections with basic shape explained here 
         * https://datatables.net/manual/data/ */
        var converted = _.map(collections, function(list) {
            return [
                moment(list.startTime).format("YYYY-MM-DD"),
                list.when,
                list.duration,
                list.visible,
                list.total,
                list.timelineId
            ];
        });

        $(containerId).DataTable( {
            data: converted,
            "createdRow": function ( row, data, index ) {
                $(row).click(function() {
                    renderTimeline(detailsContainer, detailDesc, data[5]);
                });
            } 
        });
    });
};

function fillmetablob(containerId, entry) {
    $('<pre>' + 
        JSON.stringify(entry, undefined, 2) + 
      '</pre>').appendTo(containerId);
};

function renderTimeline(containerId, detailDesc, timelineId) {
    var url = '/api/v1/metadata/' + timelineId;

    $(detailDesc).text("Showing content from " + url);
    $(containerId).empty();
    $.getJSON(url, function(collections) {
        _.each(collections, function(metaentry) {
            fillmetablob(containerId, metaentry);
        });
    });
};

/* ----------------------- */

function loadPromoted(userId, containerId) {
    var url = "/api/v1/personal/promoted/" + userId + '/0/10';
    console.log(url);

    /* When Owner MediaType PromotedLink */
    $.getJSON(url, function(collections) {
        /* convert collections with basic shape explained here 
         * https://datatables.net/manual/data/ */
        console.log(collections);
        var converted = _.map(collections, function(o) {
            return [ o.daysago, o.ownerName, o.promotedMedia, o.promotedPage ];
        });
        console.log(converted[0]);
        $(containerId).DataTable( {
            data: converted
        });
    });
};

/* This is temporarly not used, was called in the two-heatmap landing page */
function loadHeatmap(userId, recentC, olderC) {
    var url = "/api/v1/personal/heatmap/" + userId;

    /* you can ask for a time window from the API */
    var recentUrl = "/api/v1/personal/heatmap/" + userId + "/0/1";
    var olderUrl = "/api/v1/personal/heatmap/" + userId + "/2/20";

    var recent = new CalHeatMap();
    recent.init({
        itemSelector: recentC,
        data: recentUrl,
        legendColors: {
            min: "#efefef",
            max: "steelblue",
            empty: "white"
        },
        verticalOrientation: true,
        displayLegend: false,
        cellSize: 25,
        domainGutter: 2,
        label: { position: 'top' },
        range: 2,
        start: new Date(moment().subtract(1,'d')),
        domain: "day",
        subDomain: "hour"
    });

    var older = new CalHeatMap();
    older.init({
        itemSelector: olderC,
        data: olderUrl,
        start: new Date(moment().subtract(20, 'd')),
        range: 20,
        domain: "day",
        subDomain: "hour"
    });
};

function getSupporterId() {
    var chunks = document.location.pathname.split('/');
    // ["", "realitycheck", "100009030987674", "recent"]
    _.reverse(chunks);
    chunks.pop();
    chunks.pop();
    var userId = chunks.pop();
    console.log("Extracted from URL " + userId);
    return userId;
};

function loadCalmap(userId, containerId) {
    var url = "/api/v1/personal/heatmap/" + userId;

    /* you can ask for a time window from the API */
    var lastTen= "/api/v1/personal/heatmap/" + userId + "/0/10";

    console.log("loading last 10 days calendar heatmap " + lastTen);
    var calhtmp= new CalHeatMap();
    calhtmp.init({
        itemSelector: containerId,
        data: lastTen,
        cellSize: 20,
        start: new Date(moment().subtract(9, 'd')),
        range: 10,
        domain: "day",
        subDomain: "hour",
        legendColors: [ "yellow", "steelblue" ]
    });
    $(containerId).append('<p>This is the results from</p>');
    $(containerId).append('<pre>' + url + '</pre>');
};

function loadContribution(userId, containerId) {
    var url = "/api/v1/personal/contribution/" + userId + '/0/10';
    console.log("loading last 10 days of impressions contributed " + url);<commit_msg>if no data are available, nice message appear<commit_after>function loadTimelines(userId, containerId, detailsContainer, detailDesc) {
    var url = '/api/v1/timelines/' + userId;

    $.getJSON(url, function(collections) {

        /* convert collections with basic shape explained here 
         * https://datatables.net/manual/data/ */
        var converted = _.map(collections, function(list) {
            return [
                moment(list.startTime).format("YYYY-MM-DD"),
                list.when,
                list.duration,
                list.visible,
                list.total,
                list.timelineId
            ];
        });

        $(containerId).DataTable( {
            data: converted,
            "createdRow": function ( row, data, index ) {
                $(row).click(function() {
                    renderTimeline(detailsContainer, detailDesc, data[5]);
                });
            } 
        });
    });
};

function fillmetablob(containerId, entry) {
    $('<pre>' + 
        JSON.stringify(entry, undefined, 2) + 
      '</pre>').appendTo(containerId);
};

function renderTimeline(containerId, detailDesc, timelineId) {
    var url = '/api/v1/metadata/' + timelineId;

    $(detailDesc).text("Showing content from " + url);
    $(containerId).empty();
    $.getJSON(url, function(collections) {
        _.each(collections, function(metaentry) {
            fillmetablob(containerId, metaentry);
        });
    });
};

/* ----------------------- */

function loadPromoted(userId, containerId) {
    var url = "/api/v1/personal/promoted/" + userId + '/0/10';
    console.log(url);

    /* When Owner MediaType PromotedLink */
    $.getJSON(url, function(collections) {
        /* convert collections with basic shape explained here 
         * https://datatables.net/manual/data/ */
        console.log(collections);
        var converted = _.map(collections, function(o) {
            return [ o.daysago, o.ownerName, o.promotedMedia, o.promotedPage ];
        });
        console.log(converted[0]);
        $(containerId).DataTable( {
            data: converted
        });
    });
};

/* This is temporarly not used, was called in the two-heatmap landing page */
function loadHeatmap(userId, recentC, olderC) {
    var url = "/api/v1/personal/heatmap/" + userId;

    /* you can ask for a time window from the API */
    var recentUrl = "/api/v1/personal/heatmap/" + userId + "/0/1";
    var olderUrl = "/api/v1/personal/heatmap/" + userId + "/2/20";

    var recent = new CalHeatMap();
    recent.init({
        itemSelector: recentC,
        data: recentUrl,
        legendColors: {
            min: "#efefef",
            max: "steelblue",
            empty: "white"
        },
        verticalOrientation: true,
        displayLegend: false,
        cellSize: 25,
        domainGutter: 2,
        label: { position: 'top' },
        range: 2,
        start: new Date(moment().subtract(1,'d')),
        domain: "day",
        subDomain: "hour"
    });

    var older = new CalHeatMap();
    older.init({
        itemSelector: olderC,
        data: olderUrl,
        start: new Date(moment().subtract(20, 'd')),
        range: 20,
        domain: "day",
        subDomain: "hour"
    });
};

function getSupporterId() {
    var chunks = document.location.pathname.split('/');
    // ["", "realitycheck", "100009030987674", "recent"]
    _.reverse(chunks);
    chunks.pop();
    chunks.pop();
    var userId = chunks.pop();
    console.log("Extracted from URL " + userId);
    return userId;
};

function loadCalmap(userId, containerId) {

    /* you can ask for a time window from the API */
    var lastTen= "/api/v1/personal/heatmap/" + userId + "/0/10";
    console.log("loading last 10 days calendar heatmap " + lastTen);

    var calhtmp= new CalHeatMap();

    return $.getJSON(lastTen, function(content) {
        if(!_.size(content)) {
            var sorry = [ '<h3>',
                          '…Sorry! Seems you have not yet submitted data!',
                          '</h3>', '<p>',
                          'Is your key publication been done properly, in a public post, right? (can only post the key, and delete the post later)',
                          '</p>', '<p>',
                          'If some problem is going on, admin manually try to fix it, keep using the browser with the extension installed, and thank you for belonging to this collective experiment.',
                          '</p>' ];
            $(containerId).html(sorry.join(''));
            return;
        } 
        calhtmp.init({
            itemSelector: containerId,
            data: content,
            cellSize: 20,
            start: new Date(moment().subtract(9, 'd')),
            range: 10,
            domain: "day",
            subDomain: "hour",
            legendColors: [ "yellow", "steelblue" ]
        });
    });
};

function loadContribution(userId, containerId) {
    var url = "/api/v1/personal/contribution/" + userId + '/0/10';
    console.log("loading last 10 days of impressions contributed " + url);
{'fraction_non_alphanumeric': 0.1472043803306307, 'fraction_numerical': 0.012530272717700327, 'mean_word_length': 2.0530376084860174, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 4, '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': '3001459', 'n_tokens_mistral': 2849, 'n_tokens_neox': 2745, 'n_words': 663}