Ai
1 Star 0 Fork 0

keeplooking/personal

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Score.java 5.97 KB
一键复制 编辑 原始数据 按行查看 历史
import java.io.File;
import java.io.FileInputStream;
import java.util.Enumeration;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class Score {
/**
* before:课前自测
* base:课堂完成
* test:课堂小测
* program:编程题
* add:附加题
*/
//定义自己每一部分的经验变量并设置初始值
static int before = 0;
static int base = 0;
static int test = 0;
static int program = 0;
static int add = 0;
//定义云班课的经验值变量
static int allBefore = 0;
static int allBase = 0;
static int allTest = 0;
static int allProgram = 0;
static int allAdd = 0;
public static void main(String[] args){
//调用配置文件获取每一部分的总经验值信息
try {
Properties pps = new Properties();
pps.load(new FileInputStream("config/total.properties"));
Enumeration fileName = pps.propertyNames();
allBefore = Integer.parseInt(pps.getProperty("before"));
allBase = Integer.parseInt(pps.getProperty("base"));
allTest = Integer.parseInt(pps.getProperty("test"));
allProgram = Integer.parseInt(pps.getProperty("program"));
allAdd = Integer.parseInt(pps.getProperty("add"));
}catch(Exception e) {
e.printStackTrace();
}
try {
/**
* 功能:使用jsoup来解析html文件从而获取我的经验值信息
*/
Document document = Jsoup.parse(new File(args[0]),"utf-8");
Document document2 = Jsoup.parse(new File(args[1]),"utf-8");
small_Class(document);
//大班课经验
big_Class(document2);
//计算分数规则
System.out.println(Score());
}catch(Exception e) {
e.printStackTrace();
}
//小班课经验
}
public static void small_Class(Document document) {
//解析html文件
try {
// Document document = Jsoup.parse(new File("small.htm"), "utf-8");
/**
* 功能:
* 提取小班课的经验值
* 参数:
* classs_Length:活动的个数
* section:选取某个活动
* section_Name:每个活动的名字。(课前自测,课堂小测,课堂完成,编程题,附加题)
* experiences:我获得的经验值
* sum:每个活动经验值和互评经验值之和
* attend:读出或读不出“已参与”
* isAttend:判断是否已参与
*/
int classs_Length = document.select("div[class = interaction-row]").size();
/*
* 注意:活动排序是页面上从上到下的顺序
*/
for(int i=0;i<classs_Length;i++) {
Element section = document.select("div[class = interaction-row]").get(i);
String section_Name = section.select("span.interaction-name").text();
String attend = section.select("span[style='color:#8FC31F']").text();
Boolean isAttend = attend.contains("已参与");
if(section_Name.contains("课堂小测") && isAttend == true) {
//通过正则表达式,将“经验值”和“互评经验值”按一定的规则解析相加
String experiences = section.select("span[style='color:#8FC31F;']").text();
String regex = "\\d+";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(experiences);
int sum = 0;
while(matcher.find()) {
sum += str_Num(matcher.group());
}
test += sum;
}
if(section_Name.contains("课堂完成") && isAttend == true) {
String experiences = section.select("span[style='color:#8FC31F;']").text();
base += str_Num(experiences);
}
if(section_Name.contains("编程题") && isAttend == true) {
String experiences = section.select("span[style='color:#8FC31F;']").text();
program += str_Num(experiences);
}
if(section_Name.contains("附加题") && isAttend == true) {
String experiences = section.select("span[style='color:#8FC31F;']").text();
add += str_Num(experiences);
}
if(section_Name.contains("课前自测") && isAttend == true) {
String experiences = section.select("span[style='color:#8FC31F;']").text();
before += str_Num(experiences);
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
public static void big_Class(Document document2){
try{
/**
* 功能:
* 提取大班课的经验
* 参数:
* classs_Length2:活动的个数
* section2:获取某个活动
* section_Name2:每个活动的名字。(课前自测,课堂小测,课堂完成,编程题,附加题)
* ex2:我获得的经验值
* attend2:读出或读不出“已参与”
* isAttend2:判断是否已参与
*/
int classs_Length2 = document2.select("div[class = interaction-row]").size();
for(int i=0;i<classs_Length2;i++) {
Element section2 = document2.select("div[class = interaction-row]").get(i);
String section_Name2 = section2.select("span.interaction-name").text();
String attend = section2.select("span[style='color:#8FC31F']").text();
Boolean isAttend = attend.contains("已参与");
if(section_Name2.contains("课前自测") ) {
String ex = section2.select("span[style='color:#8FC31F;']").text();
before += str_Num(ex);
}
}
}catch(Exception e) {
e.printStackTrace();
}
}
//将字符串中的数字提取出来。
public static int str_Num(String str) {
String str2="";
if(str != null && !"".equals(str)){
for(int i=0;i<str.length();i++)
if(str.charAt(i)>=48 && str.charAt(i)<=57)
str2+=str.charAt(i);
}
int str3 = Integer.parseInt(str2);
return str3;
}
public static double Score(){
/**
* 功能:定义分数计算规则
*/
//经验值换算百分制成绩
double before0 = before*1.0/allBefore*100;
double test0 = test*1.0/allTest*100;
double base0 = base*1.0/allBase*100*0.95;
double program0 = program*1.0/allProgram*100;
if(program0>95) {
program0 = 95.0;
}
double add0 = add*1.0/allAdd*100;
if(add0>90) {
add0 = 90.0;
}
double score = base0*0.3+test0*0.2+before0*0.25+program0*0.1+add0*0.05 + 6;
return score;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/keep-looking/personal.git
git@gitee.com:keep-looking/personal.git
keep-looking
personal
personal
master

搜索帮助