Class: DiarySleepAsAndroid

DiarySleepAsAndroid(file, serialiseropt)

new DiarySleepAsAndroid(file, serialiseropt)

Parameters:
Name Type Attributes Description
file Object file contents, or filename/contents pairs (for archive files)
serialiser function <optional>
function to serialise output
Source:
Example
let diary = new_sleep_diary(contents_of_my_file));

console.log( this.records );
-> [ // "records" is an array of objects:
     {

       // normalised event times - use these where possible:
       "start" : 12345678,
       "end" : 23456789,
       "alarm" : 23456789,
       "duration" : 11111111, // "Hours" hours minus "LenAdjust" minutes

       // native event times - see README.md#date-issues
       "Id" : "12345678",
       "Tz" : "Europe/London",
       "From" : {
         "string"   : "01. 02. 2003 04:05",
         "year"     : 2003,
         "month"    : 2,
         "day"      : 1,
         "hour"     : 4,
         "minute"   : 5,
       },
       "To" : {
         "string"   : "01. 02. 2003 05:06",
         "year"     : 2003,
         "month"    : 2,
         "day"      : 1,
         "hour"     : 5,
         "minute"   : 6,
       },
       "Sched" : {
         "string"   : "01. 02. 2003 06:07",
         "year"     : 2003,
         "month"    : 2,
         "day"      : 1,
         "hour"     : 6,
         "minute"   : 7,
       },
       "Hours" : 1.1,

       "Rating" : 2.5,
       "Comment" : {
         "string": "comment string with a #tag",
         "tags"  : [{ "count": 1, "value": "tag" }],
         "notags": "comment string with a"
       },
       "Framerate" : "10000",
       "Snore" : null,
       "Noise" : null,
       "Cycles" : null,
       "DeepSleep" : null,
       "LenAdjust" : null,
       "Geo" : "",
       "times" : [
         {
           "header_string": "04:40",
           "hours"        : 4,
           "minutes"      : 40,
           "actigraphy"   : 0.5,
           "noise"        : 10.0,
         },
         ...
       ],
       "events" : [
         {
           "label"    : "LUX",
           "timestamp": 123456789,
           "value"    : 10.0,
         },
       ]
     },
     ...
   ]

console.log( this.prefs );
-> { key/value pairs, format not guaranteed by this library }

console.log( this.alarms );
-> [ list of alarms, format not guaranteed by this library ]

Extends

Members

"alarms"

User alarms
Source:

"prefs"

User preferences
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 ) );