guanxi app 's changelog from francis
date: 2013-4-3
commend#index
支持基于 sql 的无限翻页- 重新定义智能推荐逻辑
- 定义活跃度算法
- 定义了定时任务用于更新智能推荐和活跃用户
- 提高了推荐模块的执行性能
user
fields:
gps [x,y]
:login_time, type: string
attr
:distance
:distance_range #0..100, 100..500, 500..1000, 1000..5000
set commend user must logintime less than 2.hours
# GxUser.only([:UserID, :GuanxiID, :UserName]).limit(1).first
GxUser.limit(10).collect{|u| st_time= Time.now;u.users_similar(u,[1]).only(:UserID).limit(200).entries.count;puts "take #{Time.now - st_time}'s"}
take 0.254902492's
take 0.293922163's
take 0.279348809's
take 0.284525304's
take 0.074807277's
take 0.05721699
首先需要用户通过 server check if user exists?
if user exists?
unless user exists?
handle authorize callback
if has state with {new_user: true} then create new and navgiter to welcome page
else then navgiter to use main page
例如, 我们的 自动消息(回复人数)的统计, 关系表情(新旧版本兼容)
关系表情(新旧版本兼容)流程类似
这里 state 如同一个令牌在两个点间传递, 最终回到 sender 这里有个难点需要 state 的托管人知道这是一个 托管参数, 并且在 处理流程回到 sender 并且原样传回 state
remove at 2013-3-19
date 2014-02-20:
要推前一日优质用户和新注册的活跃用户
对于老用户则按照关系度推荐用户
对于新用户则选取一定(200 个有相同 Hobbys and Lookfor 的)相关用户(计算静态关系分)来按照关系度推荐
尽量采用局部更新 relation score(当天有 action 的用户) 和 commend users(当天有 action 的用户), 以减少数据库压力
按照 desc(:commend_index, :relation_score)
排序,其中 commend_index
为优质用户(20
) 新用户(5
) 高关系分(0
)
以一个新注册用户开始:
static_relation_score
(对于新用户静态关系分也就是关系分) 存储在表 commend_users
create user account(assume called A), pick up 100 user (which has same
hobby or lookfor) caluate the static_relation_score
(for new user same as relation score) store in to table commend_users
commend_users
返回推荐的用户
when user A navigate to 智能推荐, refer the commend_users
and return commend userscommend_users
中推荐的(100)个用户 以及
随机的 100
优质用户(不足则以活跃新用户代替)计算与 A 的关系分存到数据库
(after 1 day) caluate the A's relation score on backend queue, collect the commend users(100) in commend_users
and top random 100 recommend_users (or activly newer as instead) caluate relation score and caluate relation score with A store in dbgenerate user's commend_users, for new user who first time visit referred
, or user who have some trouble on update commend_users task (can also alise new user commend, main handle method name UserCommendable#generate_commend_users
and UserCommendable#generate_statis_commend_users
)
生成用户的智能推荐, 适用于新用户第一次访问 referred
, 或者在更新用户智能推荐的时候发生故障
update user's commend_users (can also alise old user commend, main handle method named generate_commend_user#update_commend_user
)
更新用户的智能推荐
:relation_score
as desc
) but exclude friends(100..150)
高关系用户非朋友:active_score
as desc
and equal slice 100 length but choose each chunk's first 10) (0..100)
优质用户(or activly newer)date 2014-02-20:
grade_score
today and whose level greater than 1 (GxGradeScoreDaily.daily_speedup_rank
), and split to male_recommend_user_ids
and female_recommend_user_ids
.1
): f:m = 8:7
male(0
): f:m = 6:9daily_speedup_rank
matched use GxUser.active_new_users
insteadGxCommendUser.try_new_user_recommend_for(user)
else call repair_commend_users for current_userGxCommendUser#launch_recommend_for_new_user(user_arg)
)launch_recommend_for_new_user
1 times during 1 dayssome tips
智能推荐用户组成:
当天与用户非好友并且关系分最高的前 `100..150` 个用户
优质用户
优质用户组成:
美女帅哥
活跃新用户组成:
当天注册的活跃新用户
关系用户集合(可以理解为与用户有关系的用户的集合)组成:
有相互访问, 并且在 nearby 列表中的用户
更新 智能推荐 添加的时候插入的活跃用户
class GxRelationScore
include Mongoid::Document
include Mongoid::Timestamps
store_in session: "gxrecommend"
# field :userids, type: String
# field :user_ids, type: Array
# 约定 较小的为 user_id, 较大的为 relation_user_id
field :user_id, type: String
field :relation_user_id, type: String
# ...
field :score, type: Float #总分
field :bak_score, type: Float #备份分数,用于分数更新
field :last_update_time, type: Time, default: -> { Time.now }
index({user_id: 1, relation_user_id: 1}, {background: true})
index({user_id: 1, be_friends: 1, score: -1}, {background: true})
index({relation_user_id: 1, be_friends: 1, score: -1}, {background: true})
index({ updated_at: 1 }, { expire_after_seconds: 3 * 24 * 3600, background: true })
end
RelationScoreable#get_relation_users
desc(:commend_index, :relation_score)
CommendCalculate#quickly_commend_users
will fetch all commend_user_ids exists in collection gx_commend_usersLogintime
(mean user who opend us app)
更新范围date: 2013-3-8
date: 2013-4-8