Advertisement
Guest User

TagProAnalyticsWinRateByMap

a guest
Dec 16th, 2016
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.net.URL;
  5. import java.net.URLConnection;
  6. import java.util.ArrayList;
  7. import java.util.Arrays;
  8. import java.util.Scanner;
  9. import java.util.Comparator;
  10.  
  11. public class TagProAnalyticsWinRateByMap {
  12. public static void main(String[] args) throws IOException {
  13. String s = "";
  14. Scanner sc = new Scanner(System.in);
  15. System.out.println("What is your TagPro name?");
  16. String name = sc.nextLine().replace(" ", "+");
  17. System.out.println("How many pages of your tagpro.eu games would you like to check? (1 page = 50 matches, including group matches)");
  18. int j = sc.nextInt(); j++;
  19. System.out.println("Include non-public matches? (true/false)");
  20. boolean op = sc.nextBoolean();
  21. System.out.println("Include matches where you had stats off? (true/false)");
  22. boolean so = sc.nextBoolean();
  23. sc.close();
  24. System.out.println("Reading tagpro.eu data...");
  25. for(int i = 1; i < j; i ++){
  26. s += getUrlSource("https://tagpro.eu/?search=player&name=" + name + "&page=" + i);
  27. }
  28. System.out.println("Done reading data.");
  29. String strs[] = s.split("\\?map\\=");
  30. ArrayList<String> maps = new ArrayList<String>();
  31. ArrayList<Integer> wins = new ArrayList<Integer>();
  32. ArrayList<Integer> games = new ArrayList<Integer>();
  33. int n = 1;
  34. String map = " ";
  35. for(String st : strs){
  36. if(op || st.contains("public") && so || st.contains("°")){
  37. if(!map.equals(" ")){
  38. map = st.split(">")[1].split("<")[0];
  39. map = map.substring(0, Math.min(map.length(), 7));
  40. int l = maps.lastIndexOf(map);
  41. if(l < 0){
  42. maps.add(map);
  43. wins.add(0);
  44. games.add(1);
  45. l = maps.size() - 1;
  46. }
  47. else{
  48. games.set(l, games.get(l) + 1);
  49. }
  50. if(st.contains("✓<")){
  51. wins.set(l, wins.get(l) + 1);
  52. if(wins.get(l) > n) n ++;
  53. }
  54. }
  55. map = st.split(">")[st.split(">").length - 1];
  56. }
  57. }
  58. String lines[] = new String[maps.size()];
  59. for(int i = 0; i < maps.size(); i ++){
  60. lines[i] = maps.get(i) + "\t" + wins.get(i) + "\t" + games.get(i) + "\t" + (100 * wins.get(i)) / games.get(i) + "%";
  61. }
  62. System.out.println("Sorting maps...");
  63. Arrays.sort(lines, new TagProAnalyticsWinRateByMap().new LineComparator());
  64. for(String line: lines) if(!line.substring(0, 7).equals("Death T")) System.out.println(line);
  65. }
  66. private static String getUrlSource(String url) throws IOException {
  67. URL page = new URL(url);
  68. URLConnection yc = page.openConnection();
  69. BufferedReader in = new BufferedReader(new InputStreamReader(
  70. yc.getInputStream(), "UTF-8"));
  71. String inputLine;
  72. StringBuilder a = new StringBuilder();
  73. while ((inputLine = in.readLine()) != null)
  74. a.append(inputLine);
  75. in.close();
  76. return a.toString();
  77. }
  78. public class LineComparator implements Comparator<String>{
  79. public int compare(String arg0, String arg1) {
  80. int a = Integer.valueOf(arg0.split("\t")[2]) - Integer.valueOf(arg1.split("\t")[2]);
  81. if(a > 0) return -1;
  82. if(a < 0) return 1;
  83. return 0;
  84. }
  85. }
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement