const DB_RECORD_LEN = 4; const DB_RECORDS_PER_HR = 6; const DB_RECORDS_PER_DAY = DB_RECORDS_PER_HR*24 + 1/*summary*/; const DB_RECORDS_PER_MONTH = DB_RECORDS_PER_DAY*31; const DB_HEADER_LEN = 8; const DB_FILE_LEN = DB_HEADER_LEN + DB_RECORDS_PER_MONTH*DB_RECORD_LEN; function getRecordFN(d) { return "health-"+d.getFullYear()+"-"+d.getMonth()+".raw"; } function getRecordIdx(d) { return (DB_RECORDS_PER_DAY*(d.getDate()-1)) + (DB_RECORDS_PER_HR*d.getHours()) + (0|(d.getMinutes()*DB_RECORDS_PER_HR/60)); } // Read all records from the given month exports.readAllRecords = function(d, cb) { var fn = getRecordFN(d); var f = require("Storage").read(fn); if (f===undefined) return; var idx = DB_HEADER_LEN; for (var day=0;day<31;day++) { for (var hr=0;hr<24;hr++) { // actually 25, see below for (var m=0;m