-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpwinr.java
133 lines (126 loc) · 3.93 KB
/
tpwinr.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package tpwinr;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;
public class TagProAnalyticsWinRateByMap {
public static void main(String[] args) throws IOException {
String s = "";
Scanner sc = new Scanner(System.in);
System.out.println("What is your TagPro name?");
String name = sc.nextLine().replace(" ", "+");
System.out.println("How many pages of your tagpro.eu games would you "
+ "like to check? (1 page = 50 matches, including group matches)");
int j = sc.nextInt(); j++;
sc.nextLine();
do {
System.out.println("Include non-public matches? (y/n)");
s = sc.nextLine();
} while(!s.toLowerCase().equals("y") && !s.toLowerCase().equals("n"));
boolean op = s.toLowerCase().equals("y");
do {
System.out.println("Include matches where you had stats off? (y/n)");
s = sc.nextLine();
} while(!s.toLowerCase().equals("y") && !s.toLowerCase().equals("n"));
boolean so = s.toLowerCase().equals("y");
sc.close();
System.out.println("Reading tagpro.eu data...");
s = "";
for(int i = 1; i < j; i ++){
s = addPage(s, i, name);
}
System.out.println("Done reading data.");
String strs[] = s.split("\\?map\\=");
ArrayList<String> maps = new ArrayList<String>();
ArrayList<Integer> wins = new ArrayList<Integer>();
ArrayList<Integer> games = new ArrayList<Integer>();
int n = 1;
int totalGames = 0;
int totalWins = 0;
String map = " ";
for(String st : strs){
if(op || st.contains("public") && so || st.contains("°")){
if(!map.equals(" ")){
map = st.split(">")[1].split("<")[0];
map = map.substring(0, Math.min(map.length(), 15));
while(map.length() < 16) map = map + " ";
int l = maps.lastIndexOf(map);
if(!map.equals("Death Trap ")){
if(l < 0){
maps.add(map);
wins.add(0);
games.add(1);
totalGames ++;
l = maps.size() - 1;
}
else{
games.set(l, games.get(l) + 1);
totalGames ++;
}
if(st.contains("\u2713<")){
wins.set(l, wins.get(l) + 1);
if(wins.get(l) > n) n ++;
totalWins ++;
}
}
}
map = st.split(">")[st.split(">").length - 1];
}
}
String lines[] = new String[maps.size()];
for(int i = 0; i < maps.size(); i ++){
lines[i] = makeLine(maps.get(i), wins.get(i), games.get(i));
}
System.out.println("Sorting maps...");
Arrays.sort(lines,
new TagProAnalyticsWinRateByMap().new LineComparator());
System.out.println("\nMap \t\tWins Games Win Rate");
System.out.println(makeLine("Total", totalWins, totalGames));
for(String line: lines) System.out.println(line);
}
private static String getUrlSource(String url) throws IOException {
URLConnection page = new URL(url).openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(page.getInputStream(), "UTF-8"));
StringBuilder sb = new StringBuilder();
String inrl = in.readLine();
while (inrl != null){
sb.append(inrl);
inrl = in.readLine();
}
in.close();
return sb.toString();
}
public class LineComparator implements Comparator<String>{
public int compare(String arg0, String arg1) {
int a = Integer.valueOf(arg0.substring(22, 29).trim())
- Integer.valueOf(arg1.substring(22, 29).trim());
if(a > 0) return -1;
if(a < 0) return 1;
return 0;
}
}
public static String makeLine(String m, int w, int g){
String s = m;
while(s.length() < 16) s = s + " ";
s = s + w;
while(s.length() < 22) s = s + " ";
s = s + g;
while(s.length() < 29) s = s + " ";
s = s + (100 * w) / g + "%";
return s;
}
public static String addPage(String s, int i, String name) throws IOException {
try {
return s + getUrlSource("https://tagpro.eu/?search=player&name="
+ name + "&page=" + i);
} catch(Exception e) {
return s;
}
}
}