javascript 属性和基于事件的评分

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 属性和基于事件的评分相关的知识,希望对你有一定的参考价值。

//Create an array of all the points we give
const scores = [];

//Helper method to push to the scores array.
const addToScore = points => points && scores.push(points);


//Scoring based on User Attributes.
const {
  is_beta,
  is_invited,
  trial_expired,
  embed_code_installed,
  trial_length,
  totalcustomproperties,
  account_domains,
  total_flows,
} = user.traits;

if (is_beta === true) addToScore(3);
if (trial_expired === true) addToScore(-1);
if (embed_code_installed === true) addToScore(8);
if (trial_length && trial_length > 14) addToScore(3);
if (is_invited === true) addToScore(5);
if (account_domains.length === 1) addToScore(-1);
if (total_flows) {
  if (total_flows >= 5) {
    addToScore(total_flows*15)
  } else if (total_flows >= 3) {
    addToScore(total_flows*5);
  } else {
    addToScore(total_flows*2);
  }
}


//compute total score based on attribute from scratch,
//and save as an attribute.
if(scores.length>0) {
  const total = _.sum(scores);
  hull.traits({
    attribute_score: total
  });
}


//Scoring based on User Events

//Another way to do so, just use a number...
const event_score = 0;

//Loop over every event
events.map(e => {
  const { event, properties, context } = e // event: "Email Opened"
  if (event === "Email Opened") event_score += 2;
  if (event === "Requested Demo" && properties.optin===true) event_score += 3;
});


// Take care. Here we INCREMENT the score instead of resetting it...
// We do this with the {operation: "inc", value:xxx} hash
// And we do it because the Processor does NOT go over every event,
// But rather only over the NEW events when it runs.
if (event_score!==0) {
  hull.traits({
    event_score: { operation: "inc", value: event_score }
  })
}

以上是关于javascript 属性和基于事件的评分的主要内容,如果未能解决你的问题,请参考以下文章

基于商品属性的相似商品推荐算法——推荐与评分高的商品属性相似的商品

基于规则评分的密码强度检测算法分析及实现(JavaScript)

Javascript设置特殊属性

干货之运用CALayer创建星级评分组件(五角星)

JavaScript的事件

将事件和模型属性从视图传递到 javascript 函数