<commit_before>import { Component } from "@angular/core";
import { TimelineSettings } from "../_common/timelineSettings.ts";
import {FormsModule, NgForm} from "@angular/forms";
import "vis/dist/vis.css";
var vis = require("vis/dist/vis.js");
@Component({
    selector: 'timeline-comp',
    templateUrl: 'timeline.template.html',
    styleUrls: ["./timeline.style.scss".toString()]
})

export class TimelineComponent {

    model = new TimelineSettings('Kruk07', "2016-12-12", "2016-12-13");
    submitted = false;

    constructor() {

    }

    onSubmit() {
        this.submitted = true;
    }

    getTimeline(timelineForm: NgForm) {
        var xhttp = new XMLHttpRequest();

        //TODO: add date to params when server ready
        var params = JSON.stringify({
            login: timelineForm.value.login
        });

        xhttp.open("POST", "/userinfo", true);
        xhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
        xhttp.onreadystatechange = function(){
            if (this.readyState == 4 && this.status == 200) {
                var jsonResponse = JSON.parse(xhttp.responseText);
                var container = document.getElementById('visualization');
                var options = new Array();
                var data = new Array();

                var lastDate = '';
                var lastDate2 = '';
                var j = 0;
                var reverseDate = '';

                for(var i=0; i<jsonResponse.length; i++) {
                    /*If new day, then create new pair of options and data*/
                    if(jsonResponse[i].begin.split("@")[0] != reverseDate) {

                        /*13/12/2016 to 2016-12-13*/
                        reverseDate = jsonResponse[i].begin.split("@")[0];
                        lastDate = reverseDate.split("/")[2] + "-" + reverseDate.split("/")[1] + "-" + reverseDate.split("/")[0];

                        options.push({min: lastDate + ' 00:01', max: lastDate + ' 23:59'});
                        data.push(new vis.DataSet(options[j]));
                        j = j+1;
                    }
                    /*If end of work has a different date than start of work, split it into days*/
                    //Works only when less than 3 days length
                    if(jsonResponse[i].end.split("@")[0] != reverseDate) {

                        reverseDate = jsonResponse[i].end.split("@")[0];
                        lastDate2 = reverseDate.split("/")[2] + "-" + reverseDate.split("/")[1] + "-" + reverseDate.split("/")[0];
                        data[j-1].add([{id: i, content: ' ', start: lastDate + ' ' + jsonResponse[i].begin.split("@")[1], end: lastDate + '23:59'}]);

                        options.push({min: lastDate2 + ' 00:01', max: lastDate2 + ' 23:59'});
                        j = j+1;
                        data[j-1].add([{id: i, content: ' ', start: lastDate2 + ' 00:00', end: lastDate2 + ' ' + jsonResponse[i].end.split("@")[1]}]);

                    } else {
                        data[j-1].add([{id: i, content: ' ', start: lastDate + ' ' + jsonResponse[i].begin.split("@")[1], end: lastDate + ' ' + jsonResponse[i].end.split("@")[1]}]);
                    }

                }
                for(var k = 0; k < j; k++) {
                    var timeline = new vis.Timeline(container, data[k], options[k]);
                }

                //For testing
                //document.getElementById("serverAnswer").innerHTML = xhttp.responseText.toString();
            }
        };
        xhttp.send(params);
    }
}<commit_msg>Rewritten timeline (7 days splitting)<commit_after>import { Component } from "@angular/core";
import { TimelineSettings } from "../_common/timelineSettings.ts";
import {FormsModule, NgForm} from "@angular/forms";
import "vis/dist/vis.css";
var vis = require("vis/dist/vis.js");
@Component({
    selector: 'timeline-comp',
    templateUrl: 'timeline.template.html',
    styleUrls: ["./timeline.style.scss".toString()]
})

export class TimelineComponent {

    model = new TimelineSettings('Kruk07', "2016-12-12", "2016-12-13");
    submitted = false;

    constructor() {

    }

    onSubmit() {
        this.submitted = true;
    }

