0.0.4 • Published 4 years ago

@amilas/rest.client v0.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

presentation

This library aim is to offer an API to communicate with an amilas-server instance

Some unseful libraries:

installation

npm install @amilas/res.api

examples

2nd degree polynome

import {AmilasContext} from "@amilas/core";
import {AmilasNumberApi} from "@amilas/number.api";
import {AmilasMathApi} from "@amilas/math.api";
import {AmilasBooleanApi} from "@amilas/boolean.api";
import {AmilasRestClient} from "@amilas/rest.client";

// import required symbols
const context = new AmilasContext();
const {number, minus, opposite} = new AmilasNumberApi(context);
const {sqrt} = new AmilasMathApi(context);
const {variable} = new AmilasStdApi(context);

/** 
    configure your model, here:
    f(x) = ax^2 + bx + c
    delta = b^2 - 4ac
    root1 = (-b - sqrt(delta)) / 2a
    root2 = (-b + sqrt(delta)) / 2a 
*/
function buildModel() {
    const a = number(1);
    const b = number(2);
    const c = number(3);
    const x = variable();
    
    const delta = x2(b).minus(times(4, a, c));
    const root1 = opposite(b).minus(sqrt(delta)).divide(a.times(2))
    const root2 = opposite(b).sum(sqrt(delta)).divide(a.times(2))
    const fx = a.times(x2(x)).sum(b.times(x)).sum(c);
    
    const solutionExists = delta.isPositive();

    return {x, fx, solutionExists, root1, root2}
}

function connectClient() {
    const url = '[url]';
    const token = '[my-personal-token]'
    return new AmilasRestClient(url, token);
}

/**
    Use the client connection to solve the problem the model is representing
*/
async function solvePolynome(model, client, a, b, c) {
  
    await client.affect({
        [model.a]: a,
        [model.b]: b,
        [model.c]: c
    });
    
    // eval node
    const resultSolutionExists = await client.eval(model.solutionExists); // true/false
    if(resultSolutionExists == false) throw 'This polynome has no real solution';
  
    const resultRoot1 = await client.eval(model.root1);
    const resultRoot2 = await client.eval(model.root2);
}


const model = buildModel();
const client = connectClient();
await client.load(context);

// solve many polynome you want
solvePolynome(model, client, 1, 2, 3);
solvePolynome(model, client, 12, 32, 1);
solvePolynome(model, client, 2, 22, 9);
0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago