Installation and usage instructions:
1. Add recommender.js to any page or all pages in your web application
2. Add special datasets to the elements you want recommended:
anything here
- data-recommenderattributes: Comma delimited whole numbers. Each number links elements to each other.
- data-recommendertable: Table name where the data will be stored in IDB.
- data-recommenderid: A unique id for each element.
3. To access the recommendations, call the following method on page load
(new Recommender()).getData("data-recommendertable", yourFunction);
- The "data-recommendertable" is the name of your recommender enabled element table
- yourFunction is your callback function. You'll receive an array containing your
results in index 0 and an object with the data formatted in index 1, as shown below.
function yourFunction(arrayFromRecommender) {
// [id1, id2, id3, etc...] order by highest to lowest score
const orderedArrayOfRecommendedElementIds
= arrayFromRecommender[0];
/**
* Example of data in object
* {
* id1: {
* attributes: ['1','2', ...], recommenderattributes in element
* datapoints: [1640705016252, 1640705016253, ...], timestamps when element was clicked
* degree: 3, nth number
* occurence: 1, nth number
* related: ['id2', 'id3'] elements with the same recommenderattributes
* }
*}
*/
const orderedObjectOfRecommendedElementData
= arrayFromRecommender[1];
}
*You can see the results and data for this page by viewing the Console under Inspect in your browser
4. To save data on click of a recommender enabled element, and then get back the newly recommended results, use the following code snippet.
document.addEventListener('click', (event) => {
if (event.target && event.target.hasAttribute("data-recommendertable")) {
(new Recommender()).saveAndGetData(event, yourFunction);
}
});
*saveAndGetData will return the same data as in getData.
5. To delete a table of data, call the following method
(new Recommender()).deleteData("data-recommendertable", yourFunction);