    getTimeline(timelineForm: NgForm) {
        var xhttp = new XMLHttpRequest();

        var fromDateStr = timelineForm.value.fromDate.split("-")[2] + "/" +
        timelineForm.value.fromDate.split("-")[1] + "/" +
        timelineForm.value.fromDate.split("-")[0] + "@00:00";

        var toDateStr = timelineForm.value.toDate.split("-")[2] + "/" +
            timelineForm.value.toDate.split("-")[1] + "/" +
            timelineForm.value.toDate.split("-")[0] + "@23:59";

        var params = JSON.stringify({
            login: timelineForm.value.login,
            begin: fromDateStr,
            end: toDateStr
        });


        xhttp.open("POST", "/userinfo", true);
        xhttp.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
        xhttp.onreadystatechange = function(){
            if (this.readyState == 4 && this.status == 200) {

                var jsonResponse = JSON.parse(xhttp.responseText);
                var container = document.getElementById('visualization');
                var options = new Array();
                var data = new Array();


                //GATE FOR USER CHOICE IN DISPLAYING
                var maxDaysInRow = 7;

                //start-end date for a one row
                var dateStart = new Date();;
                var dateEnd = new Date();;

                //How many rows prepared already
                var j = 0;

                //for changing 13/12/2016 to 2016-12-13
                var reverseDate = '';

                var timeDiff = 0;
                var diffDays = 0;

                var actualCheckingDateBegin = new Date();
                var actualCheckingDateEnd = new Date();

                //for cutting data when exceeds dateEnd
                var actualCheckingDateTmp = new Date();
                var howManyDaysToCut = 0;

                /*need to create first dateStart and dateEnd*/
                reverseDate = jsonResponse[0].begin.split("@")[0];
                if(jsonResponse.length >= 1) {

                    dateStart = new Date(reverseDate.split("/")[2] + '-'
                        + reverseDate.split("/")[1] + '-'
                        + reverseDate.split("/")[0]);
                    dateEnd = new Date();
                    dateEnd.setDate(dateStart.getDate() + (maxDaysInRow-1));
                    options.push({min: dateStart.toDateString() + ' 00:00', max: dateEnd.toDateString() + ' 23:59'});
                    data.push(new vis.DataSet(options[j]));
                    j = j+1;
                }
                /*for every received "work signal" */
                for(var i=0; i<jsonResponse.length; i++) {

                    reverseDate = jsonResponse[i].begin.split("@")[0];
                    actualCheckingDateBegin = new Date(reverseDate.split("/")[2] + '-'
                        + reverseDate.split("/")[1] + '-'
                        + reverseDate.split("/")[0]);
                    reverseDate = jsonResponse[i].end.split("@")[0];
                    actualCheckingDateEnd = new Date(reverseDate.split("/")[2] + '-'
                        + reverseDate.split("/")[1] + '-'
                        + reverseDate.split("/")[0]);

                    timeDiff = Math.abs(actualCheckingDateBegin.getTime() - dateStart.getTime());
                    diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

                    /*if start of received "work signal" has a date that exceeds max days in one row - create new row*/
                    if(diffDays >= maxDaysInRow) {

                        reverseDate = jsonResponse[i].begin.split("@")[0];
                        dateStart = new Date(reverseDate.split("/")[2] + '-'
                            + reverseDate.split("/")[1] + '-'
                            + reverseDate.split("/")[0]);
                        dateEnd = new Date();
                        dateEnd.setDate(dateStart.getDate() + maxDaysInRow-1);
                        options.push({min: dateStart.toDateString() + ' 00:00', max: dateEnd.toDateString() + ' 23:59'});
                        data.push(new vis.DataSet(options[j]));
                        j = j+1;

                    } else {

                        timeDiff = Math.abs(actualCheckingDateEnd.getTime() - dateStart.getTime());
                        diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

                        /*if start of received "work signal" has a date that exceeds max days in one row - split it into 2 rows*/
                        if(diffDays >= maxDaysInRow) {

                            actualCheckingDateTmp = new Date(actualCheckingDateEnd.getMonth(),
                                actualCheckingDateEnd.getDay(),
                                actualCheckingDateEnd.getFullYear());

                            /*count how many days cant fit into actual row*/
                            while(diffDays >= maxDaysInRow) {
                                howManyDaysToCut += 1;
                                actualCheckingDateTmp = new Date(   actualCheckingDateEnd.getMonth(),
                                    (actualCheckingDateEnd.getDay() - howManyDaysToCut),
                                    actualCheckingDateEnd.getFullYear());

                                timeDiff = Math.abs(actualCheckingDateTmp.getTime() - dateStart.getTime());
                                diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
                            }
                            howManyDaysToCut = 0;

                            dateEnd = new Date(dateStart.getMonth(), dateStart.getDay()+6, dateStart.getFullYear());
                            options.push({min: actualCheckingDateBegin.toDateString() + ' 00:00',
                                max: actualCheckingDateTmp.toDateString() + ' 23:59'});
                            j = j+1;
                            data[j-1].add([{id: i, content: ' ',
                                start: actualCheckingDateBegin.toDateString() + ' ' + jsonResponse[i].begin.split("@")[1],
                                end: actualCheckingDateTmp.toDateString() + ' 23:59'}]);

                            options.push({min: actualCheckingDateTmp.toDateString() + ' 00:00',
                                max: actualCheckingDateEnd.toDateString() + ' 23:59'});
                            j = j+1;
                            data[j-1].add([{id: i, content: ' ',
                                start: actualCheckingDateTmp.toDateString() + ' 00:01',
                                end: actualCheckingDateEnd.toDateString() + ' ' + jsonResponse[i].end.split("@")[1]}]);

                            dateStart = new Date(actualCheckingDateTmp.getMonth(),
                                actualCheckingDateTmp.getDay(),
                                actualCheckingDateTmp.getFullYear());

                        } else {

                            data[j-1].add([{id: i, content: ' ',
                                start: actualCheckingDateBegin.toDateString() + ' ' + jsonResponse[i].begin.split("@")[1],
                                end: actualCheckingDateEnd.toDateString() + ' ' + jsonResponse[i].end.split("@")[1]}]);
                        }
                    }

                }
                /*display created rows*/
                for(var k = 0; k < j; k++) {
                    var timeline = new vis.Timeline(container, data[k], options[k]);
                }

            }

        };
        xhttp.send(params);
    }
}
{'fraction_non_alphanumeric': 0.14110324835876886, 'fraction_numerical': 0.02199676016710717, 'mean_word_length': 1.4888605983450032, 'pattern_counts': {'":': 0, '<': 7, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6350726', 'n_tokens_mistral': 3434, 'n_tokens_neox': 3090, 'n_words': 619}