<commit_before>//require("moment");
var moment = require('moment-timezone');
var https = require('https');

ROOMS = {
  'Kaffeeklatsch': '<EMAIL>',
  'Gretchenfrage': '<EMAIL>',
  'Zeitgeist': '<EMAIL>',
}
// display in local time, which is:
var TARGET_TZ = "Europe/Berlin";

function makeURL(addr) {
    return 'https://mail.mozilla.com/home/'+addr+'?view=day&fmt=ifb&start=0d&end=24h';
}

exports.ROOMSTATUS = {};
exports.whatsFree = give_me_a_room;

function get_busy_times(vcal_s) {
    /* accepts vcalfreebusystring, returns start/end tuple */
    var events = [];
    for (var j=0; j < vcal_s.split("\r\n").length; j++) {
        var line = vcal_s.split("\r\n")[j];
        if (line == "") continue
        var kv = line.split(":");
        var key = kv[0];
        var value = kv[1];
        if (key == "FREEBUSY;FBTYPE=BUSY") {
          var start,end;
          var mt = value.split("/");
          start = mt[0];
          end = mt[1];
          // parse as given (UTC)
          start = moment.tz(start, "YYYYMMDDTHHmmssZ", "UTC")
          end = moment.tz(end, "YYYYMMDDTHHmmssZ", "UTC")
          // convert to local (e.g. europe/berlin)
          events.push([start.tz(TARGET_TZ), end.tz(TARGET_TZ)])
        }
    }
    return events;
}


function get_room_status(addr, name) {
    var now = moment.tz(TARGET_TZ);
    https.get(makeURL(addr), function(res) {
        var data = '';
    res.on('data', function(bits) {
        data += bits;
    }).on('end', function() {
        var events = get_busy_times(data);
        var next_meeting = undefined;
        var currently_busy = false;        
        for (var i=0; i< events.length; i++) {
            var start = events[i][0];
            var end = events[i][1];
            if (now.diff(end) < 0) {
                // meeting hasn't ended yet
                if (now.diff(start) > 0) {
                    // this meeting is running
                    currently_busy = true;
                }
                else {
                    // this meeting is in the future,
                    // but does it start earlier than the one we already know?
                    if (next_meeting) {
                        if (now.diff(start) < now.diff(next_meeting[0])) {
                            next_meeting = [start, end];
                        }
                    }
                    else {
                        next_meeting = [start, end];
                    }
                }
            }
            else {
                // this meeting has already ended
            }            
        }
        exports.ROOMSTATUS[name] = [currently_busy, next_meeting];
    });
    }).on('error', function(e) {<commit_msg>changed logic for comparing. requesting previous status for existing meetings<commit_after>//require("moment");
var moment = require('moment-timezone');
var https = require('https');

ROOMS = {
  'Kaffeeklatsch': '<EMAIL>',
  'Gretchenfrage': '<EMAIL>',
  'Zeitgeist': '<EMAIL>',
}
// display in local time, which is:
var TARGET_TZ = "Europe/Berlin";

function makeURL(addr) {
    return 'https://mail.mozilla.com/home/'+addr+'?view=day&fmt=ifb&start=-1h&end=24h';
}

exports.ROOMSTATUS = {};
exports.whatsFree = give_me_a_room;

function get_busy_times(vcal_s) {
    /* accepts vcalfreebusystring, returns start/end tuple */
    var events = [];
    for (var j=0; j < vcal_s.split("\r\n").length; j++) {
        var line = vcal_s.split("\r\n")[j];
        if (line == "") continue
        var kv = line.split(":");
        var key = kv[0];
        var value = kv[1];
        if (key == "FREEBUSY;FBTYPE=BUSY") {
          var start,end;
          var mt = value.split("/");
          start = mt[0];
          end = mt[1];
          // parse as given (UTC)
          start = moment.tz(start, "YYYYMMDDTHHmmssZ", "UTC");
          end = moment.tz(end, "YYYYMMDDTHHmmssZ", "UTC");
          // convert to local (e.g. europe/berlin)
          events.push([start.tz(TARGET_TZ), end.tz(TARGET_TZ)]);
        }
    }
    return events;
}


function get_room_status(addr, name) {
    var now = moment.tz(TARGET_TZ);
    https.get(makeURL(addr), function(res) {
        var data = '';
    res.on('data', function(bits) {
        data += bits;
    }).on('end', function() {
        var events = get_busy_times(data);
        var next_meeting = undefined;
        var currently_busy = false;        
        for (var i=0; i< events.length; i++) {
            var start = events[i][0];
            var end = events[i][1];
            if (end.diff(now) > 0) {
                // meeting hasn't ended yet
                if (start.diff(now) < 0) {
                    // this meeting is running
                    currently_busy = true;
                }
                else {
                    // this meeting is in the future,
                    // but does it start earlier than the one we already know?
                    if (next_meeting) {
                        if (start.diff(now) > next_meeting[0].diff(now)) {
                            next_meeting = [start, end];
                        }
                    }
                    else {
                        next_meeting = [start, end];
                    }
                }
            }
            else {
                // this meeting has already ended
            }            
        }
        exports.ROOMSTATUS[name] = [currently_busy, next_meeting];
    });
    }).on('error', function(e) {
{'fraction_non_alphanumeric': 0.1429879165140974, 'fraction_numerical': 0.005126327352618088, 'mean_word_length': 1.6014285714285714, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 12, 'https://': 2, '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': '5123422', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1670, 'n_words': 383}