implement progress dialog
This commit is contained in:
@@ -1,250 +0,0 @@
|
|||||||
package ru.trader.controllers;
|
|
||||||
|
|
||||||
import javafx.application.Platform;
|
|
||||||
import javafx.beans.property.LongProperty;
|
|
||||||
import javafx.beans.property.SimpleLongProperty;
|
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
|
||||||
import javafx.beans.property.StringProperty;
|
|
||||||
import javafx.collections.FXCollections;
|
|
||||||
import javafx.collections.ListChangeListener;
|
|
||||||
import javafx.collections.ObservableList;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.control.ProgressBar;
|
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import javafx.scene.layout.VBox;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import ru.trader.core.MarketAnalyzer;
|
|
||||||
import ru.trader.core.MarketAnalyzerCallBack;
|
|
||||||
import ru.trader.core.Place;
|
|
||||||
import ru.trader.core.Vendor;
|
|
||||||
import ru.trader.graph.Connectable;
|
|
||||||
import ru.trader.graph.GraphCallBack;
|
|
||||||
import ru.trader.graph.RouteSearcherCallBack;
|
|
||||||
import ru.trader.graph.Vertex;
|
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
public class AnalyzerProgress {
|
|
||||||
private VBox tasks;
|
|
||||||
private TaskVisual task;
|
|
||||||
|
|
||||||
public void show(Parent main, String text, MarketAnalyzer analyzer){
|
|
||||||
tasks = new VBox(5);
|
|
||||||
task = new TaskVisual(text);
|
|
||||||
Button button = new Button("Cancel");
|
|
||||||
|
|
||||||
Scene scene = new Scene(tasks, 200, 200);
|
|
||||||
Stage stage = new Stage();
|
|
||||||
stage.setScene(scene);
|
|
||||||
stage.show();
|
|
||||||
|
|
||||||
MarketAnalyzerCallBack callBack = new AnalyzerCallBack(task);
|
|
||||||
analyzer.setCallback(callBack);
|
|
||||||
button.setOnAction(e -> callBack.cancel());
|
|
||||||
createProgress(task);
|
|
||||||
tasks.getChildren().add(button);
|
|
||||||
|
|
||||||
task.getSubTasks().addListener((ListChangeListener<TaskVisual>)l -> {
|
|
||||||
while (l.next()) {
|
|
||||||
if (l.wasRemoved()) {
|
|
||||||
l.getRemoved().forEach(this::removeProgress);
|
|
||||||
}
|
|
||||||
if (l.wasAdded()) {
|
|
||||||
l.getAddedSubList().forEach(this::createProgress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createProgress(TaskVisual task){
|
|
||||||
HBox hBox = new HBox(10);
|
|
||||||
hBox.setUserData(task);
|
|
||||||
Label txt = new Label("Процесс");
|
|
||||||
ProgressBar bar = new ProgressBar();
|
|
||||||
txt.textProperty().bind(task.messageProperty());
|
|
||||||
bar.progressProperty().bind(task.countProperty().divide(task.maxProperty()));
|
|
||||||
hBox.getChildren().addAll(txt, bar);
|
|
||||||
tasks.getChildren().addAll(hBox);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void removeProgress(TaskVisual task){
|
|
||||||
tasks.getChildren().removeIf(n -> task.equals(n.getUserData()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TaskVisual {
|
|
||||||
private final StringProperty message;
|
|
||||||
private final LongProperty count;
|
|
||||||
private final LongProperty max;
|
|
||||||
private final ObservableList<TaskVisual> subTasks;
|
|
||||||
|
|
||||||
private TaskVisual(String text) {
|
|
||||||
message = new SimpleStringProperty(text);
|
|
||||||
count = new SimpleLongProperty(0);
|
|
||||||
max = new SimpleLongProperty(1);
|
|
||||||
subTasks = FXCollections.observableArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMessage() {
|
|
||||||
return message.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringProperty messageProperty() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMessage(String message) {
|
|
||||||
Platform.runLater(() -> this.message.set(message));
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCount() {
|
|
||||||
return count.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LongProperty countProperty() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCount(long count) {
|
|
||||||
Platform.runLater(() -> this.count.set(count));
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMax() {
|
|
||||||
return max.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LongProperty maxProperty() {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMax(long max) {
|
|
||||||
Platform.runLater(() -> this.max.set(max));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<TaskVisual> getSubTasks() {
|
|
||||||
return subTasks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSubTask(TaskVisual task){
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
synchronized (subTasks) {
|
|
||||||
subTasks.add(task);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeSubTask(TaskVisual task){
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
synchronized (subTasks) {
|
|
||||||
subTasks.remove(task);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AnalyzerCallBack extends MarketAnalyzerCallBack {
|
|
||||||
private final TaskVisual task;
|
|
||||||
private final AtomicLong count = new AtomicLong();
|
|
||||||
|
|
||||||
private AnalyzerCallBack(TaskVisual task) {
|
|
||||||
this.task = task;
|
|
||||||
count.set(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected RouteSearcherCallBack getRouteSearcherCallBackInstance() {
|
|
||||||
return new RSCallBack(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected GraphCallBack<Place> getGraphCallBackInstance() {
|
|
||||||
TaskVisual subtask = new TaskVisual("Build graph of system");
|
|
||||||
task.addSubTask(subtask);
|
|
||||||
return new GCallBack<Place>(subtask, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onEnd() {
|
|
||||||
task.setMessage("Finish");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCount(long count) {
|
|
||||||
task.setMax(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inc() {
|
|
||||||
task.setCount(count.incrementAndGet());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RSCallBack extends RouteSearcherCallBack {
|
|
||||||
private final TaskVisual task;
|
|
||||||
|
|
||||||
private RSCallBack(TaskVisual task) {
|
|
||||||
this.task = task;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected GraphCallBack<Vendor> getGraphCallBackInstance() {
|
|
||||||
TaskVisual subtask = new TaskVisual("Build graph of stations");
|
|
||||||
task.addSubTask(subtask);
|
|
||||||
return new GCallBack<>(subtask, task);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class GCallBack<T extends Connectable<T>> extends GraphCallBack<T> {
|
|
||||||
private final TaskVisual task;
|
|
||||||
private final TaskVisual owner;
|
|
||||||
private final AtomicLong count = new AtomicLong();
|
|
||||||
|
|
||||||
private GCallBack(TaskVisual task, TaskVisual owner) {
|
|
||||||
this.task = task;
|
|
||||||
this.owner = owner;
|
|
||||||
count.set(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartBuild(T from) {
|
|
||||||
task.setMessage(String.format("Build graph from %s", from));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEndBuild() {
|
|
||||||
task.setMessage("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartFind(Vertex<T> from, Vertex<T> to) {
|
|
||||||
if (to != null) {
|
|
||||||
task.setMessage(String.format("Find path from %s graph to %s", from.getEntry(), to.getEntry()));
|
|
||||||
} else {
|
|
||||||
task.setMessage(String.format("Find path from %s graph", from.getEntry()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFound() {
|
|
||||||
task.setMessage("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEndFind() {
|
|
||||||
owner.removeSubTask(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCount(long count) {
|
|
||||||
task.setMax(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void inc() {
|
|
||||||
task.setCount(count.incrementAndGet());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package ru.trader.controllers;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.ProgressBar;
|
||||||
|
import javafx.scene.layout.VBox;
|
||||||
|
import org.controlsfx.control.ButtonBar;
|
||||||
|
import org.controlsfx.control.action.Action;
|
||||||
|
import org.controlsfx.dialog.Dialog;
|
||||||
|
import org.controlsfx.dialog.DialogAction;
|
||||||
|
import ru.trader.services.*;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
public class ProgressController {
|
||||||
|
private Label text;
|
||||||
|
private ProgressBar bar;
|
||||||
|
private Action cancel;
|
||||||
|
private Dialog dlg;
|
||||||
|
private final static String TASK_KEY = "task";
|
||||||
|
|
||||||
|
|
||||||
|
public ProgressController(Parent owner, String title) {
|
||||||
|
dlg = new Dialog(owner, title);
|
||||||
|
createStage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createStage(){
|
||||||
|
text = new Label();
|
||||||
|
bar = new ProgressBar();
|
||||||
|
bar.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
VBox vbox = new VBox(10, text, bar);
|
||||||
|
vbox.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
vbox.setPrefSize(300, 100);
|
||||||
|
|
||||||
|
dlg.setClosable(false);
|
||||||
|
dlg.setContent(vbox);
|
||||||
|
cancel = new DialogAction(impl.org.controlsfx.i18n.Localization.asKey("dlg.cancel.button"), ButtonBar.ButtonType.CANCEL_CLOSE, e -> {
|
||||||
|
AnalyzerTask<?> task = (AnalyzerTask<?>) cancel.getProperties().get(TASK_KEY);
|
||||||
|
if (task != null){
|
||||||
|
task.stop();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dlg.getActions().addAll(cancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void bind(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
||||||
|
bar.progressProperty().bind(task.progressProperty());
|
||||||
|
text.textProperty().bind(task.messageProperty());
|
||||||
|
cancel.getProperties().put(TASK_KEY, task);
|
||||||
|
task.setOnSucceeded(e -> {
|
||||||
|
dlg.hide();
|
||||||
|
onSuccess.accept(task.getValue());
|
||||||
|
unbind();
|
||||||
|
});
|
||||||
|
task.setOnCancelled(e -> {
|
||||||
|
dlg.hide();
|
||||||
|
onSuccess.accept(task.getValue());
|
||||||
|
unbind();
|
||||||
|
});
|
||||||
|
|
||||||
|
task.setOnFailed(e -> {
|
||||||
|
dlg.hide();
|
||||||
|
Screeners.showException(task.getException());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unbind(){
|
||||||
|
bar.progressProperty().unbind();
|
||||||
|
text.textProperty().unbind();
|
||||||
|
cancel.getProperties().remove(TASK_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> void run(AnalyzerTask<T> task, Consumer<T> onSuccess){
|
||||||
|
bind(task, onSuccess);
|
||||||
|
Platform.runLater(dlg::show);
|
||||||
|
new Thread(task).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -172,12 +172,13 @@ public class RouterController {
|
|||||||
public void editOrders(){
|
public void editOrders(){
|
||||||
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
|
OrderModel sel = tblOrders.getSelectionModel().getSelectedItem();
|
||||||
int index = tblOrders.getSelectionModel().getSelectedIndex();
|
int index = tblOrders.getSelectionModel().getSelectedIndex();
|
||||||
|
market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance(), result -> {
|
||||||
OrderModel order = Screeners.showOrders(market.getOrders(sel.getStation(), sel.getBuyer(), sel.getBalance()));
|
OrderModel order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order!=null){
|
||||||
orders.set(index, order);
|
orders.set(index, order);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSelected(){
|
public void removeSelected(){
|
||||||
@@ -204,11 +205,13 @@ public class RouterController {
|
|||||||
|
|
||||||
|
|
||||||
public void showTopOrders(){
|
public void showTopOrders(){
|
||||||
OrderModel order = Screeners.showOrders(market.getTop(totalBalance.getValue().doubleValue()));
|
market.getTop(totalBalance.getValue().doubleValue(), result -> {
|
||||||
|
OrderModel order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order!=null){
|
||||||
orders.add(order);
|
orders.add(order);
|
||||||
addOrderToPath(order);
|
addOrderToPath(order);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showOrders(){
|
public void showOrders(){
|
||||||
@@ -216,11 +219,13 @@ public class RouterController {
|
|||||||
SystemModel t = target.getValue();
|
SystemModel t = target.getValue();
|
||||||
StationModel sS = sStation.getValue();
|
StationModel sS = sStation.getValue();
|
||||||
StationModel tS = tStation.getValue();
|
StationModel tS = tStation.getValue();
|
||||||
OrderModel order = Screeners.showOrders(market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue()));
|
market.getOrders(s, sS, t, tS, totalBalance.getValue().doubleValue(), result -> {
|
||||||
|
OrderModel order = Screeners.showOrders(result);
|
||||||
if (order!=null){
|
if (order!=null){
|
||||||
orders.add(order);
|
orders.add(order);
|
||||||
addOrderToPath(order);
|
addOrderToPath(order);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showRoutes(){
|
public void showRoutes(){
|
||||||
@@ -228,20 +233,23 @@ public class RouterController {
|
|||||||
SystemModel t = target.getValue();
|
SystemModel t = target.getValue();
|
||||||
StationModel sS = sStation.getValue();
|
StationModel sS = sStation.getValue();
|
||||||
StationModel tS = tStation.getValue();
|
StationModel tS = tStation.getValue();
|
||||||
Platform.runLater(() -> {
|
market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue(), routes -> {
|
||||||
PathRouteModel path = Screeners.showRouters(market.getRoutes(s, sS, t, tS, totalBalance.getValue().doubleValue()));
|
PathRouteModel path = Screeners.showRouters(routes);
|
||||||
if (path!=null){
|
if (path!=null){
|
||||||
orders.addAll(path.getOrders());
|
orders.addAll(path.getOrders());
|
||||||
addRouteToPath(path);
|
addRouteToPath(path);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showTopRoutes(){
|
public void showTopRoutes(){
|
||||||
PathRouteModel path = Screeners.showRouters(market.getTopRoutes(totalBalance.getValue().doubleValue()));
|
market.getTopRoutes(totalBalance.getValue().doubleValue(), routes -> {
|
||||||
|
PathRouteModel path = Screeners.showRouters(routes);
|
||||||
if (path!=null){
|
if (path!=null){
|
||||||
orders.addAll(path.getOrders());
|
orders.addAll(path.getOrders());
|
||||||
addRouteToPath(path);
|
addRouteToPath(path);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addRouteToPath(PathRouteModel route){
|
private void addRouteToPath(PathRouteModel route){
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package ru.trader.model;
|
package ru.trader.model;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.ListProperty;
|
import javafx.beans.property.ListProperty;
|
||||||
import javafx.beans.property.ReadOnlyListProperty;
|
import javafx.beans.property.ReadOnlyListProperty;
|
||||||
import javafx.beans.property.SimpleListProperty;
|
import javafx.beans.property.SimpleListProperty;
|
||||||
@@ -9,17 +10,19 @@ import javafx.collections.ObservableList;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.trader.World;
|
import ru.trader.World;
|
||||||
import ru.trader.controllers.AnalyzerProgress;
|
import ru.trader.controllers.ProgressController;
|
||||||
import ru.trader.controllers.Screeners;
|
import ru.trader.controllers.Screeners;
|
||||||
import ru.trader.core.*;
|
import ru.trader.core.*;
|
||||||
import ru.trader.graph.PathRoute;
|
import ru.trader.graph.PathRoute;
|
||||||
import ru.trader.model.support.BindingsHelper;
|
import ru.trader.model.support.BindingsHelper;
|
||||||
import ru.trader.model.support.Notificator;
|
import ru.trader.model.support.Notificator;
|
||||||
|
import ru.trader.services.OrdersSearchTask;
|
||||||
|
import ru.trader.services.RoutesSearchTask;
|
||||||
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
|
||||||
public class MarketModel {
|
public class MarketModel {
|
||||||
@@ -121,94 +124,72 @@ public class MarketModel {
|
|||||||
return market.getStat(type, item);
|
return market.getStat(type, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<OrderModel> getOrders(SystemModel from, double balance) {
|
public void getOrders(SystemModel from, double balance, Consumer<ObservableList<OrderModel>> result) {
|
||||||
return getOrders(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance);
|
getOrders(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<OrderModel> getOrders(SystemModel from, SystemModel to, double balance) {
|
public void getOrders(SystemModel from, SystemModel to, double balance, Consumer<ObservableList<OrderModel>> result) {
|
||||||
return getOrders(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance);
|
getOrders(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<OrderModel> getOrders(StationModel from, StationModel to, double balance) {
|
public void getOrders(StationModel from, StationModel to, double balance, Consumer<ObservableList<OrderModel>> result) {
|
||||||
return getOrders(from.getSystem(), from, to.getSystem(), to, balance);
|
getOrders(from.getSystem(), from, to.getSystem(), to, balance, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableList<OrderModel> getOrders(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance) {
|
public void getOrders(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance, Consumer<ObservableList<OrderModel>> result) {
|
||||||
Collection<Order> orders;
|
ProgressController progress = new ProgressController(Screeners.getMainScreen(), Localization.getString("analyzer.orders.title"));
|
||||||
if (stationFrom != null && stationFrom != ModelFabric.NONE_STATION){
|
OrdersSearchTask task = new OrdersSearchTask(this,
|
||||||
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
|
from == null || from == ModelFabric.NONE_SYSTEM ? null : from.getSystem(),
|
||||||
orders = analyzer.getOrders(stationFrom.getStation(), stationTo.getStation(), balance);
|
stationFrom == null || stationFrom == ModelFabric.NONE_STATION ? null : stationFrom.getStation(),
|
||||||
} else {
|
to == null || to == ModelFabric.NONE_SYSTEM ? null : to.getSystem(),
|
||||||
if (to != null && to != ModelFabric.NONE_SYSTEM){
|
stationTo == null || stationTo == ModelFabric.NONE_STATION ? null : stationTo.getStation(),
|
||||||
orders = analyzer.getOrders(stationFrom.getStation(), to.getSystem(), balance);
|
balance
|
||||||
} else {
|
);
|
||||||
orders = analyzer.getOrders(stationFrom.getStation(), balance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (stationTo != null && stationTo != ModelFabric.NONE_STATION){
|
|
||||||
orders = analyzer.getOrders(from.getSystem(), stationTo.getStation(), balance);
|
|
||||||
} else {
|
|
||||||
if (to != null && to != ModelFabric.NONE_SYSTEM){
|
|
||||||
orders = analyzer.getOrders(from.getSystem(), to.getSystem(), balance);
|
|
||||||
} else {
|
|
||||||
orders = analyzer.getOrders(from.getSystem(), balance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return BindingsHelper.observableList(orders, modeler::get);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<OrderModel> getTop(double balance){
|
progress.run(task, order -> {
|
||||||
return BindingsHelper.observableList(analyzer.getTop(balance), modeler::get);
|
ObservableList<OrderModel> res = BindingsHelper.observableList(order, modeler::get);
|
||||||
}
|
if (Platform.isFxApplicationThread()){
|
||||||
|
result.accept(res);
|
||||||
public ObservableList<PathRouteModel> getRoutes(SystemModel from, double balance){
|
|
||||||
return getRoutes(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<PathRouteModel> getRoutes(SystemModel from, SystemModel to, double balance){
|
|
||||||
return getRoutes(from, ModelFabric.NONE_STATION, to, ModelFabric.NONE_STATION, balance);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<PathRouteModel> getRoutes(SystemModel from, StationModel stationFrom, SystemModel to, StationModel stationTo, double balance) {
|
|
||||||
AnalyzerProgress progress = new AnalyzerProgress();
|
|
||||||
progress.show(Screeners.getMainScreen(), "Get routes", analyzer);
|
|
||||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
||||||
ObservableList<PathRouteModel> res = FXCollections.observableArrayList();
|
|
||||||
executor.execute(() -> {
|
|
||||||
Collection<PathRoute> routes;
|
|
||||||
|
|
||||||
if (stationFrom != null && stationFrom != ModelFabric.NONE_STATION) {
|
|
||||||
if (stationTo != null && stationTo != ModelFabric.NONE_STATION) {
|
|
||||||
routes = analyzer.getPaths(stationFrom.getStation(), stationTo.getStation(), balance);
|
|
||||||
} else {
|
} else {
|
||||||
if (to != null && to != ModelFabric.NONE_SYSTEM) {
|
Platform.runLater(() -> result.accept(res));
|
||||||
routes = analyzer.getPaths(stationFrom.getStation(), to.getSystem(), balance);
|
|
||||||
} else {
|
|
||||||
routes = analyzer.getPaths(stationFrom.getStation(), balance);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (stationTo != null && stationTo != ModelFabric.NONE_STATION) {
|
|
||||||
routes = analyzer.getPaths(from.getSystem(), stationTo.getStation(), balance);
|
|
||||||
} else {
|
|
||||||
if (to != null && to != ModelFabric.NONE_SYSTEM) {
|
|
||||||
routes = analyzer.getPaths(from.getSystem(), to.getSystem(), balance);
|
|
||||||
} else {
|
|
||||||
routes = analyzer.getPaths(from.getSystem(), balance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
routes.stream().map(modeler::get).forEach(res::add);
|
|
||||||
});
|
});
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getTop(double balance, Consumer<ObservableList<OrderModel>> result){
|
||||||
|
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){
|
||||||
|
getRoutes(from, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableList<PathRouteModel> getTopRoutes(double balance){
|
public void getRoutes(SystemModel from, SystemModel to, double balance, Consumer<ObservableList<PathRouteModel>> result){
|
||||||
return BindingsHelper.observableList(analyzer.getTopPaths(balance), modeler::get);
|
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) {
|
||||||
|
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(),
|
||||||
|
stationFrom == null || stationFrom == ModelFabric.NONE_STATION ? null : stationFrom.getStation(),
|
||||||
|
to == null || to == ModelFabric.NONE_SYSTEM ? null : to.getSystem(),
|
||||||
|
stationTo == null || stationTo == ModelFabric.NONE_STATION ? null : stationTo.getStation(),
|
||||||
|
balance
|
||||||
|
);
|
||||||
|
|
||||||
|
progress.run(task, route -> {
|
||||||
|
ObservableList<PathRouteModel> res = BindingsHelper.observableList(route, modeler::get);
|
||||||
|
if (Platform.isFxApplicationThread()){
|
||||||
|
result.accept(res);
|
||||||
|
} else {
|
||||||
|
Platform.runLater(() -> result.accept(res));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getTopRoutes(double balance, Consumer<ObservableList<PathRouteModel>> result){
|
||||||
|
getRoutes(ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, ModelFabric.NONE_SYSTEM, ModelFabric.NONE_STATION, balance, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
PathRoute getPath(StationModel from, StationModel to) {
|
PathRoute getPath(StationModel from, StationModel to) {
|
||||||
|
|||||||
163
client/src/main/java/ru/trader/services/AnalyzerTask.java
Normal file
163
client/src/main/java/ru/trader/services/AnalyzerTask.java
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
package ru.trader.services;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.LongProperty;
|
||||||
|
import javafx.beans.property.SimpleLongProperty;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import ru.trader.core.MarketAnalyzer;
|
||||||
|
import ru.trader.core.MarketAnalyzerCallBack;
|
||||||
|
import ru.trader.core.Place;
|
||||||
|
import ru.trader.core.Vendor;
|
||||||
|
import ru.trader.graph.Connectable;
|
||||||
|
import ru.trader.graph.GraphCallBack;
|
||||||
|
import ru.trader.graph.RouteSearcherCallBack;
|
||||||
|
import ru.trader.graph.Vertex;
|
||||||
|
import ru.trader.model.MarketModel;
|
||||||
|
import ru.trader.view.support.Localization;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
public abstract class AnalyzerTask<T> extends Task<T> {
|
||||||
|
private final AnalyzerCallBack callback;
|
||||||
|
protected final MarketAnalyzer analyzer;
|
||||||
|
|
||||||
|
private final LongProperty found;
|
||||||
|
private final AtomicReference<Long> foundUpdate;
|
||||||
|
|
||||||
|
public AnalyzerTask(MarketModel market) {
|
||||||
|
foundUpdate = new AtomicReference<>((long) 0);
|
||||||
|
found = new SimpleLongProperty(0);
|
||||||
|
analyzer = market.getAnalyzer();
|
||||||
|
callback = new AnalyzerCallBack();
|
||||||
|
analyzer.setCallback(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFound() {
|
||||||
|
return found.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LongProperty foundProperty() {
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateFound(long value){
|
||||||
|
if (Platform.isFxApplicationThread()) {
|
||||||
|
this.found.set(value);
|
||||||
|
} else {
|
||||||
|
if (foundUpdate.getAndSet(value) == null) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
final long f = foundUpdate.getAndSet(null);
|
||||||
|
found.set(f);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(){
|
||||||
|
callback.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class AnalyzerCallBack extends MarketAnalyzerCallBack {
|
||||||
|
private final AtomicLong max;
|
||||||
|
private final AtomicLong counter;
|
||||||
|
private final AtomicLong found;
|
||||||
|
|
||||||
|
private AnalyzerCallBack() {
|
||||||
|
max = new AtomicLong(0);
|
||||||
|
counter = new AtomicLong(0);
|
||||||
|
found = new AtomicLong(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected RouteSearcherCallBack getRouteSearcherCallBackInstance() {
|
||||||
|
return new RSCallBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GraphCallBack<Place> getGraphCallBackInstance() {
|
||||||
|
return new GCallBack<Place>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onEnd() {
|
||||||
|
updateProgress(counter.incrementAndGet(), max.get());
|
||||||
|
updateMessage(Localization.getString("analyser.finish"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMax(long value) {
|
||||||
|
max.addAndGet(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inc() {
|
||||||
|
updateProgress(counter.incrementAndGet(), max.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RSCallBack extends RouteSearcherCallBack {
|
||||||
|
@Override
|
||||||
|
protected GraphCallBack<Vendor> getGraphCallBackInstance() {
|
||||||
|
return new GCallBack<Vendor>(){
|
||||||
|
@Override
|
||||||
|
public void onStartBuild(Vendor from) {
|
||||||
|
updateMessage(String.format(Localization.getString("analyzer.graph.station.build"), from.getPlace().getName(), from.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartFind(Vertex<Vendor> from, Vertex<Vendor> to) {
|
||||||
|
if (to != null) {
|
||||||
|
updateMessage(String.format(Localization.getString("analyzer.find.route"),
|
||||||
|
from.getEntry().getPlace().getName(),
|
||||||
|
from.getEntry().getName(),
|
||||||
|
to.getEntry().getPlace().getName(),
|
||||||
|
to.getEntry().getName()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
updateMessage(String.format(Localization.getString("analyzer.find.routes"),
|
||||||
|
from.getEntry().getPlace().getName(),
|
||||||
|
from.getEntry().getName()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GCallBack<T extends Connectable<T>> extends GraphCallBack<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartBuild(T from) {
|
||||||
|
updateMessage(String.format(Localization.getString("analyzer.graph.build"), from));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndBuild() {
|
||||||
|
updateProgress(counter.incrementAndGet(), max.get());
|
||||||
|
updateMessage(Localization.getString("analyzer.graph.success"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFound() {
|
||||||
|
updateFound(found.incrementAndGet());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEndFind() {
|
||||||
|
updateMessage(String.format(Localization.getString("analyzer.find.success"), found.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMax(long value) {
|
||||||
|
max.addAndGet(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inc() {
|
||||||
|
updateProgress(counter.incrementAndGet(), max.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package ru.trader.services;
|
||||||
|
|
||||||
|
import ru.trader.core.Order;
|
||||||
|
import ru.trader.core.Place;
|
||||||
|
import ru.trader.core.Vendor;
|
||||||
|
import ru.trader.model.MarketModel;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class OrdersSearchTask extends AnalyzerTask<Collection<Order>>{
|
||||||
|
private final Place from;
|
||||||
|
private final Vendor stationFrom;
|
||||||
|
private final Place to;
|
||||||
|
private final Vendor stationTo;
|
||||||
|
private final double balance;
|
||||||
|
|
||||||
|
public OrdersSearchTask(MarketModel market, Place from, Vendor stationFrom, Place to, Vendor stationTo, double balance) {
|
||||||
|
super(market);
|
||||||
|
this.from = from;
|
||||||
|
this.stationFrom = stationFrom;
|
||||||
|
this.to = to;
|
||||||
|
this.stationTo = stationTo;
|
||||||
|
this.balance = balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<Order> call() throws Exception {
|
||||||
|
Collection<Order> orders;
|
||||||
|
if (stationFrom != null){
|
||||||
|
if (stationTo != null){
|
||||||
|
orders = analyzer.getOrders(stationFrom, stationTo, balance);
|
||||||
|
} else {
|
||||||
|
if (to != null){
|
||||||
|
orders = analyzer.getOrders(stationFrom, to, balance);
|
||||||
|
} else {
|
||||||
|
orders = analyzer.getOrders(stationFrom, balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (stationTo != null){
|
||||||
|
orders = analyzer.getOrders(from, stationTo, balance);
|
||||||
|
} else {
|
||||||
|
if (to != null){
|
||||||
|
orders = analyzer.getOrders(from, to, balance);
|
||||||
|
} else {
|
||||||
|
if (from != null){
|
||||||
|
orders = analyzer.getOrders(from, balance);
|
||||||
|
} else {
|
||||||
|
orders = analyzer.getTop(balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return orders;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package ru.trader.services;
|
||||||
|
|
||||||
|
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>>{
|
||||||
|
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);
|
||||||
|
this.from = from;
|
||||||
|
this.stationFrom = stationFrom;
|
||||||
|
this.to = to;
|
||||||
|
this.stationTo = stationTo;
|
||||||
|
this.balance = balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<PathRoute> call() throws Exception {
|
||||||
|
Collection<PathRoute> routes;
|
||||||
|
|
||||||
|
if (stationFrom != null) {
|
||||||
|
if (stationTo != null) {
|
||||||
|
routes = analyzer.getPaths(stationFrom, stationTo, balance);
|
||||||
|
} else {
|
||||||
|
if (to != null) {
|
||||||
|
routes = analyzer.getPaths(stationFrom, to, balance);
|
||||||
|
} else {
|
||||||
|
routes = analyzer.getPaths(stationFrom, balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (stationTo != null) {
|
||||||
|
routes = analyzer.getPaths(from, stationTo, balance);
|
||||||
|
} else {
|
||||||
|
if (to != null) {
|
||||||
|
routes = analyzer.getPaths(from, to, balance);
|
||||||
|
} else {
|
||||||
|
if (from != null){
|
||||||
|
routes = analyzer.getPaths(from, balance);
|
||||||
|
} else {
|
||||||
|
routes = analyzer.getTopPaths(balance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return routes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -138,3 +138,14 @@ filter.radius=Rsdius(LY):
|
|||||||
filter.distance=Distance to station(Ls):
|
filter.distance=Distance to station(Ls):
|
||||||
filter.services=Services:
|
filter.services=Services:
|
||||||
filter.excludes=Excludes stations:
|
filter.excludes=Excludes stations:
|
||||||
|
|
||||||
|
# analyzer progress
|
||||||
|
analyzer.orders.title=Search orders
|
||||||
|
analyzer.routes.title=Search paths
|
||||||
|
analyzer.find.route=Finding paths from %s (%s) to %s (%s)
|
||||||
|
analyzer.find.routes=Finding paths from %s (%s)
|
||||||
|
analyzer.find.success=%d paths found
|
||||||
|
analyzer.graph.station.build=Building graph from %s (%s)
|
||||||
|
analyzer.graph.build=Building graph from %s
|
||||||
|
analyzer.graph.success=Graph is built
|
||||||
|
analyser.finish=Finish
|
||||||
@@ -138,3 +138,14 @@ filter.radius=\u0420\u0430\u0434\u0438\u0443\u0441(LY):
|
|||||||
filter.distance=\u0414\u0438\u0441\u0442\u0430\u043D\u0446\u0438\u044F \u0434\u043E \u0441\u0442\u0430\u043D\u0446\u0438\u0438(Ls):
|
filter.distance=\u0414\u0438\u0441\u0442\u0430\u043D\u0446\u0438\u044F \u0434\u043E \u0441\u0442\u0430\u043D\u0446\u0438\u0438(Ls):
|
||||||
filter.services=\u0421\u0435\u0440\u0432\u0438\u0441\u044B:
|
filter.services=\u0421\u0435\u0440\u0432\u0438\u0441\u044B:
|
||||||
filter.excludes=\u0418\u0441\u043A\u043B\u044E\u0447\u0430\u0435\u043C\u044B\u0435 \u0441\u0442\u0430\u043D\u0446\u0438\u0438:
|
filter.excludes=\u0418\u0441\u043A\u043B\u044E\u0447\u0430\u0435\u043C\u044B\u0435 \u0441\u0442\u0430\u043D\u0446\u0438\u0438:
|
||||||
|
|
||||||
|
# analyzer progress
|
||||||
|
analyzer.orders.title=\u041F\u043E\u0438\u0441\u043A \u0437\u0430\u043A\u0430\u0437\u043E\u0432
|
||||||
|
analyzer.routes.title=\u041F\u043E\u0438\u0441\u043A \u043C\u0430\u0440\u0448\u0440\u0443\u0442\u043E\u0432
|
||||||
|
analyzer.find.route=\u041F\u043E\u0438\u0441\u043A \u043F\u0443\u0442\u0435\u0439 \u043E\u0442 %s (%s) \u0434\u043E %s (%s)
|
||||||
|
analyzer.find.routes=\u041F\u043E\u0438\u0441\u043A \u043F\u0443\u0442\u0435\u0439 \u043E\u0442 %s (%s)
|
||||||
|
analyzer.find.success=%d \u043F\u0443\u0442\u0435\u0439 \u043D\u0430\u0439\u0434\u0435\u043D\u043E
|
||||||
|
analyzer.graph.station.build=\u041F\u043E\u0441\u0442\u0440\u043E\u0439\u043A\u0430 \u0433\u0440\u0430\u0444\u0430 \u043E\u0442 %s (%s)
|
||||||
|
analyzer.graph.build=\u041F\u043E\u0441\u0442\u0440\u043E\u0439\u043A\u0430 \u0433\u0440\u0430\u0444\u0430 \u043E\u0442 %s
|
||||||
|
analyzer.graph.success=\u0413\u0440\u0430\u0444 \u043F\u043E\u0441\u0442\u0440\u043E\u0435\u043D
|
||||||
|
analyser.finish=\u0413\u043E\u0442\u043E\u0432\u043E
|
||||||
@@ -68,7 +68,7 @@ public class MarketAnalyzer {
|
|||||||
LOG.debug("Get top {}", limit);
|
LOG.debug("Get top {}", limit);
|
||||||
Collection<Place> places = getPlaces();
|
Collection<Place> places = getPlaces();
|
||||||
List<Order> top = new ArrayList<>(limit);
|
List<Order> top = new ArrayList<>(limit);
|
||||||
callback.setCount(places.size());
|
callback.setMax(places.size());
|
||||||
for (Place place : places) {
|
for (Place place : places) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
LOG.trace("Check place {}", place);
|
LOG.trace("Check place {}", place);
|
||||||
@@ -98,7 +98,7 @@ public class MarketAnalyzer {
|
|||||||
|
|
||||||
private Collection<Order> getOrders(Graph<Place> graph, Collection<Vendor> sellers, double balance, double lowProfit) {
|
private Collection<Order> getOrders(Graph<Place> graph, Collection<Vendor> sellers, double balance, double lowProfit) {
|
||||||
List<Order> res = new ArrayList<>(20);
|
List<Order> res = new ArrayList<>(20);
|
||||||
callback.setCount(sellers.size());
|
callback.setMax(sellers.size());
|
||||||
for (Vendor vendor : sellers) {
|
for (Vendor vendor : sellers) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
if (isFiltered(vendor)){
|
if (isFiltered(vendor)){
|
||||||
@@ -143,7 +143,7 @@ public class MarketAnalyzer {
|
|||||||
|
|
||||||
private Collection<Order> getOrders(Collection<Vendor> sellers, Collection<Vendor> buyers, double balance, double lowProfit) {
|
private Collection<Order> getOrders(Collection<Vendor> sellers, Collection<Vendor> buyers, double balance, double lowProfit) {
|
||||||
List<Order> res = new ArrayList<>();
|
List<Order> res = new ArrayList<>();
|
||||||
callback.setCount(sellers.size());
|
callback.setMax(sellers.size());
|
||||||
for (Vendor seller : sellers) {
|
for (Vendor seller : sellers) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
if (isFiltered(seller)){
|
if (isFiltered(seller)){
|
||||||
@@ -235,7 +235,7 @@ public class MarketAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<PathRoute> getPaths(Vendor from, double balance){
|
public Collection<PathRoute> getPaths(Vendor from, double balance){
|
||||||
callback.setCount(1);
|
callback.setMax(1);
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors();
|
||||||
Collection<PathRoute> res = searcher.getPaths(from, vendors, jumps, balance, cargo, limit);
|
Collection<PathRoute> res = searcher.getPaths(from, vendors, jumps, balance, cargo, limit);
|
||||||
@@ -247,7 +247,7 @@ public class MarketAnalyzer {
|
|||||||
public Collection<PathRoute> getPaths(Place from, double balance){
|
public Collection<PathRoute> getPaths(Place from, double balance){
|
||||||
List<PathRoute> top = new ArrayList<>(limit);
|
List<PathRoute> top = new ArrayList<>(limit);
|
||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors();
|
||||||
callback.setCount(vendors.size());
|
callback.setMax(vendors.size());
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
for (Vendor vendor : from.get()) {
|
for (Vendor vendor : from.get()) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
@@ -265,7 +265,7 @@ public class MarketAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<PathRoute> getPaths(Vendor from, Vendor to, double balance){
|
public Collection<PathRoute> getPaths(Vendor from, Vendor to, double balance){
|
||||||
callback.setCount(1);
|
callback.setMax(1);
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
Collection<PathRoute> res = searcher.getPaths(from, to, getVendors(), jumps, balance, cargo, limit);
|
Collection<PathRoute> res = searcher.getPaths(from, to, getVendors(), jumps, balance, cargo, limit);
|
||||||
callback.inc();
|
callback.inc();
|
||||||
@@ -279,7 +279,7 @@ public class MarketAnalyzer {
|
|||||||
Collection<Vendor> fVendors = from.get();
|
Collection<Vendor> fVendors = from.get();
|
||||||
Collection<Vendor> toVendors = to.get();
|
Collection<Vendor> toVendors = to.get();
|
||||||
int count = (int) Math.ceil(limit / fVendors.size());
|
int count = (int) Math.ceil(limit / fVendors.size());
|
||||||
callback.setCount(fVendors.size() * toVendors.size());
|
callback.setMax(fVendors.size() * toVendors.size());
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
for (Vendor fromVendor : fVendors) {
|
for (Vendor fromVendor : fVendors) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
@@ -309,7 +309,7 @@ public class MarketAnalyzer {
|
|||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors();
|
||||||
Collection<Vendor> toVendors = to.get();
|
Collection<Vendor> toVendors = to.get();
|
||||||
int count = (int) Math.ceil(limit / toVendors.size());
|
int count = (int) Math.ceil(limit / toVendors.size());
|
||||||
callback.setCount(toVendors.size());
|
callback.setMax(toVendors.size());
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
for (Vendor toVendor : toVendors) {
|
for (Vendor toVendor : toVendors) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
@@ -331,7 +331,7 @@ public class MarketAnalyzer {
|
|||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors();
|
||||||
Collection<Vendor> fVendors = from.get();
|
Collection<Vendor> fVendors = from.get();
|
||||||
int count = (int) Math.ceil(limit / fVendors.size());
|
int count = (int) Math.ceil(limit / fVendors.size());
|
||||||
callback.setCount(fVendors.size());
|
callback.setMax(fVendors.size());
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
for (Vendor fromVendor : fVendors) {
|
for (Vendor fromVendor : fVendors) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
@@ -351,7 +351,7 @@ public class MarketAnalyzer {
|
|||||||
public Collection<PathRoute> getTopPaths(double balance){
|
public Collection<PathRoute> getTopPaths(double balance){
|
||||||
List<PathRoute> top = new ArrayList<>(limit);
|
List<PathRoute> top = new ArrayList<>(limit);
|
||||||
Collection<Vendor> vendors = getVendors();
|
Collection<Vendor> vendors = getVendors();
|
||||||
callback.setCount(vendors.size());
|
callback.setMax(vendors.size());
|
||||||
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
RouteSearcher searcher = new RouteSearcher(maxDistance, tank, segmentSize, callback.onStartSearch());
|
||||||
for (Vendor vendor : vendors) {
|
for (Vendor vendor : vendors) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class MarketAnalyzerCallBack {
|
|||||||
|
|
||||||
protected void onEnd(){}
|
protected void onEnd(){}
|
||||||
|
|
||||||
public void setCount(long count){}
|
public void setMax(long max){}
|
||||||
public void inc(){}
|
public void inc(){}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class Graph<T extends Connectable<T>> {
|
|||||||
public TopList<Path<T>> getPathsTo(T entry, int max, int deep){
|
public TopList<Path<T>> getPathsTo(T entry, int max, int deep){
|
||||||
Vertex<T> target = getVertex(entry);
|
Vertex<T> target = getVertex(entry);
|
||||||
TopList<Path<T>> paths = newTopList(max);
|
TopList<Path<T>> paths = newTopList(max);
|
||||||
callback.setCount(1);
|
callback.setMax(1);
|
||||||
findPathsTo(target, paths, deep);
|
findPathsTo(target, paths, deep);
|
||||||
callback.inc();
|
callback.inc();
|
||||||
paths.finish();
|
paths.finish();
|
||||||
@@ -118,7 +118,7 @@ public class Graph<T extends Connectable<T>> {
|
|||||||
|
|
||||||
public TopList<Path<T>> getPaths(int count, int deep){
|
public TopList<Path<T>> getPaths(int count, int deep){
|
||||||
TopList<Path<T>> paths = newTopList(count);
|
TopList<Path<T>> paths = newTopList(count);
|
||||||
callback.setCount(vertexes.size());
|
callback.setMax(vertexes.size());
|
||||||
for (Vertex<T> target : vertexes.values()) {
|
for (Vertex<T> target : vertexes.values()) {
|
||||||
if (callback.isCancel()) break;
|
if (callback.isCancel()) break;
|
||||||
TopList<Path<T>> p = newTopList(minJumps);
|
TopList<Path<T>> p = newTopList(minJumps);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public class GraphCallBack<T extends Connectable<T>> {
|
|||||||
public void onEndFind(){}
|
public void onEndFind(){}
|
||||||
|
|
||||||
|
|
||||||
public void setCount(long count){}
|
public void setMax(long count){}
|
||||||
public void inc(){}
|
public void inc(){}
|
||||||
|
|
||||||
public final boolean isCancel() {
|
public final boolean isCancel() {
|
||||||
|
|||||||
Reference in New Issue
Block a user