<commit_before>var LOADING_LOG_CLEAN_DELAY = 2000;
var LOADING_LOG = {
	getTypeMark: function(type) {
		if (type == 'success') {
			return '<i class = "fa fa-check-circle"></i>';
		} else if (type == 'error') {
			return '<i class = "fa fa-times-circle"></i>';
		} else {
			return '<i class = "fa fa-info-circle"></i>';
		}
	},
	getTypeClass: function(type) {
		if (type == 'success' || type == 'error') {
			return type;
		} else {
			return '';
		}
	},
	addMessage: function(message, type) {
		type = type || 'info';

		var loading_log = $('.loading-log');
		loading_log.show();
		loading_log.prepend(
			'<p '
				+ 'class = "'
					+ 'content-padded '
					+ LOADING_LOG.getTypeClass(type)
				+ '">'
				+ LOADING_LOG.getTypeMark(type) + ' '
				+ message
			+ '</p>'
		);
	},
	finish: function(callback, message, type) {
		callback = callback || function() {};
		message = message || 'All done.'
		type = type || 'success';

		LOADING_LOG.addMessage(message, type);

		setTimeout(
			function() {
				LOADING_LOG.clean();
				callback();
			},
			LOADING_LOG_CLEAN_DELAY
		);
	},
	clean: function() {
		var loading_log = $('.loading-log');
		loading_log.empty();
		loading_log.hide();
	}
};

var HOURS_VIEW_PRECISION = 2;
function ProcessHours() {
	var current_date = new Date();
	var work_calendar = JSON.parse(activity.getSetting('work_calendar'));
	var month_date = work_calendar[current_date.getMonth()];
	var worked_hours = JSON.parse(activity.getSetting('worked_hours'));

	var expected_hours = 0;
	var month_worked_hours = 0;
	for (var day = 1; day <= current_date.getDate(); day++) {
		var day_type = month_date[day - 1];
		if (day_type == 'ordinary') {
			expected_hours += 8;
		} else if (day_type == 'short') {
			expected_hours += 7;
		}

		var day_worked_hours = worked_hours[day.toString()];
		if (typeof day_worked_hours !== 'undefined') {
			month_worked_hours += day_worked_hours;
		}
	}

	var hours_data = {
		month: moment().format('MMMM'),
		expected_hours: expected_hours,
		month_worked_hours: month_worked_hours,
		difference: expected_hours - month_worked_hours
	};
	activity.setSetting('hours_data', JSON.stringify(hours_data));

	ShowHours(hours_data);
	activity.updateWidget();
}
function ShowHours(hours_data) {
	$('#hours-segment .month-view').text(hours_data.month);

	var hours_view = $('#hours-segment .hours-view');
	$('.expected-hours-view', hours_view).text(
		hours_data.expected_hours
	);
	$('.hours-worked-view', hours_view).text(
		hours_data.month_worked_hours.toFixed(HOURS_VIEW_PRECISION)
	);

	var difference_view = $('.difference-view', hours_view);
	difference_view.text(
		hours_data.difference.toFixed(HOURS_VIEW_PRECISION)
	);
	if (hours_data.difference < 0) {
		difference_view.removeClass('lack').addClass('excess');
	} else {
		difference_view.removeClass('excess').addClass('lack');
	}
}

