舆情热度计算
舆情热度计算涉及文章发布时间、当前时间、评论量、点赞量以及转发量,通过计算获得两个时间相差的秒数取log,在对评论量、点赞量以及转发量乘以一定权重,可以根据需要适当改变,需要注意的是,对评论量、点赞量以及转发量需要进行处理。
package com.liip.yqjc.action;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.vividsolutions.jts.io.ParseException;
/**
* 文件名:scoreAction
* 创建者: 马九顺
* 创建时间:2022/10/27 17:21
* 描述:计算score
*/
public class scoreAction {
//score
//计算两个时间相差的秒数
public static long getTime(String endTime) throws ParseException, java.text.ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long eTime = 0;
long sTime = 0;
long diff = 0;
Date now = new Date();
String datenow = df.format(now);
if(datenow.length() == 10){
StringBuilder stringBuilder=new StringBuilder(datenow);
stringBuilder.append(" 00:00:00");
}
else{
sTime = df.parse(datenow).getTime();
}
if(endTime.length() == 10){
StringBuilder stringBuilder=new StringBuilder(endTime);
stringBuilder.append(" 00:00:00");
}
else{
eTime = df.parse(endTime).getTime();
}
diff = ((eTime - sTime) / 1000) + 2626560;
return diff;
}
public String yqrdAction(String fbsj, String pll,String dzl, String zfl) throws ParseException, java.text.ParseException {
//保留一个小数点
//String strM = String.format("%.1f",M);
//String strR = String.format("%.1f",R);
//String strD = String.format("%.1f",D);
double m = 0;
double r = 0;
double d = 0;
double t = 0;
double z = 0;
double s = 0;
double s1 = 0;
String str1;
String score;
//将字符串转换为数字
if("".equals(pll) || "null".equals(pll) || "评论".equals(pll)){
m = Double.parseDouble("0");
}
else{
if(pll.substring(pll.length()-1).equals("万")||pll.substring(pll.length()-1).equals("w")){
pll = pll.substring(0, pll.length() - 1);
m = Double.parseDouble(pll)*10000;
}
else{
m = Double.parseDouble(pll);
}
}
if("".equals(dzl) || "null".equals(dzl)){
r = Double.parseDouble("0");
}
else{
if(dzl.substring(dzl.length()-1).equals("万")||dzl.substring(dzl.length()-1).equals("w")){
dzl = dzl.substring(0, dzl.length() - 1);
r = Double.parseDouble(dzl)*10000;
}
else{
r = Double.parseDouble(dzl);
}
}
if("".equals(zfl) || "null".equals(zfl)){
d = Double.parseDouble("0");
}
else{
if(zfl.substring(zfl.length()-1).equals("万")||zfl.substring(zfl.length()-1).equals("w")){
zfl = zfl.substring(0, zfl.length() - 1);
d = Double.parseDouble(zfl)*10000;
}
else{
d = Double.parseDouble(zfl);
}
}
//调用getTime函数计算时间差
t = getTime(fbsj);
if(t<0){
t = 0;
}
z = m*3 + r*1 + d*0.8;
if(z == 0){
s = Math.log10(z+1.00000001) + t/45000;
}
else{
s = Math.log10(z) + t/45000;
}
if(Double.isNaN(s)){
score = "0.0";
}
else{
str1 = String.format("%.1f",s);
score = str1;
}
return score;
}
}