use of org.magic.api.beans.CardDominance in project MtgDesktopCompanion by nicho92.
the class MTGoldFishDashBoard method getBestCards.
@Override
public List<CardDominance> getBestCards(FORMAT f, String filter) throws IOException {
// spells, creatures, all, lands
String u = getString("WEBSITE") + "/format-staples/" + f.toString().toLowerCase() + "/full/" + filter;
Document doc = read(u);
logger.debug("get best cards : " + u);
Elements trs = doc.select("table tr");
trs.remove(0);
trs.remove(0);
List<CardDominance> ret = new ArrayList<>();
for (Element e : trs) {
Elements tds = e.select(MTGConstants.HTML_TAG_TD);
try {
int correct = filter.equalsIgnoreCase("lands") ? 1 : 0;
CardDominance d = new CardDominance();
d.setPosition(Integer.parseInt(tds.get(0).text()));
d.setCardName(tds.get(1).text());
d.setDominance(Double.parseDouble(tds.get(3 - correct).text().replaceAll("\\%", "")));
d.setDecksPercent(Double.parseDouble(tds.get(4 - correct).text().replaceAll("\\%", "")));
d.setPlayers(Double.parseDouble(tds.get(5 - correct).text()));
ret.add(d);
} catch (Exception ex) {
logger.error("Error parsing " + tds, ex);
}
}
return ret;
}
use of org.magic.api.beans.CardDominance in project MtgDesktopCompanion by nicho92.
the class MTGStockDashBoard method getBestCards.
@Override
public List<CardDominance> getBestCards(FORMAT f, String filter) throws IOException {
if (!connected)
connect();
List<CardDominance> ret = new ArrayList<>();
int id = 1;
switch(f) {
case LEGACY:
id = 1;
break;
case MODERN:
id = 3;
break;
case STANDARD:
id = 4;
break;
case VINTAGE:
id = 2;
break;
// 1=Legacy 2=Vintage 3=Modern 4=Standard 7=Pauper
default:
break;
}
String url = MTGSTOCK_API_URI + "/analytics/mostplayed/" + id;
HttpURLConnection con = getConnection(url);
JsonObject obj = parser.parse(new JsonReader(new InputStreamReader(con.getInputStream()))).getAsJsonObject();
JsonArray arr = obj.get("mostplayed").getAsJsonArray();
int i = 1;
for (JsonElement el : arr) {
CardDominance cd = new CardDominance();
cd.setCardName(el.getAsJsonObject().get("card").getAsJsonObject().get("name").getAsString());
cd.setPlayers(el.getAsJsonObject().get("quantity").getAsDouble());
cd.setPosition(i++);
ret.add(cd);
}
return ret;
}
Aggregations