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

@awarns/human-activity

v1.0.0

Published

AwarNS Framework package that allows to detect and react to physical activity changes

Downloads

17

Readme

@awarns/human-activity

npm (scoped) npm

This module allows to detect and react to the changes in the activity being performed by the user (or object) carrying the phone: standing still, walking, running, riding a bicycle or being inside a vehicle. Depending on the granularity of the detection mechanism being used, it can even detect user stand-ups too.

This plugin acts as a wrapper on top of the nativescript-context-apis plugin (from the same authors), offering human activity change detection tasks. Obtain human activity updates even in background.

Install the plugin using the following command line instruction:

ns plugin add @awarns/human-activity

Usage

After installing and setting up this plugin, you'll have access to two task groups to start and stop listening human activity updates at different granularity levels. The received updates, will be a HumanActivityChange record, described below.

Setup

This plugin requires you to register its loader during the framework initialization, like this:

// ... platform imports
import { awarns } from '@awarns/core';
import { demoTasks } from '../tasks';
import { demoTaskGraph } from '../graph';
import { registerHumanActivityPlugin } from '@awarns/human-activity';

awarns
  .init(
    demoTasks,
    demoTaskGraph,
    [
      registerHumanActivityPlugin(),
    ]
  )
  // ... handle initialization promise

Plugin loader parameters:

This plugin loader takes no parameters.

Tasks

| Task name | Description | |---------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | startDetectingCoarseHumanActivityChanges | Allows to start detecting human activity changes at a coarse granularity level. This level of granularity means that activity changes will be reported no sooner than 1 minute after the activity started. In contrast, the detection mechanism will be more robust against in-between activity stops. This means, for example, that if the user is walking and stops for a few seconds, or is inside a vehicle and stops at traffic light, these subtle changes won't be detected at this granularity level | | stopDetectingCoarseHumanActivityChanges | The complement to the previous task. Allows to stop receiving coarse activity updates on demand | | startDetectingIntermediateHumanActivityChanges | Allows to start detecting human activity changes at an intermediate granularity level. This level of granularity means that activity changes will be reported as soon as they are detected. In contrast, the detection mechanism will be more sensitive to in-between activity stops. This means, for example, that if the user is walking and stops for a few seconds, or is inside a vehicle and stops at traffic light, these subtle changes will be detected as transitions to becoming still. Due to this extra of granularity, this activity detection mechanism is able to detect user stand-up actions (phone tilts abruptly) | | stopDetectingIntermediateHumanActivityChanges | The complement to the previous task. Allows to stop receiving intermediate activity updates on demand |

Note: All the tasks require physical activity access permission for their execution. Each task will automatically request what is missing during framework's initialization

Start / stop receiving updates on human activity changes at a coarse level

To register these tasks for their use, you just need to import them and call their generator functions inside your application's task list:

import { Task } from '@awarns/core/tasks';
import {
  startDetectingCoarseHumanActivityChangesTask,
  stopDetectingCoarseHumanActivityChangesTask,
} from '@awarns/human-activity';

export const demoTasks: Array<Task> = [
  startDetectingCoarseHumanActivityChangesTask(),
  stopDetectingCoarseHumanActivityChangesTask(),
];

Task generator parameters:

These task generators take no parameters

Task output events:

These tasks don't produce significant events after they complete their execution aside from the regular {task-name}Finished events, which are: startDetectingCoarseHumanActivityChangesFinished and stopDetectingCoarseHumanActivityChangesFinished.

However, once the start task has finished running, relevant events will be emitted by the internal listeners once the corresponding action has been detected. These are listed below.

Example usage in the application task graph:

on('startEvent', run('startDetectingCoarseHumanActivityChanges'));
on('stopEvent', run('stopDetectingCoarseHumanActivityChanges'));

on('userStartedBeingStill', run('writeRecords'));
on('userFinishedBeingStill', run('writeRecords'));

on('userStartedWalking', run('writeRecords'));
on('userFinishedWalking', run('writeRecords'));

on('userStartedRunning', run('writeRecords'));
on('userFinishedRunning', run('writeRecords'));

