import com.sun.javafx.binding.StringFormatter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
public class Score {
public static void main(String args[]) throws IOException {
Document all=input( "D:/htmlSave/all.html");
Document small=input("D:/htmlSave/small.html");
System.out.println(String.format("%.2f",Calculator(all)));
System.out.println(String.format("%.2f",Calculator(small)));
}
public static Document input(String Html) throws IOException {
//找到本地html文件并导入
File html = new File(Html);
Document doc = Jsoup.parse(html, "UTF-8");
return doc;
}
public static double Calculator(Document file1) throws IOException {
//初始化参数
int before=0;
int base=0;
int test=0;
int program=0;
int add=0;
Properties properties=new Properties();//导入配置文件
properties.load(new FileInputStream("src/total.properties"));
//导入配置文件中的参数
double t_before=Integer.parseInt(properties.getProperty("before"));
double t_base=Integer.parseInt(properties.getProperty("base"));
double t_test=Integer.parseInt(properties.getProperty("test"));
double f_program=Integer.parseInt(properties.getProperty("program"));
double f_add=Integer.parseInt(properties.getProperty("add"));
Elements element=file1.getElementsByAttributeValue("class","interaction-row");//筛选
if(file1!=null){
for(Element e:element){
if (e.child(1).child(0).toString().contains("课前自测")){
if (e.child(1).child(2).toString().contains("color:#8FC31F\"")){
Scanner scanner=new Scanner(e.child(1).child(2).children().get(0).children().get(10).text());
before+=scanner.nextInt();
}
}else if (e.child(1).child(0).toString().contains("课堂完成")){
if (e.child(1).child(2).toString().contains("已参与 ")){
Scanner scanner=new Scanner(e.child(1).child(2).children().get(0).children().get(7).text());
base+=scanner.nextInt();
}
}else if (e.child(1).child(0).toString().contains("课堂小测")){
if (e.child(1).child(2).toString().contains("已参与 ")){
Scanner scanner=new Scanner(e.child(1).child(2).children().get(0).children().get(7).text());
test+=scanner.nextInt();
}
}else if (e.child(1).child(0).toString().contains("编程题")){
if (e.child(1).child(2).toString().contains("已参与 ")){
Scanner scanner=new Scanner(e.child(1).child(2).children().get(0).children().get(7).text());
program+=scanner.nextInt();
}
}else if (e.child(1).child(0).toString().contains("附加题")){
if (e.child(1).child(2).toString().contains("已参与 ")){
Scanner scanner=new Scanner(e.child(1).child(2).children().get(0).children().get(7).text());
add+=scanner.nextInt();
}
}
}
}
//计算总分
double r_before = before / t_before * 100 * 0.25;
double r_base = base / t_base * 100 * 0.3 * 0.95;
double r_test = test / t_test * 100 * 0.2;
double r_program = program / f_program * 100 * 0.1;
double r_add = add / f_add * 100 * 0.05;
double t_score = (r_add + r_base + r_before + r_program + r_test) * 0.9 + 6;
return t_score;
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史