function RequestToHarvest(request_name, path) {
	var harvest_subdomain = activity.getSetting('harvest_subdomain');
	var url = 'https://' + harvest_subdomain + '.harvestapp.com' + path;

	var harvest_username = activity.getSetting('harvest_username');
	var harvest_password = activity.getSetting('harvest_password');
	var headers = {
		'Content-Type': 'application/json',
		Accept: 'application/json',
		Authorization:
			'Basic '
			+ Base64.encode(harvest_username + ':' + harvest_password)
	};

	activity.httpRequest(request_name, url, JSON.stringify(headers));<commit_msg>Fixes #83: working off calculation.<commit_after>var LOADING_LOG_CLEAN_DELAY = 2000;
var LOADING_LOG = {
	getTypeMark: function(type) {
		if (type == 'success') {
			return '<i class = "fa fa-check-circle"></i>';
		} else if (type == 'error') {
			return '<i class = "fa fa-times-circle"></i>';
		} else {
			return '<i class = "fa fa-info-circle"></i>';
		}
	},
	getTypeClass: function(type) {
		if (type == 'success' || type == 'error') {
			return type;
		} else {
			return '';
		}
	},
	addMessage: function(message, type) {
		type = type || 'info';

		var loading_log = $('.loading-log');
		loading_log.show();
		loading_log.prepend(
			'<p '
				+ 'class = "'
					+ 'content-padded '
					+ LOADING_LOG.getTypeClass(type)
				+ '">'
				+ LOADING_LOG.getTypeMark(type) + ' '
				+ message
			+ '</p>'
		);
	},
	finish: function(callback, message, type) {
		callback = callback || function() {};
		message = message || 'All done.'
		type = type || 'success';

		LOADING_LOG.addMessage(message, type);

		setTimeout(
			function() {
				LOADING_LOG.clean();
				callback();
			},
			LOADING_LOG_CLEAN_DELAY
		);
	},
	clean: function() {
		var loading_log = $('.loading-log');
		loading_log.empty();
		loading_log.hide();
	}
};

var HOURS_VIEW_PRECISION = 2;
function ProcessHours() {
	var MAXIMAL_DAY = 31;

	var current_date = new Date();
	var work_calendar = JSON.parse(activity.getSetting('work_calendar'));
	var month_data = work_calendar[current_date.getMonth()];
	var worked_hours = JSON.parse(activity.getSetting('worked_hours'));

	var expected_hours = 0;
	var month_worked_hours = 0;
	var month_rest_days = 0;
	for (var day = 1; day <= MAXIMAL_DAY; day++) {
		var day_type = month_data[day - 1];
		if (typeof day_type !== 'undefined') {
			if (day <= current_date.getDate()) {
				if (day_type === 'ordinary') {
					expected_hours += 8;
				} else if (day_type === 'short') {
					expected_hours += 7;
				}
			} else {
				if (day_type === 'ordinary' || day_type === 'short') {
					month_rest_days++;
				}
			}
		}

		var day_worked_hours = worked_hours[day.toString()];
		if (typeof day_worked_hours !== 'undefined') {
			month_worked_hours += day_worked_hours;
		}
	}

	var difference = expected_hours - month_worked_hours;
	var hours_data = {
		month: moment().format('MMMM'),
		expected_hours: expected_hours,
		month_worked_hours: month_worked_hours,
		difference: difference,
		working_off: difference / month_rest_days
	};
	activity.setSetting('hours_data', JSON.stringify(hours_data));

	ShowHours(hours_data);
	activity.updateWidget();
}
function ShowHours(hours_data) {
	$('#hours-segment .month-view').text(hours_data.month);

	var hours_view = $('#hours-segment .hours-view');
	$('.expected-hours-view', hours_view).text(
		hours_data.expected_hours
	);
	$('.hours-worked-view', hours_view).text(
		hours_data.month_worked_hours.toFixed(HOURS_VIEW_PRECISION)
	);

	var difference_view = $('.difference-view', hours_view);
	difference_view.text(
		hours_data.difference.toFixed(HOURS_VIEW_PRECISION)
	);
	if (hours_data.difference < 0) {
		difference_view.removeClass('lack').addClass('excess');
	} else {
		difference_view.removeClass('excess').addClass('lack');
	}

	var working_off_view = $('.working-off-view', hours_view);
	working_off_view.text(
		hours_data.working_off.toFixed(HOURS_VIEW_PRECISION)
	);
}

function RequestToHarvest(request_name, path) {
	var harvest_subdomain = activity.getSetting('harvest_subdomain');
	var url = 'https://' + harvest_subdomain + '.harvestapp.com' + path;

	var harvest_username = activity.getSetting('harvest_username');
	var harvest_password = activity.getSetting('harvest_password');
	var headers = {
		'Content-Type': 'application/json',
		Accept: 'application/json',
		Authorization:
			'Basic '
			+ Base64.encode(harvest_username + ':' + harvest_password)
	};

	activity.httpRequest(request_name, url, JSON.stringify(headers));
{'fraction_non_alphanumeric': 0.16086778550961933, 'fraction_numerical': 0.0045026606631191155, 'mean_word_length': 4.350364963503649, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 19, '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': '485991', 'n_tokens_mistral': 2909, 'n_tokens_neox': 2523, 'n_words': 463}