Created
April 30, 2012 22:17
-
-
Save wedtm/2563138 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public float[] calculateRank(Server server) { | |
float rank = 10.0f; | |
Jedis jedis = // REDACTED SERVER SPECIFIC | |
List<String> checks_json = // REDACTED SERVER SPECIFIC | |
App.pool.returnResource(jedis); | |
float good = 0; | |
float total = checks_json.size(); | |
for(String check : checks_json) { | |
Result res = gson.fromJson(check, Result.class); | |
if(res.result == true) | |
{ | |
good++; | |
} | |
} | |
boolean premium = Boolean.parseBoolean(serverObj.get("premium").toString()); | |
boolean perm_premium = Boolean.parseBoolean(serverObj.get("perm_premium").toString()); | |
float percentage = good / total; | |
rank = rank * percentage; | |
if (premium == false && perm_premium == true) { | |
premium = true; | |
} | |
int votes = 0; | |
if (serverObj.containsField("votes")) { | |
try { | |
votes = Integer.parseInt(serverObj.get("votes").toString()); | |
rank = (float) (rank + (votes * 0.001)); | |
} catch (NumberFormatException ex) { | |
} | |
} | |
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); | |
Date c = null; | |
try { | |
// Fri Apr 20 14:25:12 PDT 2012 | |
c = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(serverObj.get("created_at").toString()); | |
} catch (ParseException ex) { | |
Logger.getLogger(Checker.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
DateTime creation = new DateTime(c.getTime()); | |
// 7 days and younger need to be down ranked | |
if(creation.isAfter(new DateTime().minusDays(7))) { | |
rank = rank * 0.75f; | |
} | |
// 5% bonus for 3 months or longer | |
if(creation.isBefore(new DateTime().minusMonths(3))) { | |
rank = rank * 1.05f; | |
} | |
// 5% bonus for 3 months or longer | |
if(creation.isBefore(new DateTime().minusMonths(6))) { | |
rank = rank * 1.05f; | |
} | |
// 5% bonus for 6 months or longer | |
if(creation.isBefore(new DateTime().minusYears(1))) { | |
rank = rank * 1.1f; | |
} | |
// 10% increase for premium | |
if(premium) { | |
rank = rank * 1.1f; | |
} | |
float[] res = new float[2]; | |
res[0] = rank; | |
res[1] = percentage; | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment