prune: add pretty display
This commit is contained in:
parent
a2cef7f54d
commit
1a596fae73
@ -1,25 +1,32 @@
|
||||
|
||||
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 {
|
||||
public List<User> users;
|
||||
|
||||
public void prettyPrint() {
|
||||
for (LogParser.User u : users) {
|
||||
System.out.println(u.prettyStr());
|
||||
}
|
||||
}
|
||||
|
||||
static class User {
|
||||
int order;
|
||||
String name;
|
||||
int wucan = 0;
|
||||
int jiaotong = 0;
|
||||
int wancan = 0;
|
||||
double totalBu = 0;
|
||||
int totalDay = 0;
|
||||
int validDay = 0;
|
||||
int D = 0;
|
||||
double R;
|
||||
double A;
|
||||
double dur = 0D;
|
||||
int totalDay = 0;
|
||||
int missingDay = 0;
|
||||
|
||||
double totalBu = 0;
|
||||
|
||||
public User setName(String name) {
|
||||
this.name = name.replaceAll("\"", "");
|
||||
|
||||
@ -27,21 +34,27 @@ public class LogParser {
|
||||
}
|
||||
|
||||
public void calTotalBu() {
|
||||
totalBu = wucan + jiaotong + wancan + R * 600 + A * 400;
|
||||
totalBu = wucan + wancan + D * 25 + R * 600 + A * 300;
|
||||
}
|
||||
|
||||
public User setOrder(String order) {
|
||||
this.order = Integer.valueOf(order.replaceAll("\"", ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public String prettyStr() {
|
||||
calTotalBu();
|
||||
return String.format("%s wucan:%d wancan:%d totalDay:%d validDay:%d dur:%.2f D:%d R:%.2f A:%.2f total:%.2f", name, wucan, wancan, totalDay, validDay, dur, D, R, A, totalBu);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length >= 2) {
|
||||
new LogParser().go(args[0], args[1]);
|
||||
|
||||
} else{
|
||||
LogParser logParser = new LogParser();
|
||||
logParser.go(args[0], args[1]);
|
||||
logParser.prettyPrint();
|
||||
} else {
|
||||
System.out.println("usage: java -jar xx.jar ztolog.csv randa.csv");
|
||||
}
|
||||
|
||||
@ -66,15 +79,17 @@ public class LogParser {
|
||||
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 >= 6) {
|
||||
u.validDay++;
|
||||
u.wucan += 25;
|
||||
}
|
||||
if (dur >= 8.5 && getTime(from) <= getTime("09:30")) u.D++;
|
||||
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));
|
||||
}
|
||||
@ -82,42 +97,39 @@ public class LogParser {
|
||||
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>() {
|
||||
users = new ArrayList<>();
|
||||
users.addAll(user.values());
|
||||
users.removeIf(new Predicate<User>() {
|
||||
@Override
|
||||
public boolean test(User user) {
|
||||
return fil.contains(user.order + "");
|
||||
}
|
||||
});
|
||||
for (User u : r) {
|
||||
for (User u : users)
|
||||
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));
|
||||
calculateBu();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateBu() {
|
||||
for (User u : users) {
|
||||
u.calTotalBu();
|
||||
}
|
||||
users.sort(new Comparator<User>() {
|
||||
@Override
|
||||
public int compare(User o1, User o2) {
|
||||
return o1.order - o2.order;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private int findOrder(int order) {
|
||||
for (int i = 0; i < map.length; i++)
|
||||
if (map[i] == order)
|
||||
@ -127,11 +139,14 @@ public class LogParser {
|
||||
|
||||
static int[] map = new int[]{12, 11, 13, 10, 9, 5, 7, 8};
|
||||
|
||||
private double getTime(String hourAndmin) {
|
||||
String[] s = hourAndmin.split(":");
|
||||
return Integer.valueOf(s[0]) * 60 + Integer.valueOf(s[1]);
|
||||
}
|
||||
|
||||
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]);
|
||||
double frommin = getTime(from);
|
||||
double tomin = getTime(to);
|
||||
if (tomin < frommin) tomin += 24 * 60;
|
||||
return (tomin - frommin) / 60;
|
||||
}
|
||||
|
@ -2,10 +2,23 @@ import org.junit.Test;
|
||||
|
||||
public class PerfTest {
|
||||
@Test
|
||||
public void go(){
|
||||
public void go() {
|
||||
String file = "./testinput/20211201kq.csv";
|
||||
String randa = "./testinput/jixiao11.csv";
|
||||
LogParser parser = new LogParser();
|
||||
parser.go(file, randa);
|
||||
add11Extra(parser);
|
||||
parser.prettyPrint();
|
||||
}
|
||||
|
||||
new LogParser().go(file, randa);
|
||||
public void add11Extra(LogParser log) {
|
||||
for (LogParser.User u : log.users) {
|
||||
u.D += 5;
|
||||
u.wucan += 25 * 5;
|
||||
u.dur += 45;
|
||||
u.validDay += 5;
|
||||
u.totalDay += 5;
|
||||
}
|
||||
log.calculateBu();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user