Class: DiarySleepmeter

DiarySleepmeter(file, serialiseropt)

new DiarySleepmeter(file, serialiseropt)

Parameters:
Name Type Attributes Description
file Object file contents
serialiser function <optional>
function to serialise output
Source:
Example
let diary = new_sleep_diary(contents_of_my_file));

console.log( diary.custom_aids );
-> [
     { "custom_aid_id": "CUSTOM_0001", "class": "READING", "name": "The Cat in the Hat" },
     ...
   ]

console.log( diary.custom_hindrances );
-> [
     { "custom_hindrance_id": "CUSTOM_0001", "class": "OBLIGATION", "name": "Appointment" },
     ...
   ]

console.log( diary.custom_tags );
-> [
     { "custom_tag_id": "CUSTOM_0001", "name": "ate cheese before bed" },
     ...
   ]

// Print the complete list of records
console.log(diary.records);
-> [
     {

       // normalised event times - use these where possible:
       "start" : 12345678, // based on "bedtime"
       "end" : 23456789, // based on "wake"
       "duration" : 11111111, // "wake" minus "sleep" and minus "holes"

       "wake" : {
         "string": "2001-02-03 04:05+0600",
         "year"  : 2001,
         "month" : 2,
         "day"   : 3,
         "hour"  : 4,
         "minute": 5,
         "offset": 6
       },
       "sleep" : {
         "string": "2001-02-03 04:04+0600",
         "year"  : 2001,
         "month" : 2,
         "day"   : 3,
         "hour"  : 4,
         "minute": 4,
         "offset": 6
       },
       "bedtime" : {
         "string": "2001-02-03 04:00+0600",
         "year"  : 2001,
         "month" : 2,
         "day"   : 3,
         "hour"  : 4,
         "minute": 0,
         "offset": 6
       },
       "holes" : [ { "wake": 0, "sleep": 1 } ],
       "type" : "NAP",
       "dreams" : [
         { "type": "GOOD", "mood": 5, "themes": [ "PRECOGNITIVE", "LUCID" ] }
       ],
       "aids" : [ "CPAP", "CUSTOM_0001" ],
       "hindrances" : [ "ALARM_CLOCK", "CUSTOM_0001" ],
       "tags" : [ "OUT_OF_TOWN", "CUSTOM_0001" ],
       "quality" : 5,
       "notes" : "sleep notes"
     },
     ...
   ]

Extends

Members

"custom_aids"

Things that aid sleep
Source:

"custom_hindrances"

Things that hinder sleep
Source:

"custom_tags"

Arbitrary tags describing the sleep experience
Source:

"records"

Individual records from the sleep diary
Source:

(protected) "spreadsheet" :Spreadsheet

Spreadsheet manager
Type:
Source:

serialiser :function

Serialise a value for output
Type:
  • function
Overrides:
Source:

Methods

clone()

Create a deep copy of the current object
Overrides:
Source:

(protected) corrupt(file, message)

Indicates the file is a corrupt file in the specified format
Parameters:
Name Type Description
file string | Object file contents, or filename/contents pairs (for archive files)
message string optional error message
Overrides:
Source:

(protected) invalid(file)

Indicates the file is not valid in our file format
Parameters:
Name Type Description
file string | Object file contents, or filename/contents pairs (for archive files)
Overrides:
Source:

merge(other)

Merge another diary into this one
Parameters:
Name Type Description
other DiaryBase diary to merge in
Overrides:
Source:
Example
diary.merge(my_data);

(protected) serialise()

Serialise data for output
Overrides:
Source:

software_version() → {string}

Version ID for this package
Overrides:
Source:
Returns:
Type
string

timezones() → {Array.<string>}

Complete list of allowed timezones
Overrides:
Source:
Returns:
Type
Array.<string>

to(to_format) → {*}

Convert a value to some other format

Supported formats:

  • url - contents serialised for inclusion in a URL
  • json - contents serialised to JSON
  • storage-line - contents serialised for inclusion in a newline-separated list of diaries
  • Standard - Standard format
  • (other formats) - the name of any other diary format

to_async() supports more formats and should be used where possible. You should only call this function directly if you want to guarantee synchronous execution.

Parameters:
Name Type Description
to_format string requested format
Overrides:
Source:
Returns:
diary data in new format
Type
*
Example
console.log( diary.to("NewFormat") );

to_async(to_format) → {Promise|Object}

Convert a value to some other format

Supported formats:

  • output - contents serialised for output (e.g. to a file)
  • spreadsheet - binary data that can be loaded by a spreadsheet program
  • (formats supported by to())

See also to(), a lower-level function that supports formats that can be generated synchronously. You can use that function if a Promise interface would be cumbersome or unnecessary in a given piece of code.

Parameters:
Name Type Description
to_format string requested format
Overrides:
Source:
Returns:
Promise that returns the converted diary
Type
Promise | Object
Example
diary.to_async("NewFormat").then( reformatted => console.log( reformatted_diary ) );