手动质量分析,本地运行

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

@ -108,7 +108,11 @@
<version>2.6.10</version>
</dependency>
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
<build>

@ -192,7 +192,8 @@ public class SonarService {
"-Dsonar.java.binaries=./ " +
"-Dsonar.projectBaseDir=" + projectPath;
log.info("projectPath:{},key:{}, command: {}", projectPath, key, command);
SystemUtil.executeAndGetExitStatus(command);
SystemUtil.ExecuteResp executeResp = SystemUtil.executeAndGetExitStatus(command);
log.info("projectPath:{},key:{}, result: {}", projectPath, key, executeResp.getOutput());
}
/**
@ -257,7 +258,7 @@ public class SonarService {
*/
public void scanExcel(String excelPath) {
int homeworkId = 20210101;
int homeworkId = 20230102;
try {
List<Person> personList = ExcelUtil.readExcel(excelPath);

@ -1,17 +1,20 @@
package net.educoder.ecsonar.task;
import cn.hutool.core.util.ZipUtil;
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.UrlUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @Author: youys
@ -83,4 +86,77 @@ 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());
}
}
}
}
}

@ -5,10 +5,10 @@
#spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.initSize=20
spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
#spring.datasource.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.master.username=root
spring.datasource.master.password=root
#spring.datasource.master.url=jdbc:postgresql://127.0.0.1:5432/sonar7.7
spring.datasource.master.url=jdbc:postgresql://117.50.14.123:5432/sonar
spring.datasource.master.username=sonar
spring.datasource.master.password=sonar
spring.datasource.master.driverClassName=org.postgresql.Driver
@ -43,8 +43,8 @@ zip.save.path=/tmp/
#excel.template.path=/Users/guange/work/java/ecsonar/src/main/resources/template.xlsx
excel.template.path=template.xlsx
sonar.url=http://127.0.0.1:9000
#sonar.url=http://117.50.14.123:9000
#sonar.url=http://127.0.0.1:9000
sonar.url=http://117.50.14.123:9000
# token令牌
sonar.token=0253a518e824a976ea2f11aec17938cb0f8c0495

@ -67,8 +67,8 @@ public class EcsonarApplicationTests {
public void scanExcel(){
CountDownLatch countDownLatch = new CountDownLatch(1);
String excelPath = "/Users/youyongsheng/Desktop/res.xls";
// String excelPath = "/Users/youyongsheng/Desktop/res-test.xlsx";
// String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.xlsx";
String excelPath = "/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/datattt.xlsx";
sonarService.scanExcel(excelPath);
try {
@ -81,13 +81,13 @@ public class EcsonarApplicationTests {
@Test
public void writeExcel() throws Exception {
int homeworkId = 20210101;
String directory = "/tmp/20210101/";
int homeworkId = 20230102;
String directory = "/tmp/20230102/";
File file = new File(directory);
File[] files = file.listFiles();
System.out.println("学生数:" + files.length);
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/res.xls");
List<Person> personList = ExcelUtil.readExcel("/Users/youyongsheng/Desktop/ZQ/质量分析/2023-05-16/data.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/202100000004.xlsx";
String outPath = "/Users/youyongsheng/Desktop/2222222.xlsx";
System.out.println("第"+(i++)+"个学生," + uid);
if (CollectionUtils.isEmpty(collect.get(uid))) {

Loading…
Cancel
Save