Skip to content

Commit b06b150

Browse files
committed
The old version of SumSeries has been restored under the same name. The new version of SumSeries has been renamed and now it is SumNodes
1 parent 7c2d3cc commit b06b150

File tree

2 files changed

+167
-39
lines changed

2 files changed

+167
-39
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* GNU GPL v3 License
3+
*
4+
* Copyright 2015 Marialaura Bancheri
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
package sumSeries;
21+
22+
import static org.jgrasstools.gears.libs.modules.JGTConstants.isNovalue;
23+
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
27+
import oms3.annotations.Description;
28+
import oms3.annotations.Execute;
29+
import oms3.annotations.Finalize;
30+
import oms3.annotations.In;
31+
import oms3.annotations.Initialize;
32+
import oms3.annotations.Out;
33+
34+
import org.jgrasstools.gears.libs.modules.JGTModel;
35+
36+
/**
37+
* The Class SumSeries compute the sum of two time series
38+
*
39+
* @author sidereus <francesco.serafin.3@gmail.com>
40+
* @date Nov 2nd, 2016
41+
*/
42+
public class SumNodes extends JGTModel {
43+
44+
@Description("Input first discharge Hashmap")
45+
@In
46+
public HashMap<Integer, double[]> inHMDischarge;
47+
48+
@Description("Input second discharge Hashmap")
49+
@In
50+
public HashMap<Integer, double[]> inHMDischarge2;
51+
52+
53+
@Description("The output HashMap with the sum"
54+
+ "for the considered layer ")
55+
@Out
56+
public static HashMap<Integer, double[]> outHMQtot;
57+
58+
@In
59+
public static Integer id;
60+
61+
private static int timeSeriesCounter = 0;
62+
63+
@Initialize
64+
public void init() {
65+
outHMQtot = new HashMap<>();
66+
timeSeriesCounter = 0;
67+
}
68+
69+
/**
70+
* Process.
71+
*
72+
* @throws Exception the exception
73+
*/
74+
@Execute
75+
public void process() throws Exception {
76+
77+
System.out.println(id + ": processing sum series - Time step: " +
78+
timeSeriesCounter+1);
79+
80+
checkNull(inHMDischarge);
81+
double[] sum = new double[1];
82+
83+
sumInHMDischarge(sum, inHMDischarge, timeSeriesCounter);
84+
sumInHMDischarge(sum, inHMDischarge2, 0);
85+
86+
outHMQtot.put(id, sum);
87+
timeSeriesCounter += 1;
88+
89+
}
90+
91+
@Finalize
92+
public void finalize() {
93+
timeSeriesCounter = 0;
94+
outHMQtot.clear();
95+
}
96+
97+
private void sumInHMDischarge(double[] sum, final HashMap<Integer,
98+
double[]> discharge, int index) {
99+
100+
if (discharge != null) {
101+
for (Map.Entry<Integer, double[]> me : discharge.entrySet()) {
102+
double tmpDischarge = me.getValue()[index];
103+
if (isNovalue(tmpDischarge)) tmpDischarge = 0.0;
104+
sum[0] += tmpDischarge;
105+
}
106+
}
107+
108+
}
109+
110+
}
111+

src/main/java/sumSeries/SumSeries.java

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,27 @@
2222
import static org.jgrasstools.gears.libs.modules.JGTConstants.isNovalue;
2323

2424
import java.util.HashMap;
25-
import java.util.Map;
25+
import java.util.Set;
26+
import java.util.Map.Entry;
2627

2728
import oms3.annotations.Description;
2829
import oms3.annotations.Execute;
29-
import oms3.annotations.Finalize;
3030
import oms3.annotations.In;
31-
import oms3.annotations.Initialize;
3231
import oms3.annotations.Out;
3332

33+
import org.geotools.feature.SchemaException;
3434
import org.jgrasstools.gears.libs.modules.JGTModel;
35+
import java.io.IOException;
3536

