<commit_before>var app = {
    planGroup: null,
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    renderData: function() {
        // this.responseText is the file content
        var plans = [];
        try {
            plans = JSON.parse(this.responseText);
        } catch(e) {
            console.log('DEBUG: Unable to parse the JSON file');
        }
        app.createUI(plans);
    },
    createUI: function(plans) {
        // using day of the week in current language
        navigator.globalization.getDateNames(function(dayOfWeek){
            navigator.globalization.getFirstDayOfWeek(function(firstDay){
                app.drawUI(plans, dayOfWeek, firstDay);
            });
        }, function() {}, {type: 'narrow', item: 'days'});
    },
    drawUI: function(plans, dayOfWeek, firstDay) {
        var deck = document.getElementById('plan-group');
        var tabbar = document.getElementById('plan-group-menu');
        // calculate the shift based on first day
        var dayShift = (1 - firstDay.value) % 7;
        
        // XXX: there is a possibility of race condition, a simple hack is 
        // to select the tab after a timeout.
        function selectTab(activeTab) {
            function selectActiveTab() {
                activeTab.select();
            }
            window.setTimeout(selectActiveTab, 100);
        }

        for (var i = 0; i < plans.length; i++) {
            var plan = plans[i];
            var numberOfDays = plan.week.length;
            // create plan table
            var table = document.createElement('table');
            // create table header
            var thead = document.createElement('thead');
            var th_empty = document.createElement('th');
            thead.appendChild(th_empty);
            for (var j = 0; j < numberOfDays; j++) {
                // add th only if week isn't empty
                if (plan.week[j].length > 0) {
                    var th = document.createElement('th');
                    th.appendChild(document.createTextNode(dayOfWeek.value[j + dayShift]));
                    thead.appendChild(th);
                }
            }
            table.appendChild(thead);
            // create table body
            //
            // transpone table (tables are created per hour instead
            // of per day as data is written)
            var daysInHours = [];
            // delete non existing days

            var cleanPlan = [];
            for (j = 0; j < numberOfDays; j++) {
                if (plan.week[j].length > 0) {
                    cleanPlan.push(plan.week[j]);
                }
            }
            for (j = 0; j < cleanPlan.length; j++) {
                for (var k = 0; k < cleanPlan[j].length; k++) {
                    if (!daysInHours[k]) {
                        daysInHours[k] = [];
                    }
                    daysInHours[k][j] = cleanPlan[j][k];
                }
            }
            var tbody = document.createElement('tbody');

            //create tab
            var tab = document.createElement('brick-tabbar-tab');
            tab.setAttribute('target', plan.id);
            tab.appendChild(document.createTextNode(plan.title));
            tabbar.appendChild(tab);

            // create card
            var card = document.createElement('brick-card');
            card.setAttribute('id', plan.id);
            deck.appendChild(card); 

            // Switching from one tab to another is done automatically
            // We just need to link it backwards - change tab if
            // card is changed without touching the tabbar elements
            card.tabElement = tab;
            card.addEventListener('show', function() {
                this.tabElement.select();
            });

            // create content of the card
            for (var j = 0; j < daysInHours.length; j++) {
                var tr = document.createElement('tr');
                var td = document.createElement('td');
                tr.appendChild(td);
                td.appendChild(document.createTextNode(j + 1));
                // we use cleanPlan.length here as we want all hours to
                // be rendered in all days
                for (var k = 0; k < cleanPlan.length; k++) {
                    var td = document.createElement('td');
                    if (daysInHours[j][k]) {
                        td.appendChild(document.createTextNode(daysInHours[j][k]));
                    }
                    tr.appendChild(td);
                }
                tbody.appendChild(tr);
            }
            table.appendChild(tbody);
            card.appendChild(table);
            
            // select the active tab
            if (plan.active) {
                selectTab(tab);<commit_msg>use table API use polling and select card instead of tab<commit_after>var app = {
    planGroup: null,
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    renderData: function() {
        // this.responseText is the file content
        var plans = [];
        try {
            plans = JSON.parse(this.responseText);
        } catch(e) {
            console.log('DEBUG: Unable to parse the JSON file');
        }
        app.createUI(plans);
    },
    createUI: function(plans) {
        // using day of the week in current language
        navigator.globalization.getDateNames(function(dayOfWeek){
            navigator.globalization.getFirstDayOfWeek(function(firstDay){
                app.drawUI(plans, dayOfWeek, firstDay);
            });
        }, function() {}, {type: 'narrow', item: 'days'});
    },
    drawUI: function(plans, dayOfWeek, firstDay) {
        var deck = document.getElementById('plan-group');
        var tabbar = document.getElementById('plan-group-menu');
        // calculate the shift based on first day
        var dayShift = (1 - firstDay.value) % 7;
        
        // there is a possibility of race condition, a simple hack is 
        // to use polling.
        function selectTab(activeTab) {
            function selectActiveTab() {
                if (!activeTab.targetElement) {
                    return window.setTimeout(selectActiveTab, 100);
                }
                deck.showCard(activeTab.targetElement);
            }
            selectActiveTab();
        }

        for (var i = 0; i < plans.length; i++) {
            var plan = plans[i];

            //create tab
            var tab = document.createElement('brick-tabbar-tab');
            tab.setAttribute('target', plan.id);
            tab.appendChild(document.createTextNode(plan.title));
            tabbar.appendChild(tab);

            // create card
            var card = document.createElement('brick-card');
            card.setAttribute('id', plan.id);
            deck.appendChild(card); 

            // create plan table
            var table = document.createElement('table');

            // transpone table (tables are created per hour instead
            // of per day as data is written)
            var numberOfDays = plan.week.length;
            var daysInHours = [];
            // delete non existing days

            var cleanPlan = [];
            for (j = 0; j < numberOfDays; j++) {
                if (plan.week[j].length > 0) {
                    cleanPlan.push(plan.week[j]);
                }
            }
            for (j = 0; j < cleanPlan.length; j++) {
                for (var k = 0; k < cleanPlan[j].length; k++) {
                    if (!daysInHours[k]) {
                        daysInHours[k] = [];
                    }
                    daysInHours[k][j] = cleanPlan[j][k];
                }
            }

            // Switching from one tab to another is done automatically
            // We just need to link it backwards - change tab if
            // card is changed without touching the tabbar elements
            card.tabElement = tab;
            card.addEventListener('show', function() {
                this.tabElement.select();
            });

            // create content of the card
            for (var j = 0; j < daysInHours.length; j++) {
                var tr = table.insertRow(-1);
                var td = tr.insertCell();
                td.appendChild(document.createTextNode(j + 1));
                // we use cleanPlan.length here as we want all hours to
                // be rendered in all days
                for (var k = 0; k < cleanPlan.length; k++) {
                    var td = tr.insertCell();
                    if (daysInHours[j][k]) {
                        td.appendChild(document.createTextNode(daysInHours[j][k]));
                    }
                }
            }
            // create table header
            var thead = table.createTHead();
            var tr = thead.insertRow();
            var th_empty = document.createElement('th');
            tr.appendChild(th_empty);
            for (var j = 0; j < numberOfDays; j++) {
                // add th only if week isn't empty
                if (plan.week[j].length > 0) {
                    var th = document.createElement('th');
                    th.appendChild(document.createTextNode(dayOfWeek.value[j + dayShift]));
                    tr.appendChild(th);
                }
            }
            card.appendChild(table);
            
            // select the active tab
            if (plan.active) {
                selectTab(tab);
{'fraction_non_alphanumeric': 0.11129397243365563, 'fraction_numerical': 0.0031886443118699856, 'mean_word_length': 1.451588502269289, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 7, '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': '68058', 'n_tokens_mistral': 2528, 'n_tokens_neox': 2398, 'n_words': 644}