Skip to content

Commit

Permalink
Item Margins Fork
Browse files Browse the repository at this point in the history
* Added ISK Margins for items

* That being said this is purely calculation as it still displays in its native format with ISK for the margin percentage.

* Next stage would be to make the front-end changes
  • Loading branch information
awhipp committed Apr 7, 2016
1 parent fd8c5db commit 99c88e6
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@

/**
* Created by Jeremy on 3/1/2016.
*
* Modified by Alexander Whipp on 4/7/2016.
*/
public final class OrdersTabAdapter extends FragmentStatePagerAdapter {

private Resources resources;
private long typeId;

final int PAGE_COUNT = 3;
final int PAGE_COUNT = 4;

public OrdersTabAdapter(FragmentManager fragmentManager, Context context, long typeId) {
super(fragmentManager);
Expand All @@ -44,6 +46,8 @@ public CharSequence getPageTitle(int position) {
return resources.getString(R.string.sell_orders);
case 2:
return resources.getString(R.string.buy_orders);
case 3:
return resources.getString(R.string.margins);
default:
return "";
}
Expand Down
89 changes: 87 additions & 2 deletions app/src/main/java/com/w9jds/marketbot/data/loader/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.provider.ContactsContract;

import com.w9jds.eveapi.Callback;
import com.w9jds.eveapi.Client.Crest;
import com.w9jds.eveapi.Models.MarketGroup;
import com.w9jds.eveapi.Models.MarketOrder;
import com.w9jds.eveapi.Models.OrderType;
import com.w9jds.eveapi.Models.Reference;
import com.w9jds.eveapi.Models.Region;
import com.w9jds.eveapi.Models.ServerInfo;
import com.w9jds.eveapi.Models.Type;
Expand All @@ -28,12 +29,15 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

import javax.inject.Inject;
import javax.inject.Named;

/**
* Created by Jeremy Shore on 2/19/16.
*
* Modified by Alexander Whipp on 4/7/2016
*/
public abstract class DataManager extends BaseDataManager {

Expand Down Expand Up @@ -218,7 +222,7 @@ private void updateMarketTypes() {
}

public void loadNextPageTypes(String targetLocation) {
publicCrest.getMarketTypes(targetLocation, marketTypeCallback);
publicCrest.getMarketTypes(targetLocation, marketTypeCallback);
}

private void updateRegions() {
Expand Down Expand Up @@ -340,6 +344,87 @@ public void failure(String error) {
});
}

public void loadMarginOrders(final Region region, final Type type){
loadStarted();
incrementLoadingCount();

publicCrest.getOrders(region.getId(), type.getHref(), OrderType.buy, new Callback<MarketOrders>() {
@Override
public void success(final MarketOrders marketBuyOrders) {
if (marketBuyOrders != null) {

publicCrest.getOrders(region.getId(), type.getHref(), OrderType.sell, new Callback<MarketOrders>() {
@Override
public void success(MarketOrders marketSellOrders) {
if (marketSellOrders != null) {
onDataLoaded(combineOrders(marketBuyOrders, marketSellOrders).orders);
}
decrementLoadingCount();
loadFinished();
}

@Override
public void failure(String error) {
decrementLoadingCount();
loadFinished();
}
});
}
}

@Override
public void failure(String error) {
decrementLoadingCount();
loadFinished();
}
});

}

private MarketOrders combineOrders(MarketOrders buyOrders, MarketOrders sellOrders){
HashMap<String, MarketOrder> buyOrderMaximums = new HashMap<>();
for(MarketOrder m: buyOrders.orders){
if(buyOrderMaximums.containsKey(m.getLocation().getName())){
if(buyOrderMaximums.get(m.getLocation().getName()).getPrice() < m.getPrice()){
buyOrderMaximums.put(m.getLocation().getName(), m);
}
}else{
buyOrderMaximums.put(m.getLocation().getName(), m);
}
}

HashMap<String, MarketOrder> sellOrderMinimums = new HashMap<>();
for(MarketOrder m: sellOrders.orders){
if(sellOrderMinimums.containsKey(m.getLocation().getName())){
if(sellOrderMinimums.get(m.getLocation().getName()).getPrice() > m.getPrice()){
sellOrderMinimums.put(m.getLocation().getName(), m);
}
}else{
sellOrderMinimums.put(m.getLocation().getName(), m);
}
}

ArrayList<MarketOrder> finalOrderList = new ArrayList<>();

for(String station_name : buyOrderMaximums.keySet()){
if(sellOrderMinimums.containsKey(station_name)){
MarketOrder buyOrder = buyOrderMaximums.get(station_name);
MarketOrder sellOrder = sellOrderMinimums.get(station_name);
//(sales price - taxes and fees - purchase price) / purchase price
double price = (sellOrder.getPrice() - buyOrder.getPrice()) / buyOrder.getPrice();
buyOrder.setPrice(price);
finalOrderList.add(buyOrder);
}
}

MarketOrders finalOrders = new MarketOrders();
finalOrders.orders = finalOrderList;
finalOrders.size = finalOrderList.size();

return finalOrders;

}

public void searchMarketTypes(String queryString) {
loadStarted();
incrementLoadingCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

/**
* Created by Jeremy on 3/1/2016.
*
* Modified by Alexander Whipp on 4/7/2016.
*/
public final class OrdersTab extends Fragment implements BaseDataManager.DataLoadingCallbacks {

Expand Down Expand Up @@ -137,6 +139,9 @@ public void updateOrdersList(Region region, Type type) {
case 2:
dataManager.loadBuyOrders(region, type);
break;
case 3:
dataManager.loadMarginOrders(region, type);
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">Market Bot</string>

<string name="margins">Margins</string>
<string name="sell_orders">Sell Orders</string>
<string name="buy_orders">Buy Orders</string>
<string name="type_info_label">Info</string>
Expand Down
9 changes: 7 additions & 2 deletions eveapi/src/main/java/com/w9jds/eveapi/Models/MarketOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import com.google.gson.annotations.SerializedName;

import java.util.Date;

/**
* Created by Jeremy on 3/1/2016.
*
* Modified by Alexander Whipp on 4/7/2016.
*/

public final class MarketOrder extends MarketItemBase {

@SerializedName("buy")
Expand Down Expand Up @@ -52,6 +53,8 @@ public double getPrice() {
return price;
}

public void setPrice(double price) { this.price = price; }

public int getDuration() {
return duration;
}
Expand Down Expand Up @@ -79,4 +82,6 @@ public int getVolumeStart() {
public boolean isBuyOrder() {
return isBuyOrder;
}


}

0 comments on commit 99c88e6

Please sign in to comment.