all-prices.txt?
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
10 posts
• Page 1 of 1
all-prices.txt?
by Rob Cashwalker » 25 Jun 2010, 03:07
How does the CardShop read all-prices.txt?
CardShop calls ReadPriceList, which calls ForgeProps.getFile(QUEST.PRICE) which points to "quest/price" not "quest/all-prices"......
I'm writing my first GUI for a price-updater....
CardShop calls ReadPriceList, which calls ForgeProps.getFile(QUEST.PRICE) which points to "quest/price" not "quest/all-prices"......
I'm writing my first GUI for a price-updater....
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Rob Cashwalker » 25 Jun 2010, 03:34
Never mind, I figured it out.
The properties files define the all-prices.txt, over-riding the defaults in NewConstants class.
The properties files define the all-prices.txt, over-riding the defaults in NewConstants class.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Rob Cashwalker » 25 Jun 2010, 20:28
Alright, so I've got this bit of code working. Working in the sense that it does indeed download the MOTL price list and parses it for cardnames and value. If we can resolve the issue I have, then I will fancy it up a bit, and make a menu link like the download pics.
The problem I now have is twofold -
one, the resulting pricelist is completely out of order.
second, the result of averaging the value of printings skews a few cards by a lot, and most cards by a little.
When Dennis first worked on the all-prices file, I don't know how he had taken account of the various printings, but some cheap commons may have Alpha and Beta printings worth 10-50x (or more) than their current counterparts.
I'm using a HashMap to store Cardname as the key, and the price as the value. If I read another price for a card already in the Map, I average the two prices then store the result back to the Map.
Subsequently, I iterate through the Map's entrySet and print the Cardname=Price. The resulting iteration is all over the map, not in the alphabetic order of the raw price list.
Note - I feel strongly about the value of averaging... it's not like we can specifically choose an Alpha Giant Growth over an M10....
The problem I now have is twofold -
one, the resulting pricelist is completely out of order.
second, the result of averaging the value of printings skews a few cards by a lot, and most cards by a little.
When Dennis first worked on the all-prices file, I don't know how he had taken account of the various printings, but some cheap commons may have Alpha and Beta printings worth 10-50x (or more) than their current counterparts.
I'm using a HashMap to store Cardname as the key, and the price as the value. If I read another price for a card already in the Map, I average the two prices then store the result back to the Map.
Subsequently, I iterate through the Map's entrySet and print the Cardname=Price. The resulting iteration is all over the map, not in the alphabetic order of the raw price list.
Note - I feel strongly about the value of averaging... it's not like we can specifically choose an Alpha Giant Growth over an M10....
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Rob Cashwalker » 26 Jun 2010, 02:45
I figured I'd post the current price list for comparison to my proposed (auto-generated) version as well as the raw data.
- Attachments
-
all-prices.zip
- Current
- (75.98 KiB) Downloaded 298 times
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Chris H. » 26 Jun 2010, 03:01
I downloaded the files and will take a closer look at it tomorrow. I see what you mean about the data in the proposed all prices file being in a non alphabetic order. It looks like some of the price differences are fairly close to one another while others are farther apart. The is a big difference in Bad Moon. I imagine that others are similar.
It is getting late and I will take another look at it tomorrow.
It is getting late and I will take another look at it tomorrow.
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: all-prices.txt?
by Rob Cashwalker » 27 Jun 2010, 04:48
I wrote a quick VB program to merge the two lists so I could see all cards together...
There's 11040 Entries, BTW. Minus 227 Un-cards, 3428/10813 = Forge supports 31.7% of all Magic cards.
There's 11040 Entries, BTW. Minus 227 Un-cards, 3428/10813 = Forge supports 31.7% of all Magic cards.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Rob Cashwalker » 27 Jun 2010, 12:49
I was able to revise the code a little bit to sort the cardnames before output.
Might as well post it all:
Might as well post it all:
- Code: Select all
package forge;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import forge.properties.ForgeProps;
import forge.properties.NewConstants.QUEST;
import java.awt.Dimension;
import java.awt.Point;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;
public class Gui_dp extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
/**
* This is the default constructor
*/
public Gui_dp() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(386, 200);
this.setContentPane(getJContentPane());
this.setTitle("Download Pictures");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setText("Download Pictures");
jButton.setLocation(new Point(120, 46));
jButton.setSize(158, 89);
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
//System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
BufferedInputStream in = null;
BufferedOutputStream out = null;
File f = new File(".//tmppl.txt");
String url = "http://www.magictraders.com/pricelists/current-magic-excel.txt";
Proxy p = Proxy.NO_PROXY;
byte[] buf = new byte[1024];
try {
in = new BufferedInputStream(new URL(url).openConnection(p).getInputStream());
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out = new BufferedOutputStream(new FileOutputStream(f));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
int len = 0;
try {
while((len = in.read(buf)) != -1) {
out.write(buf, 0, len);
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}//while - read and write file
try {
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.flush();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
out.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileReader fr = null;
try {
fr = new FileReader(".//tmppl.txt");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
BufferedReader inBR = new BufferedReader(fr);
String line = null;
HashMap<String, Integer> prices = new HashMap<String, Integer>();
try {
line = inBR.readLine();
line = inBR.readLine();
while (line != null && (!line.equals(""))) {
String ll[] = line.split("\\|");
if (ll[0].contains("("))
{
int n = ll[0].indexOf(" (");
ll[0] = ll[0].substring(0, n);
}
Float np = Float.parseFloat(ll[3]) * 100;
if (prices.containsKey(ll[0]))
{
int cp = prices.get(ll[0]);
int ap = (cp + np.intValue()) / 2;
prices.put(ll[0], ap);
}
else
prices.put(ll[0], np.intValue());
line = inBR.readLine();
System.out.println(line);
}
FileWriter fw = new FileWriter(ForgeProps.getFile(QUEST.PRICE));
BufferedWriter outBW = new BufferedWriter(fw);
//Collection<String> keys = prices.keySet();
ArrayList<String> keys = new ArrayList<String>();
keys.addAll(prices.keySet());
Collections.sort(keys);
for (int i=0; i<keys.size(); i++)
{
//keys.add(key);
outBW.write(keys.get(i) + "=" + prices.get(keys.get(i)) + "\r\n");
}
fw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fr.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return;
}
});
}
return jButton;
}
} // @jve:decl-index=0:visual-constraint="10,10"
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Chris H. » 27 Jun 2010, 21:50
Nice work. I seem to remember Dennis stating that he adjusted the cost of several of the cards by hand. I think that we want to get away from that and automate the process.
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: all-prices.txt?
by Rob Cashwalker » 28 Jun 2010, 00:00
Look, I'm mostly proud of it being my first GUI. I must admit I cheated, I finally found the Visual Editor for Eclpise. It doesn't render any of our existing screens, but it does help me to build a new one. My first attempt at this, was to hack a copy of the picture download screen, but I couldn't follow the code.
Before I commit, I want to know if the revised costs will be acceptable.. or should I work on a different algorithm to better deal with the extreme changes?
Before I commit, I want to know if the revised costs will be acceptable.. or should I work on a different algorithm to better deal with the extreme changes?
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: all-prices.txt?
by Chris H. » 28 Jun 2010, 00:19
I don't think it is cheating to find some tools to help make our job easier. I often times get lost looking through the code and I surprised myself by finding the spot to get the computer to use Forbidden Orchard correctly.
I have looked through your price compare list and it makes it easier to see the changes.
From what I could tell most of the price differences were fairly small.
I have looked through your price compare list and it makes it easier to see the changes.

-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 22 guests