Commit 74b8e7a0 authored by patrick.lambert's avatar patrick.lambert
Browse files

typing

parent d7e0d36a
......@@ -18,44 +18,42 @@ import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import species.DiadromousFish;
import species.DiadromousFishGroup;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import environment.Basin.BasinType;
import fr.cemagref.observation.gui.Configurable;
import fr.cemagref.observation.gui.Drawable;
import species.DiadromousFish;
import species.DiadromousFishGroup;
@SuppressWarnings("serial")
public class BasinNetworkObserverWith2Basins extends BasinNetworkObserver implements Configurable,
Drawable, MouseMotionListener {
@Deprecated
public class BasinNetworkObserverWith2Basins extends BasinNetworkObserver implements Configurable, Drawable, MouseMotionListener {
private double maxDistance =1000.;
private double maxDistance = 1000.;
private double minDistance = 50.;
private double maxSurface=100000.;
private double maxSurface = 100000.;
// list of reachRect
private transient Map<Shape, Basin> shapeBasinMap;
private transient Map<Basin, Shape> basinShapeMap;
// list of color
//private transient Color[] colorList;
// private transient Color[] colorList;
@Override
public void init() {
// create a uniform generator to calculate 100 xAlea and yAlea
// create a uniform generator to calculate 100 xAlea and yAlea
// to randomly locate the fish in a basin
nbAlea = 1000;
aleaX=new double[nbAlea];
aleaY=new double[nbAlea];
for (int i=0; i < nbAlea; i++){
aleaX[i]= Math.random();
aleaY[i]= Math.random();
aleaX = new double[nbAlea];
aleaY = new double[nbAlea];
for (int i = 0; i < nbAlea; i++) {
aleaX[i] = Math.random();
aleaY[i] = Math.random();
}
display = new JPanel(new BorderLayout());
......@@ -67,114 +65,96 @@ Drawable, MouseMotionListener {
display.add(displayComponent, BorderLayout.CENTER);
display.add(label, BorderLayout.PAGE_START);
/* // color list
colorList = new Color[6];
colorList[0]= Color.GREEN;
colorList[1]= Color.CYAN;
colorList[2]= Color.MAGENTA;
colorList[3]= Color.PINK;
colorList[4]= Color.ORANGE;
colorList[5]= Color.YELLOW;*/
/* // list of color
colors= new ArrayList<Color>(25);
colors.add(new Color(0, 157, 0));
colors.add(new Color(0, 163, 0));
colors.add(new Color(0, 168, 0));
colors.add(new Color(0, 172, 0));
colors.add(new Color(17, 175, 0));
colors.add(new Color(57, 178, 0));
colors.add(new Color(82, 179, 0));
colors.add(new Color(103, 180, 0));
colors.add(new Color(122, 179, 0));
colors.add(new Color(138, 178, 39));
colors.add(new Color(153, 175, 117));
colors.add(new Color(165, 173, 153));
colors.add(new Color(171, 171, 171));
colors.add(new Color(183, 167, 157));
colors.add(new Color(201, 159, 127));
colors.add(new Color(219, 149, 78));
colors.add(new Color(235, 139, 0));
colors.add(new Color(248, 127, 0));
colors.add(new Color(255, 114, 0));
colors.add(new Color(255, 101, 0));
colors.add(new Color(255, 87, 0));
colors.add(new Color(255, 72, 0));
colors.add(new Color(255, 57, 0));
colors.add(new Color(255, 39, 0));
colors.add(new Color(255, 14, 0));*/
/*
* // color list colorList = new Color[6]; colorList[0]= Color.GREEN; colorList[1]= Color.CYAN; colorList[2]=
* Color.MAGENTA; colorList[3]= Color.PINK; colorList[4]= Color.ORANGE; colorList[5]= Color.YELLOW;
*/
/*
* // list of color colors= new ArrayList<Color>(25); colors.add(new Color(0, 157, 0)); colors.add(new Color(0,
* 163, 0)); colors.add(new Color(0, 168, 0)); colors.add(new Color(0, 172, 0)); colors.add(new Color(17, 175,
* 0)); colors.add(new Color(57, 178, 0)); colors.add(new Color(82, 179, 0)); colors.add(new Color(103, 180,
* 0)); colors.add(new Color(122, 179, 0)); colors.add(new Color(138, 178, 39)); colors.add(new Color(153, 175,
* 117)); colors.add(new Color(165, 173, 153)); colors.add(new Color(171, 171, 171)); colors.add(new Color(183,
* 167, 157)); colors.add(new Color(201, 159, 127)); colors.add(new Color(219, 149, 78)); colors.add(new
* Color(235, 139, 0)); colors.add(new Color(248, 127, 0)); colors.add(new Color(255, 114, 0)); colors.add(new
* Color(255, 101, 0)); colors.add(new Color(255, 87, 0)); colors.add(new Color(255, 72, 0)); colors.add(new
* Color(255, 57, 0)); colors.add(new Color(255, 39, 0)); colors.add(new Color(255, 14, 0));
*/
// list of color
colors= new ArrayList<Color>(2);
colors = new ArrayList<Color>(2);
colors.add(Color.BLACK);
colors.add(Color.GRAY);
// Initialize the map linking shape with basin
shapeBasinMap = new HashMap<Shape, Basin>();
}
@Override
public JComponent getDisplay() {
// compute the range with a small margin
double marginRatio = .02;
double surf= maxSurface/2, interRect=maxSurface*.05;
minX = -2*(surf + interRect);
rangeX = maxSurface - minX;
minX -= rangeX *marginRatio;
rangeX += 2*rangeX *marginRatio;
double surf = maxSurface / 2, interRect = maxSurface * .05;
minX = -2 * (surf + interRect);
rangeX = maxSurface - minX;
minX -= rangeX * marginRatio;
rangeX += 2 * rangeX * marginRatio;
bn = (GridBasinNetwork) pilot.getAquaticWorld().getEnvironment();
minY = Double.POSITIVE_INFINITY;
for (RiverBasin basin : bn.getRiverBasins()) {
minY = Math.min(minY ,basin.getLatitude());
minY = Math.min(minY, basin.getLatitude());
}
minY = (minY -minDistance/2.) ;
minY = (minY - minDistance / 2.);
rangeY = maxDistance - minY;
minY -= rangeY * marginRatio;
rangeY += 2*rangeY*marginRatio;
rangeY += 2 * rangeY * marginRatio;
// define the shape for each basin
basinShapeMap = new HashMap<Basin, Shape>();
for (Basin basin : bn.getBasins()) {
Path2D.Double shape = new Path2D.Double();
if (basin.getType() == BasinType.RIVER){
shape.moveTo( 0., ((RiverBasin) basin).getLatitude()- minDistance/2);
shape.lineTo(((RiverBasin) basin).getSurface(), ((RiverBasin) basin).getLatitude()- minDistance/2);
shape.lineTo(((RiverBasin) basin).getSurface(), ((RiverBasin) basin).getLatitude()+ minDistance/2);
shape.lineTo( 0., ((RiverBasin) basin).getLatitude()+ minDistance/2);
if (basin.getType() == BasinType.RIVER) {
shape.moveTo(0., ((RiverBasin) basin).getLatitude() - minDistance / 2);
shape.lineTo(((RiverBasin) basin).getSurface(), ((RiverBasin) basin).getLatitude() - minDistance / 2);
shape.lineTo(((RiverBasin) basin).getSurface(), ((RiverBasin) basin).getLatitude() + minDistance / 2);
shape.lineTo(0., ((RiverBasin) basin).getLatitude() + minDistance / 2);
shape.closePath();
} else {
RiverBasin rivBas = (RiverBasin) bn.getAssociatedRiverBasin(basin);
double lag= surf +interRect;
double lag = surf + interRect;
if (basin.getType() == BasinType.OFFSHORE)
lag *=2 ;
shape.moveTo(-lag, rivBas.getLatitude()- minDistance/2);
shape.lineTo(-lag+surf, rivBas.getLatitude()- minDistance/2);
shape.lineTo( -lag+surf, rivBas.getLatitude()+ minDistance/2);
shape.lineTo( -lag ,rivBas.getLatitude()+ minDistance/2);
lag *= 2;
shape.moveTo(-lag, rivBas.getLatitude() - minDistance / 2);
shape.lineTo(-lag + surf, rivBas.getLatitude() - minDistance / 2);
shape.lineTo(-lag + surf, rivBas.getLatitude() + minDistance / 2);
shape.lineTo(-lag, rivBas.getLatitude() + minDistance / 2);
shape.closePath();
}
basinShapeMap.put(basin, shape);
}
return display;
}
public static void main(String[] args) { System.out.println((new
XStream(new DomDriver())) .toXML(new BasinNetworkObserverWith2Basins())); }
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new BasinNetworkObserverWith2Basins()));
}
private class DisplayComponent extends JComponent {
@Override
protected synchronized void paintComponent(Graphics g) {
double W =this.getWidth();
double H =this.getHeight();
AffineTransform af = new AffineTransform(W/rangeX, 0., 0.,
-H/rangeY, -W*minX/rangeX, H*(1. + minY/rangeY));
//System.out.println(af.toString());
double W = this.getWidth();
double H = this.getHeight();
AffineTransform af = new AffineTransform(W / rangeX, 0., 0., -H / rangeY, -W * minX / rangeX,
H * (1. + minY / rangeY));
// System.out.println(af.toString());
// prepare the graphics
this.paintComponents(g);
......@@ -187,23 +167,23 @@ Drawable, MouseMotionListener {
// prepare the diameter for the fish circle
double fishX, fishY;
int fishDiameter = (int) Math.round(Math.min(W,H) / 100.);
int fishDiameter = (int) Math.round(Math.min(W, H) / 100.);
shapeBasinMap.clear();
int idxColor;
//System.out.println("minX="+minX+ " rangeX=" + rangeX+ " minY="+minY+ "rangeY="+rangeY);
// System.out.println("minX="+minX+ " rangeX=" + rangeX+ " minY="+minY+ "rangeY="+rangeY);
for (Basin basin : basinShapeMap.keySet()) {
// draw each basin
//System.out.println( basin.getName() +" "+ basinShapeMap.get(basin).getBounds2D().toString());
Path2D.Double displayShape = (Path2D.Double)
((Path2D.Double) basinShapeMap.get(basin)).createTransformedShape(af);
//System.out.println( basin.getName() +" "+ displayShape.getBounds2D().toString());
// System.out.println( basin.getName() +" "+ basinShapeMap.get(basin).getBounds2D().toString());
Path2D.Double displayShape = (Path2D.Double) ((Path2D.Double) basinShapeMap.get(basin))
.createTransformedShape(af);
// System.out.println( basin.getName() +" "+ displayShape.getBounds2D().toString());
shapeBasinMap.put(displayShape, basin); // to be used by the mouseMoved()
// fill the
if (basin instanceof RiverBasin)
// fill the
if (basin instanceof RiverBasin)
g.setColor(new Color(0, 204, 255));
else if (basin instanceof InshoreBasin)
g.setColor(new Color(0, 102, 255));
......@@ -213,40 +193,35 @@ Drawable, MouseMotionListener {
g2d.fill(displayShape);
// draw the contour of the basin
if (basin instanceof RiverBasin) {
if (basin instanceof RiverBasin) {
idxColor = bn.getRow(basin.getId()) % colors.size();
g.setColor(colors.get(idxColor));
g2d.draw(displayShape);
}
// draw fish
int cpt=0;
Map<DiadromousFishGroup, List<DiadromousFish>> fishPerGroup= basin.getFishPerGroup();
for (DiadromousFishGroup group : fishPerGroup.keySet()){
//g.setColor(group.getColor());
int cpt = 0;
Map<DiadromousFishGroup, List<DiadromousFish>> fishPerGroup = basin.getFishPerGroup();
for (DiadromousFishGroup group : fishPerGroup.keySet()) {
// g.setColor(group.getColor());
for (DiadromousFish fish : fishPerGroup.get(group)){
for (DiadromousFish fish : fishPerGroup.get(group)) {
do {
fishX = displayShape.getBounds2D().getMinX() + displayShape.getBounds2D().getWidth()
* (0.2 + .6 * aleaX[cpt % nbAlea]); //- fishDiameter/2;
fishY = displayShape.getBounds2D().getMinY()+ displayShape.getBounds2D().getHeight()
* (0.2 + .6 * aleaY[cpt % nbAlea]);// - fishDiameter/2;
//System.out.println(! displayShape.contains(fishX, fishY));
fishX = displayShape.getBounds2D().getMinX()
+ displayShape.getBounds2D().getWidth() * (0.2 + .6 * aleaX[cpt % nbAlea]); // -
// fishDiameter/2;
fishY = displayShape.getBounds2D().getMinY()
+ displayShape.getBounds2D().getHeight() * (0.2 + .6 * aleaY[cpt % nbAlea]);// -
// fishDiameter/2;
// System.out.println(! displayShape.contains(fishX, fishY));
cpt++;
} while (! displayShape.contains(fishX, fishY));
} while (!displayShape.contains(fishX, fishY));
idxColor = bn.getRow(fish.getBirthBasin().getId()) % colors.size();
g.setColor(colors.get(idxColor));
g2d.fillOval((int) fishX, (int) fishY, fishDiameter,
fishDiameter);
g2d.fillOval((int) fishX, (int) fishY, fishDiameter, fishDiameter);
}
}
}
}
}
}
......@@ -33,9 +33,9 @@ import fr.cemagref.simaqualife.kernel.util.TransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot;
import species.DiadromousFishGroup;
@Deprecated
@SuppressWarnings("serial")
public class BasinNetworkObserverWithRealBasin extends ObserverListener
implements Configurable, Drawable, MouseMotionListener {
public class BasinNetworkObserverWithRealBasin extends ObserverListener implements Configurable, Drawable, MouseMotionListener {
private String title;
private double threshold = 13000000.;
......@@ -131,8 +131,7 @@ public class BasinNetworkObserverWithRealBasin extends ObserverListener
txt += (basin.getName() + " ");
for (DiadromousFishGroup group : basin.getGroups()) {
txt += group.getName() + "=" + basin.getEffective(group) + " in " + basin.getSuperFishNumber(group)
+ " SI ";
txt += group.getName() + "=" + basin.getEffective(group) + " in " + basin.getSuperFishNumber(group) + " SI ";
}
break;
}
......
......@@ -26,6 +26,7 @@ import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientPara
import fr.cemagref.simaqualife.pilot.Pilot;
import miscellaneous.QueueMemoryMap;
@Deprecated
public class BasinNetworkReal extends GridBasinNetwork {
private String basinFile = "data/input/reality/basins.csv";
......
......@@ -461,5 +461,4 @@ public class BasinNetworkSWithContinent extends GridBasinNetwork {
public Map<String, Path2D.Double> getMapContinent() {
return mapContinent;
}
}
......@@ -9,6 +9,7 @@ import environment.OffshoreBasin.OffshoreBasinFunction;
import fr.cemagref.simaqualife.kernel.util.TransientParameters.InitTransientParameters;
import fr.cemagref.simaqualife.pilot.Pilot;
@Deprecated
public class BasinNetworkWith2Basins extends GridBasinNetwork {
private String nameOfBv[] = { "BV1", "BV2" };
......
......@@ -39,7 +39,7 @@ import species.DiadromousFish.Stage;
/**
*
*/
public class WriteEffectiveAndBiomassFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
public class WriteEffectiveAndBiomassImportFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private Season exportSeason = Season.SPRING;
......@@ -50,7 +50,7 @@ public class WriteEffectiveAndBiomassFluxes extends AquaNismsGroupProcess<Diadro
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver())).toXML(new WriteEffectiveAndBiomassFluxes()));
System.out.println((new XStream(new DomDriver())).toXML(new WriteEffectiveAndBiomassImportFluxes()));
}
......
......@@ -39,6 +39,7 @@ import species.DiadromousFish.Stage;
/**
*
*/
@Deprecated
public class WriteEffectivesFluxes extends AquaNismsGroupProcess<DiadromousFish, DiadromousFishGroup> {
private Season exportSeason = Season.SPRING;
......@@ -46,36 +47,42 @@ public class WriteEffectivesFluxes extends AquaNismsGroupProcess<DiadromousFish,
private String fileNameOutput = "effectiveFluxes";
private transient BufferedWriter bW;
private transient String sep=";";
private transient String sep = ";";
public static void main(String[] args) {
System.out.println((new XStream(new DomDriver()))
.toXML(new WriteEffectivesFluxes()));
System.out.println((new XStream(new DomDriver())).toXML(new WriteEffectivesFluxes()));
}
/* (non-Javadoc)
* @see fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.pilot.Pilot)
/*
* (non-Javadoc)
*
* @see
* fr.cemagref.simaqualife.kernel.processes.AquaNismsGroupProcess#initTransientParameters(fr.cemagref.simaqualife.
* pilot.Pilot)
*/
@Override
public void initTransientParameters(Pilot pilot) {
super.initTransientParameters(pilot);
sep=";";
sep = ";";
}
@Override
public void doProcess(DiadromousFishGroup group) {
if (bW==null){
if (fileNameOutput != null){
new File(group.getOutputPath()+fileNameOutput).getParentFile().mkdirs();
if (bW == null) {
if (fileNameOutput != null) {
new File(group.getOutputPath() + fileNameOutput).getParentFile().mkdirs();
try {
bW = new BufferedWriter(new FileWriter(new File(group.getOutputPath()+
fileNameOutput +group.getSimulationId()+ ".csv")));
bW = new BufferedWriter(
new FileWriter(new File(group.getOutputPath() + fileNameOutput + group.getSimulationId() + ".csv")));
bW.write("year"+sep+"migrationBasin" ); //create the field of the column
bW.write("year" + sep + "migrationBasin"); // create the field of the column
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep + birthBasinName); // write each basin name in the file
bW.write(sep + birthBasinName); // write each basin name in the file
}
bW.write("\n");
......@@ -85,40 +92,41 @@ public class WriteEffectivesFluxes extends AquaNismsGroupProcess<DiadromousFish,
}
}
try {
Time time = group.getEnvironment().getTime();
if (time.getSeason(pilot) == exportSeason & time.getYear(pilot) >= group.getMinYearToWrite()) {
for (RiverBasin migrationBasin : group.getEnvironment().getRiverBasins()) {
//Create the map to get the abundance in each birth basin
Map<String, Long> spawnerOriginsBeforeReproduction = new HashMap<String, Long>(group.getEnvironment().getRiverBasinNames().length);
for (String basinName : group.getEnvironment().getRiverBasinNames()){
spawnerOriginsBeforeReproduction.put(basinName, 0L);
// Create the map to get the abundance in each birth basin
Map<String, Long> spawnerOriginsBeforeReproduction = new HashMap<String, Long>(
group.getEnvironment().getRiverBasinNames().length);
for (String basinName : group.getEnvironment().getRiverBasinNames()) {
spawnerOriginsBeforeReproduction.put(basinName, 0L);
}
//compute the cumulative effective per birth basin
// compute the cumulative effective per birth basin
if (migrationBasin.getFishs(group) != null) {
for (DiadromousFish fish : migrationBasin.getFishs(group)) {
if (fish.getStage() == Stage.MATURE) {
String birthBasinName = fish.getBirthBasin().getName();
spawnerOriginsBeforeReproduction.put(birthBasinName, spawnerOriginsBeforeReproduction.get(birthBasinName) + fish.getAmount() );
spawnerOriginsBeforeReproduction.put(birthBasinName,
spawnerOriginsBeforeReproduction.get(birthBasinName) + fish.getAmount());
}
}
}
//write the first two fields of the line
bW.write(time.getYear(pilot)+sep+migrationBasin.getName());
// write the first two fields of the line
bW.write(time.getYear(pilot) + sep + migrationBasin.getName());
//write the cumulative effective from birth basin
// write the cumulative effective from birth basin
for (String birthBasinName : group.getEnvironment().getRiverBasinNames()) {
bW.write(sep+spawnerOriginsBeforeReproduction.get(birthBasinName));
bW.write(sep + spawnerOriginsBeforeReproduction.get(birthBasinName));
}
// write an end-of-line
bW.write("\n");
}
}
if (group.getPilot().getCurrentTime()== group.getPilot().getSimBegin()+group.getPilot().getSimDuration()-1) {
if (group.getPilot().getCurrentTime() == group.getPilot().getSimBegin() + group.getPilot().getSimDuration() - 1) {
bW.flush();
bW.close();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment