<commit_before>#!/usr/bin/env node --harmony

exports.dataToWorkbook = dataToWorkbook;
exports.processDiaEvent = processDiaEvent;
exports.webServerWorkbook = webServerWorkbook;

var Excel = require('exceljs');
const COL_HEADERS = require('./excel-col-headers.js').COL_HEADERS;
const BG_CONVERSION = 18.01559;
const tempy = require('tempy');

function dataToWorkbook(diaEvents, filepath) {

	var wb = webServerWorkbook(filepath);

	var indexes = {};

	var smbgSheet = wb.addWorksheet('smbg');
	smbgSheet.columns = COL_HEADERS.SMBG_COLS;
	indexes.smbg = {
		index: 1
	};

	var cbgSheet = wb.addWorksheet('cgm');
	cbgSheet.columns = COL_HEADERS.CBG_COLS;
	indexes.cbg = {
		index: 1
	};

	var cgmSettingsSheet = wb.addWorksheet('cgmSettings');
	cgmSettingsSheet.columns = COL_HEADERS.CGM_SETTINGS_COLS;
	indexes.cgmSettings = {
		index: 1
	};

	var bolusSheet = wb.addWorksheet('bolus');
	bolusSheet.columns = COL_HEADERS.BOLUS_COLS;
	indexes.bolus = {
		index: 1
	};

	var wizardSheet = wb.addWorksheet('wizard');
	wizardSheet.columns = COL_HEADERS.WIZARD_COLS;
	indexes.wizard = {
		index: 1
	};

	var basalSheet = wb.addWorksheet('basal');
	basalSheet.columns = COL_HEADERS.BASAL_COLS;
	indexes.basal = {
		index: 1,
		group: 1
	};

	var basalScheduleSheet = wb.addWorksheet('basalSchedules');
	basalScheduleSheet.columns = COL_HEADERS.BASAL_SCHEDULE_COLS;
	indexes.basalSchedule = {
		index: 1,
		group: 1
	};

	var bgTargetSheet = wb.addWorksheet('bgTarget');
	bgTargetSheet.columns = COL_HEADERS.BG_TARGET_COLS;
	indexes.bgTarget = {
		index: 1,
		group: 1
	};

	var carbRatioSheet = wb.addWorksheet('carbRatio');
	carbRatioSheet.columns = COL_HEADERS.CARB_RATIO_COLS;
	indexes.carbRatio = {
		index: 1,
		group: 1
	};

	var insulinSensitivitySheet = wb.addWorksheet('insulinSensitivity');
	insulinSensitivitySheet.columns = COL_HEADERS.INSULIN_SENSITIVITY_COLS;
	indexes.insulinSensitivity = {
		index: 1,
		group: 1
	};

	var bloodKetoneSheet = wb.addWorksheet('bloodKetone');
	bloodKetoneSheet.columns = COL_HEADERS.BLOOD_KETONE_COLS;
	indexes.bloodKetone = {
		index: 1
	};

	var uploadSheet = wb.addWorksheet('upload');
	uploadSheet.columns = COL_HEADERS.UPLOAD_COLS;
	indexes.upload = {
		index: 1,
		group: 1
	};

	var deviceEventSheet = wb.addWorksheet('deviceEvent and suspend');
	deviceEventSheet.columns = COL_HEADERS.DEVICE_EVENT_COLS;
	indexes.deviceEvent = {
		index: 1,
		group: 1
	};

	for(diaEvent of diaEvents){
		processDiaEvent(wb, indexes, diaEvent);
	}

	wb.commit();

	return wb;
}


function dateForDateString(datetime) {<commit_msg>Write to a stream rather than a temp file.<commit_after>#!/usr/bin/env node --harmony

exports.dataToWorkbook = dataToWorkbook;
exports.processDiaEvent = processDiaEvent;
exports.webServerWorkbook = webServerWorkbook;

var Excel = require('exceljs');
const COL_HEADERS = require('./excel-col-headers.js').COL_HEADERS;
const BG_CONVERSION = 18.01559;

function dataToWorkbook(diaEvents, stream) {

	var wb = new Excel.Workbook();

	var indexes = {};

	var smbgSheet = wb.addWorksheet('smbg');
	smbgSheet.columns = COL_HEADERS.SMBG_COLS;
	indexes.smbg = {
		index: 1
	};

	var cbgSheet = wb.addWorksheet('cgm');
	cbgSheet.columns = COL_HEADERS.CBG_COLS;
	indexes.cbg = {
		index: 1
	};

	var cgmSettingsSheet = wb.addWorksheet('cgmSettings');
	cgmSettingsSheet.columns = COL_HEADERS.CGM_SETTINGS_COLS;
	indexes.cgmSettings = {
		index: 1
	};

	var bolusSheet = wb.addWorksheet('bolus');
	bolusSheet.columns = COL_HEADERS.BOLUS_COLS;
	indexes.bolus = {
		index: 1
	};

	var wizardSheet = wb.addWorksheet('wizard');
	wizardSheet.columns = COL_HEADERS.WIZARD_COLS;
	indexes.wizard = {
		index: 1
	};

	var basalSheet = wb.addWorksheet('basal');
	basalSheet.columns = COL_HEADERS.BASAL_COLS;
	indexes.basal = {
		index: 1,
		group: 1
	};

	var basalScheduleSheet = wb.addWorksheet('basalSchedules');
	basalScheduleSheet.columns = COL_HEADERS.BASAL_SCHEDULE_COLS;
	indexes.basalSchedule = {
		index: 1,
		group: 1
	};

	var bgTargetSheet = wb.addWorksheet('bgTarget');
	bgTargetSheet.columns = COL_HEADERS.BG_TARGET_COLS;
	indexes.bgTarget = {
		index: 1,
		group: 1
	};

	var carbRatioSheet = wb.addWorksheet('carbRatio');
	carbRatioSheet.columns = COL_HEADERS.CARB_RATIO_COLS;
	indexes.carbRatio = {
		index: 1,
		group: 1
	};

	var insulinSensitivitySheet = wb.addWorksheet('insulinSensitivity');
	insulinSensitivitySheet.columns = COL_HEADERS.INSULIN_SENSITIVITY_COLS;
	indexes.insulinSensitivity = {
		index: 1,
		group: 1
	};

	var bloodKetoneSheet = wb.addWorksheet('bloodKetone');
	bloodKetoneSheet.columns = COL_HEADERS.BLOOD_KETONE_COLS;
	indexes.bloodKetone = {
		index: 1
	};

	var uploadSheet = wb.addWorksheet('upload');
	uploadSheet.columns = COL_HEADERS.UPLOAD_COLS;
	indexes.upload = {
		index: 1,
		group: 1
	};

	var deviceEventSheet = wb.addWorksheet('deviceEvent and suspend');
	deviceEventSheet.columns = COL_HEADERS.DEVICE_EVENT_COLS;
	indexes.deviceEvent = {
		index: 1,
		group: 1
	};

	for(diaEvent of diaEvents){
		processDiaEvent(wb, indexes, diaEvent);
	}

	// Return a Promise to the file write
	return wb.xlsx.write(stream);
}


function dateForDateString(datetime) {
{'fraction_non_alphanumeric': 0.12036497767423801, 'fraction_numerical': 0.010483401281304601, 'mean_word_length': 4.888, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5247274', 'n_tokens_mistral': 2154, 'n_tokens_neox': 1973, 'n_words': 332}