<commit_before>'use strict';

var util = require('util');
var EventEmitter = require('events').EventEmitter;
var http = require('http');
var moment = require('moment');

var schedule = {};

function LibrarySchedule() {
    EventEmitter.call(this);
}
util.inherits(LibrarySchedule, EventEmitter);

LibrarySchedule.prototype.update = function (options) {
    var self = this;
    options = options || {};
    var logger = options.logger || util.log;

    var httpOptions = {
        host: 'api.libcal.com',
        path: '/api_hours_grid.php?iid=138&format=json&weeks=2'
    };

    var data = '';

    http.get(httpOptions, function (resp) {
        if (resp.statusCode !== 200) {
            var errorMsg = 'updateScheduleAsync error: code ' + resp.statusCode;
            logger(errorMsg);
        }
        resp.on('data', function (chunk) {
            data += chunk;
        });
        resp.on('end', function () {
            function extractHours(weeks) {
                var now = moment(),
                    rv = [],
                    day,
                    myDay,
                    date,
                    text;
                for (var i = 0; i < 7; i++) {
                    day = now.format('dddd');
                    date = now.format('YYYY-MM-DD');
                    text = '';
                    for (var j = 0, l = weeks.length; j < l; j++) {
                        if (weeks[j][day] && weeks[j][day].date === date) {
                            myDay = weeks[j][day];
                            if (myDay.times && myDay.times.status === '24hours') {
                                text = '24 hours';
                            } else if (myDay.times && myDay.times.status === 'closed') {
                                text = 'closed';
                            } else if (myDay.times && myDay.times.hours && myDay.times.hours[0] && myDay.times.hours[0].from && myDay.times.hours[0].to) {
                                text = myDay.times.hours[0].from + ' - ' + myDay.times.hours[0].to;
                            }
                            break;
                        }
                    }
                    rv.push({
                        day: now.format('ddd'),
                        date: now.format('MMM DD'),
                        text: text
                    });
                    now.add(1, 'days');
                }
                return (rv);
            }

            if (resp.statusCode === 200) {
                var result;
                try {<commit_msg>refactor, increase test coverage<commit_after>'use strict';

var util = require('util');
var EventEmitter = require('events').EventEmitter;
var http = require('http');
var moment = require('moment');

var schedule = {};

function LibrarySchedule() {
    EventEmitter.call(this);
}
util.inherits(LibrarySchedule, EventEmitter);

LibrarySchedule.prototype.update = function (options) {
    var self = this;
    options = options || {};
    var logger = options.logger || util.log;

    var httpOptions = {
        host: 'api.libcal.com',
        path: '/api_hours_grid.php?iid=138&format=json&weeks=2'
    };

    var data = '';

    http.get(httpOptions, function (resp) {
        if (resp.statusCode !== 200) {
            var errorMsg = 'updateScheduleAsync error: code ' + resp.statusCode;
            logger(errorMsg);
        }
        resp.on('data', function (chunk) {
            data += chunk;
        });
        resp.on('end', function () {
            function extractHours(weeks) {
                var now = moment(),
                    rv = [],
                    day,
                    myDay,
                    date,
                    text;

                var retrieveTextCallback = function (value) {
                    myDay = value[day];
                    if (myDay.date === date) {
                        if (myDay.times && myDay.times.status === '24hours') {
                            text = '24 hours';
                        } else if (myDay.times && myDay.times.status === 'closed') {
                            text = 'closed';
                        } else if (myDay.times && myDay.times.hours && myDay.times.hours[0] && myDay.times.hours[0].from && myDay.times.hours[0].to) {
                            text = myDay.times.hours[0].from + ' - ' + myDay.times.hours[0].to;
                        }
                    }
                };
                
                for (var i = 0; i < 7; i++) {
                    day = now.format('dddd');
                    date = now.format('YYYY-MM-DD');
                    text = '';
                    weeks.forEach(retrieveTextCallback);
                    rv.push({
                        day: now.format('ddd'),
                        date: now.format('MMM DD'),
                        text: text
                    });
                    now.add(1, 'days');
                }
                return (rv);
            }

            if (resp.statusCode === 200) {
                var result;
                try {
{'fraction_non_alphanumeric': 0.1335575781559161, 'fraction_numerical': 0.00890383854372774, 'mean_word_length': 1.183585313174946, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '7453859', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1296, 'n_words': 279}