From 4ef0b60c45e6f4e813e4bbbb641adbf03612adc2 Mon Sep 17 00:00:00 2001 From: CaiHQ Date: Thu, 2 Dec 2021 09:13:49 +0800 Subject: [PATCH] initial commit --- .gitignore | 1 + .idea/.gitignore | 3 + README.md | 6 +- build.gradle | 38 ++++++++++ settings.gradle | 1 + src/main/java/LogParser.java | 140 +++++++++++++++++++++++++++++++++++ src/test/java/PerfTest.java | 11 +++ 7 files changed, 199 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 build.gradle create mode 100644 settings.gradle create mode 100644 src/main/java/LogParser.java create mode 100644 src/test/java/PerfTest.java diff --git a/.gitignore b/.gitignore index 84adb3f..69f49c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # ---> Java # Compiled class file +testinput *.class # Log file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/README.md b/README.md index 7932720..f53fe94 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # PerfCalculator -算绩效,输入两个csv文件,输出每月绩效。 \ No newline at end of file +算绩效,输入两个csv文件,输出每月绩效。 +使用方式一,修改test/java/PefTest的两个测试文件名,执行go。 +使用方式二,运行LogParser.main。输入为俩文件名。 +其中,第一个文件为考勤机导出文件。 +第二个文件为以"姓名 R A"格式的串。 \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..55c1487 --- /dev/null +++ b/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'java' + id 'idea' +} +def currVersion = "1.0.0" +ext.projectIds = ['group': 'com.bdware.perfcalculator', 'version': currVersion] +sourceCompatibility = 1.8 +sourceSets { + main { + java { + srcDir 'src/main/java' + } + resources { + srcDir 'src/main/resources' + } + } + test { + java { + srcDirs 'src/test/java', 'src/test/deploy' + } + resources { + srcDir 'src/test/resources' + } + } +} +dependencies { + implementation 'com.google.code.gson:gson:2.8.8' + implementation 'junit:junit:4.13.1' + testImplementation 'junit:junit:4.13.2' + +} +task copyLibs(type: Copy) { + from configurations.runtimeClasspath + into "./build/libs/" +} +repositories { + mavenCentral() +} diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..57366e9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'PerfCalculator' \ No newline at end of file diff --git a/src/main/java/LogParser.java b/src/main/java/LogParser.java new file mode 100644 index 0000000..fb66512 --- /dev/null +++ b/src/main/java/LogParser.java @@ -0,0 +1,140 @@ + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.*; +import java.util.function.Predicate; + +public class LogParser { + static class User { + int order; + String name; + int wucan = 0; + int jiaotong = 0; + int wancan = 0; + double totalBu = 0; + double R; + double A; + double dur = 0D; + int totalDay = 0; + int missingDay = 0; + public User setName(String name) { + this.name = name.replaceAll("\"", ""); + + return this; + } + + public void calTotalBu() { + totalBu = wucan + jiaotong + wancan + R * 600 + A * 400; + } + + public User setOrder(String order) { + this.order = Integer.valueOf(order.replaceAll("\"", "")); + return this; + } + } + + public static void main(String[] args) { + + if (args.length >= 2) { + new LogParser().go(args[0], args[1]); + + } else{ + System.out.println("usage: java -jar xx.jar ztolog.csv randa.csv"); + } + + } + + public void go(String ztoFile, String randaFile) { + try { + Scanner sc = new Scanner(new FileInputStream(ztoFile)); + sc.nextLine(); + Map user = new HashMap<>(); + for (; sc.hasNextLine(); ) { + String line = sc.nextLine(); + String[] tabs = line.split("\t"); + String date = tabs[5]; + String name = tabs[3]; + name = name.replaceAll("\"", ""); + String from = tabs[9]; + String to = tabs[10]; + String order = tabs[1]; + if (date.contains("2021/12/1")) continue; + + if (!user.containsKey(name)) + user.put(name, new User().setName(name).setOrder(order)); + User u = user.get(name); + u.totalDay++; + if (!to.contains(":") || !from.contains(":")) { + u.missingDay++; + continue; + } + // System.out.println(line); + double dur = calDate(from, to); + u.dur += dur; + int extra = 0; + if (dur >= 6) u.wucan += 25; + if (dur >= 8.5) u.jiaotong += 25; + if (dur >= 12) u.wancan += 35; + System.out.println(String.format("%s\t%s\t%s\t%s\t%.2f", date, name, from, to, dur)); + } + for (Scanner jxsc = new Scanner(new FileInputStream(randaFile)); jxsc.hasNextLine(); ) { + String line = jxsc.nextLine(); + String[] lines = line.split(" "); + if (lines.length < 3) continue; + System.out.println(line); + System.out.println("name--->" + lines[0]); + User u = user.get(lines[0]); + u.R = Double.valueOf(lines[1]); + u.A = Double.valueOf(lines[2]); + } + for (User u : user.values()) { + u.jiaotong += 25 * 5; + u.wucan += 25 * 5; + } + String fil = "0,1,2,3,4,6,14"; + List r = new ArrayList<>(); + r.addAll(user.values()); + r.removeIf(new Predicate() { + @Override + public boolean test(User user) { + return fil.contains(user.order + ""); + } + }); + for (User u : r) { + u.order = findOrder(u.order); + u.calTotalBu(); + } + r.sort(new Comparator() { + @Override + public int compare(User o1, User o2) { + return o1.order - o2.order; + } + }); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + System.out.println(gson.toJson(r)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private int findOrder(int order) { + for (int i = 0; i < map.length; i++) + if (map[i] == order) + return i; + return -1; + } + + static int[] map = new int[]{12, 11, 13, 10, 9, 5, 7, 8}; + + private double calDate(String from, String to) { + String[] froms = from.split(":"); + String[] tos = to.split(":"); + double frommin = Integer.valueOf(froms[0]) * 60 + Integer.valueOf(froms[1]); + double tomin = Integer.valueOf(tos[0]) * 60 + Integer.valueOf(tos[1]); + if (tomin < frommin) tomin += 24 * 60; + return (tomin - frommin) / 60; + } +} diff --git a/src/test/java/PerfTest.java b/src/test/java/PerfTest.java new file mode 100644 index 0000000..5d4a574 --- /dev/null +++ b/src/test/java/PerfTest.java @@ -0,0 +1,11 @@ +import org.junit.Test; + +public class PerfTest { + @Test + public void go(){ + String file = "./testinput/20211201kq.csv"; + String randa = "./testinput/jixiao11.csv"; + + new LogParser().go(file, randa); + } +}