Revert "Implement a stat bucket filler tool"

This reverts commit 5e4ff63b9c.
This commit is contained in:
Alexander Meech 2017-11-06 01:20:22 -05:00
parent c188cbea7e
commit 0e95fa3ce7
2 changed files with 6 additions and 212 deletions

View File

@ -1,192 +0,0 @@
package com.mineplex.statconverter;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import com.google.common.io.Files;
import com.mineplex.statconverter.database.mysql.DBPool;
public class BucketFiller
{
private File _info;
private boolean _complete = false;
private List<Integer> _statIds;
private int _nextStat;
private int _nextStartLimit;
public BucketFiller()
{
int stat = 0;
int startLimit = 0;
try
{
if (new File(new File(".").getCanonicalPath() + File.separator + "completeBuckets.dat").exists())
{
return;
}
_info = new File(new File(".").getCanonicalPath() + File.separator + "bucketInfo.dat");
System.out.println(_info.getCanonicalPath());
_statIds = loadStatIds();
if (_statIds.isEmpty() || _statIds == null)
{
return;
}
if (_info.exists())
{
String startStr = Files.readFirstLine(_info, Charset.defaultCharset());
if (startStr != null && !startStr.isEmpty() && startStr.contains(",") && !startStr.endsWith(",") && !startStr.startsWith(","))
{
String[] starts = startStr.split(Pattern.quote(","));
stat = Integer.parseInt(starts[0]);
startLimit = Integer.parseInt(starts[1]);
}
}
else
{
_info.createNewFile();
stat = _statIds.get(0);
Files.write((stat + ",0").getBytes(), _info);
}
_nextStat = stat;
_nextStartLimit = startLimit;
while (!_complete)
{
try
{
convertStat(_nextStat, _nextStartLimit);
}
catch (SQLException | IOException e)
{
e.printStackTrace();
break;
}
}
}
catch (IOException e)
{
e.printStackTrace();
return;
}
}
private List<Integer> loadStatIds()
{
List<Integer> ids = new ArrayList<>();
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection();
PreparedStatement ps = c.prepareStatement("SELECT id FROM stats ORDER BY id DESC;");
ResultSet rs = ps.executeQuery();
)
{
while (rs.next())
{
ids.add(rs.getInt("id"));
}
}
catch (SQLException e)
{
e.printStackTrace();
return null;
}
return ids;
}
private void convertStat(int stat, int start) throws SQLException, IOException
{
System.out.println("[INFO] Starting " + stat + ": " + start + " to " + (start + 9999));
Map<Integer, Long> accounts = new HashMap<>();
try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection())
{
try (Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT accountId, value FROM accountStatsAllTime WHERE statId=" + stat + " LIMIT " + start + ",10000;")
)
{
while (rs.next())
{
accounts.put(rs.getInt("accountId"), rs.getLong("value"));
}
}
if (!accounts.isEmpty())
{
for (Entry<Integer, Long> entry : accounts.entrySet())
{
Long value = entry.getValue();
try (Statement s = c.createStatement())
{
s.execute("UPDATE accountStatsAllTimeBuckets SET playerCount=playerCount+1 WHERE minScore <= " + value + " AND maxScore >= " + value + " AND statId=" + stat + " LIMIT 1;");
}
}
completeStatGroup(stat, start);
}
else
{
try
{
completeStat(stat);
}
catch (IndexOutOfBoundsException ex)
{
complete();
}
}
}
}
private void completeStatGroup(int stat, int start) throws IOException
{
_nextStartLimit = start + 10000;
if (_info.delete())
{
_info.createNewFile();
Files.write((stat + "," + start).getBytes(), _info);
System.out.println("[INFO] Completed " + stat + ": " + start + " to " + (_nextStartLimit - 1));
}
else
{
throw new IOException("Unable to delete info file");
}
}
private void completeStat(int stat) throws IOException, IndexOutOfBoundsException
{
if (_info.delete())
{
_info.createNewFile();
Files.write((stat + "," + 0).getBytes(), _info);
System.out.println("[INFO] Conversion of stat " + stat + " complete");
}
else
{
throw new IOException("Unable to delete info file");
}
_nextStat = _statIds.get(_statIds.indexOf(stat) + 1);
_nextStartLimit = 0;
}
private void complete() throws IOException
{
_complete = true;
System.out.println("[INFO] Conversion of buckets complete");
new File(new File(".").getCanonicalPath() + File.separator + "completeBuckets.dat").createNewFile();
}
}

View File

@ -19,23 +19,9 @@ import com.mineplex.statconverter.database.mysql.DBPool;
public class Main
{
public static void main(String[] args)
{
try
{
if (new File(new File(".").getCanonicalPath() + File.separator + "doBuckets.dat").exists())
{
new BucketFiller();
}
else
{
new Main();
}
}
catch (IOException e)
{
new Main();
}
}
private File _info;
@ -65,7 +51,7 @@ public class Main
else
{
_info.createNewFile();
Files.write(String.valueOf(0).getBytes(), _info);
Files.write("0".getBytes(), _info);
}
_nextStart = start;
@ -181,7 +167,7 @@ public class Main
try
{
_info.createNewFile();
Files.write(String.valueOf(_nextStart).getBytes(), _info);
Files.write((_nextStart + "").getBytes(), _info);
System.out.println("[INFO] Completed " + start + " to " + (_nextStart - 1));
}
catch (IOException e)