on('userStartedRidingABicycle', run('writeRecords'));
on('userFinishedRidingABicycle', run('writeRecords'));

on('userStartedBeingInAVehicle', run('writeRecords'));
on('userFinishedBeingInAVehicle', run('writeRecords'));

Note: To use the writeRecords task, the persistence package must be installed and configured. See persistence package docs.

Start / stop receiving updates on human activity changes at an intermediate level

To register these tasks for their use, you just need to import them and call their generator functions inside your application's task list:

import { Task } from '@awarns/core/tasks';
import {
  startDetectingIntermediateHumanActivityChangesTask,
  stopDetectingIntermediateHumanActivityChangesTask,
} from '@awarns/human-activity';

export const demoTasks: Array<Task> = [
  startDetectingIntermediateHumanActivityChangesTask(),
  stopDetectingIntermediateHumanActivityChangesTask(),
];

Task generator parameters:

These task generators take no parameters

Task output events:

These tasks don't produce significant events after they complete their execution aside from the regular {task-name}Finished events, which are: startDetectingIntermediateHumanActivityChangesFinished and stopDetectingIntermediateHumanActivityChangesFinished.

However, once the start task has finished running, relevant events will be emitted by the internal listeners once the corresponding action has been detected. These are listed below.

Example usage in the application task graph:

on('startEvent', run('startDetectingCoarseHumanActivityChanges'));
on('stopEvent', run('stopDetectingCoarseHumanActivityChanges'));

on('userStartedBeingStill', run('writeRecords'));
on('userFinishedBeingStill', run('writeRecords'));

on('userStartedStandingUp', run('writeRecords'));
on('userFinishedStandingUp', run('writeRecords'));

on('userStartedWalking', run('writeRecords'));
on('userFinishedWalking', run('writeRecords'));

on('userStartedRunning', run('writeRecords'));
on('userFinishedRunning', run('writeRecords'));

on('userStartedRidingABicycle', run('writeRecords'));
on('userFinishedRidingABicycle', run('writeRecords'));

on('userStartedBeingInAVehicle', run('writeRecords'));
on('userFinishedBeingInAVehicle', run('writeRecords'));

Note: To use the writeRecords task, the persistence package must be installed and configured. See persistence package docs.

Events

| Name | Payload | Description | |-------------------------------|-----------------------------------------------|---------------------------------------------------------------------| | userStartedBeingStill | HumanActivityChange | Indicates that the user of the phone has stopped moving | | userFinishedBeingStill | HumanActivityChange | Indicates that the user of the phone has started moving | | userStartedStandingUp | HumanActivityChange | Indicates that the user of the phone has started standing up | | userFinishedStandingUp | HumanActivityChange | Indicates that the user of the phone has finished standing up | | userStartedWalking | HumanActivityChange | Indicates that the user of the phone has started to walk | | userFinishedWalking | HumanActivityChange | Indicates that the user of the phone has stopped walking | | userStartedRunning | HumanActivityChange | Indicates that the user of the phone has started to run | | userFinishedRunning | HumanActivityChange | Indicates that the user of the phone has stopped running | | userStartedRidingABicycle | HumanActivityChange | Indicates that the user of the phone has started riding a bicycle | | userFinishedRidingABicycle | HumanActivityChange | Indicates that the user of the phone has stopped riding a bicycle | | userStartedBeingInAVehicle | HumanActivityChange | Indicates that the user of the phone has started being in a vehicle | | userFinishedBeingInAVehicle | HumanActivityChange | Indicates that the user of the phone has stopped being in a vehicle |

Records

HumanActivityChange

| Property | Type | Description | |--------------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | id | string | Record's unique id | | type | string | Always human-activity | | change | Change | Can be either start or end. Indicates if the change reflects the activity starting or finishing | | timestamp | Date | The local time when the change was detected | | activity | HumanActivity | The activity which was detected. Can be any of the ones supported by the context-apis plugin (see context-apis API docs section on human activity, to obtain the full list) | | confidence | number | Probability value of the detected action reported by the activity detection mechanism. Ranges from 0 to 1. This field will contain an undefined value in records reported by the coarse detection mechanism |

License

Apache License Version 2.0