initial commit
This commit is contained in:
parent
9dc7229aa3
commit
4ef0b60c45
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,6 @@
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
testinput
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
|
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -1,3 +1,7 @@
|
||||
# PerfCalculator
|
||||
|
||||
算绩效,输入两个csv文件,输出每月绩效。
|
||||
算绩效,输入两个csv文件,输出每月绩效。
|
||||
使用方式一,修改test/java/PefTest的两个测试文件名,执行go。
|
||||
使用方式二,运行LogParser.main。输入为俩文件名。
|
||||
其中,第一个文件为考勤机导出文件。
|
||||
第二个文件为以"姓名 R A"格式的串。
|
38
build.gradle
Normal file
38
build.gradle
Normal file
@ -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()
|
||||
}
|
1
settings.gradle
Normal file
1
settings.gradle
Normal file
@ -0,0 +1 @@
|
||||
rootProject.name = 'PerfCalculator'
|
140
src/main/java/LogParser.java
Normal file
140
src/main/java/LogParser.java
Normal file
@ -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<String, User> 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<User> r = new ArrayList<>();
|
||||
r.addAll(user.values());
|
||||
r.removeIf(new Predicate<User>() {
|
||||
@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<User>() {
|
||||
@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;
|
||||
}
|
||||
}
|
11
src/test/java/PerfTest.java
Normal file
11
src/test/java/PerfTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user