37+
38+
39+
40+
// TODO: Auto-generated Javadoc
3641
/**
3742
* The Class SumSeries compute the sum of two time series
38-
*
39-
* @author sidereus <francesco.serafin.3@gmail.com>
40-
* @date Nov 2nd, 2016
4143
*/
42-
public class SumSeries extends JGTModel {
44+
public class SumSeries extends JGTModel{
45+
4346

4447
@Description("Input first discharge Hashmap")
4548
@In
@@ -53,18 +56,9 @@ public class SumSeries extends JGTModel {
5356
@Description("The output HashMap with the sum"
5457
+ "for the considered layer ")
5558
@Out
56-
public static HashMap<Integer, double[]> outHMQtot;
59+
public HashMap<Integer, double[]> outHMQtot= new HashMap<Integer, double[]>() ;
5760

58-
@In
59-
public static Integer id;
6061

61-
private static int timeSeriesCounter = 0;
62-
63-
@Initialize
64-
public void init() {
65-
outHMQtot = new HashMap<>();
66-
timeSeriesCounter = 0;
67-
}
6862

6963
/**
7064
* Process.
@@ -74,38 +68,61 @@ public void init() {
7468
@Execute
7569
public void process() throws Exception {
7670

77-
System.out.println(id + ": processing sum series - Time step: " +
78-
timeSeriesCounter+1);
71+
//checkNull(inHMDischarge);
7972

80-
checkNull(inHMDischarge);
81-
double[] sum = new double[1];
73+
Set<Entry<Integer, double[]>> entrySet = inHMDischarge.entrySet();
8274

83-
sumInHMDischarge(sum, inHMDischarge, timeSeriesCounter);
84-
sumInHMDischarge(sum, inHMDischarge2, 0);
75+
Set<Entry<Integer, double[]>> entrySet2 = inHMDischarge2.entrySet();
8576

86-
outHMQtot.put(id, sum);
87-
timeSeriesCounter += 1;
8877

89-
}
78+
for (Entry<Integer, double[]> entry : entrySet){
79+
for (Entry<Integer, double[]> entry2 : entrySet2){
9080

91-
@Finalize
92-
public void finalize() {
93-
timeSeriesCounter = 0;
94-
outHMQtot.clear();
95-
}
81+
Integer ID = entry.getKey();
82+
Integer ID2 = entry2.getKey();
9683

97-
private void sumInHMDischarge(double[] sum, final HashMap<Integer,
98-
double[]> discharge, int index) {
84+
double Q1 =inHMDischarge.get(ID)[0];
85+
if (isNovalue(Q1)) Q1= 0;
9986

100-
if (discharge != null) {
101-
for (Map.Entry<Integer, double[]> me : discharge.entrySet()) {
102-
double tmpDischarge = me.getValue()[index];
103-
if (isNovalue(tmpDischarge)) tmpDischarge = 0.0;
104-
sum[0] += tmpDischarge;
87+
double Q2 =inHMDischarge2.get(ID2)[0];
88+
if (isNovalue(Q2)) Q2= 0;
89+
90+
/** sum of the given quantities */
91+
double sum=sum(Q1,Q2);
92+
93+
/** Save the result in hashmap output */
94+
storeResult_series(ID,sum);
10595
}
10696
}
10797

10898
}
10999

110-
}
111100

101+
102+
103+
/**
104+
* Sum: computation of the sum
105+
*
106+
* @param Q1: the first quantity
107+
* @param Q2 : the second quantity
108+
* @return the double value of the sum
109+
* @throws IOException Signals that an I/O exception has occurred.
110+
*/
111+
public double sum(double Q1, double Q2) throws IOException {
112+
double Qtot=Q1+Q2;
113+
return Qtot;
114+
}
115+
116+
117+
/**
118+
* Store result_series
119+
*
120+
* @param Qtot: the vector with the sums
121+
* @throws SchemaException the schema exception
122+
*/
123+
private void storeResult_series(int ID,double Qtot) throws SchemaException {
124+
outHMQtot.put(ID, new double[]{Qtot});
125+
126+
127+
}
128+
}

0 commit comments

Comments
 (0)