feat(加入docker-java): 加入docker-java

This commit is contained in:
ovo 2024-12-27 16:07:04 +08:00
parent 9afa1cb1c4
commit 45b2eea3d2
3 changed files with 232 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,117 @@
package com.guwan.backend;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class ScoreProcessor {
public static void main(String[] args) {
String inputFilePath = "D:\\00_桌面\\今日识别.txt"; // 输入日志文件路径
List<Double> scores = extractScoresFromFile(inputFilePath); // 提取分数
// 将分数 * 100
List<Integer> scaledScores = scaleScores(scores);
// 计算平均分最高分最低分
double averageScore = calculateAverage(scaledScores);
int maxScore = Collections.max(scaledScores);
int minScore = Collections.min(scaledScores);
// 计算每10分区间的出现概率
Map<String, Integer> scoreDistribution = calculateScoreDistribution(scaledScores);
System.out.println("今日总次数:"+scaledScores.size());
// 输出结果
System.out.println("平均分: " + averageScore);
System.out.println("最高分: " + maxScore);
System.out.println("最低分: " + minScore);
System.out.println("每10分区间的出现概率");
for (Map.Entry<String, Integer> entry : scoreDistribution.entrySet()) {
String formattedProbability = String.format("%.3f", entry.getValue() / (double) scaledScores.size());
System.out.println(entry.getKey() + ": " + Double.parseDouble(formattedProbability) * 100 + "%");
}
}
/**
* 从日志文件中提取分数
*
* @param filePath 文件路径
* @return 提取的分数列表
*/
public static List<Double> extractScoresFromFile(String filePath) {
List<Double> scores = new ArrayList<>();
String pattern = "本次识别分数:([0-9]+\\.[0-9]+)"; // 匹配分数的正则表达式
try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
String line;
Pattern r = Pattern.compile(pattern);
while ((line = reader.readLine()) != null) {
Matcher m = r.matcher(line);
if (m.find()) {
scores.add(Double.parseDouble(m.group(1))); // 提取分数并添加到列表
}
}
} catch (IOException e) {
e.printStackTrace();
}
return scores;
}
/**
* 将分数乘以 100
*
* @param scores 原始分数列表
* @return 乘以 100 后的分数列表
*/
public static List<Integer> scaleScores(List<Double> scores) {
List<Integer> scaledScores = new ArrayList<>();
for (Double score : scores) {
scaledScores.add((int) (score * 100)); // 乘以 100 后转为整数
}
return scaledScores;
}
/**
* 计算平均分
*
* @param scores 分数列表
* @return 平均分
*/
public static double calculateAverage(List<Integer> scores) {
double sum = 0;
for (int score : scores) {
sum += score;
}
return sum / scores.size();
}
/**
* 计算每10分区间的出现次数
*
* @param scores 分数列表
* @return 每10分区间的出现次数
*/
public static Map<String, Integer> calculateScoreDistribution(List<Integer> scores) {
Map<String, Integer> distribution = new HashMap<>();
for (int score : scores) {
int rangeStart = (score / 10) * 10; // 计算所在的区间
int rangeEnd = rangeStart + 9;
// 生成区间字符串
String range = rangeStart + "-" + rangeEnd;
// 记录每个区间的出现次数
distribution.put(range, distribution.getOrDefault(range, 0) + 1);
}
return distribution;
}
}

View File

@ -0,0 +1,60 @@
package com.guwan.backend;
import java.io.*;
import java.util.*;
public class TxtFilter {
public static void main(String[] args) {
// 输入文件路径和输出文件路径
String inputFilePath = "D:\\00_桌面\\logback_error.log";
String outputFilePath = "D:\\00_桌面\\a.txt";
// 调用方法获取只包含 "本次识别分数" 的行
List<String> filteredLines = filterLinesContainingScore(inputFilePath);
// 将筛选后的行写入新文件
writeToFile(filteredLines, outputFilePath);
// 输出筛选的行可选
filteredLines.forEach(System.out::println);
}
/**
* 读取文件并过滤出包含本次识别分数字符串的行
*
* @param inputFilePath 输入文件路径
* @return 只包含本次识别分数字符串的行列表
*/
public static List<String> filterLinesContainingScore(String inputFilePath) {
List<String> result = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(inputFilePath))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("本次识别分数")) { // 检查行是否包含目标字符串
result.add(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
/**
* 将筛选后的行写入文件
*
* @param lines 要写入的行列表
* @param outputFilePath 输出文件路径
*/
public static void writeToFile(List<String> lines, String outputFilePath) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath))) {
for (String line : lines) {
writer.write(line);
writer.newLine(); // 写入换行符
}
} catch (IOException e) {
e.printStackTrace();
}
}
}