@digital-generation/gen-characteristics
v1.1.2
Published
This library helps people to add characteristics to objects and describe those objects based on their characteristics and the inherited characteristics.
Downloads
24
Readme
gen-characteristics-repository
This project is an API that helps people to add characteristics to objects and describe those objects based on their characteristics and the inherited characteristics.
Use Case
Let's explain it with an example: Imagine you are a food-lover that share your insights about places/food and everything related.
So you describe the food with some attributes such as:
| Attribute | Allowed Values | | --- | --- | | isSpicy | true/false | | stars | 1,2,3,4,5 | | isHealthy | true/false | | cost | cheap. medium, expensive. |
Because some of this attributes/characteristics are shared by the food places you make a hierachy that describes the groups and also the food to save time. So you create a hierachy like this: | Scope | Allowed Values | | --- | --- | | Zone | Fancy Zone, Gym restaurant, Fastfood Foodcourt, Foodtruck, street places.| | Kind of food | Mexican food, Vietnamese food, Fast Food.| | Place | All the places you can imagine|
So each time you want to describe a new food discovery you atached the characterics that are already setted for the Zone, and kind of food that you assign.
Let's say that you discover one of the most incredible "taquerías" in Mexico City. The taquería is called Orinoco (this is really serious even when it's an example) so let's describe it:
| Scope | ScopeInstance | Characteristic | Value | | --- | --- | --- | --- | | Zone | Fancy Zone | cost | expensive | | Kind of food | Mexican food | isHealthy | true | | Kind of food | Mexican food | isSpicy | true | | Place | Taquería Orinoco | stars | 5 | | Place | Taquería Orinoco | isHealthy | false | | Place | Taquería Orinoco | cost | medium |
Know that we know the characteristics of the Place, Kind of food and Zone what's the next step?
Well basically here's the problem.
If we ask for the isHealthy characteristic for: Taquería Orinoco that is a Kind of food: Mexican food, and that is located in a Fancy Zone. What should be the isHealthy value if the Taqueria Orinoco isHealthy characteristic is false but the MexicanFood isHealthy characteristic is true? It's confusing right?
We can use priorities to give high importance to some scope characterics. So let's say that we prioritize in the following way: Place, Kind of food, Zone.
Now we know that the whole characteristics that describe Taquería Orinoco that is a Kind of food: Mexican food, and that is located in a Fancy Zone are:
- stars: 5,
- isHealthy: false
- cost: medium
- ~~cost: expensive~~ * This characteristic is overrided because Place cost has higher priority
- ~~isHealthy: true~~ * This characteristic is overrided because Place isHealthy has higher priority
- isSpicy: true * This is inherited from Mexican Food
This API can help you to manage this kind of use cases.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Prerequisites
Setting database
Let's start with installing all the project dependencies
$ npm install
Run this command with your own parameters
node_modules/.bin/sequelize db:migrate --url [YOUR CONNECTION STRING]
Process Environment variables
You will need to set this variables before running this project:
| Variable Name | Description | |---|---| | DB_USER | User to get acccess to your database. | | DB_PASS | Password to get access to your database. | | DB_NAME | Name of the schema that contains all the model | | DB_ENDPOINT_URL | Endpoint of the mysql server | | NODE_ENV | Use "development" for local purpose | | DB_PORT | Port of the mysql server | | API_PORT | Port where you want to raise this API |
Installing
To include this library into your project use npm
npm install --save gen-characteristics
Usage
const genCharacteristics = require('./src/index');
const example = async () => {
await genCharacteristics.setDatabaseConfig(process.env.DB_USER,
process.env.DB_PASS,
process.env.DB_DATABASE,
{
host: process.env.DB_HOST,
dialect: 'mysql',
logging: false,
});
console.log('setCharacteristicObject', await genCharacteristics.setCharacteristicForObject([
{
scope: 'Country',
characteristic: 'requiredStage',
referenceId: 'sg',
value: 'true',
}]));
console.log('getCharacteristicForObject', await genCharacteristics.getCharacteristicForObject(
{
Country: ['sg'],
Stage: ['2', '3', '4', '11', '12'],
},
['requiredStage'],
));
};
example();