import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.Scanner;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Score{
public static void main(String[] args) throws Exception {
//读取配置文件--total.properties
Properties p =new Properties();
p.load(new FileInputStream("total.properties"));
//获取配置文件中各个元素的值
double proBefore = Double.parseDouble(p.getProperty("before"));
double proBase = Double.parseDouble(p.getProperty("base"));
double proTest = Double.parseDouble(p.getProperty("test"));
double proProgram = Double.parseDouble(p.getProperty("program"));
double proAdd = Double.parseDouble(p.getProperty("add"));
//Jsoup解析small.html和all.html
Document document1 = Jsoup.parse(new File("src/small.html"), "utf-8");
Document document2 = Jsoup.parse(new File("src/all.html"), "utf-8");
double htmlBefore=0,htmlBase=0,htmlProgram=0,htmlAdd=0,htmlTest=0;
//计算small.html中获得的经验
if (document1 != null) {
Elements small = document1.getElementsByAttributeValue("class", "interaction-row");
int temp;
for (int i = 0; i < small.size(); i++) {
if (small.get(i).child(1).child(0).toString().contains("课堂完成部分")) {
if (small.get(i).child(1).child(2).toString().contains("已参与 ")) {
Scanner scanner1 = new Scanner(small.get(i).child(1).child(2).children().get(0).children().get(7).text());
temp = scanner1.nextInt();
htmlBefore = htmlBefore + temp;
scanner1.close();
}
} else if (small.get(i).child(1).child(0).toString().contains("课堂小测")) {
if (small.get(i).child(1).child(2).toString().contains("已参与 ")) {
Scanner scanner1 = new Scanner(
small.get(i).child(1).child(2).children().get(0).children().get(7).text());
temp = scanner1.nextInt();
htmlTest = htmlTest + temp;
scanner1.close();
}
} else if (small.get(i).child(1).child(0).toString().contains("编程题")) {
if (small.get(i).child(1).child(2).toString().contains("已参与 ")) {
Scanner scanner1 = new Scanner(
small.get(i).child(1).child(2).children().get(0).children().get(7).text());
temp = scanner1.nextInt();
htmlProgram = htmlProgram + temp;
scanner1.close();
}
} else if (small.get(i).child(1).child(0).toString().contains("附加题")) {
if (small.get(i).child(1).child(2).toString().contains("已参与 ")) {
Scanner scanner1 = new Scanner(
small.get(i).child(1).child(2).children().get(0).children().get(7).text());
temp = scanner1.nextInt();
htmlAdd = htmlAdd + temp;
scanner1.close();
}
} else if (small.get(i).child(1).child(0).toString().contains("课前自测"))
if (small.get(i).child(1).child(2).toString().contains("color:#8FC31F")) {
Scanner scanner1 = new Scanner(
small.get(i).child(1).child(2).children().get(0).children().get(10).text());
temp = scanner1.nextInt();
htmlBefore = htmlBefore + temp;
scanner1.close();
}
}
}
//计算all.html中获得的经验
if (document2 != null) {
Elements all = document2.getElementsByAttributeValue("class", "interaction-row");
int temp1;
for (int i = 0; i < all.size(); i++)
if (all.get(i).child(1).child(0).toString().contains("课前自测"))
if (all.get(i).child(1).child(2).toString().contains("color:#8FC31F")) {
Scanner scanner2 = new Scanner(
all.get(i).child(1).child(2).children().get(0).children().get(10).text());
temp1 = scanner2.nextInt();
htmlBefore = htmlBefore + temp1;
scanner2.close();
}
}
//计算总得分
double finBefore = htmlBefore/proBefore*0.25*100;
double finBase = htmlBase/proBase*0.3*0.95*100;
double finTest = htmlTest/proTest*0.2*100;
proProgram=95;
double finProgram = htmlProgram/proProgram*0.1*100;
proAdd=90;
double finAdd = htmlAdd/proAdd*0.05*100;
double total=finBefore+finBase+finTest+finProgram+finAdd;
System.out.println(String.format("%.2f",total));
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史