-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add "external biomass grid process" using gRPC and tables using TableSaw
A bit of a sloppy commit since I tackled those two things in parallel. They could have been better separated...
- Loading branch information
1 parent
6dfe878
commit 1994c6b
Showing
20 changed files
with
361 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,4 +24,5 @@ plugins { | |
dependencies { | ||
api(project(":biology")) | ||
api(project(":geography")) | ||
api(project(":io")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
agents/src/main/java/uk/ac/ox/poseidon/agents/tables/ActionListenerTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package uk.ac.ox.poseidon.agents.tables; | ||
|
||
import tech.tablesaw.api.DateTimeColumn; | ||
import tech.tablesaw.api.StringColumn; | ||
import tech.tablesaw.api.Table; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.io.tables.ListenerTable; | ||
|
||
public abstract class ActionListenerTable<A extends Action> implements ListenerTable<A> { | ||
private final StringColumn vesselId = StringColumn.create("vessel_id"); | ||
private final DateTimeColumn actionStart = DateTimeColumn.create("action_start"); | ||
private final DateTimeColumn actionEnd = DateTimeColumn.create("action_end"); | ||
|
||
private final Table table = | ||
Table.create( | ||
vesselId, | ||
actionStart, | ||
actionEnd | ||
); | ||
|
||
@Override | ||
public void receive(final A action) { | ||
actionStart.append(action.getStart()); | ||
actionEnd.append(action.getEnd()); | ||
vesselId.append(action.getVessel().getId()); | ||
} | ||
|
||
@Override | ||
public Table get() { | ||
return table; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
agents/src/main/java/uk/ac/ox/poseidon/agents/tables/FishingActionListenerTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package uk.ac.ox.poseidon.agents.tables; | ||
|
||
import tech.tablesaw.api.DoubleColumn; | ||
import tech.tablesaw.api.StringColumn; | ||
import uk.ac.ox.poseidon.agents.behaviours.fishing.FishingAction; | ||
import uk.ac.ox.poseidon.geography.grids.GridExtent; | ||
|
||
public class FishingActionListenerTable extends GridActionListenerTable<FishingAction> { | ||
|
||
private final StringColumn speciesCode = StringColumn.create("species_code"); | ||
private final DoubleColumn biomassCaught = DoubleColumn.create("biomass_caught"); | ||
|
||
public FishingActionListenerTable(final GridExtent gridExtent) { | ||
super(gridExtent); | ||
get().addColumns(speciesCode, biomassCaught); | ||
} | ||
|
||
@Override | ||
public void receive(final FishingAction fishingAction) { | ||
super.receive(fishingAction); | ||
fishingAction.getFishCaught().getMap().forEach((species, content) -> { | ||
speciesCode.append(species.getCode()); | ||
biomassCaught.append(content.asBiomass().getValue()); | ||
}); | ||
} | ||
|
||
@Override | ||
public Class<FishingAction> getEventClass() { | ||
return FishingAction.class; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
agents/src/main/java/uk/ac/ox/poseidon/agents/tables/FishingActionListenerTableFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package uk.ac.ox.poseidon.agents.tables; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.fishing.FishingAction; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
import uk.ac.ox.poseidon.geography.grids.GridExtent; | ||
import uk.ac.ox.poseidon.io.tables.ListenerTableFactory; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FishingActionListenerTableFactory | ||
extends ListenerTableFactory<FishingAction, FishingActionListenerTable> { | ||
|
||
private Factory<? extends GridExtent> gridExtent; | ||
|
||
@Override | ||
protected FishingActionListenerTable newTable(final Simulation simulation) { | ||
return new FishingActionListenerTable(gridExtent.get(simulation)); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
agents/src/main/java/uk/ac/ox/poseidon/agents/tables/GridActionListenerTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package uk.ac.ox.poseidon.agents.tables; | ||
|
||
import com.vividsolutions.jts.geom.Coordinate; | ||
import tech.tablesaw.api.DoubleColumn; | ||
import uk.ac.ox.poseidon.agents.behaviours.GridAction; | ||
import uk.ac.ox.poseidon.geography.grids.GridExtent; | ||
|
||
public abstract class GridActionListenerTable<A extends GridAction> extends ActionListenerTable<A> { | ||
private final GridExtent gridExtent; | ||
private final DoubleColumn lon = DoubleColumn.create("lon"); | ||
private final DoubleColumn lat = DoubleColumn.create("lat"); | ||
|
||
public GridActionListenerTable(final GridExtent gridExtent) { | ||
super(); | ||
get().addColumns(lon, lat); | ||
this.gridExtent = gridExtent; | ||
} | ||
|
||
@Override | ||
public void receive(final A action) { | ||
super.receive(action); | ||
final Coordinate coordinate = gridExtent.toCoordinate(action.getCell()); | ||
lon.append(coordinate.x); | ||
lat.append(coordinate.y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.