Archived
0

change for new analyzer

This commit is contained in:
iMoHax
2015-07-17 15:57:51 +03:00
parent 2a4465d3fc
commit 77c931d770
17 changed files with 212 additions and 310 deletions

View File

@@ -13,13 +13,17 @@ public class Settings {
private final Properties values = new Properties();
private final File file;
private Profile profile;
public Settings() {
this.file = null;
profile = new Profile(new Ship());
}
public Settings(File file) {
this.file = file;
profile = new Profile(new Ship());
}
public void load() {
@@ -30,10 +34,12 @@ public class Settings {
} catch (IOException e) {
LOG.error("Error on load settings", e);
}
profile = Profile.readFrom(values);
}
public void save(){
try (OutputStream os = new FileOutputStream(file)) {
profile.writeTo(values);
values.store(os,"settings");
} catch (IOException e) {
LOG.error("Error on load settings", e);
@@ -82,59 +88,43 @@ public class Settings {
}
public void setBalance(double balance){
values.setProperty("ship.balance", String.valueOf(balance));
profile.setBalance(balance);
}
public double getBalance(){
return Double.valueOf(values.getProperty("ship.balance","1000"));
return profile.getBalance();
}
public void setCargo(int cargo){
values.setProperty("ship.cargo", String.valueOf(cargo));
profile.getShip().setCargo(cargo);
}
public int getCargo(){
return Integer.valueOf(values.getProperty("ship.cargo","4"));
return profile.getShip().getCargo();
}
public void setTank(double tank){
values.setProperty("ship.tank", String.valueOf(tank));
profile.getShip().setTank(tank);
}
public double getTank(){
return Double.valueOf(values.getProperty("ship.tank","20"));
}
public void setDistance(double distance){
values.setProperty("ship.distance", String.valueOf(distance));
}
public double getDistance(){
return Double.valueOf(values.getProperty("ship.distance","7"));
return profile.getShip().getTank();
}
public void setJumps(int jumps){
values.setProperty("ship.jumps", String.valueOf(jumps));
profile.setJumps(jumps);
}
public int getJumps(){
return Integer.valueOf(values.getProperty("ship.jumps","3"));
return profile.getJumps();
}
public void setSegmentSize(int segmentSize){
values.setProperty("performance.segment", String.valueOf(segmentSize));
public void setRoutesCount(int routesCount){
profile.setRoutesCount(routesCount);
}
public int getSegmentSize(){
return Integer.valueOf(values.getProperty("performance.segment","0"));
}
public void setPathsCount(int pathsCount){
values.setProperty("performance.limit", String.valueOf(pathsCount));
}
public int getPathsCount(){
return Integer.valueOf(values.getProperty("performance.limit","100"));
public int getRoutesCount(){
return profile.getRoutesCount();
}
public MarketFilter getFilter(Market market){
@@ -144,4 +134,8 @@ public class Settings {
public void setFilter(MarketFilter filter){
filter.writeTo(values);
}
public Profile getProfile() {
return profile;
}
}

View File

@@ -3,6 +3,7 @@ package ru.trader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;
import ru.trader.analysis.FilteredMarket;
import ru.trader.core.Market;
import ru.trader.core.MarketAnalyzer;
import ru.trader.store.simple.SimpleMarket;
@@ -59,14 +60,7 @@ public class World {
}
public static MarketAnalyzer buildAnalyzer(Market market){
MarketAnalyzer analyzer = new MarketAnalyzer(market);
analyzer.setSegmentSize(Main.SETTINGS.getSegmentSize());
analyzer.setPathsCount(Main.SETTINGS.getPathsCount());
analyzer.setFilter(Main.SETTINGS.getFilter(market));
analyzer.setCargo(Main.SETTINGS.getCargo());
analyzer.setTank(Main.SETTINGS.getTank());
analyzer.setMaxDistance(Main.SETTINGS.getDistance());
analyzer.setJumps(Main.SETTINGS.getJumps());
return analyzer;
FilteredMarket fMarket = new FilteredMarket(market, Main.SETTINGS.getFilter(market));
return new MarketAnalyzer(fMarket, Main.SETTINGS.getProfile());
}
}

View File

@@ -254,7 +254,8 @@ public class MainController {
}
public void editFilter(){
Screeners.showFilter(market.getAnalyzer().getFilter());
//TODO: implement
//Screeners.showFilter(market.getFilter());
}
public void impMadSystems(ActionEvent actionEvent) {

View File

@@ -10,19 +10,18 @@ import org.controlsfx.control.ButtonBar;
import org.controlsfx.control.action.Action;
import org.controlsfx.dialog.Dialog;
import org.controlsfx.dialog.DialogAction;
import ru.trader.model.PathRouteModel;
import ru.trader.model.RouteModel;
import ru.trader.model.support.BindingsHelper;
import ru.trader.view.support.Localization;
import java.util.Collection;
import java.util.List;
public class PathsController {
private final Action OK = new DialogAction("OK", ButtonBar.ButtonType.OK_DONE, false, true, false);
@FXML
private TableView<PathRouteModel> tblPaths;
private final List<PathRouteModel> paths = FXCollections.observableArrayList();
private TableView<RouteModel> tblPaths;
private final List<RouteModel> paths = FXCollections.observableArrayList();
@FXML
@@ -31,7 +30,7 @@ public class PathsController {
}
public PathRouteModel showDialog(Parent parent, Parent content, ObservableList<PathRouteModel> paths) {
public RouteModel showDialog(Parent parent, Parent content, ObservableList<RouteModel> paths) {
init(paths);
@@ -39,20 +38,20 @@ public class PathsController {
dlg.setContent(content);
dlg.getActions().addAll(OK, Dialog.ACTION_CANCEL);
dlg.setResizable(false);
PathRouteModel res = dlg.show() == OK ? getPath() : null;
RouteModel res = dlg.show() == OK ? getPath() : null;
paths.clear();
return res;
}
public PathRouteModel getPath(){
public RouteModel getPath(){
return tblPaths.getSelectionModel().getSelectedItem();
}
private void init(ObservableList<PathRouteModel> paths) {
private void init(ObservableList<RouteModel> paths) {
tblPaths.getSelectionModel().clearSelection();
this.paths.clear();
this.paths.addAll(paths);
paths.addListener((ListChangeListener<PathRouteModel>) l -> {
paths.addListener((ListChangeListener<RouteModel>) l -> {
while (l.next()) {
if (l.wasAdded()) {
this.paths.addAll(l.getAddedSubList());

View File

@@ -65,7 +65,7 @@ public class RouterController {
private NumberField totalBalance;
private MarketModel market;
private PathRouteModel route;
private RouteModel route;
private final ObservableList<OrderModel> orders = FXCollections.observableArrayList();
@FXML
@@ -75,22 +75,9 @@ public class RouterController {
totalBalance.setValue(n);
Main.SETTINGS.setBalance(n.doubleValue());
});
cargo.numberProperty().addListener((ov, o, n) -> {
market.getAnalyzer().setCargo(n.intValue());
Main.SETTINGS.setCargo(n.intValue());
});
tank.numberProperty().addListener((ov, o, n) -> {
market.getAnalyzer().setTank(n.doubleValue());
Main.SETTINGS.setTank(n.doubleValue());
});
distance.numberProperty().addListener((ov, o, n) -> {
market.getAnalyzer().setMaxDistance(n.doubleValue());
Main.SETTINGS.setDistance(n.doubleValue());
});
jumps.numberProperty().addListener((ov, o, n) -> {
market.getAnalyzer().setJumps(n.intValue());
Main.SETTINGS.setJumps(n.intValue());
});
cargo.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setCargo(n.intValue()));
tank.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setTank(n.doubleValue()));
jumps.numberProperty().addListener((ov, o, n) -> Main.SETTINGS.setJumps(n.intValue()));
source.valueProperty().addListener((ov, o, n) -> {
if (n != null) {
sStation.setItems(n.getStationsList());
@@ -116,7 +103,6 @@ public class RouterController {
balance.setValue(Main.SETTINGS.getBalance());
cargo.setValue(Main.SETTINGS.getCargo());
tank.setValue(Main.SETTINGS.getTank());
distance.setValue(Main.SETTINGS.getDistance());
jumps.setValue(Main.SETTINGS.getJumps());
addBtn.disableProperty().bind(Bindings.createBooleanBinding(()-> {
@@ -181,10 +167,10 @@ public class RouterController {
public void addStationToRoute(){
StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue();
PathRouteModel r = market.getPath(sS, tS);
RouteModel r = market.getPath(sS, tS);
if (r == null) return;
if (route != null){
route = route.add(r);
route.add(r);
} else {
route = r;
}
@@ -196,13 +182,14 @@ public class RouterController {
public void editOrders(){
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
int index = tblOrders.getSelectionModel().getSelectedIndex();
market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
//TODO: implement
/* market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
OrderModel order = Screeners.showOrders(result);
if (order!=null){
orders.set(index, order);
}
});
});*/
}
public void removeSelected(){
@@ -210,7 +197,7 @@ public class RouterController {
if (!select.isEmpty()){
int index = select.getSelectedIndex();
if (index > 0){
route = route.remove(select.getSelectedItem());
route.remove(select.getSelectedItem());
} else {
route = null;
}
@@ -221,7 +208,8 @@ public class RouterController {
public void recompute(){
if (route != null){
route.recompute(balance.getValue().doubleValue(), cargo.getValue().longValue());
//TODO: implement
/// route.recompute(balance.getValue().doubleValue(), cargo.getValue().longValue());
orders.clear();
orders.addAll(route.getOrders());
refreshPath();
@@ -230,7 +218,7 @@ public class RouterController {
public void rebuild(){
if (route != null){
PathRouteModel r = market.getRoute(route, balance.getValue().doubleValue());
RouteModel r = market.getRoute(route, balance.getValue().doubleValue());
if (r != null){
route = r;
orders.clear();
@@ -281,7 +269,7 @@ public class RouterController {
StationModel sS = sStation.getValue();
StationModel tS = tStation.getValue();
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), routes -> {
PathRouteModel path = Screeners.showRouters(routes);
RouteModel path = Screeners.showRouters(routes);
if (path!=null){
orders.addAll(path.getOrders());
addRouteToPath(path);
@@ -291,7 +279,7 @@ public class RouterController {
public void showTopRoutes(){
market.getTopRoutes(totalBalance.getValue().doubleValue(), routes -> {
PathRouteModel path = Screeners.showRouters(routes);
RouteModel path = Screeners.showRouters(routes);
if (path!=null){
orders.addAll(path.getOrders());
addRouteToPath(path);
@@ -299,18 +287,18 @@ public class RouterController {
});
}
private void addRouteToPath(PathRouteModel route){
private void addRouteToPath(RouteModel route){
if (this.route == null){
this.route = route;
} else {
this.route = this.route.add(route);
this.route.add(route);
}
refreshPath();
}
private void addOrderToPath(OrderModel order){
if (route != null){
route = route.add(order);
route.add(order);
} else {
route = market.getPath(order);
}

View File

@@ -226,7 +226,7 @@ public class Screeners {
return topOrdersController.showDialog(mainScreen, topOrdersScreen, orders);
}
public static PathRouteModel showRouters(ObservableList<PathRouteModel> routers) {
public static RouteModel showRouters(ObservableList<RouteModel> routers) {
return pathsController.showDialog(mainScreen, pathsScreen, routers);
}

View File

@@ -12,8 +12,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.EMDNUpdater;
import ru.trader.Main;
import ru.trader.core.MarketAnalyzer;
import ru.trader.model.MarketModel;
import ru.trader.view.support.Localization;
import ru.trader.view.support.NumberField;
@@ -47,8 +45,7 @@ public class SettingsController {
emdnOn.setSelected(Main.SETTINGS.getEMDNActive());
emdnUpdateOnly.setSelected(Main.SETTINGS.getEMDNUpdateOnly());
emdnUpdateTime.setValue(Main.SETTINGS.getEMDNAutoUpdate());
segmentSize.setValue(Main.SETTINGS.getSegmentSize());
pathsCount.setValue(Main.SETTINGS.getPathsCount());
pathsCount.setValue(Main.SETTINGS.getRoutesCount());
}
private void save() {
@@ -60,12 +57,6 @@ public class SettingsController {
EMDNUpdater.setUpdateOnly(emdnUpdateOnly.isSelected());
Main.SETTINGS.setEMDNAutoUpdate(emdnUpdateTime.getValue().longValue());
EMDNUpdater.setInterval(emdnUpdateTime.getValue().longValue());
MarketAnalyzer analyzer = MainController.getMarket().getAnalyzer();
Main.SETTINGS.setSegmentSize(segmentSize.getValue().intValue());
analyzer.setSegmentSize(segmentSize.getValue().intValue());
Main.SETTINGS.setPathsCount(pathsCount.getValue().intValue());
analyzer.setPathsCount(pathsCount.getValue().intValue());
}
public Action showDialog(Parent parent, Parent content){

View File

@@ -10,10 +10,10 @@ import javafx.collections.ObservableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ru.trader.World;
import ru.trader.analysis.Route;
import ru.trader.controllers.ProgressController;
import ru.trader.controllers.Screeners;
import ru.trader.core.*;
import ru.trader.graph.PathRoute;
import ru.trader.model.support.BindingsHelper;
import ru.trader.model.support.Notificator;
import ru.trader.services.OrdersSearchTask;
@@ -45,7 +45,7 @@ public class MarketModel {
notificator = new Notificator();
groups = new SimpleListProperty<>(BindingsHelper.observableList(market.getGroups(), modeler::get));
items = new SimpleListProperty<>(BindingsHelper.observableList(market.getItems(), modeler::get));
items.sort((i1, i2) -> i1.compareTo(i2));
items.sort(ItemModel::compareTo);
systems = new SimpleListProperty<>(BindingsHelper.observableList(market.get(), modeler::get));
systemsList = new SimpleListProperty<>(FXCollections.observableArrayList(ModelFabric.NONE_SYSTEM));
systemsList.addAll(systems);
@@ -168,15 +168,15 @@ public class MarketModel {
getOrders(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
}
public void getRoutes(SystemModel from, double balance, Consumer<ObservableList<PathRouteModel>> result){
public void getRoutes(SystemModel from, double balance, Consumer<ObservableList<RouteModel>> result){
getRoutes(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
}
public void getRoutes(SystemModel from, SystemModel to, double balance, Consumer<ObservableList<PathRouteModel>> result){
public void getRoutes(SystemModel from, SystemModel to, double balance, Consumer<ObservableList<RouteModel>> result){
getRoutes(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance, result);
}
public void getRoutes(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance, Consumer<ObservableList<PathRouteModel>> result) {
public void getRoutes(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance, Consumer<ObservableList<RouteModel>> result) {
ProgressController progress = new ProgressController(Screeners.getMainScreen(), Localization.getString("analyzer.routes.title"));
RoutesSearchTask task = new RoutesSearchTask(this,
from == null || from == ModelFabric.NONE_SYSTEM ? null : from.getSystem(),
@@ -187,7 +187,7 @@ public class MarketModel {
);
progress.run(task, route -> {
ObservableList<PathRouteModel> res = BindingsHelper.observableList(route, modeler::get);
ObservableList<RouteModel> res = BindingsHelper.observableList(route, modeler::get);
if (Platform.isFxApplicationThread()){
result.accept(res);
} else {
@@ -196,30 +196,29 @@ public class MarketModel {
});
}
public void getTopRoutes(double balance, Consumer<ObservableList<PathRouteModel>> result){
public void getTopRoutes(double balance, Consumer<ObservableList<RouteModel>> result){
getRoutes(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
}
public PathRouteModel getRoute(PathRouteModel path, double balance) {
PathRoute p = analyzer.getPath(path.getPath().getEntries(), balance);
if (p == null) return null;
public RouteModel getRoute(RouteModel path, double balance) {
//TODO: implement
/*Route r = analyzer.getRoute(path.getRoute());
if (r == null) return null;
return modeler.get(r);*/
return null;
}
Route _getPath(OrderModel order) {
return analyzer.getPath(order.getOrder());
}
public RouteModel getPath(StationModel from, StationModel to) {
Route p = analyzer.getPath(from.getStation(), to.getStation());
return modeler.get(p);
}
PathRoute _getPath(StationModel from, StationModel to) {
return analyzer.getPath(from.getStation(), to.getStation());
}
public PathRouteModel getPath(StationModel from, StationModel to) {
PathRoute p = analyzer.getPath(from.getStation(), to.getStation());
if (p == null) return null;
return modeler.get(p);
}
public PathRouteModel getPath(OrderModel order) {
PathRoute p = analyzer.getPath(order.getStation().getStation(), order.getBuyer().getStation());
if (p == null) return null;
p.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount()));
public RouteModel getPath(OrderModel order) {
Route p = analyzer.getPath(order.getOrder());
return modeler.get(p);
}

View File

@@ -5,8 +5,8 @@ import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import ru.trader.analysis.Route;
import ru.trader.core.*;
import ru.trader.graph.PathRoute;
import java.lang.ref.WeakReference;
import java.util.Collection;
@@ -29,8 +29,8 @@ public class ModelFabric {
return new OrderModel(get(order.getSell()), get(order.getBuy()), order.getCount());
}
public PathRouteModel get(PathRoute path) {
return new PathRouteModel(path, market);
public RouteModel get(Route route) {
return new RouteModel(route, market);
}
public SystemModel get(Place system){

View File

@@ -4,7 +4,6 @@ import javafx.beans.binding.Bindings;
import javafx.beans.property.*;
import javafx.beans.value.ObservableValue;
import ru.trader.core.Order;
import ru.trader.graph.PathRoute;
import ru.trader.model.support.ModelBindings;
import java.util.List;
@@ -19,7 +18,6 @@ public class OrderModel {
private DoubleProperty profit;
private DoubleProperty distance;
private DoubleProperty bestProfit;
private PathRoute path;
public OrderModel(OfferModel offer) {
this.offer = offer;
@@ -49,15 +47,10 @@ public class OrderModel {
this.max.setValue(Order.getMaxCount(offer.getOffer(), balance, limit));
}
PathRoute getPath() {
return path;
Order getOrder(){
return new Order(getOffer().getOffer(), getBuyOffer().getOffer(), getCount());
}
void setPath(PathRoute path) {
this.path = path;
}
public OfferModel getOffer() {
return offer;
}
@@ -160,9 +153,4 @@ public class OrderModel {
}
return distance;
}
public double getBalance(){
return path != null ? path.getRoot().getBalance() : getMax() * offer.getPrice();
}
}

View File

@@ -1,111 +0,0 @@
package ru.trader.model;
import ru.trader.core.Order;
import ru.trader.graph.PathRoute;
import java.util.ArrayList;
import java.util.Collection;
public class PathRouteModel {
private final MarketModel market;
private final double distance;
private final double totalProfit;
private final int jumps;
private final int refuels;
private final int lands;
private final PathRoute _path;
PathRouteModel(PathRoute path, MarketModel market) {
this.market = market;
this._path = path;
PathRoute p = path.getRoot();
totalProfit = p.getProfit();
lands = p.getLandsCount();
double d = 0; int j = 0, r = 0;
while (p.hasNext()){
p = p.getNext();
d += p.getDistance();
j++;
if (p.isRefill()) r++;
}
distance = d;
jumps = j;
refuels = r;
}
public double getDistance() {
return distance;
}
public double getTotalProfit() {
return totalProfit;
}
public int getJumps() {
return jumps;
}
public int getRefuels() {
return refuels;
}
public PathRoute getPath() {
return _path;
}
public int getLands() {
return lands;
}
public double getAvgProfit(){
return totalProfit/lands;
}
public Collection<OrderModel> getOrders(){
Collection<OrderModel> res = new ArrayList<>(lands);
PathRoute path = _path.getRoot();
Order cargo = null;
while (path.hasNext()){
path = path.getNext();
if (cargo == null && path.getBest()!=null){
cargo = path.getBest();
OrderModel order = market.getModeler().get(cargo);
order.setPath(path);
res.add(order);
}
if (cargo!=null && cargo.isBuyer(path.get())){
cargo = null;
}
}
return res;
}
PathRoute _add(PathRoute route){
return _path.add(route, true);
}
public PathRouteModel add(OrderModel order){
PathRoute path = market._getPath(order.getStation(), order.getBuyer());
if (path == null) return this;
path.getRoot().getNext().setOrder(new Order(order.getOffer().getOffer(), order.getBuyOffer().getOffer(), order.getCount()));
PathRoute head = _path.getEnd();
PathRouteModel res = new PathRouteModel(_add(path), market);
order.setPath(head);
return res;
}
public PathRouteModel add(PathRouteModel route){
return new PathRouteModel(_add(route.getPath()), market);
}
public PathRouteModel remove(OrderModel order) {
return new PathRouteModel(_path.dropTo(order.getStation().getStation()), market);
}
public void recompute(double balance, long cargo) {
_path.refresh();
_path.sort(balance, cargo);
}
}

View File

@@ -0,0 +1,72 @@
package ru.trader.model;
import ru.trader.analysis.Route;
import ru.trader.analysis.RouteEntry;
import ru.trader.core.Order;
import java.util.ArrayList;
import java.util.Collection;
public class RouteModel {
private final MarketModel market;
private final Route _route;
RouteModel(Route route, MarketModel market) {
this.market = market;
this._route = route;
}
public double getDistance() {
return _route.getDistance();
}
public double getTotalProfit() {
return _route.getProfit();
}
public int getJumps() {
return _route.getLands();
}
public int getRefuels() {
return _route.getRefills();
}
public Route getRoute() {
return _route;
}
public int getLands() {
return _route.getLands();
}
public double getAvgProfit(){
return _route.getProfit()/_route.getLands();
}
public Collection<OrderModel> getOrders(){
Collection<OrderModel> res = new ArrayList<>();
for (RouteEntry entry : _route.getEntries()) {
for (Order o : entry.getOrders()) {
OrderModel order = market.getModeler().get(o);
res.add(order);
}
}
return res;
}
public void add(OrderModel order){
Route path = market._getPath(order);
if (path == null) return;
_route.join(path);
}
public void add(RouteModel route){
_route.join(route.getRoute());
}
public void remove(OrderModel order) {
_route.dropTo(order.getStation().getStation());
}
}

View File

@@ -28,25 +28,25 @@ public class OrdersSearchTask extends AnalyzerTask<Collection<Order>>{
Collection<Order> orders;
if (stationFrom != null){
if (stationTo != null){
orders = analyzer.getOrders(stationFrom, stationTo, balance);
orders = analyzer.getOrders(stationFrom, stationTo);
} else {
if (to != null){
orders = analyzer.getOrders(stationFrom, to, balance);
orders = analyzer.getOrders(stationFrom, to);
} else {
orders = analyzer.getOrders(stationFrom, balance);
orders = analyzer.getOrders(stationFrom);
}
}
} else {
if (stationTo != null){
orders = analyzer.getOrders(from, stationTo, balance);
orders = analyzer.getOrders(from, stationTo);
} else {
if (to != null){
orders = analyzer.getOrders(from, to, balance);
orders = analyzer.getOrders(from, to);
} else {
if (from != null){
orders = analyzer.getOrders(from, balance);
orders = analyzer.getOrders(from);
} else {
orders = analyzer.getTop(balance);
orders = analyzer.getTop(100);
}
}
}

View File

@@ -1,18 +1,17 @@
package ru.trader.services;
import ru.trader.analysis.Route;
import ru.trader.core.Place;
import ru.trader.core.Vendor;
import ru.trader.graph.PathRoute;
import ru.trader.model.MarketModel;
import java.util.Collection;
public class RoutesSearchTask extends AnalyzerTask<Collection<PathRoute>>{
public class RoutesSearchTask extends AnalyzerTask<Collection<Route>>{
private final Place from;
private final Vendor stationFrom;
private final Place to;
private final Vendor stationTo;
private final double balance;
public RoutesSearchTask(MarketModel market, Place from, Vendor stationFrom, Place to, Vendor stationTo, double balance) {
super(market);
@@ -20,34 +19,34 @@ public class RoutesSearchTask extends AnalyzerTask<Collection<PathRoute>>{
this.stationFrom = stationFrom;
this.to = to;
this.stationTo = stationTo;
this.balance = balance;
market.getAnalyzer().getProfile().setBalance(balance);
}
@Override
protected Collection<PathRoute> call() throws Exception {
Collection<PathRoute> routes;
protected Collection<Route> call() throws Exception {
Collection<Route> routes;
if (stationFrom != null) {
if (stationTo != null) {
routes = analyzer.getPaths(stationFrom, stationTo, balance);
routes = analyzer.getRoutes(stationFrom, stationTo);
} else {
if (to != null) {
routes = analyzer.getPaths(stationFrom, to, balance);
routes = analyzer.getRoutes(stationFrom, to);
} else {
routes = analyzer.getPaths(stationFrom, balance);
routes = analyzer.getRoutes(stationFrom);
}
}
} else {
if (stationTo != null) {
routes = analyzer.getPaths(from, stationTo, balance);
routes = analyzer.getRoutes(from, stationTo);
} else {
if (to != null) {
routes = analyzer.getPaths(from, to, balance);
routes = analyzer.getRoutes(from, to);
} else {
if (from != null){
routes = analyzer.getPaths(from, balance);
routes = analyzer.getRoutes(from);
} else {
routes = analyzer.getTopPaths(balance);
routes = analyzer.getTopRoutes(100);
}
}
}

View File

@@ -6,10 +6,10 @@ import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import org.controlsfx.glyphfont.Glyph;
import ru.trader.core.Order;
import ru.trader.analysis.Route;
import ru.trader.analysis.RouteEntry;
import ru.trader.core.Vendor;
import ru.trader.graph.PathRoute;
import ru.trader.model.PathRouteModel;
import ru.trader.model.RouteModel;
import ru.trader.view.support.cells.DistanceCell;
public class RouteNode {
@@ -22,67 +22,51 @@ public class RouteNode {
private final static String CSS_SYSTEM_TEXT = "path-system-text";
private final static String CSS_STATION_TEXT = "path-station-text";
private final PathRoute path;
private final Route route;
private final HBox node = new HBox();
public RouteNode(PathRouteModel path) {
this.path = path.getPath();
public RouteNode(RouteModel route) {
this.route = route.getRoute();
node.getStyleClass().add(CSS_PATH);
build();
}
private void build(){
HBox v = new HBox();
VBox icons = new VBox();
Vendor prev = null;
for (RouteEntry entry : route.getEntries()) {
if (prev != null){
VBox track = new VBox();
VBox.setVgrow(track, Priority.ALWAYS);
VBox.setVgrow(icons, Priority.ALWAYS);
v.getStyleClass().add(CSS_SYSTEM);
icons.getStyleClass().add(CSS_ICONS);
track.getStyleClass().add(CSS_TRACK);
PathRoute p = path.getRoot();
v.getChildren().add(buildText(p.get()));
Order cargo = null;
while (p.hasNext()){
p = p.getNext();
if (cargo == null && p.getBest() != null){
cargo = p.getBest();
icons.getChildren().add(Glyph.create("FontAwesome|UPLOAD"));
}
if (p.isRefill()) icons.getChildren().add(Glyph.create("FontAwesome|REFRESH"));
node.getChildren().addAll(v, icons);
Text t = new Text(DistanceCell.distanceToString(p.getDistance()));
Text t = new Text(DistanceCell.distanceToString(entry.getVendor().getDistance(prev)));
t.getStyleClass().add(CSS_TRACK_TEXT);
track.getChildren().addAll(t, Glyph.create("FontAwesome|LONG_ARROW_RIGHT"));
node.getChildren().addAll(track);
v = new HBox();
icons = new VBox();
track = new VBox(0);
VBox.setVgrow(track, Priority.ALWAYS);
}
HBox v = new HBox();
VBox icons = new VBox();
VBox.setVgrow(icons, Priority.ALWAYS);
v.getStyleClass().add(CSS_SYSTEM);
icons.getStyleClass().add(CSS_ICONS);
track.getStyleClass().add(CSS_TRACK);
v.getChildren().add(buildText(entry.getVendor()));
v.getChildren().add(buildText(p.get()));
v.getChildren().add(icons);
if (cargo != null && cargo.isBuyer(p.get())){
v.getChildren().add(new Text(String.format(" (%+.0f) ", cargo.getProfit())));
cargo = null;
if (!entry.getOrders().isEmpty()){
v.getChildren().add(new Text(String.format(" (%+.0f) ", entry.getProfit())));
icons.getChildren().add(Glyph.create("FontAwesome|UPLOAD"));
}
if (entry.isRefill()){
icons.getChildren().add(Glyph.create("FontAwesome|REFRESH"));
}
if (!entry.isRefill() && entry.isLand()){
icons.getChildren().add(Glyph.create("FontAwesome|DOWNLOAD"));
}
}
node.getChildren().addAll(v, icons);
prev = entry.getVendor();
}
}
private VBox buildText(Vendor vendor){

View File

@@ -4,20 +4,20 @@ import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.util.Callback;
import ru.trader.model.PathRouteModel;
import ru.trader.model.RouteModel;
import ru.trader.view.support.RouteNode;
public class PathRouteCell<T> implements Callback<TableColumn<PathRouteModel, T>, TableCell<PathRouteModel, T>> {
public class PathRouteCell<T> implements Callback<TableColumn<RouteModel, T>, TableCell<RouteModel, T>> {
@Override
public TableCell<PathRouteModel, T> call(TableColumn<PathRouteModel, T> param) {
return new TableCell<PathRouteModel, T>(){
public TableCell<RouteModel, T> call(TableColumn<RouteModel, T> param) {
return new TableCell<RouteModel, T>(){
@Override
public void updateItem(T value, boolean empty) {
super.updateItem(value, empty);
TableRow row = getTableRow();
if (!empty && row !=null && row.getItem() != null){
RouteNode route = new RouteNode((PathRouteModel) row.getItem());
RouteNode route = new RouteNode((RouteModel) row.getItem());
setText(null);
setGraphic(route.getNode());
} else {

View File

@@ -17,6 +17,10 @@ public class FilteredMarket {
this.filter = filter;
}
public MarketFilter getFilter() {
return filter;
}
public void disableFilter(boolean disableFilter) {
this.disableFilter = disableFilter;
}