# hapiger

> Hapi.js HTTP wrapper for Good Enough Recommendation engine (GER)

Latest version **0.0.12** (published 2015-10-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapiger
pnpm add hapiger
yarn add hapiger
bun add hapiger
```

Provides the command `hapiger`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.12 |
| Published | 2015-10-12 |
| First published | 2015-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 13 |
| Known vulnerabilities | 0 (+10 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 176 |
| Author | Graham Jenson |
| Maintainers | grahamjenson |
| Keywords | hapiger, recommendations |

## Links

- npm: https://www.npmjs.com/package/hapiger
- Repository: https://github.com/grahamjenson/hapiger
- Issues: https://github.com/grahamjenson/hapiger/issues
- npm.io page: https://npm.io/package/hapiger

## Dependencies (13)

- [ger](https://npm.io/package/ger.md) 0.0.98
- [joi](https://npm.io/package/joi.md) 6.9.0
- [boom](https://npm.io/package/boom.md) 2.9.0
- [good](https://npm.io/package/good.md) 6.4.0
- [hapi](https://npm.io/package/hapi.md) 10.4.1
- [chalk](https://npm.io/package/chalk.md) 0.5.1
- [moment](https://npm.io/package/moment.md) 2.9.0
- [bluebird](https://npm.io/package/bluebird.md) 2.10.2
- [commander](https://npm.io/package/commander.md) 2.6.0
- [underscore](https://npm.io/package/underscore.md) 1.7.0
- [good-console](https://npm.io/package/good-console.md) 5.1.0
- [coffee-script](https://npm.io/package/coffee-script.md) 1.9.3
- [ger_rethinkdb_esm](https://npm.io/package/ger_rethinkdb_esm.md) 0.0.05

## Recent versions

- 0.0.12 (latest) — 2015-10-12
- 0.0.11 — 2015-10-12
- 0.0.2 — 2015-02-07
- 0.0.1 — 2015-02-05

## README

# HapiGER

<img src="./assets/hapiger300x200.png" align="right" alt="HapiGER logo" />

Providing good recommendations can create greater user engagement and directly provide value by recommending items the customer might additionally like. However, many applications don't provide recommendations to users because of the difficulty in implementing a custom engine or the pain of using an off-the-shelf engine.

**HapiGER** is a recommendations service that uses the [Good Enough Recommendations (**GER**)](https://www.npmjs.com/package/ger), a scalable, simple recommendations engine, and the [Hapi.js](http://hapijs.org) framework. It has been developed to be easy to integrate, easy to use and very scalable.

[Project Site](http://www.hapiger.com)

## Quick Start Guide

<br/>
***
#### Install HapiGER

Install with `npm`

```bash
npm install -g hapiger
```

<br/>
***

#### Start HapiGER

By default it will start with an in-memory event store (events are not persisted)

```bash
hapiger
```

*There are also PostgreSQL and RethinkDB event stores for persistence and scaling*

<br/>
***

#### Create a Namespace

A Namespace is a bucket where all the events are put:

```bash
curl -X POST 'http://localhost:3456/namespaces' -d'{
    "namespace": "movies"
  }'
```

<br/>
***

#### Create some Events

An event occurs when a person actions something, e.g. `Alice` `view`s `Harry Potter`:

```bash
curl -X POST 'http://localhost:3456/events' -d '{
    "events": [
    {
      "namespace": "movies",
      "person":    "Alice",
      "action":    "view",
      "thing":     "Harry Potter"
    }
  ]
}'
```

Then, `Bob` also `view`s `Harry Potter` (now `Bob` has similar viewing habits to `Alice`)

```bash
curl -X POST 'http://localhost:3456/events' -d '{
    "events": [
    {
      "namespace": "movies",
      "person":    "Bob",
      "action":    "view",
      "thing":     "Harry Potter"
    }
  ]
}'
```

When a person actions and thing, it serves two purposes in HapiGER:

1. It is used to measure a persons similarity to other people
2. It can be a recommendation of that thing

For example, when `Bob` `buy`s `LOTR`

```bash
curl -X POST 'http://localhost:3456/events' -d '{
    "events": [
    {
      "namespace":  "movies",
      "person":     "Bob",
      "action":     "buy",
      "thing":      "LOTR",
      "expires_at": "2016-10-12"
    }
  ]
}'
```

This is an action that can be used to find similar people **AND** it can be seen as `Bob` recommending  `LOTR`. For an event to be a recommendation as well it must have an expiration date set with `expires_at`, which is how long the recommendation will be available for.

<br/>
***

#### Recommendations

What books should `Alice` `buy`?

```bash
curl -X POST 'http://localhost:3456/recommendations' -d '{
    "namespace": "movies",
    "person": "Alice",
    "configuration": {
      "actions" : {"view": 5, "buy": 10}
    }
}'
```

```
{
  "recommendations": [
    {
      "thing": "LOTR",
      "weight": 0.44721359549996,
      "last_actioned_at": "2015-10-12T17:04:14+01:00",
      "last_expires_at": "2016-10-12T01:00:00+01:00",
      "people": [
        "Bob"
      ]
    }
  ],
  "neighbourhood": {
    "Bob": 0.44721359549996,
    "Alice": 1
  },
  "confidence": 0.00036398962692384
}
```

`Alice` should buy `The Hobbit` as it was recommended by `Bob` with a weight of about `0.2`.

The `configuration` defines many variables that can be used to customise the search for recommendations. The object is directly passed to GER and the available variables are listed in the [GER Documentation](https://github.com/grahamjenson/ger).

*The `confidence` of these recommendations is pretty low because there are not many events in the system*

<br/>
***

#### How HapiGER Works (the Quick Version)

The HapiGER API calculates recommendations for `Alice` to `buy` by:

1. Finding people (neighbors) that are like `Alice` by looking at her past events
2. Calculating the similarities between `Alice` and her neighbors
3. Looking at the recent `things` that those similar people recommended
4. Weight those recommendations using the similarity of the people

<br/>
***

#### Event Stores

The "in-memory" memory event store is the default, this will not scale well or persist event so is not recommended for production.

The **recommended** event store is **PostgreSQL**, which can be used with:

```
hapiger --es pg --esoptions '{
    "connection":"postgres://localhost/hapiger"
  }'
```

*Options are passed to [knex](http://knexjs.org/).*

HapiGER also supports a [RethinkDB](http://rethinkdb.com/) event store:

```
hapiger --es rethinkdb --esoptions '{
    "host":"127.0.0.1",
    "port": 28015,
    "db":"hapiger"
  }'
```

*Options passed to [rethinkdbdash](https://github.com/neumino/rethinkdbdash).*

<br/>
***

#### Compacting the Event Store

The event store needs to be regularly maintained by removing old, outdated, or superfluous events; this is called **compacting**

```
curl -X POST 'http://localhost:3456/compact' -d '{
  "namespace": "movies"
}'
```


<br/>
***

#### Namespaces

In addition to creating namespaces, you can also list and destroy them:

```
curl -X GET 'http://localhost:3456/namespaces'
```

To delete a namespace (**and all its events!**):

```
curl -X DELETE 'http://localhost:3456/namespaces/movies'
```


<br/>
***

## Changelog

12/10/15 -- Updated README, new version of GER
8/02/15 -- Updated readme and bumped version

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