Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Locale loc = new Locale("en", "UK"); //change "en" and "UK" to "de" and "DE" for example to get other number formats.
- boolean lineChart = YES // Do u want to see ur stats in a line chart? (Values: YES, NO)
- //Stop here! End of configuration.
- @ImportsDefinitionStart
- import java.util.Date
- import java.text.NumberFormat
- import java.text.DateFormat
- import org.jfree.chart.ChartFactory
- import org.jfree.chart.ChartPanel
- import org.jfree.data.category.DefaultCategoryDataset
- import org.jfree.chart.plot.PlotOrientation as Orientation
- @ImportsDefinitionEnd
- Connection conn = getDBConn();
- Statement statement = conn.createStatement();
- NumberFormat nf = NumberFormat.getInstance(loc);
- DateFormat df = DateFormat.getDateInstance(2, loc);
- Date dateBis = new Date();
- Date dateVon = new Date();
- def dataset
- if(lineChart)
- {
- dataset = new DefaultCategoryDataset()
- }
- long timeVon;
- long timeBis;
- long timeNow = getRealTime2DBSec(dateBis.getTime());
- String query = "SELECT COUNT(*), SUM(Metal), SUM(Crystal), SUM(Deuterium) FROM ATTACK_STATS WHERE AttackedInactive=1 AND ";
- ResultSet result;
- printOut "Date\tAttacks\tMetal\tCrystal\tDeuterium\tTotal\t";
- printOut "-------------------------------------------------------------------------------------------------------------" +
- "------------------------------------";
- if(dateVon.getMonth() != 1)
- {
- dateVon.setMonth(dateVon.getMonth() - 1);
- }
- else
- {
- dateVon.setYear(dateVon.getYear() - 1);
- dateVon.setMonth(12);
- }
- if(dateVon.getHours() < 3)
- {
- dateVon.setTime(dateVon.getTime() - 24*3600*1000);
- }
- dateVon.setHours(3);
- dateVon.setMinutes(0);
- dateVon.setSeconds(0);
- dateBis.setTime(dateVon.getTime()+24*3600*1000);
- int attacksAllOver = 0;
- long metalAllOver = 0;
- long crystalAllOver = 0;
- long deutAllOver = 0;
- int attacks = 0;
- long metal = 0;
- long crystal = 0;
- long deut = 0;
- while(timeBis < timeNow)
- {
- timeVon = getRealTime2DBSec(dateVon.getTime());
- timeBis = getRealTime2DBSec(dateBis.getTime());
- result = statement.executeQuery(query + "TimeSec >= " + timeVon + " AND TimeSec < " + timeBis);
- if(result.next())
- {
- attacks = result.getInt(1);
- metal = result.getLong(2);
- crystal = result.getLong(3);
- deut = result.getLong(4);
- attacksAllOver += attacks;
- metalAllOver += metal;
- crystalAllOver += crystal;
- deutAllOver += deut;
- printOut df.format(dateVon) +
- "\t" + nf.format(attacks) +
- "\t" + nf.format(metal) +
- "\t" + nf.format(crystal) +
- "\t" + nf.format(deut) +
- "\t" + nf.format(metal + crystal + deut);
- if(lineChart)
- {
- dataset.with {
- if(timeNow > timeBis)
- {
- addValue(attacks, "Attacks", dateVon.getDate()+"")
- addValue(metal, "Metal", dateVon.getDate()+"")
- addValue(crystal, "Crystal", dateVon.getDate()+"")
- addValue(deut, "Deuterium", dateVon.getDate()+"")
- addValue((long)(metal + crystal + deut), "Total", dateVon.getDate()+"")
- //addValue((long)(metal/3 + crystal/2 + deut), "Value(3:2:1)", dateVon.getDate()+"")
- }
- else
- {
- addValue(attacks, "Attacks", "T")
- addValue(metal, "Metal", "T")
- addValue(crystal, "Crystal", "T")
- addValue(deut, "Deuterium", "T")
- addValue((long)(metal + crystal + deut), "Total", "T")
- //addValue((long)(metal/3 + crystal/2 + deut), "Value(3:2:1)", "T")
- }
- }
- }
- dateBis.setTime(dateBis.getTime()+24*3600*1000);
- dateVon.setTime(dateVon.getTime()+24*3600*1000);
- }
- }
- printOut "-------------------------------------------------------------------------------------------------------------" +
- "------------------------------------";
- printOut "Total:\t" +
- nf.format(attacksAllOver) +
- "\t" + nf.format(metalAllOver) +
- "\t" + nf.format(crystalAllOver) +
- "\t" + nf.format(deutAllOver) +
- "\t" + nf.format(metalAllOver + crystalAllOver + deutAllOver);
- statement.close();
- result.close();
- closeDBConn(conn);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement