npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smartsleep-analyzer

v1.1.4

Published

Provides an effective solution for sleep problems.

Downloads

18

Readme

Getting started

Provides an effective solution for sleep problems.

How to Build

The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here

NPM is installed by default when Node is installed

To check if node and npm have been successfully installed, write the following commands in command prompt:

  • node --version
  • npm -version

Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):

npm install

This will install all dependencies in the node_modules folder.

Once dependencies are resolved, you will need to move the folder SmartSleepAnalyzer in to your node_modules folder.

How to Use

The following section explains how to use the library in a new project.

1. Open Project Folder

Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

Click on File and select Open Folder.

Select the folder of your SDK and click on Select Folder to open it up in Sublime Text. The folder will become visible in the bar on the left.

2. Creating a Test File

Now right click on the folder name and select the New File option to create a new test file. Save it as index.js Now import the generated NodeJS library using the following lines of code:

var lib = require('lib');

Save changes.

3. Running The Test File

To run the index.js file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:

node index.js

How to Test

These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:

Method 1 (Run all tests)

  1. Navigate to the <repo-root>/SSA-NodeJS/test/ directory from command prompt.
  2. Type mocha --<YourClientId> --<YourClientSecret> * to run all the tests.

Method 2 (Run specific controller's tests)

  1. Navigate to the <repo-root>/SSA-NodeJS/test/ directory from command prompt.
  2. Edit the clientid and secretKey properties in the Configuration.js file with your Client Id and Secret.
  3. Type mocha <ControllerFileName> to run all the tests in that controller file.

To increase mocha's default timeout, you can change the TEST_TIMEOUT parameter's value in TestBootstrap.js.

Initialization

API client can be initialized as following:

const lib = require('lib');

Class Reference

List of Controllers

Class: ScoringController

Get singleton instance

The singleton instance of the ScoringController class can be accessed from the API Client.

var SSA_ClientLib = lib(_config.clientid,_config.secretKey);

Method: getRequiredQuestionSenses

Returns all question senses required to compute the target sense.

function getRequiredQuestionSenses(targetSenseId, locale)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | targetSenseId | Required | Id of sense for which required inputs are returned. | | locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |

Example Usage

var targetSenseId = 'targetSenseId';
var locale = 'locale';

SSA_ClientLib.ScoringController.getRequiredQuestionSenses(targetSenseId, locale).then(function(result) {
    //TODO Business Logic
});

Method: getComputableSleepProblemSenses

Returns all sleep problem senses which can be computed from the given input sense ids.

function getComputableSleepProblemSenses(senseIds)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | senseIds | Optional Collection | List of ids for all input senses that would be provided. |

Example Usage

var senseIds = ['senseIds'];

SSA_ClientLib.ScoringController.getComputableSleepProblemSenses(senseIds).then(function(result) {
    //TODO Business Logic
});

Method: getComputableSenses

Returns all senses which can be computed from the given input sense ids.

function getComputableSenses(senseIds)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | senseIds | Optional Collection | List of ids for all input senses that would be provided. |

Example Usage

var senseIds = ['senseIds'];

SSA_ClientLib.ScoringController.getComputableSenses(senseIds).then(function(result) {
    //TODO Business Logic
});

Method: getComputedSenses

Returns metadata information about all computed senses. Computed senses are derived from other senses and should

not be asked directly to an end-user.

function getComputedSenses()

Example Usage

SSA_ClientLib.ScoringController.getComputedSenses().then(function(result) {
    //TODO Business Logic
});

Method: getSleepProblemSenses

Returns metadata information about all sleep problem senses.

function getSleepProblemSenses()

Example Usage

SSA_ClientLib.ScoringController.getSleepProblemSenses().then(function(result) {
    //TODO Business Logic
});

Method: getQuestionSenses

Returns metadata information about all question senses. Question senses are simple value senses which can be asked

to an end-user in the form of a question.

function getQuestionSenses(locale)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |

Example Usage

var locale = 'locale';

SSA_ClientLib.ScoringController.getQuestionSenses(locale).then(function(result) {
    //TODO Business Logic
});

Method: getAllSenses

Returns metadata information about all available senses.

function getAllSenses(locale)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |

Example Usage

var locale = 'locale';

SSA_ClientLib.ScoringController.getAllSenses(locale).then(function(result) {
    //TODO Business Logic
});

Method: getSense

Returns metadata information about a single sense.

function getSense(senseId, locale)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | senseId | Required | The id of the sense. | | locale | Optional DefaultValue | Optional query param locale used to localize question sense text. |

Example Usage

var senseId = 'senseId';
var locale = 'locale';

SSA_ClientLib.ScoringController.getSense(senseId, locale).then(function(result) {
    //TODO Business Logic
});

Method: computeIntermediateAndSleepProblemSenses

Computes the values of all possible intermediate and sleep problem senses based on the provided input values.

function computeIntermediateAndSleepProblemSenses(inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | inputValues | Optional | Map of sense input values, keyed by sense id. |

Example Usage

var inputValues = {
    id : 21
};

SSA_ClientLib.ScoringController.computeIntermediateAndSleepProblemSenses(inputValues).then(function(result) {
    //TODO Business Logic
});

Method: computeSleepProblemSenses

Computes the values of all possible sleep problem senses based on the provided input values.

function computeSleepProblemSenses(inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | inputValues | Optional | Map of sense input values, keyed by sense id. |

Example Usage

var inputValues = {
    id : 21
};

SSA_ClientLib.ScoringController.computeSleepProblemSenses(inputValues).then(function(result) {
    //TODO Business Logic
});

Method: computeSense

Computes the value of a single sense based on the provided input values.

function computeSense(senseId, inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | senseId | Required | Id of the sense to compute. | | inputValues | Optional | Map of sense input values, keyed by sense id. |

Example Usage

var senseId = 'senseId';
var inputValues = {
    id : 21
};

SSA_ClientLib.ScoringController.computeSense(senseId, inputValues).then(function(result) {
    //TODO Business Logic
});

Method: computeAllSenses

Computes the values of all possible senses based on the provided input values.

function computeAllSenses(inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | inputValues | Optional | Map of sense input values, keyed by sense id. |

Example Usage

var inputValues = {
    id : 21
};

SSA_ClientLib.ScoringController.computeSense(inputValues).then(function(result) {
    //TODO Business Logic
});

Back to List of Controllers

Class: ResultController

Get singleton instance

The singleton instance of the ResultController class can be accessed from the API Client.

var SSA_ClientLib = lib(_config.clientid,_config.secretKey);

Method: getTipsByConditionAndInputValues

Computes and returns all tips that would be associated with the given condition, based on the given input values.

function getTipsByConditionAndInputValues(conditionId, inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | conditionId | Optional | The id of the sleep problem. | | inputValues | Optional | The sense input values. |

Example Usage

var conditionId = 'conditionId';
var inputValues = {
    id : 21
};

SSA_ClientLib.ResultController.getTipsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
    //TODO Business Logic
});

Method: getTipIdsByConditionAndInputValues

Computes and returns the ids of all tips that would be associated with the given condition, based on the given input values.

function getTipIdsByConditionAndInputValues(conditionId, inputValues)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | conditionId | Required | The id of the sleep problem. | | inputValues | Optional | The sense input values. |

Example Usage

var conditionId = 'conditionId';
var inputValues = {
    id : 21
};

SSA_ClientLib.ResultController.getTipIdsByConditionAndInputValues(conditionId, inputValues).then(function(result) {
    //TODO Business Logic
});

Method: getTidbitIdsByCondition

Returns the ids of all tidbits that could be associated with the given condition.

function getTidbitIdsByCondition(conditionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | conditionId | Required | The id of the condition. |

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getTidbitIdsByCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: getTipIdsByCondition

Returns the ids of all tips that could be associated with the given condition.

function getTipIdsByCondition(conditionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | conditionId | Required | The id of the condition. |

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getTipIdsByCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: getCondition

Returns metadata information about an single condition.

function getCondition(conditionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | conditionId | Required | The id of the condition. |

Example Usage

var conditionId = 'conditionId';

SSA_ClientLib.ResultController.getCondition(conditionId).then(function(result) {
    //TODO Business Logic
});

Method: submitTipFeedback

Submits feedback for the session on the indicated tip.

function submitTipFeedback(requestDTO)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | requestDTO | Optional | The request object. |

Example Usage

var requestDTO = new UpdateTipFeedbackRequestDTO({"key":"value"});

SSA_ClientLib.ResultController.submitTipFeedback(requestDTO).then(function(result) {
    //TODO Business Logic
});

Method: getAllConditions

Returns metadata information about all available conditions.

function getAllConditions()

Example Usage

SSA_ClientLib.ResultController.getAllConditions().then(function(result) {
    //TODO Business Logic
});

Method: submitConditionFeedback

Submits feedback for the session on the indicated condition.

function submitConditionFeedback(requestDTO)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | requestDTO | Optional | The request object. |

Example Usage

var requestDTO = new UpdateConditionFeedbackRequestDTO({"key":"value"});

SSA_ClientLib.ResultController.submitConditionFeedback(requestDTO).then(function(result) {
    //TODO Business Logic
});

Method: computeResult

Computes Results output for the given survey.

function computeResult(surveyIdentifier, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | surveyIdentifier | Required | The identifier of the survey. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var surveyIdentifier = 'surveyIdentifier';
var sessionId = null; 

SSA_ClientLib.ResultController.submitConditionFeedback(surveyIdentifier, sessionId).then(function(result) {
    //TODO Business Logic
});

Back to List of Controllers

Class: SessionController

Get singleton instance

The singleton instance of the SessionController class can be accessed from the API Client.

var SSA_ClientLib = lib(_config.clientid,_config.secretKey);

Method: activateSession

Activates a session.

function activateSession(sessionDTO)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | sessionDTO | Optional | Object containing the session's credentials. |

Example Usage

var sessionDTO = new SessionDTO({"key":"value"});

SSA_ClientLib.SessionController.activateSession(sessionDTO).then(function(result) {
    //TODO Business Logic
});

Method: retrieveActivatedSession

Retrieves the details of the activated session.

function retrieveActivatedSession()

Example Usage

SSA_ClientLib.SessionController.retrieveActivatedSession().then(function(result) {
    //TODO Business Logic
});

Method: deactivateSession

Deactivates the current session.

function deactivateSession()

Example Usage

SSA_ClientLib.SessionController.deactivateSession().then(function(result) {
    //TODO Business Logic
});

Method: createSession

Creates a new session with the provided information.

function createSession(sessionDTO)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | sessionDTO | Optional | The provided session information. |

Example Usage

var sessionDTO = new SessionDTO({"key":"value"});

SSA_ClientLib.SessionController.createSession(sessionDTO).then(function(result) {
    //TODO Business Logic
});

Back to List of Controllers

Class: SurveyController

Get singleton instance

The singleton instance of the SurveyController class can be accessed from the API Client.

var SSA_ClientLib = lib(_config.clientid,_config.secretKey);

Method: resetSurveyState

Resets the state of the survey for the current session. In other words, all the session's answers are removed and the survey should start back at the beginning.

function resetSurveyState(identifier)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. |

Example Usage

var identifier = 'identifier';

SSA_ClientLib.SurveyController.resetSurveyState(identifier).then(function(result) {
    //TODO Business Logic
});

Method: getSurveyState

Retrieves the state of a survey for the current session.

function getSurveyState(identifier, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var sessionId = null;

SSA_ClientLib.SurveyController.getSurveyState(identifier, sessionId).then(function(result) {
    //TODO Business Logic
});

Method: updateSurveyState

Updates the state of a survey for the current session, and returns the portion of the survey state necessary for the client to render the survey based on the update.

function updateSurveyState(identifier, requestDTO, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | requestDTO | Optional | The update request object. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var requestDTO = new UpdateSurveyStateRequestDTO({"key":"value"});
var sessionId = null;

SSA_ClientLib.SurveyController.updateSurveyState(identifier, requestDTO, sessionId).then(function(result) {
    //TODO Business Logic
});

Method: getSenseQuestion

Get the QuestionDTO for a given sense, and for the given survey.

function getSenseQuestion(identifier, senseId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | senseId | Required | The id of the sense we want a list of required QuestionDTO for. |

Example Usage

var identifier = 'identifier';
var senseId = 'height';

SSA_ClientLib.SurveyController.getSenseQuestion(identifier, senseId).then(function(result) {
    //TODO Business Logic
});

Method: getSenseRequiredQuestions

Get a list of required QuestionDTO items for a given sense, and for the given survey.

function getSenseRequiredQuestions(identifier, senseId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | senseId | Required | The id of the sense we want a list of required QuestionDTO for. |

Example Usage

var identifier = 'identifier';
var senseId = 'height';

SSA_ClientLib.SurveyController.getSenseRequiredQuestions(identifier, senseId).then(function(result) {
    //TODO Business Logic
});

Method: getQuestions

Retrieves the current question set, per the current survey state, or per the given Step Id reference. Templates are also provided for immediately submitting via PostAnswers, or later submission via UpdateAnswers.

function getQuestions(identifier, stepRef, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | stepRef | Optional | Optional Step Id we wish to query QuestionDTOs for. Defaults to the latest step, if unspecified. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var stepRef = null;
var sessionId = null;

SSA_ClientLib.SurveyController.getSenseRequiredQuestions(identifier, stepRef, sessionId).then(function(result) {
    //TODO Business Logic
});

Method: postAnswers

Submits answers to the most recent, unanswered questions for the current survey session, and returns the next batch of unanswered survey questions if successful.

function postAnswers(identifier, answers, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | answers | Optional | The answers for the most recent, unanswered questions available in the survey. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var answers={'demographics1':true};
var sessionId = null;

SSA_ClientLib.SurveyController.postAnswers(identifier, answers, sessionId).then(function(result) {
    //TODO Business Logic
});

Method: updateAnswers

Re-submits answers to a potentially existing set of questions, from a previous step, and returns the next batch of unanswered survey questions if successful. This endpoint gracefully handles first-time submissions as well, similar to the simpler PostAnswers endpoint.

function updateAnswers(identifier, updateSurveyStateRequestDTO, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | updateSurveyStateRequestDTO | Required | A DTO with the step ref, and answers to re-submit. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var updateSurveyStateRequestDTO={
    'stepRef': 'demographics1',
    'answers': {
    'demographics1':true,
    }
};
var sessionId = null;

SSA_ClientLib.SurveyController.postAnswers(identifier, updateSurveyStateRequestDTO, sessionId).then(function(result) {
    //TODO Business Logic
});

Method: getSurveyStateSummary

Retrieves the state of a survey for the current session.

function getSurveyStateSummary(identifier, sessionId)

Parameters

| Parameter | Tags | Description | |-----------|------|-------------| | identifier | Required | The identifier of the survey. | | sessionId | Optional | An auth token provided by the backend, for persisting state between calls. |

Example Usage

var identifier = 'identifier';
var sessionId = null;

SSA_ClientLib.SurveyController.getSurveyStateSummary(identifier, sessionId).then(function(result) {
    //TODO Business Logic
});

Back to List of Controllers