danubePrediction - Examples
In the following, an example call and the according return values using the danubePrediction method of a DanubeClient instance are shown.Note: This example assumes the rules have already been set as shown in the setRules example.You can also download and try a set of working demo examples for each danube.ai service using the SDK here:
https://gitlab.com/danube.ai/sdkconst { DanubeClient } = require('danube-sdk');
// Initialize a DanubeClient with your API key.
const danubeClient = new DanubeClient(
'my-api-key',
);
async function runTest() {
const rulesId = 'my-sdk-test-rule-set'; // The id of your saved rules-set.
// Create some example test data and stringify it as a JSON.
const testData = [
{
id: 0,
title: "job-1",
field: "Test/QA",
salaryFrom: 36000,
salaryTo: 50000,
daysAgo: 240,
companyType: "Startup",
jobLevel: "Experienced",
technologies: ["Python", "Java", "C++", "C"],
benefits: ["Flexible working hours", "Team events"]
},
{
id: 1,
title: "job-2",
field: "Software",
salaryFrom: 42000,
salaryTo: 60000,
daysAgo: 100,
companyType: "Established company",
// jobLevel missing --> data may be incomplete
technologies: ["Git", "Docker", "JavaScript"]
// benefits missing --> data may be incomplete
},
];
const stringifiedTestData = JSON.stringify(testData);
// Create some example search data and stringify it as a JSON.
const testSearchData = {
companyType: ["Startup"],
jobLevel: ["Junior", "Experienced"],
technologies: ["SQL", "Java", "Linux"],
benefits: ["Flexible working hours", "Home office"]
};
const stringifiedTestSearchData = JSON.stringify(testSearchData);
// Define initial scores.
const initialScores = [
{property: "salaryFrom", score: 1},
{property: "salaryTo", score: 1},
{property: "daysAgo", score: 0.5}, // might be weighted less important
{property: "companyType", score: 1},
{property: "jobLevel", score: 1},
{property: "technologies", score: 2}, // might be weighted more important
{property: "benefits", score: 1},
];
// Let danube.ai sort your data.
const results = await danubeClient.danubePrediction(
rulesId,
stringifiedTestData,
stringifiedTestSearchData,
initialScores,
'mixed', // strategy
0.75, // mix-factor
1, // impact
);
}
runTest();
// Output results.
console.log(results);
/*
{
newColumnScores: [
{
property: 'salaryFrom',
score: 0.9249125017979084
},
{
property: 'salaryTo',
score: 0.9520168249967466
},
{
property: 'daysAgo',
score: 1.2820712588097503
},
{
property: 'companyType',
score: 0.6732114039806347
},
{
property: 'jobLevel',
score: 1.6026413313951928
},
{
property: 'technologies',
score: 1.1732114039806347
},
{
property: 'benefits',
score: 0.8919352750391324
}
],
rowScores: [ 3.8785199440429987, 3.159000585604405 ],
rowMatches: [
[ 0.8571428571428571, 0.8333333333333334, 0, 1, 0, 1, 0.5 ],
[ 1, 1, 1, 0, 0, 0, 0 ]
]
}
*/