手动跑评分

manual-analysis
youys 2 years ago
parent 4b971be282
commit c5c39bb23c

@ -111,7 +111,7 @@
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>4.0.0</version>
<version>7.5.4</version>
</dependency>
</dependencies>

@ -193,7 +193,7 @@ public class SonarService {
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
log.info("projectPath:{},key:{}, result: {}", projectPath, key, executeResp.getOutput());
log.info("projectPath:{},key:{}, result: {}", projectPath, key, executeResp.getStatus() != 0 ? executeResp.getOutput() : "success");
}
/**
@ -258,7 +258,7 @@ public class SonarService {
*/
public void scanExcel(String excelPath) {
int homeworkId = 20230102;
int homeworkId = 20230302;
try {
List<Person> personList = ExcelUtil.readExcel(excelPath);

@ -1,9 +1,12 @@
package net.educoder.ecsonar.task;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.github.junrar.Junrar;
import net.educoder.ecsonar.model.api.Person;
import net.educoder.ecsonar.model.api.SonarRequest;
import net.educoder.ecsonar.services.SonarService;
import net.educoder.ecsonar.utils.RarUtil;
import net.educoder.ecsonar.utils.UrlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@ -42,7 +45,7 @@ public class ReadExcelRunnable implements Runnable{
String path = String.format("/tmp/%d/%s/", homeworkId, uid);
File file = new File(path);
if(!file.exists()){
file.mkdir();
file.mkdirs();
}
// for (Person person : sonarRequest.getPersonList()) {
// String[] split = StringUtils.split(person.getDownloadUrl(), "/");
@ -54,6 +57,10 @@ public class ReadExcelRunnable implements Runnable{
// }
// }
String key = String.format("%d-%s", homeworkId, uid);
if(new File(path + "/.scannerwork/").exists()){
System.out.println(path+ "----exist");
return;
}
log.info("开始调用sonar:{}",key);
sonarService.sonar(path,key);
}
@ -87,76 +94,5 @@ public class ReadExcelRunnable implements Runnable{
}
public static void main(String[] args) {
// unzip();
valid("/tmp/20230102");
}
public static void unzip(){
String sourceDir = "/tmp/20230101";
String targetDir = "/tmp/20230102";
File directory = new File(sourceDir);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
int i=0;
for (File studentDir : studentDirs) {
if (!studentDir.isDirectory()) {
continue;
}
String studentId = studentDir.getName();
String studentTargetDir = targetDir + "/" + studentId;
File[] zipFiles = studentDir.listFiles((dir, name) -> name.endsWith(".zip"));
if (zipFiles == null) {
System.out.println("No zip files found for student: " + studentId);
continue;
}
// if(i++ < 82){
// continue;
// }
for (File zipFile : zipFiles) {
try {
unzip(zipFile.getAbsolutePath(), studentTargetDir);
} catch (Exception e) {
System.out.println("Error occurred while unzipping file: " + zipFile.getName());
e.printStackTrace();
}
}
}
}
private static void unzip(String zipFilePath, String targetDir) throws IOException {
System.out.println(zipFilePath + " to " + targetDir);
ZipUtil.unzip(zipFilePath,targetDir,Charset.forName("GBK"));
}
public static void valid(String path){
File directory = new File(path);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
for (File studentDir : studentDirs) {
if (studentDir.isDirectory()) {
for (File file : studentDir.listFiles()) {
System.out.println(studentDir.getName()+" ->" + file.getName());
}
}
}
}
}

@ -397,8 +397,16 @@ public class ExcelUtil {
Row row = sheet.getRow(i);
String name = row.getCell(0).getStringCellValue();
// String uid;
// try {
// uid = String.valueOf(row.getCell(1).getNumericCellValue());
// }catch (Exception e){
// uid = row.getCell(1).getStringCellValue();
// }
String uid = row.getCell(1).getStringCellValue();
String downloadUrl = row.getCell(2).getStringCellValue();
String downloadUrl = row.getCell(2).getStringCellValue() + "?secret_key=806ac9e5a8b40233c99bb513a315ed66";
Person person = new Person();
person.setName(name);

@ -0,0 +1,161 @@
package net.educoder.ecsonar.utils;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.ZipUtil;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
/**
* @Author: youys
* @Date: 2023/5/19
* @Description:
*/
public class RarUtil {
public static void unrar(String sourceFilePath, String outputDirectory) {
String s = RuntimeUtil.execForStr("unar", sourceFilePath,"-o", outputDirectory);
System.out.println("result====" + s);
}
public static void un7Z(String sourceFilePath, String outputDirectory) {
String s = RuntimeUtil.execForStr("unar", sourceFilePath,"-o", outputDirectory);
System.out.println("result====" + s);
}
public static void main(String[] args) {
// unrar("/tmp/20230301/201905962222/20230519153409_wuiol3vn.rar", "/Users/youyongsheng/Desktop/aa");
un7Z("/tmp/20230301/201905962241/20230519153506_i39sv5p2.7z", "/Users/youyongsheng/Desktop/aa");
// unzip();
// valid("/tmp/20230201");
removeFullCode("/tmp/20230302");
}
public static void unzip(){
String sourceDir = "/tmp/20230301";
String targetDir = "/tmp/20230302";
File directory = new File(sourceDir);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
int i=0;
for (File studentDir : studentDirs) {
if (!studentDir.isDirectory()) {
System.out.println("111--------------------------------");
continue;
}
String studentId = studentDir.getName();
String studentTargetDir = targetDir + "/" + studentId;
File[] zipFiles = studentDir.listFiles();
// File[] zipFiles = studentDir.listFiles((dir, name) -> name.endsWith(".zip"));
// if (zipFiles == null) {
// System.out.println("No zip files found for student: " + studentId);
// continue;
// }
for (File zipFile : zipFiles) {
try {
if(zipFile.getName().endsWith(".zip")){
// unzip(zipFile.getAbsolutePath(), studentTargetDir);
}else if(zipFile.getName().endsWith(".rar")){
System.out.println(zipFile.getAbsolutePath() + " to " + targetDir);
unRar(zipFile.getAbsolutePath(), studentTargetDir);
}else{
System.out.println(zipFile.getAbsolutePath() + " to " + targetDir);
RarUtil.un7Z(zipFile.getAbsolutePath(), studentTargetDir);
}
} catch (Exception e) {
System.out.println("Error occurred while unzipping file: " + zipFile.getName());
}
}
System.out.println("--------------------------------");
}
}
private static void unzip(String zipFilePath, String targetDir) throws IOException {
System.out.println(zipFilePath + " to " + targetDir);
ZipUtil.unzip(zipFilePath,targetDir, Charset.forName("GBK"));
}
private static void unRar(String zipFilePath, String targetDir) throws Exception {
System.out.println(zipFilePath + " to " + targetDir);
RarUtil.unrar(zipFilePath,targetDir);
}
public static void valid(String path){
File directory = new File(path);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
for (File studentDir : studentDirs) {
if (studentDir.isDirectory()) {
for (File file : studentDir.listFiles()) {
System.out.println(studentDir.getName()+" ->" + file.getName());
}
System.out.println("--------------------------------");
}
}
}
public static void removeFullCode(String path){
// 删除完整代码
File directory = new File(path);
File[] studentDirs = directory.listFiles();
if (studentDirs == null) {
System.out.println("No student directories found.");
return;
}
for (File studentDir : studentDirs) {
if (studentDir.isDirectory()) {
String stuNo = studentDir.getName();
File[] files = studentDir.listFiles();
if(files.length == 2){
for (File file : files) {
if (file.getName().contains("完整")) {
System.out.println(stuNo + "==11===" + file.getAbsolutePath());
cn.hutool.core.io.FileUtil.del(file.getAbsolutePath());
}
}
}else if(files.length == 1){
File file = files[0];
File[] files1 = file.listFiles();
if(files1 != null && files1.length == 2){
for (File f : files1) {
if (f.getName().contains("完整")) {
System.out.println(stuNo + "==22===" + f.getAbsolutePath());
FileUtil.del(f.getAbsolutePath());
}
}
}
}
}
}
}
}

Binary file not shown.

@ -68,7 +68,7 @@ public class EcsonarApplicationTests {
CountDownLatch countDownLatch = new CountDownLatch(1);
// String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx";
String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/datattt.xlsx";
String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/111111.xlsx";
sonarService.scanExcel(excelPath);
try {
@ -81,13 +81,13 @@ public class EcsonarApplicationTests {
@Test
public void writeExcel() throws Exception {
int homeworkId = 20230102;
String directory = "/tmp/20230102/";
int homeworkId = 20230202;
String directory = "/tmp/20230202/";
File file = new File(directory);
File[] files = file.listFiles();
System.out.println("学生数:" + files.length);
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx");
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/湘潭大学网络工程专业2023届-原始数据.xlsx");
Map<String, List<Person>> collect = personList.stream().collect(Collectors.groupingBy(Person::getUid));
@ -100,7 +100,7 @@ public class EcsonarApplicationTests {
Metrics metrics = reportService.getMetrics(projectName);
String templatePath = this.getClass().getClassLoader().getResource("template1.xlsx").getPath();
String outPath = "/Users/youyongsheng/Desktop/2222222.xlsx";
String outPath = "/Users/youyongsheng/Desktop/bbbbb.xlsx";
System.out.println("第"+(i++)+"个学生," + uid);
if (CollectionUtils.isEmpty(collect.get(uid))) {
@ -122,4 +122,7 @@ public class EcsonarApplicationTests {
System.out.println("---------end------------");
}
}

Loading…
Cancel
Save