Skip to content

Instantly share code, notes, and snippets.

@lucasmrdt
Last active April 8, 2019 12:55
Show Gist options
  • Save lucasmrdt/32aa7ca2a61c051002d2f15f28feb022 to your computer and use it in GitHub Desktop.
Save lucasmrdt/32aa7ca2a61c051002d2f15f28feb022 to your computer and use it in GitHub Desktop.

Endpoint

https://intra.epitech.eu/user/[email protected]/netsoul/?format=json

Script

from Epitech Script

function proceed_time(json) {
    var time_tmp = 0;
    var time_tmp2 = 0;
    var time = new Array();
    var time_idle = new Array();
    var time_out = new Array();
    var time_out_idle = new Array();
    var time_total = new Array();
    var time_average = new Array();
    var time_week = new Array();
    var time_idle_week = new Array();
    var time_out_week = new Array();
    var time_out_idle_week = new Array();
    var time_total_week = new Array();
    var time_average_week = new Array();
    var i = 0;
    var j = -1;
    var lastkey = -1;
    for (var key in json) {
        if (lastkey != -1 && (interval = parseInt((json[key][0] - json[lastkey][0]) / (24 * 3600))) > 1)
            for (var k = 1; k < interval; i++,
            k++) {
                time_tmp2 = time_tmp + (k * 24 * 3600 * 1000);
                time[i] = [time_tmp2, 0];
                time_idle[i] = [time_tmp2, 0];
                time_out[i] = [time_tmp2, 0];
                time_out_idle[i] = [time_tmp2, 0];
                time_total[i] = [time_tmp2, 0];
                time_average[i] = [time_tmp2, 0];
                var date = new Date(time_tmp2);
                if (date.getDay() == 1) {
                    j++;
                    time_week[j] = [time_tmp2, 0];
                    time_idle_week[j] = [time_tmp2, 0];
                    time_out_week[j] = [time_tmp2, 0];
                    time_out_idle_week[j] = [time_tmp2, 0];
                    time_total_week[j] = [time_tmp2, 0];
                    time_average_week[j] = [time_tmp2, 0]
                }
            }
        if (json[key][1] != -1) {
            time_tmp = ((json[key][0] + 7200) * 1000);
            time[i] = [time_tmp, (json[key][1] / 60 / 60)];
            time_idle[i] = [time_tmp, (json[key][2] / 60 / 60)];
            time_out[i] = [time_tmp, (json[key][3] / 60 / 60)];
            time_out_idle[i] = [time_tmp, (json[key][4] / 60 / 60)];
            time_total[i] = [time_tmp, (time[i][1] + time_idle[i][1] + time_out[i][1] + time_out_idle[i][1])];
            time_average[i] = [time_tmp, json[key][5] / 60 / 60];
            lastkey = key;
            var date = new Date(time_tmp);
            if (date.getDay() == 1) {
                j++;
                time_week[j] = [time_tmp, time[i][1]];
                time_idle_week[j] = [time_tmp, time_idle[i][1]];
                time_out_week[j] = [time_tmp, time_out[i][1]];
                time_out_idle_week[j] = [time_tmp, time_out_idle[i][1]];
                time_total_week[j] = [time_tmp, time_total[i][1]];
                time_average_week[j] = [time_tmp, time_average[i][1]]
            } else if (j != -1) {
                time_week[j][1] += time[i][1];
                time_idle_week[j][1] += time_idle[i][1];
                time_out_week[j][1] += time_out[i][1];
                time_out_idle_week[j][1] += time_out_idle[i][1];
                time_total_week[j][1] += time_total[i][1];
                time_average_week[j][1] += time_average[i][1]
            }
            i++
        } else
            lastkey = -1
        debugger;
    }
    ;return ({
        'time': time,
        'idle': time_idle,
        'out': time_out,
        'idle_out': time_out_idle,
        'total': time_total,
        'average': time_average,
        'time_week': time_week,
        'time_idle_week': time_idle_week,
        'time_out_week': time_out_week,
        'time_idle_out_week': time_out_idle_week,
        'total_week': time_total_week,
        'average_week': time_average_week
    })
}

Documentation

{
    "user_timelog": "{total}",
    "average_timelog": "{average}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment