|
From: <aka...@us...> - 2013-10-01 16:15:13
|
Revision: 322
http://sourceforge.net/p/advance-project/code/322
Author: akarnokd
Date: 2013-10-01 16:15:09 +0000 (Tue, 01 Oct 2013)
Log Message:
-----------
Demo data generator.
Modified Paths:
--------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Consignment.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Postcode.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Vehicle.java
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java 2013-09-26 13:38:06 UTC (rev 321)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java 2013-10-01 16:15:09 UTC (rev 322)
@@ -20,14 +20,41 @@
*/
package eu.advance.logistics.live.reporter.db;
+import gnu.trove.map.TLongObjectMap;
+import gnu.trove.map.hash.TLongObjectHashMap;
import hu.akarnokd.utils.crypto.BCrypt;
import hu.akarnokd.utils.database.DB;
+import hu.akarnokd.utils.sequence.SequenceUtils;
+import java.awt.Point;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Random;
+import java.util.Set;
import org.joda.time.DateMidnight;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeConstants;
+import org.joda.time.LocalTime;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
+import eu.advance.logistics.live.reporter.model.Consignment;
+import eu.advance.logistics.live.reporter.model.Depot;
+import eu.advance.logistics.live.reporter.model.Hub;
+import eu.advance.logistics.live.reporter.model.Item;
+import eu.advance.logistics.live.reporter.model.ItemEventType;
+import eu.advance.logistics.live.reporter.model.Postcode;
+import eu.advance.logistics.live.reporter.model.ServiceLevel;
+import eu.advance.logistics.live.reporter.model.StorageArea;
import eu.advance.logistics.live.reporter.model.UserView;
+import eu.advance.logistics.live.reporter.model.Vehicle;
+import eu.advance.logistics.live.reporter.model.Warehouse;
/**
* Prepares the database with demo data.
@@ -43,65 +70,555 @@
*/
public static void main(String[] args) throws Exception {
try (DB db = DB.connect()) {
- // create hubs
- int nHubs = 2;
- for (int i = 1; i <= nHubs; i++) {
- db.update("INSERT IGNORE INTO hubs VALUES (?, ?, ?, ?)", i, "Hub " + i, 1000, 1000);
+ createMaster(db);
+
+ db.commit();
+
+ ConsignmentCreator cc = new ConsignmentCreator(db);
+ cc.init();
+ cc.run();
+ cc.done();
+
+ db.commit();
+ }
+ }
+ /**
+ * Create the basic hubs and depots.
+ * @param db the database connection
+ * @throws SQLException on error
+ */
+ private static void createMaster(DB db) throws SQLException {
+ // create hubs
+ int nHubs = 2;
+ for (int i = 1; i <= nHubs; i++) {
+ db.update("INSERT IGNORE INTO hubs VALUES (?, ?, ?, ?)", i, "Hub " + i, 1000, 1000);
+ }
+
+ // create depots
+ int nDepots = 20;
+ for (int i = 1; i <= nDepots; i++) {
+ db.update("INSERT IGNORE INTO depots VALUES (?, ?) ", i, "Depot " + i);
+
+ int nVehicles = (int)Math.ceil(5d * i / nDepots);
+
+ for (int j = 1; j <= nVehicles; j++) {
+ db.update("INSERT IGNORE INTO vehicles VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ "D" + i + "V" + j, i, Integer.class, Integer.class, 50, 4, 4, 15, 4000
+ );
}
+ }
+
+ // create warehouses per hub
+ int nWarehouses = 4;
+ int nLorryPositions = 4;
+
+ Random rnd = new Random(0);
+
+ for (int i = 1; i <= nHubs; i++) {
+ for (int j = 1; j <= nWarehouses; j++) {
+ int x = 500 + (j % 2 == 1 ? -100 : 100);
+ int y = 500 + (j % 2 == 1 ? -150 : 150);
+ int wi = ((i - 1) * nWarehouses + j);
+ db.update("INSERT IGNORE INTO warehouses VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ i, "Warehouse " + wi, x, y, 60, 100, 0, rnd.nextInt(5) + 5, "Warehouse " + (wi % 2 == 0 ? wi - 1 : wi + 1));
+
+ int sa = (nDepots / 2) * ((j - 1) / 2);
+ for (int k = 0; k < nDepots / 2; k++) {
+ db.update("INSERT IGNORE INTO storage_areas VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ i, "Warehouse " + wi, k % 2, k / 2, sa + k + 1, 20, 1.5, 0, 30
+ );
+ }
+ for (int k = 0; k < nLorryPositions; k++) {
+ int lx = k % 2 == 0 ? 23 : 32;
+ int ly = k / 2 == 0 ? 10 : 60;
+
+ int et = k / 2 == 0 ? 15 : 30;
+ int lt = k / 2 == 0 ? 30 : 15;
+
+ db.update("INSERT IGNORE INTO lorry_positions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ",
+ i, "Warehouse " + wi, k, lx, ly, 5, 20, et, lt);
+ }
+ }
+ }
+
+
+ // create hub, warehouse and depot users
+ for (int i = 1; i <= nHubs; i++) {
+ db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
+ "admin" + i, 1, Long.class, true, UserView.HUB.ordinal(), BCrypt.hashpw("admin" + i, BCrypt.gensalt()));
+
+ db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
+ "hub" + i, 1, Long.class, false, UserView.HUB.ordinal(), BCrypt.hashpw("hub" + i, BCrypt.gensalt()));
+
+ db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
+ "warehouse" + i, 1, Long.class, true, UserView.WAREHOUSE.ordinal(), BCrypt.hashpw("warehouse" + i, BCrypt.gensalt()));
+ }
+
+ for (int i = 1; i <= nDepots; i++) {
+ db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
+ "depot" + i, 1, i, false, UserView.HUB.ordinal(), BCrypt.hashpw("depot" + i, BCrypt.gensalt()));
+ }
+
+
+ // create holidays
+ int nStartYear = 2013;
+ int nEndYear = 2020;
+ for (int y = nStartYear; y <= nEndYear; y++) {
+ db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 1, 1));
+ db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 25));
+ db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 26));
+ db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 31));
+ }
+
+ int nPostcodes = 2000;
+ for (int i = 0; i < nPostcodes; i++) {
+ String pcg = "X" + (char)('A' + (i / 100));
- // create depots
- int nDepots = 20;
- for (int i = 1; i <= nDepots; i++) {
- db.update("INSERT IGNORE INTO depots VALUES (?, ?) ", i, "Depot " + i);
+ String pc = String.format("%s%02d", pcg, i % 100);
+
+ db.update("INSERT IGNORE INTO postcodes VALUES (?, ?, ?) ",
+ i + 1, pc, pcg);
+ }
+ }
+ /**
+ * Returns the position of a postcode.
+ * @param postcode the postcode in form 'XA00'
+ * @return the position
+ */
+ static Point postcodeLocation(String postcode) {
+ int c = postcode.charAt(1) - 'A';
+ int n = Integer.parseInt(postcode.substring(2));
+
+ return new Point(n, c * 3);
+ }
+ /**
+ * Returns the depot position.
+ * @param depot the depot
+ * @return the
+ */
+ static Point depotLocation(long depot) {
+ int x = (int)(16 + 16 * ((depot - 1) % 5));
+ int y = (int)(10 + 10 * ((depot - 1) / 5));
+
+ return new Point(x, y);
+ }
+ /**
+ * Returns the position of the hub.
+ * @param hub the hub id
+ * @return the position
+ */
+ static Point hubLocation(long hub) {
+ return new Point((int)(hub * 33), 30);
+ }
+ /**
+ * The consignment item with back-reference to the consignment itself.
+ * @author karnokd, 2013.10.01.
+ */
+ static class ConsItem extends Item {
+ /** The parent consignment. */
+ public Cons consignment;
+ }
+ /** The created consignment. */
+ static class Cons extends Consignment {
+ /** The consignment items. */
+ public final List<ConsItem> items = new ArrayList<>();
+ }
+ /**
+ * The base agent class.
+ * @author karnokd, 2013.10.01.
+ */
+ static class BaseAgent {
+ /** The database connection. */
+ DB db;
+ /**
+ * Set the database connection.
+ * @param db the database connection
+ */
+ public void setDb(DB db) {
+ this.db = db;
+ }
+ }
+ /**
+ * A depot manager "agent".
+ * @author karnokd, 2013.10.01.
+ *
+ */
+ static class DepotAgent extends BaseAgent {
+ /** Depot identifier. */
+ public long id;
+ /** The items to deliver. */
+ public final List<ConsItem> toDelivery = new ArrayList<>();
+ /** The items to dispatch. */
+ public final List<ConsItem> toDispatch = new ArrayList<>();
+ /** The list of vehicles. */
+ public final List<VehicleAgent> vehicles = new ArrayList<>();
+
+ }
+ /**
+ * A vehicle delivering items to and from hub.
+ * @author karnokd, 2013.10.01.
+ */
+ static class VehicleAgent extends BaseAgent {
+ /** The id. */
+ public String id;
+ /** The owner/target depot. */
+ public long depot;
+ /** The vehicle capacity. */
+ public int capacity;
+ /** The target hub, if moving towards it. */
+ public Long targetHub;
+ /** The session identifier. */
+ public String sessionId;
+ /** In a warehouse if not null. */
+ public String warehouse;
+ /** In a lorry position if not null. */
+ public Integer position;
+ /** The contents. */
+ public final List<ConsItem> contents = new ArrayList<>();
+ }
+ /**
+ * The hub agent.
+ * @author karnokd, 2013.10.01.
+ */
+ static class HubAgent extends BaseAgent {
+ /** Identifier. */
+ public long id;
+ /** List of vehicles on site. */
+ public final List<VehicleAgent> vehiclesOnSite = new ArrayList<>();
+ /** List of vehicles. */
+ public final List<WarehouseAgent> warehouses = new ArrayList<>();
+ }
+ /**
+ * A warehouse managing items.
+ * @author karnokd, 2013.10.01.
+ */
+ static class WarehouseAgent extends BaseAgent {
+ /** The hub. */
+ public long hub;
+ /** The warehouse. */
+ public String warehouse;
+ /** The depots and the current contents. */
+ public final Multimap<Long, ConsItem> storageAreas = HashMultimap.create();
+ /** List of vehicles on site. */
+ public final List<VehicleAgent> vehicles = new ArrayList<>();
+ }
+ /**
+ * Consignment creator.
+ * @author karnokd, 2013.10.01.
+ *
+ */
+ static class ConsignmentCreator {
+ /** The database connection. */
+ DB db;
+ /** Field. */
+ private List<Postcode> postcodes;
+ /** Field. */
+ private TLongObjectMap<Postcode> postcodeMap;
+ /** Field. */
+ private List<Vehicle> vehicles;
+ /** Field. */
+ private Multimap<Long, Vehicle> depotVehicles;
+ /** Field. */
+ private List<Hub> hubs;
+ /** Field. */
+ private TLongObjectMap<Hub> hubMap;
+ /** Field. */
+ private List<Depot> depots;
+ /** Field. */
+ private TLongObjectMap<Depot> depotMap;
+ /** Field. */
+ private Set<DateMidnight> holidays;
+ /** Field. */
+ private List<Warehouse> warehouses;
+ /** Field. */
+ private Multimap<Long, Warehouse> warehouseMap;
+ /** Field. */
+ private List<StorageArea> storages;
+ /** Field. */
+ private Multimap<String, StorageArea> areas;
+ /** Field. */
+ private TLongObjectMap<Depot> postcodeClosestDepot;
+ /** Field. */
+ private TLongObjectMap<Hub> depotClosestHub;
+ /** The running consignment id. */
+ private long consId;
+ /** The running item ids. */
+ private long itemId;
+ /** The map of depots. */
+ private final TLongObjectMap<DepotAgent> depotAgents = new TLongObjectHashMap<>();
+ /** The map of vehicles. */
+ private final TLongObjectMap<VehicleAgent> vehicleAgents = new TLongObjectHashMap<>();
+ /** The map of warehouses. */
+ private final Map<String, WarehouseAgent> warehouseAgents = new HashMap<>();
+ /** The map of hub agents. */
+ private final TLongObjectMap<HubAgent> hubAgents = new TLongObjectHashMap<>();
+ /**
+ * Constructor, sets the database connection.
+ * @param db the database connection
+ */
+ public ConsignmentCreator(DB db) {
+ this.db = db;
+ }
+ /**
+ * Initializes the environment.
+ * @throws SQLException ignored
+ */
+ public void init() throws SQLException {
+ postcodes = db.queryReadOnly("SELECT * FROM postcodes", Postcode.SELECT);
+ postcodeMap = new TLongObjectHashMap<>();
+ for (Postcode p : postcodes) {
+ postcodeMap.put(p.id, p);
}
- // create warehouses per hub
- int nWarehouses = 4;
+ vehicles = db.queryReadOnly("SELECT * FROM vehicles", Vehicle.SELECT);
+ depotVehicles = HashMultimap.create();
+ for (Vehicle v : vehicles) {
+ depotVehicles.put(v.depot, v);
+ }
- Random rnd = new Random(0);
+ hubs = db.queryReadOnly("SELECT * FROM hubs", Hub.SELECT);
+ hubMap = new TLongObjectHashMap<>();
+ for (Hub h : hubs) {
+ hubMap.put(h.id, h);
+ }
- for (int i = 1; i <= nHubs; i++) {
- for (int j = 1; j <= nWarehouses; j++) {
- int x = 500 + (j % 2 == 1 ? -100 : 100);
- int y = 500 + (j % 2 == 1 ? -150 : 150);
- int wi = ((i - 1) * nWarehouses + j);
- db.update("INSERT IGNORE INTO warehouses VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- i, "Warehouse " + wi, x, y, 60, 100, 0, rnd.nextInt(5) + 5, "Warehouse " + (wi % 2 == 0 ? wi - 1 : wi + 1));
- }
+ depots = db.queryReadOnly("SELECT * FROM depots", Depot.SELECT);
+ depotMap = new TLongObjectHashMap<>();
+ for (Depot d : depots) {
+ depotMap.put(d.id, d);
}
+ holidays = new HashSet<>();
+ db.queryReadOnly("SELECT holiday FROM holidays", SequenceUtils.into(holidays, DB.SELECT_DATEMIDNIGHT));
- // create hub, warehouse and depot users
- for (int i = 1; i <= nHubs; i++) {
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "admin" + i, 1, Long.class, true, UserView.HUB.ordinal(), BCrypt.hashpw("admin" + i, BCrypt.gensalt()));
-
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "hub" + i, 1, Long.class, false, UserView.HUB.ordinal(), BCrypt.hashpw("hub" + i, BCrypt.gensalt()));
-
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "warehouse" + i, 1, Long.class, true, UserView.WAREHOUSE.ordinal(), BCrypt.hashpw("warehouse" + i, BCrypt.gensalt()));
+ warehouses = db.queryReadOnly("SELECT * FROM warehouses", Warehouse.SELECT);
+ warehouseMap = HashMultimap.create();
+ for (Warehouse w : warehouses) {
+ warehouseMap.put(w.hub, w);
}
+
+ storages = db.queryReadOnly("SELECT * FROM storage_areas", StorageArea.SELECT);
+ areas = HashMultimap.create();
+ for (StorageArea s : storages) {
+ areas.put(s.warehouse, s);
+ }
+
+ postcodeClosestDepot = new TLongObjectHashMap<>();
+ for (Postcode pc : postcodes) {
+ double dist = 0d;
+ Depot dmin = null;
+ Point pcp = postcodeLocation(pc.code);
+ for (Depot d : depots) {
+ Point dd = depotLocation(d.id);
+ double dist1 = dd.distance(pcp);
- for (int i = 1; i <= nDepots; i++) {
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "depot" + i, 1, i, false, UserView.HUB.ordinal(), BCrypt.hashpw("depot" + i, BCrypt.gensalt()));
+ if (dmin == null || dist > dist1) {
+ dmin = d;
+ dist = dist1;
+ }
+ }
+ postcodeClosestDepot.put(pc.id, dmin);
}
-
- // create holidays
- int nStartYear = 2013;
- int nEndYear = 2020;
- for (int y = nStartYear; y <= nEndYear; y++) {
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 1, 1));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 25));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 26));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 31));
+ depotClosestHub = new TLongObjectHashMap<>();
+ for (Depot d : depots) {
+ Hub hmin = null;
+ double dist = 0d;
+ Point dd = depotLocation(d.id);
+ for (Hub h : hubs) {
+ Point hp = hubLocation(h.id);
+ double dist1 = hp.distance(dd);
+ if (hmin == null || dist > dist1) {
+ hmin = h;
+ dist = dist1;
+ }
+ }
+ depotClosestHub.put(d.id, hmin);
}
+
+ }
+ /**
+ * Generate.
+ * @throws SQLException ingored
+ */
+ public void run() throws SQLException {
+ DateMidnight startDay = new DateMidnight(2013, 7, 1);
+ DateMidnight endDay = new DateMidnight(2013, 12, 31);
+ DateMidnight day = startDay;
+ while (day.compareTo(endDay) <= 0) {
+ if (!holidays.contains(day)) {
+ int dow = day.getDayOfWeek();
+ if (dow != DateTimeConstants.SATURDAY && dow != DateTimeConstants.SUNDAY) {
+ System.out.printf("Day: %s%n", day);
+ List<Cons> cons = generate(day);
+ saveCons(cons);
+
+ db.commit();
+ }
+ }
+
+ day = day.plusDays(1);
+ }
+ }
+ /**
+ * Generate a day.
+ * @param day the day
+ * @throws SQLException ignored
+ * @return the generated consignments
+ */
+ List<Cons> generate(DateMidnight day) throws SQLException {
+ List<Cons> r = new ArrayList<>();
+ LocalTime lt = new LocalTime(7, 0);
+ int dy = day.getDayOfYear();
+ int dm = day.getDayOfMonth();
+ int dw = day.getDayOfWeek();
+ int k = 0;
+ for (Postcode pc : postcodes) {
+ if (pc.id % 5 != dw - 1) {
+ int nf = 0;
+ int nh = 0;
+ int nq = 0;
+ switch ((int)(pc.id % 3)) {
+ case 0:
+ nf = 1;
+ break;
+ case 1:
+ nh = 1;
+ nf = dy % 2 == 0 ? 1 : 0;
+ nq = dy % 2 != 0 ? 1 : 0;
+ break;
+ case 2:
+ nh = 2;
+ break;
+ default:
+ }
+
+ Postcode dpc = postcodes.get((k + postcodes.size() / 3) % postcodes.size());
+
+ Cons cs = new Cons();
+ r.add(cs);
+ cs.id = ++consId;
+ cs.created = day.toDateTime().withTime(lt.getHourOfDay(), lt.getMinuteOfHour(), lt.getSecondOfMinute(), lt.getMillisOfSecond());
+ cs.itemCount = nf + nh + nq;
+ cs.collectionPostcode = pc.id;
+ cs.collectionDepot = postcodeClosestDepot.get(pc.id).id;
+ cs.hub = depotClosestHub.get(cs.collectionDepot).id;
+ cs.deliveryPostcode = dpc.id;
+ cs.deliveryDepot = postcodeClosestDepot.get(dpc.id).id;
+
+ int sli = ((dm + k) % 30);
+ if (sli == 0) {
+ cs.service = ServiceLevel.SPECIAL;
+ } else
+ if (sli < 5) {
+ cs.service = ServiceLevel.STANDARD;
+ } else
+ if (sli < 9) {
+ cs.service = ServiceLevel.PRIORITY;
+ } else
+ if (sli < 18) {
+ cs.service = ServiceLevel.STANDARD;
+ } else
+ if (sli < 22) {
+ cs.service = ServiceLevel.PRIORITY;
+ } else {
+ cs.service = ServiceLevel.STANDARD;
+ }
+
+ for (int i = 0; i < nf; i++) {
+ ConsItem item = new ConsItem();
+ item.consignment = cs;
+ item.id = ++itemId;
+ item.length = 1;
+ item.width = 1;
+ item.height = 1;
+ cs.items.add(item);
+ }
+ for (int i = 0; i < nh; i++) {
+ ConsItem item = new ConsItem();
+ item.consignment = cs;
+ item.id = ++itemId;
+ item.length = 1;
+ item.width = 1;
+ item.height = 0.5;
+ cs.items.add(item);
+ }
+ for (int i = 0; i < nq; i++) {
+ ConsItem item = new ConsItem();
+ item.consignment = cs;
+ item.id = ++itemId;
+ item.length = 1;
+ item.width = 1;
+ item.height = 0.25;
+ cs.items.add(item);
+ }
+ }
+
+ lt = lt.plusSeconds(15);
+ k++;
+ }
+ return r;
+ }
+ /**
+ * Save the consignments and items.
+ * @param seq the sequence
+ * @throws SQLException on error
+ */
+ void saveCons(Iterable<Cons> seq) throws SQLException {
+ for (Cons cs : seq) {
+ db.update("INSERT IGNORE INTO consignments VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ cs.id, cs.created, DateTime.class,
+ cs.hub, cs.collectionDepot, cs.collectionPostcode,
+ cs.deliveryDepot, cs.deliveryPostcode,
+ cs.service.ordinal(), cs.itemCount, String.class);
+
+ db.update("INSERT IGNORE INTO consignments_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ cs.id, cs.created, DateTime.class,
+ cs.hub, cs.collectionDepot, cs.collectionPostcode,
+ cs.deliveryDepot, cs.deliveryPostcode,
+ cs.service.ordinal(), cs.itemCount, String.class);
+
+ for (Item item : cs.items) {
+ db.update("INSERT IGNORE INTO items VALUES (?, ?, ?, ?, ?, ?) ",
+ item.id, cs.id, String.class, item.width, item.height, item.length);
+ db.update("INSERT IGNORE INTO items_history VALUES (?, ?, ?, ?, ?, ?) ",
+ item.id, cs.id, String.class, item.width, item.height, item.length);
+
+ db.update("INSERT IGNORE INTO events VALUES (?, ?, ?, ?)",
+ item.id, cs.id, cs.created, ItemEventType.CREATED.ordinal());
+ }
+ }
+ }
+ /**
+ * Returns the distance between a postcode and a depot.
+ * @param postcode the postcode
+ * @param depot the depot
+ * @return the distance
+ */
+ public double postcodeDepotDistance(long postcode, long depot) {
+ Point pc = postcodeLocation(postcodeMap.get(postcode).code);
+ Point pd = depotLocation(depot);
+ return pc.distance(pd);
+ }
+ /**
+ * The distance between a hub and depot.
+ * @param depot the depot
+ * @param hub the hub
+ * @return the distance
+ */
+ public double depotHubDistance(long depot, long hub) {
+ Point pd = depotLocation(depot);
+ Point ph = hubLocation(hub);
+ return pd.distance(ph);
+ }
+ /**
+ * Complete.
+ * @throws SQLException ignored
+ */
+ public void done() throws SQLException {
- db.commit();
}
}
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Consignment.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Consignment.java 2013-09-26 13:38:06 UTC (rev 321)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Consignment.java 2013-10-01 16:15:09 UTC (rev 322)
@@ -36,6 +36,8 @@
/** When the consignment was declared. */
@Nullable
public DateTime declared;
+ /** The target hub. */
+ public long hub;
/** Collection depot. */
public long collectionDepot;
/** Collection postcode. */
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Postcode.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Postcode.java 2013-09-26 13:38:06 UTC (rev 321)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Postcode.java 2013-10-01 16:15:09 UTC (rev 322)
@@ -20,6 +20,11 @@
*/
package eu.advance.logistics.live.reporter.model;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import hu.akarnokd.utils.database.SQLResult;
+
/**
* A postcode record class.
* @author karnokd, 2013.09.23.
@@ -31,4 +36,15 @@
public String code;
/** The grouping of the postcode. */
public String group;
+ /** Default select. */
+ public static final SQLResult<Postcode> SELECT = new SQLResult<Postcode>() {
+ @Override
+ public Postcode invoke(ResultSet t) throws SQLException {
+ Postcode r = new Postcode();
+ r.id = t.getLong(1);
+ r.code = t.getString(2);
+ r.group = t.getString(3);
+ return r;
+ }
+ };
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Vehicle.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Vehicle.java 2013-09-26 13:38:06 UTC (rev 321)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/Vehicle.java 2013-10-01 16:15:09 UTC (rev 322)
@@ -20,6 +20,12 @@
*/
package eu.advance.logistics.live.reporter.model;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import hu.akarnokd.utils.database.DB;
+import hu.akarnokd.utils.database.SQLResult;
+
/**
* A vehicle record class.
* @author karnokd, 2013.09.23.
@@ -43,4 +49,23 @@
public double length;
/** Storage weight. */
public double weight;
+ /** Default select. */
+ public static final SQLResult<Vehicle> SELECT = new SQLResult<Vehicle>() {
+ @Override
+ public Vehicle invoke(ResultSet t) throws SQLException {
+ Vehicle r = new Vehicle();
+
+ r.vehicleId = t.getString(1);
+ r.depot = t.getLong(2);
+ r.currentJob = DB.getLong(t, 3);
+ r.currentPosition = DB.getInt(t, 4);
+ r.capacity = t.getInt(5);
+ r.width = t.getDouble(6);
+ r.height = t.getDouble(7);
+ r.length = t.getDouble(8);
+ r.weight = t.getDouble(9);
+
+ return r;
+ }
+ };
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aka...@us...> - 2013-10-02 13:57:03
|
Revision: 323
http://sourceforge.net/p/advance-project/code/323
Author: akarnokd
Date: 2013-10-02 13:57:00 +0000 (Wed, 02 Oct 2013)
Log Message:
-----------
Demo refactor and more things implemented
Modified Paths:
--------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/LorryPosition.java
Added Paths:
-----------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/CompareFirst.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Cons.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsItem.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Demo.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/DepotAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/EnvironmentAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/HubAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/VehicleAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/WarehouseAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/package-info.java
Removed Paths:
-------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java
Deleted: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java 2013-10-01 16:15:09 UTC (rev 322)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/Demo.java 2013-10-02 13:57:00 UTC (rev 323)
@@ -1,624 +0,0 @@
-/*
- * Copyright 2010-2013 The Advance EU 7th Framework project consortium
- *
- * This file is part of Advance.
- *
- * Advance is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of
- * the License, or (at your option) any later version.
- *
- * Advance is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Advance. If not, see
- * <http://www.gnu.org/licenses/>.
- *
- */
-package eu.advance.logistics.live.reporter.db;
-
-import gnu.trove.map.TLongObjectMap;
-import gnu.trove.map.hash.TLongObjectHashMap;
-import hu.akarnokd.utils.crypto.BCrypt;
-import hu.akarnokd.utils.database.DB;
-import hu.akarnokd.utils.sequence.SequenceUtils;
-
-import java.awt.Point;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Random;
-import java.util.Set;
-
-import org.joda.time.DateMidnight;
-import org.joda.time.DateTime;
-import org.joda.time.DateTimeConstants;
-import org.joda.time.LocalTime;
-
-import com.google.common.collect.HashMultimap;
-import com.google.common.collect.Multimap;
-
-import eu.advance.logistics.live.reporter.model.Consignment;
-import eu.advance.logistics.live.reporter.model.Depot;
-import eu.advance.logistics.live.reporter.model.Hub;
-import eu.advance.logistics.live.reporter.model.Item;
-import eu.advance.logistics.live.reporter.model.ItemEventType;
-import eu.advance.logistics.live.reporter.model.Postcode;
-import eu.advance.logistics.live.reporter.model.ServiceLevel;
-import eu.advance.logistics.live.reporter.model.StorageArea;
-import eu.advance.logistics.live.reporter.model.UserView;
-import eu.advance.logistics.live.reporter.model.Vehicle;
-import eu.advance.logistics.live.reporter.model.Warehouse;
-
-/**
- * Prepares the database with demo data.
- * @author karnokd, 2013.09.24.
- */
-public final class Demo {
- /** Demo. */
- private Demo() { }
- /**
- * The demo program.
- * @param args no arguments
- * @throws Exception ignored
- */
- public static void main(String[] args) throws Exception {
- try (DB db = DB.connect()) {
- createMaster(db);
-
- db.commit();
-
- ConsignmentCreator cc = new ConsignmentCreator(db);
- cc.init();
- cc.run();
- cc.done();
-
- db.commit();
- }
- }
- /**
- * Create the basic hubs and depots.
- * @param db the database connection
- * @throws SQLException on error
- */
- private static void createMaster(DB db) throws SQLException {
- // create hubs
- int nHubs = 2;
- for (int i = 1; i <= nHubs; i++) {
- db.update("INSERT IGNORE INTO hubs VALUES (?, ?, ?, ?)", i, "Hub " + i, 1000, 1000);
- }
-
- // create depots
- int nDepots = 20;
- for (int i = 1; i <= nDepots; i++) {
- db.update("INSERT IGNORE INTO depots VALUES (?, ?) ", i, "Depot " + i);
-
- int nVehicles = (int)Math.ceil(5d * i / nDepots);
-
- for (int j = 1; j <= nVehicles; j++) {
- db.update("INSERT IGNORE INTO vehicles VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- "D" + i + "V" + j, i, Integer.class, Integer.class, 50, 4, 4, 15, 4000
- );
- }
- }
-
- // create warehouses per hub
- int nWarehouses = 4;
- int nLorryPositions = 4;
-
- Random rnd = new Random(0);
-
- for (int i = 1; i <= nHubs; i++) {
- for (int j = 1; j <= nWarehouses; j++) {
- int x = 500 + (j % 2 == 1 ? -100 : 100);
- int y = 500 + (j % 2 == 1 ? -150 : 150);
- int wi = ((i - 1) * nWarehouses + j);
- db.update("INSERT IGNORE INTO warehouses VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- i, "Warehouse " + wi, x, y, 60, 100, 0, rnd.nextInt(5) + 5, "Warehouse " + (wi % 2 == 0 ? wi - 1 : wi + 1));
-
- int sa = (nDepots / 2) * ((j - 1) / 2);
- for (int k = 0; k < nDepots / 2; k++) {
- db.update("INSERT IGNORE INTO storage_areas VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
- i, "Warehouse " + wi, k % 2, k / 2, sa + k + 1, 20, 1.5, 0, 30
- );
- }
- for (int k = 0; k < nLorryPositions; k++) {
- int lx = k % 2 == 0 ? 23 : 32;
- int ly = k / 2 == 0 ? 10 : 60;
-
- int et = k / 2 == 0 ? 15 : 30;
- int lt = k / 2 == 0 ? 30 : 15;
-
- db.update("INSERT IGNORE INTO lorry_positions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ",
- i, "Warehouse " + wi, k, lx, ly, 5, 20, et, lt);
- }
- }
- }
-
-
- // create hub, warehouse and depot users
- for (int i = 1; i <= nHubs; i++) {
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "admin" + i, 1, Long.class, true, UserView.HUB.ordinal(), BCrypt.hashpw("admin" + i, BCrypt.gensalt()));
-
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "hub" + i, 1, Long.class, false, UserView.HUB.ordinal(), BCrypt.hashpw("hub" + i, BCrypt.gensalt()));
-
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "warehouse" + i, 1, Long.class, true, UserView.WAREHOUSE.ordinal(), BCrypt.hashpw("warehouse" + i, BCrypt.gensalt()));
- }
-
- for (int i = 1; i <= nDepots; i++) {
- db.update("INSERT IGNORE INTO users (name, hub, depot, admin, default_view, password) VALUES (?, ?, ?, ?, ?, ?)",
- "depot" + i, 1, i, false, UserView.HUB.ordinal(), BCrypt.hashpw("depot" + i, BCrypt.gensalt()));
- }
-
-
- // create holidays
- int nStartYear = 2013;
- int nEndYear = 2020;
- for (int y = nStartYear; y <= nEndYear; y++) {
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 1, 1));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 25));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 26));
- db.update("INSERT IGNORE INTO holidays VALUES (?)", new DateMidnight(y, 12, 31));
- }
-
- int nPostcodes = 2000;
- for (int i = 0; i < nPostcodes; i++) {
- String pcg = "X" + (char)('A' + (i / 100));
-
- String pc = String.format("%s%02d", pcg, i % 100);
-
- db.update("INSERT IGNORE INTO postcodes VALUES (?, ?, ?) ",
- i + 1, pc, pcg);
- }
- }
- /**
- * Returns the position of a postcode.
- * @param postcode the postcode in form 'XA00'
- * @return the position
- */
- static Point postcodeLocation(String postcode) {
- int c = postcode.charAt(1) - 'A';
- int n = Integer.parseInt(postcode.substring(2));
-
- return new Point(n, c * 3);
- }
- /**
- * Returns the depot position.
- * @param depot the depot
- * @return the
- */
- static Point depotLocation(long depot) {
- int x = (int)(16 + 16 * ((depot - 1) % 5));
- int y = (int)(10 + 10 * ((depot - 1) / 5));
-
- return new Point(x, y);
- }
- /**
- * Returns the position of the hub.
- * @param hub the hub id
- * @return the position
- */
- static Point hubLocation(long hub) {
- return new Point((int)(hub * 33), 30);
- }
- /**
- * The consignment item with back-reference to the consignment itself.
- * @author karnokd, 2013.10.01.
- */
- static class ConsItem extends Item {
- /** The parent consignment. */
- public Cons consignment;
- }
- /** The created consignment. */
- static class Cons extends Consignment {
- /** The consignment items. */
- public final List<ConsItem> items = new ArrayList<>();
- }
- /**
- * The base agent class.
- * @author karnokd, 2013.10.01.
- */
- static class BaseAgent {
- /** The database connection. */
- DB db;
- /**
- * Set the database connection.
- * @param db the database connection
- */
- public void setDb(DB db) {
- this.db = db;
- }
- }
- /**
- * A depot manager "agent".
- * @author karnokd, 2013.10.01.
- *
- */
- static class DepotAgent extends BaseAgent {
- /** Depot identifier. */
- public long id;
- /** The items to deliver. */
- public final List<ConsItem> toDelivery = new ArrayList<>();
- /** The items to dispatch. */
- public final List<ConsItem> toDispatch = new ArrayList<>();
- /** The list of vehicles. */
- public final List<VehicleAgent> vehicles = new ArrayList<>();
-
- }
- /**
- * A vehicle delivering items to and from hub.
- * @author karnokd, 2013.10.01.
- */
- static class VehicleAgent extends BaseAgent {
- /** The id. */
- public String id;
- /** The owner/target depot. */
- public long depot;
- /** The vehicle capacity. */
- public int capacity;
- /** The target hub, if moving towards it. */
- public Long targetHub;
- /** The session identifier. */
- public String sessionId;
- /** In a warehouse if not null. */
- public String warehouse;
- /** In a lorry position if not null. */
- public Integer position;
- /** The contents. */
- public final List<ConsItem> contents = new ArrayList<>();
- }
- /**
- * The hub agent.
- * @author karnokd, 2013.10.01.
- */
- static class HubAgent extends BaseAgent {
- /** Identifier. */
- public long id;
- /** List of vehicles on site. */
- public final List<VehicleAgent> vehiclesOnSite = new ArrayList<>();
- /** List of vehicles. */
- public final List<WarehouseAgent> warehouses = new ArrayList<>();
- }
- /**
- * A warehouse managing items.
- * @author karnokd, 2013.10.01.
- */
- static class WarehouseAgent extends BaseAgent {
- /** The hub. */
- public long hub;
- /** The warehouse. */
- public String warehouse;
- /** The depots and the current contents. */
- public final Multimap<Long, ConsItem> storageAreas = HashMultimap.create();
- /** List of vehicles on site. */
- public final List<VehicleAgent> vehicles = new ArrayList<>();
- }
- /**
- * Consignment creator.
- * @author karnokd, 2013.10.01.
- *
- */
- static class ConsignmentCreator {
- /** The database connection. */
- DB db;
- /** Field. */
- private List<Postcode> postcodes;
- /** Field. */
- private TLongObjectMap<Postcode> postcodeMap;
- /** Field. */
- private List<Vehicle> vehicles;
- /** Field. */
- private Multimap<Long, Vehicle> depotVehicles;
- /** Field. */
- private List<Hub> hubs;
- /** Field. */
- private TLongObjectMap<Hub> hubMap;
- /** Field. */
- private List<Depot> depots;
- /** Field. */
- private TLongObjectMap<Depot> depotMap;
- /** Field. */
- private Set<DateMidnight> holidays;
- /** Field. */
- private List<Warehouse> warehouses;
- /** Field. */
- private Multimap<Long, Warehouse> warehouseMap;
- /** Field. */
- private List<StorageArea> storages;
- /** Field. */
- private Multimap<String, StorageArea> areas;
- /** Field. */
- private TLongObjectMap<Depot> postcodeClosestDepot;
- /** Field. */
- private TLongObjectMap<Hub> depotClosestHub;
- /** The running consignment id. */
- private long consId;
- /** The running item ids. */
- private long itemId;
- /** The map of depots. */
- private final TLongObjectMap<DepotAgent> depotAgents = new TLongObjectHashMap<>();
- /** The map of vehicles. */
- private final TLongObjectMap<VehicleAgent> vehicleAgents = new TLongObjectHashMap<>();
- /** The map of warehouses. */
- private final Map<String, WarehouseAgent> warehouseAgents = new HashMap<>();
- /** The map of hub agents. */
- private final TLongObjectMap<HubAgent> hubAgents = new TLongObjectHashMap<>();
- /**
- * Constructor, sets the database connection.
- * @param db the database connection
- */
- public ConsignmentCreator(DB db) {
- this.db = db;
- }
- /**
- * Initializes the environment.
- * @throws SQLException ignored
- */
- public void init() throws SQLException {
- postcodes = db.queryReadOnly("SELECT * FROM postcodes", Postcode.SELECT);
- postcodeMap = new TLongObjectHashMap<>();
- for (Postcode p : postcodes) {
- postcodeMap.put(p.id, p);
- }
-
- vehicles = db.queryReadOnly("SELECT * FROM vehicles", Vehicle.SELECT);
- depotVehicles = HashMultimap.create();
- for (Vehicle v : vehicles) {
- depotVehicles.put(v.depot, v);
- }
-
- hubs = db.queryReadOnly("SELECT * FROM hubs", Hub.SELECT);
- hubMap = new TLongObjectHashMap<>();
- for (Hub h : hubs) {
- hubMap.put(h.id, h);
- }
-
- depots = db.queryReadOnly("SELECT * FROM depots", Depot.SELECT);
- depotMap = new TLongObjectHashMap<>();
- for (Depot d : depots) {
- depotMap.put(d.id, d);
- }
-
- holidays = new HashSet<>();
- db.queryReadOnly("SELECT holiday FROM holidays", SequenceUtils.into(holidays, DB.SELECT_DATEMIDNIGHT));
-
- warehouses = db.queryReadOnly("SELECT * FROM warehouses", Warehouse.SELECT);
- warehouseMap = HashMultimap.create();
- for (Warehouse w : warehouses) {
- warehouseMap.put(w.hub, w);
- }
-
- storages = db.queryReadOnly("SELECT * FROM storage_areas", StorageArea.SELECT);
- areas = HashMultimap.create();
- for (StorageArea s : storages) {
- areas.put(s.warehouse, s);
- }
-
- postcodeClosestDepot = new TLongObjectHashMap<>();
- for (Postcode pc : postcodes) {
- double dist = 0d;
- Depot dmin = null;
- Point pcp = postcodeLocation(pc.code);
- for (Depot d : depots) {
- Point dd = depotLocation(d.id);
- double dist1 = dd.distance(pcp);
-
- if (dmin == null || dist > dist1) {
- dmin = d;
- dist = dist1;
- }
- }
- postcodeClosestDepot.put(pc.id, dmin);
- }
-
- depotClosestHub = new TLongObjectHashMap<>();
- for (Depot d : depots) {
- Hub hmin = null;
- double dist = 0d;
- Point dd = depotLocation(d.id);
- for (Hub h : hubs) {
- Point hp = hubLocation(h.id);
- double dist1 = hp.distance(dd);
- if (hmin == null || dist > dist1) {
- hmin = h;
- dist = dist1;
- }
- }
- depotClosestHub.put(d.id, hmin);
- }
-
- }
- /**
- * Generate.
- * @throws SQLException ingored
- */
- public void run() throws SQLException {
- DateMidnight startDay = new DateMidnight(2013, 7, 1);
- DateMidnight endDay = new DateMidnight(2013, 12, 31);
-
- DateMidnight day = startDay;
-
- while (day.compareTo(endDay) <= 0) {
- if (!holidays.contains(day)) {
- int dow = day.getDayOfWeek();
- if (dow != DateTimeConstants.SATURDAY && dow != DateTimeConstants.SUNDAY) {
- System.out.printf("Day: %s%n", day);
- List<Cons> cons = generate(day);
- saveCons(cons);
-
- db.commit();
- }
- }
-
- day = day.plusDays(1);
- }
- }
- /**
- * Generate a day.
- * @param day the day
- * @throws SQLException ignored
- * @return the generated consignments
- */
- List<Cons> generate(DateMidnight day) throws SQLException {
- List<Cons> r = new ArrayList<>();
- LocalTime lt = new LocalTime(7, 0);
- int dy = day.getDayOfYear();
- int dm = day.getDayOfMonth();
- int dw = day.getDayOfWeek();
- int k = 0;
- for (Postcode pc : postcodes) {
- if (pc.id % 5 != dw - 1) {
- int nf = 0;
- int nh = 0;
- int nq = 0;
- switch ((int)(pc.id % 3)) {
- case 0:
- nf = 1;
- break;
- case 1:
- nh = 1;
- nf = dy % 2 == 0 ? 1 : 0;
- nq = dy % 2 != 0 ? 1 : 0;
- break;
- case 2:
- nh = 2;
- break;
- default:
- }
-
- Postcode dpc = postcodes.get((k + postcodes.size() / 3) % postcodes.size());
-
- Cons cs = new Cons();
- r.add(cs);
- cs.id = ++consId;
- cs.created = day.toDateTime().withTime(lt.getHourOfDay(), lt.getMinuteOfHour(), lt.getSecondOfMinute(), lt.getMillisOfSecond());
- cs.itemCount = nf + nh + nq;
- cs.collectionPostcode = pc.id;
- cs.collectionDepot = postcodeClosestDepot.get(pc.id).id;
- cs.hub = depotClosestHub.get(cs.collectionDepot).id;
- cs.deliveryPostcode = dpc.id;
- cs.deliveryDepot = postcodeClosestDepot.get(dpc.id).id;
-
- int sli = ((dm + k) % 30);
- if (sli == 0) {
- cs.service = ServiceLevel.SPECIAL;
- } else
- if (sli < 5) {
- cs.service = ServiceLevel.STANDARD;
- } else
- if (sli < 9) {
- cs.service = ServiceLevel.PRIORITY;
- } else
- if (sli < 18) {
- cs.service = ServiceLevel.STANDARD;
- } else
- if (sli < 22) {
- cs.service = ServiceLevel.PRIORITY;
- } else {
- cs.service = ServiceLevel.STANDARD;
- }
-
- for (int i = 0; i < nf; i++) {
- ConsItem item = new ConsItem();
- item.consignment = cs;
- item.id = ++itemId;
- item.length = 1;
- item.width = 1;
- item.height = 1;
- cs.items.add(item);
- }
- for (int i = 0; i < nh; i++) {
- ConsItem item = new ConsItem();
- item.consignment = cs;
- item.id = ++itemId;
- item.length = 1;
- item.width = 1;
- item.height = 0.5;
- cs.items.add(item);
- }
- for (int i = 0; i < nq; i++) {
- ConsItem item = new ConsItem();
- item.consignment = cs;
- item.id = ++itemId;
- item.length = 1;
- item.width = 1;
- item.height = 0.25;
- cs.items.add(item);
- }
- }
-
- lt = lt.plusSeconds(15);
- k++;
- }
- return r;
- }
- /**
- * Save the consignments and items.
- * @param seq the sequence
- * @throws SQLException on error
- */
- void saveCons(Iterable<Cons> seq) throws SQLException {
- for (Cons cs : seq) {
- db.update("INSERT IGNORE INTO consignments VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- cs.id, cs.created, DateTime.class,
- cs.hub, cs.collectionDepot, cs.collectionPostcode,
- cs.deliveryDepot, cs.deliveryPostcode,
- cs.service.ordinal(), cs.itemCount, String.class);
-
- db.update("INSERT IGNORE INTO consignments_history VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
- cs.id, cs.created, DateTime.class,
- cs.hub, cs.collectionDepot, cs.collectionPostcode,
- cs.deliveryDepot, cs.deliveryPostcode,
- cs.service.ordinal(), cs.itemCount, String.class);
-
- for (Item item : cs.items) {
- db.update("INSERT IGNORE INTO items VALUES (?, ?, ?, ?, ?, ?) ",
- item.id, cs.id, String.class, item.width, item.height, item.length);
- db.update("INSERT IGNORE INTO items_history VALUES (?, ?, ?, ?, ?, ?) ",
- item.id, cs.id, String.class, item.width, item.height, item.length);
-
- db.update("INSERT IGNORE INTO events VALUES (?, ?, ?, ?)",
- item.id, cs.id, cs.created, ItemEventType.CREATED.ordinal());
- }
- }
- }
- /**
- * Returns the distance between a postcode and a depot.
- * @param postcode the postcode
- * @param depot the depot
- * @return the distance
- */
- public double postcodeDepotDistance(long postcode, long depot) {
- Point pc = postcodeLocation(postcodeMap.get(postcode).code);
- Point pd = depotLocation(depot);
- return pc.distance(pd);
- }
- /**
- * The distance between a hub and depot.
- * @param depot the depot
- * @param hub the hub
- * @return the distance
- */
- public double depotHubDistance(long depot, long hub) {
- Point pd = depotLocation(depot);
- Point ph = hubLocation(hub);
- return pd.distance(ph);
- }
- /**
- * Complete.
- * @throws SQLException ignored
- */
- public void done() throws SQLException {
-
- }
- }
-}
Added: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/CompareFirst.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/CompareFirst.java (rev 0)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/CompareFirst.java 2013-10-02 13:57:00 UTC (rev 323)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010-2013 The Advance EU 7th Framework project consortium
+ *
+ * This file is part of Advance.
+ *
+ * Advance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Advance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Advance. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+package eu.advance.logistics.live.reporter.demo;
+
+import hu.akarnokd.reactive4java.base.Pair;
+
+import java.util.Comparator;
+
+import org.joda.time.DateTime;
+
+/**
+ * Compare the first element of a pair.
+ * @author karnokd, 2013.10.02.
+ */
+public class CompareFirst implements Comparator<Pair<DateTime, ?>> {
+ @Override
+ public int compare(Pair<DateTime, ?> o1, Pair<DateTime, ?> o2) {
+ return o1.first.compareTo(o2.first);
+ }
+}
\ No newline at end of file
Added: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Cons.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Cons.java (rev 0)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Cons.java 2013-10-02 13:57:00 UTC (rev 323)
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010-2013 The Advance EU 7th Framework project consortium
+ *
+ * This file is part of Advance.
+ *
+ * Advance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Advance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Advance. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+package eu.advance.logistics.live.reporter.demo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import eu.advance.logistics.live.reporter.model.Consignment;
+
+/** The created consignment. */
+public class Cons extends Consignment {
+ /** The consignment items. */
+ public final List<ConsItem> items = new ArrayList<>();
+}
\ No newline at end of file
Added: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsItem.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsItem.java (rev 0)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsItem.java 2013-10-02 13:57:00 UTC (rev 323)
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2010-2013 The Advance EU 7th Framework project consortium
+ *
+ * This file is part of Advance.
+ *
+ * Advance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Advance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Advance. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+package eu.advance.logistics.live.reporter.demo;
+
+import eu.advance.logistics.live.reporter.model.Item;
+
+/**
+ * The consignment item with back-reference to the consignment itself.
+ * @author karnokd, 2013.10.01.
+ */
+public class ConsItem extends Item {
+ /** The parent consignment. */
+ public Cons consignment;
+}
\ No newline at end of file
Added: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java (rev 0)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java 2013-10-02 13:57:00 UTC (rev 323)
@@ -0,0 +1,387 @@
+/*
+ * Copyright 2010-2013 The Advance EU 7th Framework project consortium
+ *
+ * This file is part of Advance.
+ *
+ * Advance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * Advance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Advance. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+package eu.advance.logistics.live.reporter.demo;
+
+import gnu.trove.map.TLongObjectMap;
+import gnu.trove.map.hash.TLongObjectHashMap;
+import hu.akarnokd.utils.database.DB;
+import hu.akarnokd.utils.sequence.SequenceUtils;
+
+import java.awt.Point;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.joda.time.DateMidnight;
+import org.joda.time.DateTime;
+import org.joda.time.DateTimeConstants;
+import org.joda.time.LocalTime;
+
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
+import eu.advance.logistics.live.reporter.model.Depot;
+import eu.advance.logistics.live.reporter.model.Hub;
+import eu.advance.logistics.live.reporter.model.Item;
+import eu.advance.logistics.live.reporter.model.LorryPosition;
+import eu.advance.logistics.live.reporter.model.Postcode;
+import eu.advance.logistics.live.reporter.model.ServiceLevel;
+import eu.advance.logistics.live.reporter.model.StorageArea;
+import eu.advance.logistics.live.reporter.model.Vehicle;
+import eu.advance.logistics.live.reporter.model.Warehouse;
+
+/**
+ * Consignment creator.
+ * @author karnokd, 2013.10.01.
+ *
+ */
+public class ConsignmentCreator {
+ /** The database connection. */
+ DB db;
+ /** Field. */
+ private List<Postcode> postcodes;
+ /** Field. */
+ private TLongObjectMap<Postcode> postcodeMap;
+ /** Field. */
+ private List<Vehicle> vehicles;
+ /** Field. */
+ private Multimap<Long, Vehicle> depotVehicles;
+ /** Field. */
+ private List<Hub> hubs;
+ /** Field. */
+ private TLongObjectMap<Hub> hubMap;
+ /** Field. */
+ private List<Depot> depots;
+ /** Field. */
+ private TLongObjectMap<Depot> depotMap;
+ /** Field. */
+ private Set<DateMidnight> holidays;
+ /** Field. */
+ private List<Warehouse> warehouses;
+ /** Field. */
+ private Multimap<Long, Warehouse> warehouseMap;
+ /** Field. */
+ private List<StorageArea> storages;
+ /** Field. */
+ private Multimap<String, StorageArea> areas;
+ /** Field. */
+ private TLongObjectMap<Depot> postcodeClosestDepot;
+ /** Field. */
+ private TLongObjectMap<Hub> depotClosestHub;
+ /** The running consignment id. */
+ private long consId;
+ /** The running item ids. */
+ private long itemId;
+ /** The environment agent. */
+ private EnvironmentAgent env;
+ /**
+ * Constructor, sets the database connection.
+ * @param db the database connection
+ */
+ public ConsignmentCreator(DB db) {
+ this.db = db;
+ }
+ /**
+ * Returns the position of a postcode.
+ * @param postcode the postcode in form 'XA00'
+ * @return the position
+ */
+ static Point postcodeLocation(String postcode) {
+ int c = postcode.charAt(1) - 'A';
+ int n = Integer.parseInt(postcode.substring(2));
+
+ return new Point(n, c * 3);
+ }
+ /**
+ * Initializes the environment.
+ * @throws SQLException ignored
+ */
+ public void init() throws SQLException {
+ postcodes = db.queryReadOnly("SELECT * FROM postcode...
[truncated message content] |
|
From: <aka...@us...> - 2013-10-03 14:03:57
|
Revision: 324
http://sourceforge.net/p/advance-project/code/324
Author: akarnokd
Date: 2013-10-03 14:03:54 +0000 (Thu, 03 Oct 2013)
Log Message:
-----------
Reworking demo data generator.
Modified Paths:
--------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/Aggregates.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/HubCoord.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L1OverallData.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/ConsignmentDB.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Demo.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/DepotAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/EnvironmentAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/HubAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/VehicleAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/WarehouseAgent.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/ScanType.java
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/Aggregates.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/Aggregates.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/Aggregates.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -47,11 +47,11 @@
@NonNull
public LinkedHashMap<ItemStatus, BarData> create() {
LinkedHashMap<ItemStatus, BarData> p = new LinkedHashMap<>();
- p.put(ItemStatus.LEFT_HUB, new BarData(lefthub));
+ p.put(ItemStatus.LEFT_HUB_TODAY, new BarData(lefthub));
+ p.put(ItemStatus.CREATED, new BarData(created));
+ p.put(ItemStatus.SCANNED, new BarData(scanned));
+ p.put(ItemStatus.DECLARED, new BarData(declared));
p.put(ItemStatus.AT_HUB, new BarData(athub));
- p.put(ItemStatus.DECLARED, new BarData(declared));
- p.put(ItemStatus.SCANNED, new BarData(scanned));
- p.put(ItemStatus.CREATED, new BarData(created));
p.put(ItemStatus.PREDICTED, new BarData(predicted));
return p;
}
@@ -69,7 +69,8 @@
case CREATED:
value = created;
break;
- case LEFT_HUB:
+// case LEFT_HUB:
+ case LEFT_HUB_TODAY:
value = lefthub;
break;
case DECLARED:
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/HubCoord.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/HubCoord.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/HubCoord.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -58,7 +58,7 @@
private void setNoOfTotalTick(ServiceLevel snip, SumData sumData) {
// Count: (totalCoord - sumData.maxLeftHub() + leftHub) DIV (tickUnit * scale)
int total = super.totalCoord.subtract(sumData.maxLeftHub(true))
- .add(sumData.items.get(snip).get(OrientStatus.SINGLE).get(ItemStatus.LEFT_HUB).value).intValue();
+ .add(sumData.items.get(snip).get(OrientStatus.SINGLE).get(ItemStatus.LEFT_HUB_TODAY).value).intValue();
int tickScale = super.getTickScale().intValue();
this.noOfTotalTick.put(snip, new GraphDecimal((total / tickScale)));
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L1OverallData.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L1OverallData.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L1OverallData.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -52,7 +52,7 @@
* @return EnumSet of the used item statuses
*/
public static EnumSet<ItemStatus> getDisplayItems() {
- EnumSet<ItemStatus> result = EnumSet.of(ItemStatus.LEFT_HUB,
+ EnumSet<ItemStatus> result = EnumSet.of(ItemStatus.LEFT_HUB_TODAY,
ItemStatus.AT_HUB,
ItemStatus.DECLARED,
ItemStatus.SCANNED,
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/ConsignmentDB.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/ConsignmentDB.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/ConsignmentDB.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -483,7 +483,7 @@
for (TLongCollection ids : TroveUtils.split(consMap.keySet(), 1000)) {
sql.setLength(0);
- sql.append("SELECT consingment_id, width, height, length FROM items ")
+ sql.append("SELECT consignment_id, width, height, length FROM items ")
.append("WHERE consignment_id IN (");
TroveUtils.join(ids, ",", sql);
sql.append(")");
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/ConsignmentCreator.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -207,8 +207,8 @@
* @throws SQLException ingored
*/
public void run() throws SQLException {
- DateMidnight startDay = new DateMidnight(2013, 7, 1);
- DateMidnight endDay = new DateMidnight(2013, 12, 31);
+ DateMidnight startDay = new DateMidnight(2013, 9, 30);
+ DateMidnight endDay = new DateMidnight(2013, 9, 30);
DateMidnight day = startDay;
@@ -218,20 +218,14 @@
if (dow != DateTimeConstants.SATURDAY && dow != DateTimeConstants.SUNDAY) {
System.out.printf("Day: %s%n", day);
List<Cons> cons = generate(day);
- DateTime max = saveCons(cons);
+ saveCons(cons);
db.commit();
-
- if (max != null) {
- env.consignmentsEnd(max);
- }
}
}
day = day.plusDays(1);
-
- env.eventLoop();
- db.commit();
}
+ env.consignmentsEnd();
env.eventLoop();
db.commit();
}
@@ -243,11 +237,12 @@
*/
List<Cons> generate(DateMidnight day) throws SQLException {
List<Cons> r = new ArrayList<>();
- LocalTime lt = new LocalTime(7, 0);
+ int lt = new LocalTime(7, 0).getMillisOfDay() / 1000;
int dy = day.getDayOfYear();
int dm = day.getDayOfMonth();
int dw = day.getDayOfWeek();
int k = 0;
+ int seconds = 0;
for (Postcode pc : postcodes) {
if (pc.id % 5 != dw - 1) {
int nf = 0;
@@ -273,7 +268,7 @@
Cons cs = new Cons();
r.add(cs);
cs.id = ++consId;
- cs.created = day.toDateTime().withTime(lt.getHourOfDay(), lt.getMinuteOfHour(), lt.getSecondOfMinute(), lt.getMillisOfSecond());
+ cs.created = day.toDateTime().plusSeconds(lt + seconds);
cs.itemCount = nf + nh + nq;
cs.collectionPostcode = pc.id;
cs.collectionDepot = postcodeClosestDepot.get(pc.id).id;
@@ -282,7 +277,7 @@
cs.deliveryDepot = postcodeClosestDepot.get(dpc.id).id;
cs.externalId = "C" + cs.id;
- int sli = ((dm + k) % 30);
+ int sli = ((dm + k) % 29);
if (sli == 0) {
cs.service = ServiceLevel.SPECIAL;
} else
@@ -305,6 +300,7 @@
ConsItem item = new ConsItem();
item.consignment = cs;
item.id = ++itemId;
+ item.consignmentId = cs.id;
item.length = 1;
item.width = 1;
item.height = 1;
@@ -315,6 +311,7 @@
ConsItem item = new ConsItem();
item.consignment = cs;
item.id = ++itemId;
+ item.consignmentId = cs.id;
item.length = 1;
item.width = 1;
item.height = 0.5;
@@ -325,6 +322,7 @@
ConsItem item = new ConsItem();
item.consignment = cs;
item.id = ++itemId;
+ item.consignmentId = cs.id;
item.length = 1;
item.width = 1;
item.height = 0.25;
@@ -338,8 +336,9 @@
}
-
- lt = lt.plusSeconds(15);
+ seconds = (seconds + 20);
+
+
k++;
}
return r;
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Demo.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Demo.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/Demo.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -63,7 +63,7 @@
*/
private static void createMaster(DB db) throws SQLException {
// create hubs
- int nHubs = 2;
+ int nHubs = 1;
for (int i = 1; i <= nHubs; i++) {
db.update("INSERT IGNORE INTO hubs VALUES (?, ?, ?, ?)", i, "Hub " + i, 1000, 1000);
}
@@ -73,7 +73,7 @@
for (int i = 1; i <= nDepots; i++) {
db.update("INSERT IGNORE INTO depots VALUES (?, ?) ", i, "Depot " + i);
- int nVehicles = (int)Math.ceil(5d * i / nDepots);
+ int nVehicles = 1 + (int)Math.ceil(5d * i / nDepots);
for (int j = 1; j <= nVehicles; j++) {
db.update("INSERT IGNORE INTO vehicles VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
@@ -96,7 +96,7 @@
db.update("INSERT IGNORE INTO warehouses VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
i, "Warehouse " + wi, x, y, 60, 100, 0, rnd.nextInt(5) + 5, "Warehouse " + (wi % 2 == 0 ? wi - 1 : wi + 1));
- int sa = (nDepots / 2) * ((j - 1) / 2);
+ int sa = ((j - 1) / 2) * (nDepots / 2);
for (int k = 0; k < nDepots / 2; k++) {
db.update("INSERT IGNORE INTO storage_areas VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
i, "Warehouse " + wi, k % 2, k / 2, sa + k + 1, 20, 1.5, 0, 30
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/DepotAgent.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/DepotAgent.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/DepotAgent.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -21,13 +21,8 @@
package eu.advance.logistics.live.reporter.demo;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import org.joda.time.DateTime;
-
-import eu.advance.logistics.live.reporter.model.ItemEventType;
-
/**
* A depot manager "agent".
* @author karnokd, 2013.10.01.
@@ -42,54 +37,4 @@
public final List<VehicleAgent> vehicles = new ArrayList<>();
/** The vehicles on site. */
public final List<VehicleAgent> onSite = new ArrayList<>();
- /** The environment. */
- private EnvironmentAgent env;
- /**
- * Constructor, sets the environment.
- * @param env the environment
- */
- public DepotAgent(EnvironmentAgent env) {
- this.env = env;
- }
- /**
- * Item arrived from the collection postcode.
- * @param now the current time
- * @param item the item
- */
- public void itemArrived(DateTime now, ConsItem item) {
- toDeliver.add(item);
- checkLoadVehicle(now);
- }
- /**
- * Vehicle arrived at the depot.
- * @param now the arrival time
- * @param va the vehicle
- */
- public void vehicleArrived(DateTime now, VehicleAgent va) {
- for (ConsItem item : va.contents) {
- env.event(item.id, item.consignmentId, now, ItemEventType.DESTINATION_SCAN);
- }
- va.contents.clear();
- va.targetHub = null;
- va.atDepot = true;
- onSite.add(va);
- checkLoadVehicle(now);
- }
- /**
- * Check if vehicles can be loaded.
- * @param now the current time
- */
- public void checkLoadVehicle(DateTime now) {
- if (!onSite.isEmpty()) {
- for (ConsItem ci : new ArrayList<>(toDeliver)) {
- List<VehicleAgent> vas = new ArrayList<>(onSite);
- Collections.sort(vas, VehicleAgent.CAPACITY);
- for (VehicleAgent va : vas) {
- if (va.tryLoadInDepot(now, ci)) {
- toDeliver.remove(ci);
- }
- }
- }
- }
- }
}
\ No newline at end of file
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/EnvironmentAgent.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/EnvironmentAgent.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/EnvironmentAgent.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -36,17 +36,22 @@
import java.awt.Point;
import java.sql.SQLException;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.PriorityQueue;
import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The base environment for the agents.
* @author karnokd, 2013.10.02.
*/
public class EnvironmentAgent {
+ /** The log. */
+ private static final Logger LOG = LoggerFactory.getLogger(EnvironmentAgent.class);
/** The database connection. */
protected final DB db;
/** The map of depots. */
@@ -70,9 +75,18 @@
* The event loop.
*/
public void eventLoop() {
+ int i = 1;
while (!events.isEmpty()) {
Pair<DateTime, Action0> e = events.remove();
e.second.invoke();
+ if (i % 1000 == 0) {
+ try {
+ db.commit();
+ } catch (SQLException ex) {
+ LOG.error(ex.toString(), ex);
+ }
+ }
+ i++;
}
}
/**
@@ -90,7 +104,7 @@
public void setHubs(Iterable<Hub> hubs) {
hubAgents.clear();
for (Hub h : hubs) {
- HubAgent ha = new HubAgent(this);
+ HubAgent ha = new HubAgent();
ha.id = h.id;
hubAgents.put(ha.id, ha);
}
@@ -104,7 +118,7 @@
for (Warehouse wh : warehouses) {
HubAgent ha = hubAgents.get(wh.hub);
- WarehouseAgent wa = new WarehouseAgent(this);
+ WarehouseAgent wa = new WarehouseAgent();
wa.hub = wh.hub;
wa.warehouse = wh.warehouse;
@@ -131,7 +145,7 @@
public void setDepots(Iterable<Depot> depots) {
depotAgents.clear();
for (Depot d : depots) {
- DepotAgent da = new DepotAgent(this);
+ DepotAgent da = new DepotAgent();
da.id = d.id;
depotAgents.put(da.id, da);
@@ -147,9 +161,10 @@
for (Vehicle v : vehicles) {
DepotAgent da = depotAgents.get(v.depot);
- VehicleAgent va = new VehicleAgent(this);
+ VehicleAgent va = new VehicleAgent();
va.id = v.vehicleId;
- va.depot = v.depot;
+ va.depotId = v.depot;
+ va.depot = da;
va.capacity = v.capacity;
da.onSite.add(va);
@@ -169,20 +184,6 @@
}
}
/**
- * Stores an event for a particulare item.
- * @param itemId the item identifier
- * @param consignmentId the parent consignment id
- * @param timestamp the event timestamp
- * @param event the event
- */
- public void event(long itemId, long consignmentId, DateTime timestamp, ItemEventType event) {
- try {
- db.update("INSERT INGORE INTO events VALUES (?, ?, ?, ?)", itemId, consignmentId, timestamp, event.ordinal());
- } catch (SQLException ex) {
- throw new RuntimeException(ex);
- }
- }
- /**
* Returns the depot position.
* @param depot the depot
* @return the
@@ -259,120 +260,308 @@
return now.plusSeconds((int)d);
}
/**
- * Add a new item.
- * @param item the item
+ * Stores an event for a particulare item.
+ * @param itemId the item identifier
+ * @param consignmentId the parent consignment id
+ * @param timestamp the event timestamp
+ * @param event the event
*/
- public void newItem(final ConsItem item) {
-
- event(item.id, item.consignmentId, item.consignment.created, ItemEventType.CREATED);
-
- final DateTime depotArrive = postcodeDepotTravel(item.consignment.created, item.consignment.collectionPostcode, item.consignment.collectionDepot);
-
- final DepotAgent da = depotAgents.get(item.consignment.collectionDepot);
-
- add(depotArrive, new Action0() {
- @Override
- public void invoke() {
- da.itemArrived(depotArrive, item);
- }
- });
+ public void event(long itemId, long consignmentId, DateTime timestamp, ItemEventType event) {
+ try {
+ db.update("INSERT IGNORE INTO `events` VALUES (?, ?, ?, ?)",
+ consignmentId, itemId, timestamp, event.ordinal());
+ } catch (SQLException ex) {
+ throw new RuntimeException(ex);
+ }
}
/**
- * Register a collection scan.
- * @param vehicleId the vehicle identifier
- * @param when the scan time
- * @param item the item
+ * Record a scan onto vehicle event in the database tables.
+ * @param va the vehicle agent
+ * @param item the consignment item
+ * @param when the current time
+ * @param onto scan onto the vehicle
*/
- public void collectionScan(String vehicleId, DateTime when, ConsItem item) {
- event(item.id, item.consignmentId, when, ItemEventType.SOURCE_SCAN);
-
+ public void depotScanVehicle(VehicleAgent va, ConsItem item, DateTime when, boolean onto) {
+ ItemEventType iet = onto ? ItemEventType.SOURCE_SCAN : ItemEventType.DESTINATION_SCAN;
+ event(item.id, item.consignmentId, when, iet);
try {
- db.update("INSERT IGNORE INTO scans VALUES (?, ?, ?, ?, ?, ?, ?)",
- item.consignmentId, item.id, ScanType.SOURCE.ordinal(),
- item.consignment.collectionDepot, true, when, vehicleId);
-
- db.update("INSERT IGNORE INTO scans_history VALUES (?, ?, ?, ?, ?, ?, ?)",
- item.consignmentId, item.id, ScanType.SOURCE.ordinal(),
- item.consignment.collectionDepot, true, when, vehicleId);
+ ScanType st = onto ? ScanType.SOURCE : ScanType.DESTINATION;
+ db.update("INSERT IGNORE INTO scans VALUES (?, ?, ?, ?, ?, ?)",
+ item.consignmentId, item.id, st.ordinal(),
+ va.depot, when, va.id
+ );
+ db.update("INSERT IGNORE INTO scans_history VALUES (?, ?, ?, ?, ?, ?)",
+ item.consignmentId, item.id, st.ordinal(),
+ va.depot, when, va.id
+ );
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
/**
- * Declare a pallet on a vehicle.
- * @param vehicleId the vehicle identifier
- * @param when the time of the declaration
- * @param externalItemId the item identifier
+ * Declare the contents of the entire vehicle.
+ * @param va the vehicle
+ * @param when the current time
*/
- public void declare(String vehicleId, DateTime when, String externalItemId) {
- int iidx = externalItemId.indexOf("I");
- long consId = Long.parseLong(externalItemId.substring(1, iidx));
-// long itemId = Long.parseLong(externalItemId.substring(iidx + 1));
-
+ public void declare(VehicleAgent va, DateTime when) {
try {
- db.update("INSERT IGNORE INTO vehicle_declared VALUES (?, ?, ?)", vehicleId, when, externalItemId);
- db.update("UPDATE consignments SET declared = ? WHERE id = ?", when, consId);
- db.update("UPDATE consignments_history SET declared = ? WHERE id = ?", when, consId);
+ for (ConsItem ci : va.contents) {
+ event(ci.id, ci.consignmentId, when, ItemEventType.DECLARED);
+
+ db.update("UPDATE consignments SET declared = ? WHERE id = ? ", when, ci.consignmentId);
+
+ db.update("UPDATE consignments_history SET declared = ? WHERE id = ? ", when, ci.consignmentId);
+
+ db.update("INSERT INGORE INTO vehicle_declared VALUES (?, ?, ?)", va.id, when, ci.externalId);
+ }
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
/**
- * Vehicle arrived at hub.
- * @param now the current time
- * @param hub the hub
+ * Record a vehicle enter-leave the hub.
* @param va the vehicle
+ * @param when the current time
+ * @param enter enter?
*/
- public void hubArrive(final DateTime now, final long hub, final VehicleAgent va) {
- va.sessionId = hub + "_" + now.toString("yyyyMMdd'_'HHmmss") + "_" + va.id;
- va.atHub = true;
-
- for (ConsItem ci : va.contents) {
- event(ci.id, ci.consignmentId, now, ItemEventType.HUB_ARRIVE);
+ public void hubVehicleEnterLeave(VehicleAgent va, DateTime when, boolean enter) {
+ try {
+ for (ConsItem ci : va.contents) {
+ event(ci.id, ci.consignmentId, when, enter ? ItemEventType.HUB_ARRIVE : ItemEventType.HUB_LEAVE);
+ }
+ if (enter) {
+ va.sessionId = va.hub + "_" + when.toString("yyyyMMdd'_'HHmmss") + "_" + va.id;
+
+ db.update("INSERT IGNORE INTO vehicle_sessions VALUES (?, ?, ?, ?, ?)",
+ va.sessionId, va.id, va.hub, when, DateTime.class);
+ } else {
+ db.update("UPDATE vehicle_sessions SET leave_timestamp = ? WHERE session_id = ? ", when, va.sessionId);
+ }
+
+ } catch (SQLException ex) {
+ throw new RuntimeException(ex);
}
-
- HubAgent ha = hubAgents.get(va.targetHub);
- ha.vehiclesOnSite.add(va);
- ha.loadUnload(now);
}
/**
- * Register the contents of the vehicle entering/leaving its warehouse.
+ * Record a vehicle enter/leave a warehouse.
* @param va the vehicle
- * @param now the current time
+ * @param when the current time
* @param enter is enter?
*/
- public void warehouseScan(VehicleAgent va, DateTime now, boolean enter) {
+ public void warehouseEnterLeave(VehicleAgent va, DateTime when, boolean enter) {
try {
- long sid = db.insertAuto("INSERT INTO vehicle_scan (session_id, scan_timestamp, warehouse, entry) VALUES (?, ?, ?, ?)",
- va.sessionId, now, va.warehouse, enter
- );
+ long scanId = db.insertAuto("INSERT INTO vehicle_scan (session_id, scan_timestamp, warehouse, entry) VALUES (?, ?, ?, ?)",
+ va.sessionId, when, va.warehouse, enter);
+
for (ConsItem ci : va.contents) {
- event(ci.id, ci.consignmentId, now, ItemEventType.WAREHOUSE_ENTER);
- db.update("INSERT INTO vehicle_items VALUES (?, ?) ", sid, ci.externalId);
+ event(ci.id, ci.consignmentId, when, enter ? ItemEventType.WAREHOUSE_ENTER : ItemEventType.WAREHOUSE_LEAVE);
- ScanType st = enter ? ScanType.WAREHOUSE_ENTER : ScanType.WAREHOUSE_LEAVE;
-
db.update("INSERT IGNORE INTO scans VALUES (?, ?, ?, ?, ?, ?)",
- ci.consignmentId, ci.id, st,
- va.targetHub + " " + va.warehouse, now, va.id);
+ ci.consignmentId, ci.id, enter ? ScanType.WAREHOUSE_ENTER : ScanType.WAREHOUSE_LEAVE,
+ va.hub + " " + va.warehouse, when, va.id);
db.update("INSERT IGNORE INTO scans_history VALUES (?, ?, ?, ?, ?, ?)",
- ci.consignmentId, ci.id, st,
- va.targetHub + " " + va.warehouse, now, va.id);
-
+ ci.consignmentId, ci.id, enter ? ScanType.WAREHOUSE_ENTER : ScanType.WAREHOUSE_LEAVE,
+ va.hub + " " + va.warehouse, when, va.id);
+
+ db.update("INSERT IGNORE INTO vehicle_items VALUES (?, ?)", scanId, ci.externalId);
}
+
} catch (SQLException ex) {
throw new RuntimeException(ex);
+ }
+ }
+ /**
+ * Record the scan of the item onto/off a vehicle.
+ * @param va the vehicle
+ * @param ci the item
+ * @param when the current time
+ * @param onto the direction
+ */
+ public void warehouseItemScan(VehicleAgent va, ConsItem ci, DateTime when, boolean onto) {
+ try {
+ event(ci.id, ci.consignmentId, when, onto ? ItemEventType.SCAN_ON : ItemEventType.SCAN_OFF);
+
+ db.update("INSERT IGNORE INTO scans VALUES (?, ?, ?, ?, ?, ?)",
+ ci.consignmentId, ci.id, onto ? ScanType.WAREHOUSE_MANUAL_LOAD : ScanType.WAREHOUSE_MANUAL_UNLOAD,
+ va.hub + " " + va.warehouse, when, va.id);
+
+ db.update("INSERT IGNORE INTO scans_history VALUES (?, ?, ?, ?, ?, ?)",
+ ci.consignmentId, ci.id, onto ? ScanType.WAREHOUSE_MANUAL_LOAD : ScanType.WAREHOUSE_MANUAL_UNLOAD,
+ va.hub + " " + va.warehouse, when, va.id);
+
+ } catch (SQLException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+ /**
+ * Add a new item.
+ * @param item the item
+ */
+ public void newItem(final ConsItem item) {
+ DepotAgent da = depotAgents.get(item.consignment.collectionDepot);
+ da.toDeliver.add(item);
+ DateTime when = item.consignment.created;
+ event(item.id, item.consignmentId, when, ItemEventType.CREATED);
+
+ if (!da.onSite.isEmpty()) {
+ VehicleAgent va = Collections.max(da.onSite, VehicleAgent.CAPACITY_CONTENTS);
+ va.hubId = item.consignment.hub;
+ va.contents.add(item);
+ depotScanVehicle(va, item, when, true);
+
+ if (va.isFull()) {
+ leaveForHub(va, when);
+ }
}
}
/**
- * Indicate that no more consignments will appear on the given day.
- * @param now the current time
+ * Leave for the hub.
+ * @param va the vehicle
+ * @param when the current time
*/
- public void consignmentsEnd(DateTime now) {
- // TODO
- for (DepotAgent da : depotAgents.valueCollection()) {
+ public void leaveForHub(final VehicleAgent va, DateTime when) {
+ va.atDepot = false;
+ va.depot.onSite.remove(va);
+ final DateTime arrive = depotHubTravel(when, va.depotId, va.hubId);
+ add(arrive, new Action0() {
+ @Override
+ public void invoke() {
+ enterHub(va, arrive);
+ }
+ });
+ }
+ /**
+ * Enter the hub.
+ * @param va the vehicle.
+ * @param when the current time
+ */
+ public void enterHub(VehicleAgent va, DateTime when) {
+ va.atHub = true;
+ va.hub = hubAgents.get(va.hubId);
+ va.hub.onSite.add(va);
+
+ hubVehicleEnterLeave(va, when, true);
+
+ dispatchVehicle(va, when);
+ }
+ /**
+ * Dispatch a vehicle based on its contents.
+ * @param va the vehicle
+ * @param when the current time
+ */
+ public void dispatchVehicle(final VehicleAgent va, final DateTime when) {
+ if (va.sourceContent()) {
+ WarehouseAgent wa = findUnloadWarehouse(va);
+ if (wa != null) {
+ enterWarehouse(va, wa, when);
+ unload(va, when);
+ } else {
+ // try again later
+ final DateTime next = when.plusMinutes(1);
+ add(next, new Action0() {
+ @Override
+ public void invoke() {
+ dispatchVehicle(va, next);
+ }
+ });
+ }
+ } else
+ if (va.destinationContent()) {
+ } else
+ if (va.isEmpty()) {
+
}
}
+ /**
+ * Enter the warehouse.
+ * @param va the vehicle
+ * @param wa the warehouse
+ * @param when the current time
+ */
+ public void enterWarehouse(VehicleAgent va, WarehouseAgent wa, DateTime when) {
+ va.warehouse = wa;
+ va.position = wa.freeSlot();
+ wa.vehicles.add(va);
+
+ warehouseEnterLeave(va, when, true);
+ }
+ /**
+ * Schedule the unloading of items.
+ * @param va the vehicle
+ * @param when current time
+ */
+ public void unload(final VehicleAgent va, DateTime when) {
+ DateTime first = when.plusSeconds(va.position.enterTime);
+ for (final ConsItem ci : va.contents) {
+ if (va.warehouse.depots.contains(ci.consignment.deliveryDepot)) {
+
+ final DateTime dt = first;
+ add(first, new Action0() {
+ @Override
+ public void invoke() {
+ va.warehouse.storageAreas.put(ci.consignment.deliveryDepot, ci);
+ va.contents.remove(ci);
+
+ warehouseItemScan(va, ci, dt, false);
+ }
+ });
+
+ first = first.plusSeconds(10);
+ }
+ }
+ final DateTime dt = first;
+ add(first, new Action0() {
+ @Override
+ public void invoke() {
+ unloadComplete(va, dt);
+ }
+ });
+ }
+ /**
+ * Called when the vehicle was unloaded successfully.
+ * @param va the vehicle
+ * @param dt the current time
+ */
+ public void unloadComplete(final VehicleAgent va, DateTime dt) {
+
+ }
+ /**
+ * Find a warehouse which can accept most of the contents of the vehicle.
+ * @param va the vehicle
+ * @return the best warehouse, null if all are occupied
+ */
+ public WarehouseAgent findUnloadWarehouse(VehicleAgent va) {
+
+ WarehouseAgent wres = null;
+ int bestWres = 0;
+
+ for (WarehouseAgent wa : va.hub.warehouses) {
+ if (wa.vehicles.size() < wa.positions.size()) {
+ int contentThere = 0;
+ int contentVa = 0;
+ for (ConsItem ci : va.contents) {
+ contentThere += wa.storageAreas.get(ci.consignment.deliveryDepot).size();
+ contentVa += wa.depots.contains(ci.consignment.deliveryDepot) ? 1 : 0;
+ }
+
+ if (contentVa > 0) {
+ if (wres == null || bestWres > contentThere) {
+ wres = wa;
+ bestWres = contentThere;
+ }
+ }
+ }
+ }
+
+ return wres;
+ }
+ /**
+ * Indicate that no more consignments will be created.
+ */
+ public void consignmentsEnd() {
+ // TODO
+ }
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/HubAgent.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/HubAgent.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/HubAgent.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -23,8 +23,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.joda.time.DateTime;
-
/**
* The hub agent.
* @author karnokd, 2013.10.01.
@@ -33,33 +31,7 @@
/** Identifier. */
public long id;
/** List of vehicles on site. */
- public final List<VehicleAgent> vehiclesOnSite = new ArrayList<>();
+ public final List<VehicleAgent> onSite = new ArrayList<>();
/** List of vehicles. */
public final List<WarehouseAgent> warehouses = new ArrayList<>();
- /** The environment. */
- private EnvironmentAgent env;
- /**
- * Constructor, sets the environment.
- * @param env the environment
- */
- public HubAgent(EnvironmentAgent env) {
- this.env = env;
- }
- /**
- * Schedule the loading and unloading vehicles.
- * @param now the current time
- */
- public void loadUnload(DateTime now) {
- for (VehicleAgent va : vehiclesOnSite) {
- if (va.warehouse == null) {
- if (va.needsUnload()) {
- for (WarehouseAgent wa : warehouses) {
- if (wa.tryEnter(now, va)) {
-
- }
- }
- }
- }
- }
- }
}
\ No newline at end of file
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/VehicleAgent.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/VehicleAgent.java 2013-10-02 13:57:00 UTC (rev 323)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/demo/VehicleAgent.java 2013-10-03 14:03:54 UTC (rev 324)
@@ -20,16 +20,12 @@
*/
package eu.advance.logistics.live.reporter.demo;
-import hu.akarnokd.reactive4java.base.Action0;
-
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
-import org.joda.time.DateTime;
+import eu.advance.logistics.live.reporter.model.LorryPositio...
[truncated message content] |
|
From: <cs...@us...> - 2013-10-07 11:57:48
|
Revision: 327
http://sourceforge.net/p/advance-project/code/327
Author: csirobi
Date: 2013-10-07 11:57:44 +0000 (Mon, 07 Oct 2013)
Log Message:
-----------
HubDepot: summary chart fix
Modified Paths:
--------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumChart.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumData.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/ServiceLevel.java
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumChart.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumChart.java 2013-10-07 07:39:21 UTC (rev 326)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumChart.java 2013-10-07 11:57:44 UTC (rev 327)
@@ -71,6 +71,24 @@
return result;
}
+ /** The relevant service levels. */
+ private static final ServiceLevel[] SERVICE_LEVELS = {
+ ServiceLevel.ALL,
+ ServiceLevel.STANDARD,
+ ServiceLevel.PRIORITY,
+ ServiceLevel.SPECIAL
+ };
+
+ /** The relevant item statuses. */
+ private static final ItemStatus[] ITEM_STATUSES = {
+ ItemStatus.LEFT_HUB_TODAY,
+ ItemStatus.AT_HUB,
+ ItemStatus.DECLARED,
+ ItemStatus.SCANNED,
+ ItemStatus.CREATED,
+ ItemStatus.PREDICTED
+ };
+
/**
* Create the direction JSON object.
* @param sumData the data source
@@ -116,7 +134,7 @@
switch(sumData.type) {
case HUB:
JSONArray tickArray = new JSONArray();
- for (ServiceLevel sKey : ServiceLevel.values()) {
+ for (ServiceLevel sKey : SERVICE_LEVELS) {
tickArray.add(((HubCoord)coord).noOfTotalTick.get(sKey).toPlainString());
}
result.put("noOfTotalTick", tickArray);
@@ -135,16 +153,7 @@
return result;
}
- /** The relevant item statuses. */
- private static final ItemStatus[] ITEM_STATUSES = {
- ItemStatus.CREATED,
- ItemStatus.SCANNED,
- ItemStatus.DECLARED,
- ItemStatus.AT_HUB,
- ItemStatus.LEFT_HUB_TODAY,
- ItemStatus.PREDICTED
- };
-
+
/**
* Create the status JSON array.
* @return the created JSON array
@@ -162,6 +171,7 @@
return resultArray;
}
+
/**
* Create the bars JSON array.
* @param coord the coordinate object
@@ -176,7 +186,7 @@
JSONArray orientRec;
EnumSet<OrientStatus> orientKeys = bar.getOrientKeys();
- for (ServiceLevel uKey: ServiceLevel.values()) {
+ for (ServiceLevel uKey: SERVICE_LEVELS) {
typeRec = new JSONObject();
typeRec.put("unit", uKey.getMessage());
typeRec.put("name", bar.name);
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumData.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumData.java 2013-10-07 07:39:21 UTC (rev 326)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/SumData.java 2013-10-07 11:57:44 UTC (rev 327)
@@ -124,10 +124,12 @@
*/
public void checkBaus() {
GraphDecimal value = new GraphDecimal(0);
+ // Widest range case: login at hub and selected any depot.
+ ItemStatus[] statuses = {ItemStatus.AT_HUB, ItemStatus.DECLARED, ItemStatus.SCANNED, ItemStatus.CREATED, ItemStatus.PREDICTED};
for (OrientStatus oKey : this.getOrientKeys()) {
- GraphDecimal inner = new GraphDecimal(0);
- for (ItemStatus pKey : ItemStatus.values()) {
+ GraphDecimal inner = this.maxLeftHub(true);
+ for (ItemStatus pKey : statuses) {
BarData bd = this.items.get(ServiceLevel.ALL).get(oKey).get(pKey);
if (bd != null) {
inner = inner.add(new GraphDecimal(bd.value));
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/ServiceLevel.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/ServiceLevel.java 2013-10-07 07:39:21 UTC (rev 326)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/model/ServiceLevel.java 2013-10-07 11:57:44 UTC (rev 327)
@@ -29,7 +29,7 @@
STANDARD("Standard"),
/** Priority level. */
PRIORITY("Priority"),
- /** Special levle. */
+ /** Special level. */
SPECIAL("Special"),
/** Used by the screens to indicate aggregation. */
ALL("All services");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <aka...@us...> - 2013-11-19 11:45:19
|
Revision: 344
http://sourceforge.net/p/advance-project/code/344
Author: akarnokd
Date: 2013-11-19 11:45:16 +0000 (Tue, 19 Nov 2013)
Log Message:
-----------
Fixed layout-map related bug: not showing warehouse contents in various view settings.
Modified Paths:
--------------
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/ChartProcess.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L2StorageRawData.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSummary.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSwitch.java
advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/MasterDB.java
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/ChartProcess.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/ChartProcess.java 2013-11-18 17:42:07 UTC (rev 343)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/ChartProcess.java 2013-11-19 11:45:16 UTC (rev 344)
@@ -180,7 +180,8 @@
case NOW_AT_HUB:
// for STANDARD & PRIORITY
for (WarehouseServiceLevel wsl : L2StorageChartData.USED_SERVICES) {
- double x = storageRaw.items.get(wsl).get(ItemStatus.AT_HUB).normalValue.doubleValue();
+ BarData bd = storageRaw.items.get(wsl).get(ItemStatus.AT_HUB);
+ double x = bd.normalValue.doubleValue();
weightInput.put(wsl, x);
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L2StorageRawData.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L2StorageRawData.java 2013-11-18 17:42:07 UTC (rev 343)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/L2StorageRawData.java 2013-11-19 11:45:16 UTC (rev 344)
@@ -90,4 +90,13 @@
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "L2StorageRawData [warehouse=" + warehouse + ", type=" + type
+ + ", side=" + side + ", id=" + id + "]";
+ }
+
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSummary.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSummary.java 2013-11-18 17:42:07 UTC (rev 343)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSummary.java 2013-11-19 11:45:16 UTC (rev 344)
@@ -284,11 +284,23 @@
TLongObjectMap<EnumMap<ServiceLevel, TLongSet>> out1 = cache.getItemsInWarehouse(hubId, s.warehouse, when);
warehouseTypeMap.put(WarehouseType.A, out1);
whs.add(Pair.of(s.warehouse, WarehouseType.A));
+ // extract all item ids
+ for (EnumMap<ServiceLevel, TLongSet> m1 : out1.valueCollection()) {
+ for (TLongSet m2 : m1.values()) {
+ itemIds.addAll(m2);
+ }
+ }
if (s.pair != null) {
TLongObjectMap<EnumMap<ServiceLevel, TLongSet>> out2 = cache.getItemsInWarehouse(hubId, s.pair, when);
warehouseTypeMap.put(WarehouseType.B, out2);
whs.add(Pair.of(s.pair, WarehouseType.B));
+ // extract all item ids
+ for (EnumMap<ServiceLevel, TLongSet> m1 : out2.valueCollection()) {
+ for (TLongSet m2 : m1.values()) {
+ itemIds.addAll(m2);
+ }
+ }
} else {
warehouseTypeMap.put(WarehouseType.B, new TLongObjectHashMap<EnumMap<ServiceLevel, TLongSet>>());
}
@@ -306,12 +318,6 @@
levelTypeDepotCapacity.get(sn).get(wh.second).adjustOrPutValue((short)b.depot, b.capacity, b.capacity);
}
}
- // extract all item ids
- for (EnumMap<ServiceLevel, TLongSet> m1 : out1.valueCollection()) {
- for (TLongSet m2 : m1.values()) {
- itemIds.addAll(m2);
- }
- }
}
break;
}
@@ -410,17 +416,16 @@
* @param hubId the hub id
* @param when the current time
* @param warehouse the current warehouse name
+ * @param wtype the warehouse type.
* @param cache the data cache
*/
public static void warehouseDetails(
Map<L2DisplaySide, List<L2StorageRawData>> storageRawMap,
- long hubId, ReadableDateTime when, String warehouse,
+ long hubId, ReadableDateTime when, String warehouse, WarehouseType wtype,
HubDepotDataCache cache) {
final EnumMap<WarehouseServiceLevel, TObjectDoubleMap<WarehouseType>> levelTypeSum = new EnumMap<>(WarehouseServiceLevel.class);
EnumMap<WarehouseServiceLevel, EnumMap<WarehouseType, TLongIntMap>> levelTypeDepotCapacity = new EnumMap<>(WarehouseServiceLevel.class);
-
-
final EnumMap<WarehouseServiceLevel, EnumMap<WarehouseType, TLongDoubleMap>> levelTypeDepotSum = new EnumMap<>(WarehouseServiceLevel.class);
TLongObjectMap<EnumMap<WarehouseServiceLevel, Aggregates>> depotLevelAggregates = new TLongObjectHashMap<>();
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSwitch.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSwitch.java 2013-11-18 17:42:07 UTC (rev 343)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/charts/WarehouseSwitch.java 2013-11-19 11:45:16 UTC (rev 344)
@@ -393,7 +393,8 @@
break;
case B:
if (wh.pair != null) {
- storageInfoList = warehouseLayoutMap.get(wh.pair).get(WarehouseSide.values()[displaySide.ordinal()]);
+ Map<WarehouseSide, List<StorageAreaInfo>> map = warehouseLayoutMap.get(wh.pair);
+ storageInfoList = map.get(WarehouseSide.values()[displaySide.ordinal()]);
} else {
storageInfoList = new ArrayList<>();
}
Modified: advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/MasterDB.java
===================================================================
--- advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/MasterDB.java 2013-11-18 17:42:07 UTC (rev 343)
+++ advance-live-reporter-os/src/eu/advance/logistics/live/reporter/db/MasterDB.java 2013-11-19 11:45:16 UTC (rev 344)
@@ -440,6 +440,7 @@
}
}
mergeInto(list, b.depot, b.capacity, WarehouseType.A, sl, b.index);
+ mergeInto(list, b.depot, b.capacity, WarehouseType.B, sl, b.index);
}
}
for (Map<WarehouseSide, List<StorageAreaInfo>> m : result.values()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|