Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. Locale loc = new Locale("en", "UK"); //change "en" and "UK" to "de" and "DE" for example to get other number formats.
  2. boolean lineChart = YES // Do u want to see ur stats in a line chart? (Values: YES, NO)
  3.  
  4. //Stop here! End of configuration.
  5.  
  6. @ImportsDefinitionStart
  7. import java.util.Date
  8. import java.text.NumberFormat
  9. import java.text.DateFormat
  10. import org.jfree.chart.ChartFactory
  11. import org.jfree.chart.ChartPanel
  12. import org.jfree.data.category.DefaultCategoryDataset
  13. import org.jfree.chart.plot.PlotOrientation as Orientation
  14. @ImportsDefinitionEnd
  15.  
  16. Connection conn = getDBConn();
  17. Statement statement = conn.createStatement();
  18.  
  19. NumberFormat nf = NumberFormat.getInstance(loc);
  20. DateFormat df = DateFormat.getDateInstance(2, loc);
  21.  
  22. Date dateBis = new Date();
  23. Date dateVon = new Date();
  24. def dataset
  25. if(lineChart)
  26. {
  27. dataset = new DefaultCategoryDataset()
  28. }
  29. long timeVon;
  30. long timeBis;
  31. long timeNow = getRealTime2DBSec(dateBis.getTime());
  32.  
  33. String query = "SELECT COUNT(*), SUM(Metal), SUM(Crystal), SUM(Deuterium) FROM ATTACK_STATS WHERE AttackedInactive=1 AND ";
  34. ResultSet result;
  35.  
  36. printOut "Date\tAttacks\tMetal\tCrystal\tDeuterium\tTotal\t";
  37.  
  38. printOut "-------------------------------------------------------------------------------------------------------------" +
  39. "------------------------------------";
  40.  
  41. if(dateVon.getMonth() != 1)
  42. {
  43. dateVon.setMonth(dateVon.getMonth() - 1);
  44. }
  45. else
  46. {
  47. dateVon.setYear(dateVon.getYear() - 1);
  48. dateVon.setMonth(12);
  49. }
  50. if(dateVon.getHours() < 3)
  51. {
  52. dateVon.setTime(dateVon.getTime() - 24*3600*1000);
  53. }
  54. dateVon.setHours(3);
  55. dateVon.setMinutes(0);
  56. dateVon.setSeconds(0);
  57. dateBis.setTime(dateVon.getTime()+24*3600*1000);
  58.  
  59. int attacksAllOver = 0;
  60. long metalAllOver = 0;
  61. long crystalAllOver = 0;
  62. long deutAllOver = 0;
  63.  
  64. int attacks = 0;
  65. long metal = 0;
  66. long crystal = 0;
  67. long deut = 0;
  68.  
  69. while(timeBis < timeNow)
  70. {
  71. timeVon = getRealTime2DBSec(dateVon.getTime());
  72. timeBis = getRealTime2DBSec(dateBis.getTime());
  73. result = statement.executeQuery(query + "TimeSec >= " + timeVon + " AND TimeSec < " + timeBis);
  74.  
  75. if(result.next())
  76. {
  77. attacks = result.getInt(1);
  78. metal = result.getLong(2);
  79. crystal = result.getLong(3);
  80. deut = result.getLong(4);
  81.  
  82. attacksAllOver += attacks;
  83. metalAllOver += metal;
  84. crystalAllOver += crystal;
  85. deutAllOver += deut;
  86.  
  87. printOut df.format(dateVon) +
  88. "\t" + nf.format(attacks) +
  89. "\t" + nf.format(metal) +
  90. "\t" + nf.format(crystal) +
  91. "\t" + nf.format(deut) +
  92. "\t" + nf.format(metal + crystal + deut);
  93. if(lineChart)
  94. {
  95. dataset.with {
  96. if(timeNow > timeBis)
  97. {
  98. addValue(attacks, "Attacks", dateVon.getDate()+"")
  99. addValue(metal, "Metal", dateVon.getDate()+"")
  100. addValue(crystal, "Crystal", dateVon.getDate()+"")
  101. addValue(deut, "Deuterium", dateVon.getDate()+"")
  102. addValue((long)(metal + crystal + deut), "Total", dateVon.getDate()+"")
  103. //addValue((long)(metal/3 + crystal/2 + deut), "Value(3:2:1)", dateVon.getDate()+"")
  104. }
  105. else
  106. {
  107. addValue(attacks, "Attacks", "T")
  108. addValue(metal, "Metal", "T")
  109. addValue(crystal, "Crystal", "T")
  110. addValue(deut, "Deuterium", "T")
  111. addValue((long)(metal + crystal + deut), "Total", "T")
  112. //addValue((long)(metal/3 + crystal/2 + deut), "Value(3:2:1)", "T")
  113. }
  114. }
  115. }
  116.  
  117. dateBis.setTime(dateBis.getTime()+24*3600*1000);
  118. dateVon.setTime(dateVon.getTime()+24*3600*1000);
  119. }
  120. }
  121.  
  122. printOut "-------------------------------------------------------------------------------------------------------------" +
  123. "------------------------------------";
  124.  
  125. printOut "Total:\t" +
  126. nf.format(attacksAllOver) +
  127. "\t" + nf.format(metalAllOver) +
  128. "\t" + nf.format(crystalAllOver) +
  129. "\t" + nf.format(deutAllOver) +
  130. "\t" + nf.format(metalAllOver + crystalAllOver + deutAllOver);
  131.  
  132. statement.close();
  133. result.close();
  134. closeDBConn(conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement