# craft-ai-interpreter

> craft ai isomorphic javascript decision trees interpreter

Latest version **0.0.8** (published 2016-07-06) · BSD-3-Clause license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install craft-ai-interpreter
pnpm add craft-ai-interpreter
yarn add craft-ai-interpreter
bun add craft-ai-interpreter
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.8 |
| Published | 2016-07-06 |
| First published | 2016-06-02 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+12 in 3 direct dependencies) |
| Install scripts | no |
| Author | craft ai |
| Maintainers | craft-ai |
| Keywords | ai, craft-ai |

## Links

- npm: https://www.npmjs.com/package/craft-ai-interpreter
- Repository: https://github.com/craft-ai/craft-ai-interpreter-js
- Homepage: https://github.com/craft-ai/craft-ai-interpreter-js#readme
- Issues: https://github.com/craft-ai/craft-ai-interpreter-js/issues
- npm.io page: https://npm.io/package/craft-ai-interpreter

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) 4.13.1
- [moment](https://npm.io/package/moment.md) 2.13.0
- [semver](https://npm.io/package/semver.md) 5.1.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 0.0.8 (latest) — 2016-07-06
- 0.0.7 — 2016-06-27
- 0.0.6 — 2016-06-20
- 0.0.5 — 2016-06-16
- 0.0.4 — 2016-06-14
- 0.0.3 — 2016-06-02
- 0.0.2 — 2016-06-02

## README

# craft ai interpreter js #

[**craft ai**](http://craft.ai) isomorphic javascript decision trees interpreter

[![Version](https://img.shields.io/npm/v/craft-ai-interpreter.svg?style=flat-square)](https://npmjs.org/package/craft-ai-interpreter) [![Build](https://img.shields.io/travis/craft-ai/craft-ai-interpreter-js/master.svg?style=flat-square)](https://travis-ci.org/craft-ai/craft-ai-interpreter-js) [![License](https://img.shields.io/badge/license-BSD--3--Clause-42358A.svg?style=flat-square)](LICENSE) [![Dependencies](https://img.shields.io/david/craft-ai/craft-ai-interpreter-js.svg?style=flat-square)](https://david-dm.org/craft-ai/craft-ai-interpreter-js) [![Dev Dependencies](https://img.shields.io/david/dev/craft-ai/craft-ai-interpreter-js.svg?style=flat-square)](https://david-dm.org/craft-ai/craft-ai-interpreter-js#info=devDependencies)

## API ##

### `decide` ###

A simple function able to evaluate a decision tree computed by **craft ai**.

```js
import decide, { Time } from 'craft-ai-interpreter';

// `tree` is the decision tree as retrieved through the craft ai REST API
let tree = { ... };

// Compute the decision on a context created from the given one and filling the
// `day_of_week`, `time_of_day` and `timezone` properties from the given `Time`
let decision = decide(
  tree,
  {
    presence: 'gisele'
  },
  new Time('2010-01-01T05:06:30'));
```

> Any number of partial contextes and/or `Time` instances can be provided to `decide`, it follows the same
> semantics than
> [Object.assign(...)](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign):
> the later arguments overriding the properties value from the previous ones)

The computed `decision` looks like:

```js
{
  "context": { // In which context the decision was taken
    "presence": "gisele",
    "day": 4,
    "time": 5.108333333333333,
    "tz": "+01:00"
  },
  "decision": { // The decision itself
    "blind": "OPEN"
  },
  "confidence": 0.9937745256361138, //The confidence in the decision
  "predicates": [ // The ordered list of predicates that were validated to reach this decision
    {
      "property": "timeOfDay",
      "op": "continuous.greaterthanorequal",
      "value": "6"
    },
    {
      "property": "timeOfDay",
      "op": "continuous.lessthan",
      "value": "19"
    },
    {
      "property": "dayOfWeek",
      "op": "continuous.greaterthanorequal",
      "value": "5"
    },
    {
      "property": "timeOfDay",
      "op": "continuous.greaterthanorequal",
      "value": "10"
    }
  ]
}
```

### `Time` ###

The `Time` class facilitates the handling of time types in **craft ai**. It is
able to extract the different **craft ai** formats from various _datetime_
representations, thanks to [Moment.js](http://momentjs.com).

```js
import { Time } from 'craft-ai-interpreter'

// From a unix timestamp and an explicit UTC offset
const t1 = new Time(1465496929, '+10:00');

// t1 === {
//   utc: '2016-06-09T18:28:49.000Z',
//   timestamp: 1465496929,
//   day_of_week: 4,
//   time_of_day: 4.480277777777778,
//   timezone: '+10:00'
// }

// From a unix timestamp and using the local UTC offset.
const t2 = new Time(1465496929);

// Value are valid if in Paris !
// t2 === {
//   utc: '2016-06-09T18:28:49.000Z',
//   timestamp: 1465496929,
//   day_of_week: 3,
//   time_of_day: 20.480277777777776,
//   timezone: '+02:00'
// }

// From a ISO 8601 string
const t3 = new Time('1977-04-22T01:00:00-05:00');

// t3 === {
//   utc: '1977-04-22T06:00:00.000Z',
//   timestamp: 230536800,
//   day_of_week: 4,
//   time_of_day: 1,
//   timezone: '-05:00'
// }

// Retrieve the current time with the local UTC offset
const now = new Time();

// Retrieve the current time with the given UTC offset
const nowP5 = new Time(undefined, '+05:00');
```

## Developers ##

### Setup ###

```sh
npm install
```

### Tests ###

```sh
npm run test
```

### Releasing a new version (needs administrator rights) ###

1. Make sure the build of the master branch is passing
2. Checkout the master branch locally
````sh
git fetch
git checkout master
git reset --hard origin/master
````
3. Bump the version and push
````sh
npm version patch
git push origin master
git push --tags
````

---
_Source: https://npm.io/package/craft-ai-interpreter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
