【发布时间】:2016-02-17 12:09:33
【问题描述】:
考虑一个平台,用户可以在其中选择他更重视的因素。例如标准的5个因素A, B, C, D, E
然后每个产品评论都有A1, B1, C1, D1, E1 的权重。所以,如果他更重视A,那么称重会考虑到这一点。结果是每条评论对每个用户都有不同的总体评价。
我的问题是关于算法的。目前处理速度很慢。
对于每个类别摘要,我需要遍历该类别的所有公司,以及每个公司的所有评论。
#1 step
find companies of category X with more than 1 review published
companies_X = [1, 2, 3, 5, n]
#2 step
iterate all companies, and all reviews of these companies
for company in companies:
for review in company:
#calculate the weighing of the review for the current user criteria
#give more importance to recent reviews
#3 step
avg of all reviews for each company data
#4 step
make the avg of all companies of this category to create a final score for the category x
这可行,但我无法加载需要 30 秒才能加载的页面。
我正在考虑缓存此页面,但在这种情况下,我需要在后台为所有用户处理此页面。绝对不是一个好的解决方案。
关于改进的任何想法?欢迎任何见解。
【问题讨论】:
标签: python algorithm performance weighted-average