Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
b845c3f0
Commit
b845c3f0
authored
Jul 30, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
排序落库
parent
ca40b021
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
13 deletions
+6
-13
ThemeAnalysDO.java
.../java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
+2
-7
TopicRankQo.java
...in/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
+1
-3
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+3
-3
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeAnalysDO.java
View file @
b845c3f0
...
...
@@ -49,18 +49,13 @@ public class ThemeAnalysDO {
@ApiModelProperty
(
value
=
"用户质量"
)
private
Double
userWeight
=
0.0
;
private
Double
score
;
public
Double
calcScore
()
{
public
Double
getRank
()
{
// 质量=帖子质量+用户质量
double
w
=
(
double
)
(
viewCount
*
0.1
+
forwardCount
*
3
+
commentCount
*
2
+
likeCount
*
1
+
collectCount
*
3
)
+
userWeight
;
double
i
=
1
;
//初试权重
double
t
=
Double
.
valueOf
(
minuteTillNow
)
/
60
;
double
g
=
0.1
;
//时间系数
double
rank
=
(
w
+
i
)
/
Math
.
pow
(
t
+
1
,
g
);
this
.
score
=
score
;
return
rank
;
return
(
w
+
i
)
/
Math
.
pow
(
t
+
1
,
g
);
}
}
community-api/src/main/java/com/tanpu/community/api/beans/qo/TopicRankQo.java
View file @
b845c3f0
...
...
@@ -40,21 +40,19 @@ public class TopicRankQo {
private
Integer
hoursTillNow
;
private
Double
score
;
/**
* 热度计算算法
*
* @return
*/
public
Double
get
Rank
()
{
public
Double
get
Score
()
{
double
g
=
0.3
;
//时间系数
//顶置话题
if
(
isTop
>
0
)
{
return
Double
.
MAX_VALUE
;
}
Double
socre
=
((
disscussCount
*
3
+
viewCount
)
/
Math
.
pow
(
hoursTillNow
+
1
,
g
))
+
themeWeight
;
this
.
score
=
socre
;
return
socre
;
}
}
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
b845c3f0
...
...
@@ -96,7 +96,7 @@ public class RankService {
}
}
//打分
Map
<
ThemeAnalysDO
,
Double
>
map
=
themeAnalysDOS
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
ThemeAnalysDO:
:
calcScore
));
Map
<
ThemeAnalysDO
,
Double
>
map
=
themeAnalysDOS
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
ThemeAnalysDO:
:
getRank
));
//排序
hotestThemes
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
...
...
@@ -139,14 +139,14 @@ public class RankService {
topic
.
setDisscussCount
(
themeIds
.
size
()
+
commentCount
);
//帖子权重,求和
double
themeSum
=
getHotestThemes
().
stream
().
filter
(
o
->
topic
.
getTopicId
().
equals
(
o
.
getTopicId
()))
.
mapToDouble
(
ThemeAnalysDO:
:
calcScore
)
.
mapToDouble
(
ThemeAnalysDO:
:
getRank
)
.
sum
();
topic
.
setThemeWeight
(
themeSum
);
//格式化浏览量、讨论量
topic
.
setFormatViewCount
(
BizUtils
.
formatCountNumber
(
topic
.
getViewCount
()));
topic
.
setFormatDisscussCount
(
BizUtils
.
formatCountNumber
(
topic
.
getDisscussCount
()));
}
Map
<
TopicRankQo
,
Double
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
get
Rank
));
Map
<
TopicRankQo
,
Double
>
map
=
topicRankQos
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
TopicRankQo:
:
get
Score
));
List
<
TopicRankQo
>
rankList
=
map
.
entrySet
().
stream
()
.
sorted
(
Map
.
Entry
.
comparingByValue
(
Comparator
.
reverseOrder
()))
.
map
(
Map
.
Entry
::
getKey
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment