(can be copied to result.txt file and used to generate card deck in nanDeck)pull/16/head
@@ -381,6 +381,8 @@ public class BggApi { | |||||
details.maxplaytime = getIntegerFromString(getValueAttribute(eElement, "maxplaytime")); | details.maxplaytime = getIntegerFromString(getValueAttribute(eElement, "maxplaytime")); | ||||
details.age = getIntegerFromString(getValueAttribute(eElement, "minage")); | details.age = getIntegerFromString(getValueAttribute(eElement, "minage")); | ||||
// number of players recommendations | |||||
// Only saving up to 20 players | |||||
NodeList pollList = eElement.getElementsByTagName("poll"); | NodeList pollList = eElement.getElementsByTagName("poll"); | ||||
for(int n = 0; n < pollList.getLength(); n++) { | for(int n = 0; n < pollList.getLength(); n++) { | ||||
Node pollNode = pollList.item(n); | Node pollNode = pollList.item(n); | ||||
@@ -462,19 +464,32 @@ public class BggApi { | |||||
NodeList nodeList = pollElement.getElementsByTagName("results"); | NodeList nodeList = pollElement.getElementsByTagName("results"); | ||||
for(int n = 0; n < nodeList.getLength(); ++n) { | for(int n = 0; n < nodeList.getLength(); ++n) { | ||||
Element elem = (Element)nodeList.item(n); | Element elem = (Element)nodeList.item(n); | ||||
// TODO: numplayers can be X+ where X is the max number of players... | |||||
if(elem.hasAttribute("numplayers") && Integer.valueOf(elem.getAttribute("numplayers")) == i) { | |||||
int lastvotes = 0; | |||||
NodeList results = elem.getElementsByTagName("result"); | |||||
for(int r = 0; r < results.getLength(); ++r) { | |||||
Element result = (Element)results.item(r); | |||||
if(result.hasAttribute("value") && result.hasAttribute("numvotes")) { | |||||
Integer numvotes = Integer.valueOf(result.getAttribute("numvotes")); | |||||
if(numvotes > lastvotes) { | |||||
recommendation = recommendationValueToEnum(result.getAttribute("value")); | |||||
if(elem.hasAttribute("numplayers")) { | |||||
String attr = elem.getAttribute("numplayers"); | |||||
boolean numPlayersDoesMatch = false; | |||||
// numplayers can be X+ where X is the max number of players... | |||||
if(attr.endsWith("+")) { | |||||
attr = attr.substring(0, attr.length()-1); | |||||
if(Integer.valueOf(attr) <= i) { | |||||
numPlayersDoesMatch = true; | |||||
} | |||||
} else { | |||||
numPlayersDoesMatch = Integer.valueOf(attr) == i; | |||||
} | |||||
if(numPlayersDoesMatch) { | |||||
int lastvotes = 0; | |||||
NodeList results = elem.getElementsByTagName("result"); | |||||
for(int r = 0; r < results.getLength(); ++r) { | |||||
Element result = (Element)results.item(r); | |||||
if(result.hasAttribute("value") && result.hasAttribute("numvotes")) { | |||||
Integer numvotes = Integer.valueOf(result.getAttribute("numvotes")); | |||||
if(numvotes > lastvotes) { | |||||
recommendation = recommendationValueToEnum(result.getAttribute("value")); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -2,8 +2,8 @@ package xyz.veronie.bgg.result; | |||||
/// Holds an id and its string representation, for example for Family, Extension, Mechanic, or Category. | /// Holds an id and its string representation, for example for Family, Extension, Mechanic, or Category. | ||||
public class IdString { | public class IdString { | ||||
int id; | |||||
String string; | |||||
public int id; | |||||
public String string; | |||||
public IdString(int id, String string) { | public IdString(int id, String string) { | ||||
this.id = id; | this.id = id; | ||||
@@ -14,6 +14,7 @@ import org.eclipse.swt.graphics.Image; | |||||
import org.eclipse.swt.graphics.ImageData; | import org.eclipse.swt.graphics.ImageData; | ||||
import org.eclipse.swt.graphics.ImageLoader; | import org.eclipse.swt.graphics.ImageLoader; | ||||
import xyz.veronie.bgg.result.internal.OutputResultHelper; | |||||
import xyz.veronie.bgg.ui.helpers.Resources; | import xyz.veronie.bgg.ui.helpers.Resources; | ||||
public class Thing { | public class Thing { | ||||
@@ -79,7 +80,8 @@ public class Thing { | |||||
if(imagePath != null) | if(imagePath != null) | ||||
return imagePath.toString(); | return imagePath.toString(); | ||||
else | else | ||||
return ""; | |||||
return Paths.get(Resources.INSTANCE.getThumbsDir().toString() | |||||
+ File.separator + String.valueOf(id) + ".png").toString(); | |||||
} | } | ||||
private void getThumbImage(int thingId) { | private void getThumbImage(int thingId) { | ||||
@@ -183,12 +185,12 @@ public class Thing { | |||||
StringBuilder str = new StringBuilder(); | StringBuilder str = new StringBuilder(); | ||||
// id,name,image, | // id,name,image, | ||||
str.append(Integer.toString(id)).append(","); | |||||
str.append(metaData.getName()).append(","); | |||||
str.append(getImagePath()).append(","); | |||||
OutputResultHelper.appendToResult(str, id); | |||||
OutputResultHelper.appendToResult(str, metaData.getName()); | |||||
OutputResultHelper.appendToResult(str, getImagePath()); | |||||
if(userData != null) { | if(userData != null) { | ||||
str.append(userData.toResultTextLine()); | |||||
userData.appendToResult(str); | |||||
} else { | } else { | ||||
str.append(ThingUserData.emptyReplacerLine()); | str.append(ThingUserData.emptyReplacerLine()); | ||||
} | } | ||||
@@ -203,4 +205,6 @@ public class Thing { | |||||
} | } | ||||
} | } |
@@ -32,7 +32,9 @@ public class ThingDetails { | |||||
Integer maxplaytime; | Integer maxplaytime; | ||||
// poll suggested_numplayers | // poll suggested_numplayers | ||||
List<Recommendation> players; // 1 to 20 | |||||
// The index in the list indicates the number of players | |||||
// Recommendation indicates how well it plays based on what the majority thinks | |||||
List<Recommendation> players; | |||||
// poll suggested_playerage | // poll suggested_playerage | ||||
Float age_poll; | Float age_poll; | ||||
@@ -90,48 +92,53 @@ public class ThingDetails { | |||||
// designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime, | // designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime, | ||||
// age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median, | // age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median, | ||||
// category,mechanic, | // category,mechanic, | ||||
str.append(designer).append(","); | |||||
str.append(publisher).append(","); | |||||
str.append(artist).append(","); | |||||
str.append(yearpublished).append(","); | |||||
str.append(minplayers).append(","); | |||||
str.append(maxplayers).append(","); | |||||
str.append(playingtime).append(","); | |||||
str.append(minplaytime).append(","); | |||||
str.append(maxplaytime).append(","); | |||||
str.append(age).append(","); | |||||
str.append(usersrated).append(","); | |||||
str.append(average).append(","); | |||||
str.append(OutputResultHelper.floatToResult(bayesaverage)).append(","); | |||||
str.append(rank).append(","); | |||||
str.append(rank_wg).append(","); | |||||
str.append(numcomments).append(","); | |||||
str.append(numweights).append(","); | |||||
str.append(OutputResultHelper.floatToResult(averageweight)).append(","); | |||||
str.append(OutputResultHelper.floatToResult(stddev)).append(","); | |||||
str.append(OutputResultHelper.floatToResult(median)).append(","); | |||||
str.append(category).append(","); | |||||
str.append(mechanic).append(","); | |||||
OutputResultHelper.appendToResult(str, OutputResultHelper.getFirstIdListItem(designer)); | |||||
OutputResultHelper.appendToResult(str, OutputResultHelper.getFirstIdListItem(publisher)); | |||||
OutputResultHelper.appendToResult(str, OutputResultHelper.getFirstIdListItem(artist)); | |||||
OutputResultHelper.appendToResult(str, yearpublished); | |||||
OutputResultHelper.appendToResult(str, minplayers); | |||||
OutputResultHelper.appendToResult(str, maxplayers); | |||||
OutputResultHelper.appendToResult(str, playingtime); | |||||
OutputResultHelper.appendToResult(str, minplaytime); | |||||
OutputResultHelper.appendToResult(str, maxplaytime); | |||||
OutputResultHelper.appendToResult(str, age); | |||||
OutputResultHelper.appendToResult(str, usersrated); | |||||
OutputResultHelper.appendToResult(str, average); | |||||
OutputResultHelper.appendToResult(str, bayesaverage); | |||||
OutputResultHelper.appendToResult(str, rank); | |||||
OutputResultHelper.appendToResult(str, rank_wg); | |||||
OutputResultHelper.appendToResult(str, numcomments); | |||||
OutputResultHelper.appendToResult(str, numweights); | |||||
OutputResultHelper.appendToResult(str, averageweight); | |||||
OutputResultHelper.appendToResult(str, stddev); | |||||
OutputResultHelper.appendToResult(str, median); | |||||
OutputResultHelper.appendToResult(str, category); | |||||
OutputResultHelper.appendToResult(str, mechanic); | |||||
// owned,trading,wanting,wishing | // owned,trading,wanting,wishing | ||||
str.append(owning).append(","); | |||||
str.append(trading).append(","); | |||||
str.append(wanting).append(","); | |||||
str.append(wishing).append(","); | |||||
OutputResultHelper.appendToResult(str, owning); | |||||
OutputResultHelper.appendToResult(str, trading); | |||||
OutputResultHelper.appendToResult(str, wanting); | |||||
OutputResultHelper.appendToResult(str, wishing); | |||||
// 1player,2player,3player,4player,5player,6player,7player,8player,9player,10player, | // 1player,2player,3player,4player,5player,6player,7player,8player,9player,10player, | ||||
// 11player,12player,13player,14player,15player,16player,17player,18player,19player,20player, | // 11player,12player,13player,14player,15player,16player,17player,18player,19player,20player, | ||||
for(Recommendation r : players) { | |||||
str.append(r.name()).append(","); | |||||
for(int i = 0; i < players.size(); ++i) { | |||||
Recommendation r = players.get(i); | |||||
if(r != null) { | |||||
str.append(r.name()); | |||||
} | |||||
str.append(","); | |||||
} | } | ||||
// description,exp, | // description,exp, | ||||
str.append(description).append(","); | |||||
str.append(expansion).append(","); | |||||
OutputResultHelper.appendToResult(str, description); | |||||
OutputResultHelper.appendToResult(str, expansion); | |||||
// basegame,reimplement,reimplement_name,reimplemented,reimplemented_name, | // basegame,reimplement,reimplement_name,reimplemented,reimplemented_name, | ||||
// contains,contains_name,iscontained,iscontained_name,integration,integration_name, | // contains,contains_name,iscontained,iscontained_name,integration,integration_name, | ||||
// TODO: | |||||
// str.append(basegameId).append(","); | // str.append(basegameId).append(","); | ||||
// str.append(reimplementId).append(","); | // str.append(reimplementId).append(","); | ||||
// str.append(reimplement_name).append(","); | // str.append(reimplement_name).append(","); | ||||
@@ -143,23 +150,25 @@ public class ThingDetails { | |||||
// str.append(iscontained_name).append(","); | // str.append(iscontained_name).append(","); | ||||
// str.append(integration).append(","); | // str.append(integration).append(","); | ||||
// str.append(integration_name).append(","); | // str.append(integration_name).append(","); | ||||
// str.append("0,,\"\",,\"\",,\"\",,\"\",,\"\""); | |||||
// price,expansions,domain,family,age_poll | // price,expansions,domain,family,age_poll | ||||
str.append(price).append(","); | |||||
str.append(expansions).append(","); | |||||
str.append(domain).append(","); | |||||
str.append(family).append(","); | |||||
str.append(age_poll); | |||||
OutputResultHelper.appendToResult(str, price); | |||||
OutputResultHelper.appendToResult(str, expansions); | |||||
OutputResultHelper.appendToResult(str, domain); | |||||
OutputResultHelper.appendToResult(str, family); | |||||
str.append(OutputResultHelper.floatToResult(age_poll)); | |||||
return str.toString(); | return str.toString(); | ||||
} | } | ||||
public static String emptyReplacerLine() { | public static String emptyReplacerLine() { | ||||
return ",,,,,,,,,,,0.0,0.0,,,0,0,0.0,0.0,0.0,\"\",\"\",,,,,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,\"\",\"\",0.0,,\"\",\"\",0.0"; | return ",,,,,,,,,,,0.0,0.0,,,0,0,0.0,0.0,0.0,\"\",\"\",,,,,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,\"\",\"\",0.0,,\"\",\"\",0.0"; | ||||
} | } | ||||
public static String resultHeader() { | public static String resultHeader() { | ||||
return "designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime,age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median,category,mechanic,1player,2player,3player,4player,5player,6player,7player,8player,9player,10player,11player,12player,13player,14player,15player,16player,17player,18player,19player,20player,description,exp,price,expansions,domain,family,age_poll"; | |||||
return "designer,publisher,artist,yearpublished,minplayers,maxplayers,playingtime,minplaytime,maxplaytime,age,usersrated,average,bayesaverage,rank,rank_wg,numcomments,numweights,averageweight,stddev,median,category,mechanic,owned,trading,wanting,wishing,1player,2player,3player,4player,5player,6player,7player,8player,9player,10player,11player,12player,13player,14player,15player,16player,17player,18player,19player,20player,description,exp,price,expansions,domain,family,age_poll"; | |||||
// not doing: basegame,reimplement,reimplement_name,reimplemented,reimplemented_name,contains,contains_name,iscontained,iscontained_name,integration,integration_name, | // not doing: basegame,reimplement,reimplement_name,reimplemented,reimplemented_name,contains,contains_name,iscontained,iscontained_name,integration,integration_name, | ||||
} | } | ||||
@@ -134,9 +134,10 @@ public class ThingProvider { | |||||
} | } | ||||
} | } | ||||
System.out.println(Thing.makeResultHeader()); | |||||
ArrayList<Thing> thingsWithDetails = bggApi.getThingDetails(ids); | ArrayList<Thing> thingsWithDetails = bggApi.getThingDetails(ids); | ||||
for (Thing thing2 : thingsWithDetails) { | |||||
System.out.println(thing2.toResultTxtLine()); | |||||
for (Thing thing : thingsWithDetails) { | |||||
System.out.println(thing.toResultTxtLine()); | |||||
} | } | ||||
} | } | ||||
@@ -125,14 +125,16 @@ public class ThingUserData { | |||||
this.lastmodified = lastmodified; | this.lastmodified = lastmodified; | ||||
} | } | ||||
public String toResultTextLine() { | |||||
StringBuilder str = new StringBuilder(); | |||||
str.append(OutputResultHelper.floatToResult(getRating())).append(","); | |||||
str.append(getComment()).append(","); | |||||
str.append(getNumPlays()).append(","); | |||||
public void appendToResult(StringBuilder str) { | |||||
OutputResultHelper.appendToResult(str, getRating()); | |||||
OutputResultHelper.appendToResult(str, getComment()); | |||||
OutputResultHelper.appendToResult(str, getNumPlays()); | |||||
// TODO: find out how to get userweight... | // TODO: find out how to get userweight... | ||||
} | |||||
public String toString() { | |||||
StringBuilder str = new StringBuilder(); | |||||
appendToResult(str); | |||||
return str.toString(); | return str.toString(); | ||||
} | } | ||||
@@ -141,7 +143,7 @@ public class ThingUserData { | |||||
} | } | ||||
public static String resultHeader() { | public static String resultHeader() { | ||||
return "userrating,comment,numplays"; | |||||
return "userrating,comment,numplays,"; | |||||
} | } | ||||
// public Float getWeight() { | // public Float getWeight() { | ||||
@@ -1,14 +1,60 @@ | |||||
package xyz.veronie.bgg.result.internal; | package xyz.veronie.bgg.result.internal; | ||||
import java.util.List; | |||||
import xyz.veronie.bgg.result.IdString; | |||||
public class OutputResultHelper { | public class OutputResultHelper { | ||||
public static String floatToResult(Float rating) { | |||||
if(rating == null) { | |||||
public static String floatToResult(Float f) { | |||||
if(f == null) { | |||||
return "N/A"; | return "N/A"; | ||||
} else { | } else { | ||||
return Float.toString(rating.floatValue()); | |||||
return Float.toString(f.floatValue()); | |||||
} | } | ||||
} | } | ||||
public static String getFirstIdListItem(List<IdString> list) { | |||||
if(list != null && list.size() > 0) { | |||||
return list.get(0).string; | |||||
} | |||||
return ""; | |||||
} | |||||
public static void appendToResult(StringBuilder str, String string) { | |||||
str.append("\""); | |||||
if(string != null) { | |||||
str.append(string); | |||||
} | |||||
str.append("\","); | |||||
} | |||||
public static void appendToResult(StringBuilder str, Integer i) { | |||||
if(i != null) { | |||||
str.append(Integer.toString(i)); | |||||
} | |||||
str.append(","); | |||||
} | |||||
public static void appendToResult(StringBuilder str, Float f) { | |||||
str.append(OutputResultHelper.floatToResult(f)).append(","); | |||||
} | |||||
public static void appendToResult(StringBuilder str, List<IdString> list) { | |||||
if(list == null) { | |||||
str.append(","); | |||||
return; | |||||
} | |||||
str.append("\""); | |||||
String nanDeckSeparator = ""; | |||||
for (IdString idString : list) { | |||||
str.append(nanDeckSeparator); | |||||
nanDeckSeparator = "\\13\\"; | |||||
str.append(idString.string); | |||||
} | |||||
str.append("\","); | |||||
} | |||||
} | } |
@@ -106,6 +106,8 @@ public class LoadGameListDialog extends Dialog { | |||||
tableViewer.setInput(thingLists); | tableViewer.setInput(thingLists); | ||||
int selection = 0; | int selection = 0; | ||||
tableViewer.setSelection(new StructuredSelection(tableViewer.getElementAt(selection)), true); | tableViewer.setSelection(new StructuredSelection(tableViewer.getElementAt(selection)), true); | ||||
selectedName = (String)tableViewer.getStructuredSelection().getFirstElement(); | |||||
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { | tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { | ||||
@Override | @Override | ||||
@@ -87,7 +87,7 @@ public class BggUserSourceFilter { | |||||
bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); | bottomComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); | ||||
Label infoLabel = new Label(bottomComposite, SWT.LEFT); | Label infoLabel = new Label(bottomComposite, SWT.LEFT); | ||||
infoLabel.setText("Select which flags are used as filter. Filters follow 'AND' rule."); | |||||
infoLabel.setText("Select which flags are used as filter. Filters follow 'AND' rule for each game."); | |||||
GridData gdInfo = new GridData(SWT.FILL, SWT.FILL, true, false); | GridData gdInfo = new GridData(SWT.FILL, SWT.FILL, true, false); | ||||
gdInfo.horizontalSpan = 2; | gdInfo.horizontalSpan = 2; | ||||
infoLabel.setLayoutData(gdInfo); | infoLabel.setLayoutData(gdInfo); | ||||