Login
Artifact [435536e9ad]
Login

Artifact 435536e9ad4ce4949bffbca4920018a34cc758bf:


/**
   INCOMPLETE helper module for pending timeline/reporting bits.
*/
return requireS2(['fsl/db/repo'],
proc(db){
    const mod = {
        db: db,

        /*eventTypeMap:{
            '*': 'all',
            ci: 'checkins',
            w: 'wiki',
            g: 'tags',
            e: 'events',
            t: 'tickets'
        },*/

        /**
           Returns an array of years (integers) representing
           the years for which there is timeline activity in
           this repo. The entries are sorted ascending.
        */
        getActiveYears:proc(){
            return this.db.selectValues(<<<EOSQL
            SELECT DISTINCT CAST(strftime('%Y',mtime) AS INT) AS t
            FROM /*v_reports*/ event GROUP BY t ORDER BY t EOSQL);
        },

        /**
           Given a year in string or integer form, this function
           returns an array of integers holding the calendar week
           numbers (as determined by sqlite) of all "active" weeks
           during the give year. Returns an empty array if there is
           no timeline activity for that year.
         */
        getActiveWeeksForYear: proc(year){
            year || throw "Expecting a year (string|integer) value.";
            return this.db.selectValues(<<<EOSQL
                SELECT DISTINCT CAST(strftime('%W',mtime) AS INT) AS t
                FROM /*v_reports*/ event
                WHERE strftime('%Y',mtime)=?
                GROUP BY t ORDER BY t
                EOSQL,
                ''+year/*has to be a string for comparison to work*/);
        },

        /**
           Returns an array of objects, each with the properties
           (year, weeks), with year being the year (integer) for that
           entry and weeks being an array of the calendar weeks
           (integers, as determined by sqlite) which had activity
           during that year.
         */
        getActiveYearsAndWeeks: proc(){
            const rc = [], that = this;
            this.getActiveYears().eachIndex(proc(v){
                rc[] = {
                    year: v,
                    weeks: that.getActiveWeeksForYear(v)
                };
            });
            return rc;
        }
    };

    return mod;
});