Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCommon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSCommon
Commits
5c60d5a8
Commit
5c60d5a8
authored
7 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
A wee bit of refactoring for Java 7 (Java 6 incompatible), using diamond reference
parent
568c499c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/nibio/vips/util/WeatherUtil.java
+25
-25
25 additions, 25 deletions
src/main/java/no/nibio/vips/util/WeatherUtil.java
with
25 additions
and
25 deletions
src/main/java/no/nibio/vips/util/WeatherUtil.java
+
25
−
25
View file @
5c60d5a8
...
@@ -57,7 +57,7 @@ public class WeatherUtil {
...
@@ -57,7 +57,7 @@ public class WeatherUtil {
// Special case: List has less than 24 hourly values, return empty list
// Special case: List has less than 24 hourly values, return empty list
if
(
hourlyValues
.
size
()
<
24
)
if
(
hourlyValues
.
size
()
<
24
)
{
{
return
new
ArrayList
<
WeatherObservation
>();
return
new
ArrayList
<>();
}
}
// Sort the list
// Sort the list
Collections
.
sort
(
hourlyValues
);
Collections
.
sort
(
hourlyValues
);
...
@@ -77,7 +77,7 @@ public class WeatherUtil {
...
@@ -77,7 +77,7 @@ public class WeatherUtil {
}
}
else
else
{
{
return
new
ArrayList
<
WeatherObservation
>(
hourlyValues
.
subList
(
0
,
dateShiftIndex
));
return
new
ArrayList
<>(
hourlyValues
.
subList
(
0
,
dateShiftIndex
));
}
}
}
}
...
@@ -107,7 +107,7 @@ public class WeatherUtil {
...
@@ -107,7 +107,7 @@ public class WeatherUtil {
Collections
.
sort
(
rainfall
);
Collections
.
sort
(
rainfall
);
Collections
.
sort
(
relativeHumidity
);
Collections
.
sort
(
relativeHumidity
);
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
Iterator
<
WeatherObservation
>
humIt
=
relativeHumidity
.
iterator
();
Iterator
<
WeatherObservation
>
humIt
=
relativeHumidity
.
iterator
();
WeatherObservation
humObs
;
WeatherObservation
humObs
;
Iterator
<
WeatherObservation
>
rainIt
=
rainfall
.
iterator
();
Iterator
<
WeatherObservation
>
rainIt
=
rainfall
.
iterator
();
...
@@ -245,7 +245,7 @@ public class WeatherUtil {
...
@@ -245,7 +245,7 @@ public class WeatherUtil {
return
null
;
return
null
;
}
}
// First we organize the hourly values into one bucket per day
// First we organize the hourly values into one bucket per day
Map
<
Date
,
Map
>
dateBucket
=
new
HashMap
<
Date
,
Map
>();
Map
<
Date
,
Map
>
dateBucket
=
new
HashMap
<>();
String
expectedParameter
=
observations
.
get
(
0
).
getElementMeasurementTypeId
();
String
expectedParameter
=
observations
.
get
(
0
).
getElementMeasurementTypeId
();
Date
lastDate
=
null
;
Date
lastDate
=
null
;
Integer
numberOfDuplicates
=
0
;
Integer
numberOfDuplicates
=
0
;
...
@@ -261,7 +261,7 @@ public class WeatherUtil {
...
@@ -261,7 +261,7 @@ public class WeatherUtil {
Map
<
Date
,
Double
>
hourValuesForDate
=
dateBucket
.
get
(
theDate
);
Map
<
Date
,
Double
>
hourValuesForDate
=
dateBucket
.
get
(
theDate
);
if
(
hourValuesForDate
==
null
)
if
(
hourValuesForDate
==
null
)
{
{
hourValuesForDate
=
new
HashMap
<
Date
,
Double
>();
hourValuesForDate
=
new
HashMap
<>();
dateBucket
.
put
(
theDate
,
hourValuesForDate
);
dateBucket
.
put
(
theDate
,
hourValuesForDate
);
}
}
...
@@ -289,7 +289,7 @@ public class WeatherUtil {
...
@@ -289,7 +289,7 @@ public class WeatherUtil {
}
}
// Then we iterate the buckets, do the aggregation and create return values
// Then we iterate the buckets, do the aggregation and create return values
List
<
WeatherObservation
>
aggregatedObservations
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
aggregatedObservations
=
new
ArrayList
<>();
WeatherObservation
templateObservation
=
observations
.
get
(
0
);
WeatherObservation
templateObservation
=
observations
.
get
(
0
);
Double
aggregateValue
;
Double
aggregateValue
;
for
(
Date
aDay:
dateBucket
.
keySet
())
for
(
Date
aDay:
dateBucket
.
keySet
())
...
@@ -549,7 +549,7 @@ public class WeatherUtil {
...
@@ -549,7 +549,7 @@ public class WeatherUtil {
WeatherObservation
.
LOG_INTERVAL_ID_1H
,
WeatherObservation
.
LOG_INTERVAL_ID_1H
,
0
d
0
d
);
);
calculatedBT
=
new
ArrayList
<
WeatherObservation
>();
calculatedBT
=
new
ArrayList
<>();
calculatedBT
.
add
(
emptyObs
);
calculatedBT
.
add
(
emptyObs
);
calculatedBT
.
addAll
(
this
.
calculateLeafWetnessHourSeriesNaerstad
(
TM
,
RR
,
Q0
,
FM2
,
UM
,
null
));
calculatedBT
.
addAll
(
this
.
calculateLeafWetnessHourSeriesNaerstad
(
TM
,
RR
,
Q0
,
FM2
,
UM
,
null
));
}
}
...
@@ -593,7 +593,7 @@ public class WeatherUtil {
...
@@ -593,7 +593,7 @@ public class WeatherUtil {
*/
*/
public
List
<
WeatherObservation
>
getWeatherObservationsInPeriod
(
List
<
WeatherObservation
>
allObservations
,
Date
dateStart
,
Date
dateEnd
)
public
List
<
WeatherObservation
>
getWeatherObservationsInPeriod
(
List
<
WeatherObservation
>
allObservations
,
Date
dateStart
,
Date
dateEnd
)
{
{
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
for
(
WeatherObservation
obs:
allObservations
)
for
(
WeatherObservation
obs:
allObservations
)
{
{
if
(
if
(
...
@@ -629,7 +629,7 @@ public class WeatherUtil {
...
@@ -629,7 +629,7 @@ public class WeatherUtil {
{
{
// TODO Validation
// TODO Validation
List
<
WeatherObservation
>
calculatedLeafWetnessSeries
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
calculatedLeafWetnessSeries
=
new
ArrayList
<>();
Double
lastLatentHeatFlux
=
this
.
calculateLatentHeatFlux
(
Double
lastLatentHeatFlux
=
this
.
calculateLatentHeatFlux
(
temperature
.
get
(
0
).
getValue
(),
temperature
.
get
(
0
).
getValue
(),
relativeHumidity
.
get
(
0
).
getValue
(),
relativeHumidity
.
get
(
0
).
getValue
(),
...
@@ -759,7 +759,7 @@ public class WeatherUtil {
...
@@ -759,7 +759,7 @@ public class WeatherUtil {
}
}
else
if
(
missingValues
>
0
)
else
if
(
missingValues
>
0
)
{
{
List
<
WeatherObservation
>
calculatedValues
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
calculatedValues
=
new
ArrayList
<>();
String
elementMeasurementTypeId
=
obsList
.
get
(
i
).
getElementMeasurementTypeId
();
String
elementMeasurementTypeId
=
obsList
.
get
(
i
).
getElementMeasurementTypeId
();
String
fixingStrategy
=
this
.
getFixingStrategy
(
elementMeasurementTypeId
);
String
fixingStrategy
=
this
.
getFixingStrategy
(
elementMeasurementTypeId
);
Date
lastTimestampBeforeHole
=
obsList
.
get
(
i
-
1
).
getTimeMeasured
();
Date
lastTimestampBeforeHole
=
obsList
.
get
(
i
-
1
).
getTimeMeasured
();
...
@@ -830,7 +830,7 @@ public class WeatherUtil {
...
@@ -830,7 +830,7 @@ public class WeatherUtil {
// Removing duplicates first
// Removing duplicates first
mixedParameterList
=
this
.
removeDuplicateWeatherObservations
(
mixedParameterList
,
null
);
mixedParameterList
=
this
.
removeDuplicateWeatherObservations
(
mixedParameterList
,
null
);
Map
<
String
,
List
<
WeatherObservation
>>
separatedParameters
=
new
HashMap
<
String
,
List
<
WeatherObservation
>
>();
Map
<
String
,
List
<
WeatherObservation
>>
separatedParameters
=
new
HashMap
<>();
Date
estimatedLastTimestamp
=
lastTimestamp
;
Date
estimatedLastTimestamp
=
lastTimestamp
;
// Separating the parameters
// Separating the parameters
...
@@ -848,7 +848,7 @@ public class WeatherUtil {
...
@@ -848,7 +848,7 @@ public class WeatherUtil {
}
}
if
(
separatedParameters
.
get
(
obs
.
getElementMeasurementTypeId
())
==
null
)
if
(
separatedParameters
.
get
(
obs
.
getElementMeasurementTypeId
())
==
null
)
{
{
separatedParameters
.
put
(
obs
.
getElementMeasurementTypeId
(),
new
ArrayList
<
WeatherObservation
>());
separatedParameters
.
put
(
obs
.
getElementMeasurementTypeId
(),
new
ArrayList
<>());
}
}
separatedParameters
.
get
(
obs
.
getElementMeasurementTypeId
()).
add
(
obs
);
separatedParameters
.
get
(
obs
.
getElementMeasurementTypeId
()).
add
(
obs
);
...
@@ -918,7 +918,7 @@ public class WeatherUtil {
...
@@ -918,7 +918,7 @@ public class WeatherUtil {
// Last check, give up if not fixed
// Last check, give up if not fixed
if
(
areListsComplete
(
separatedParameters
,
firstTimestamp
,
lastTimestamp
))
if
(
areListsComplete
(
separatedParameters
,
firstTimestamp
,
lastTimestamp
))
{
{
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
for
(
String
parameterName:
separatedParameters
.
keySet
())
for
(
String
parameterName:
separatedParameters
.
keySet
())
{
{
retVal
.
addAll
(
separatedParameters
.
get
(
parameterName
));
retVal
.
addAll
(
separatedParameters
.
get
(
parameterName
));
...
@@ -988,12 +988,12 @@ public class WeatherUtil {
...
@@ -988,12 +988,12 @@ public class WeatherUtil {
{
{
maximumDuplicateRatio
=
0.05
;
maximumDuplicateRatio
=
0.05
;
}
}
HashMap
<
Long
,
WeatherObservation
>
uniqueMap
=
new
HashMap
<
Long
,
WeatherObservation
>();
HashMap
<
Long
,
WeatherObservation
>
uniqueMap
=
new
HashMap
<>();
for
(
WeatherObservation
observation:
observations
)
for
(
WeatherObservation
observation:
observations
)
{
{
uniqueMap
.
put
(
observation
.
getValiditySignature
(),
observation
);
uniqueMap
.
put
(
observation
.
getValiditySignature
(),
observation
);
}
}
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>(
uniqueMap
.
values
());
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>(
uniqueMap
.
values
());
Double
numberOfDuplicates
=
new
Double
(
observations
.
size
()
-
retVal
.
size
());
Double
numberOfDuplicates
=
new
Double
(
observations
.
size
()
-
retVal
.
size
());
//System.out.println(numberOfDuplicates/observations.size());
//System.out.println(numberOfDuplicates/observations.size());
if
(
numberOfDuplicates
/
observations
.
size
()
>
maximumDuplicateRatio
)
if
(
numberOfDuplicates
/
observations
.
size
()
>
maximumDuplicateRatio
)
...
@@ -1152,7 +1152,7 @@ public class WeatherUtil {
...
@@ -1152,7 +1152,7 @@ public class WeatherUtil {
*/
*/
public
List
<
WeatherObservation
>
truncateToLastCommonObservation
(
List
<
WeatherObservation
>
observations
)
{
public
List
<
WeatherObservation
>
truncateToLastCommonObservation
(
List
<
WeatherObservation
>
observations
)
{
// Find the latest date for each parameter
// Find the latest date for each parameter
Map
<
String
,
Date
>
latestObservations
=
new
HashMap
<
String
,
Date
>();
Map
<
String
,
Date
>
latestObservations
=
new
HashMap
<>();
for
(
WeatherObservation
obs:
observations
)
for
(
WeatherObservation
obs:
observations
)
{
{
Date
latestDateForParameter
=
latestObservations
.
get
(
obs
.
getElementMeasurementTypeId
());
Date
latestDateForParameter
=
latestObservations
.
get
(
obs
.
getElementMeasurementTypeId
());
...
@@ -1169,7 +1169,7 @@ public class WeatherUtil {
...
@@ -1169,7 +1169,7 @@ public class WeatherUtil {
date
.
compareTo
(
latestCommonDate
)
<
0
?
date
:
latestCommonDate
;
date
.
compareTo
(
latestCommonDate
)
<
0
?
date
:
latestCommonDate
;
}
}
// Then we filter out all the observations after the latestCommonDate
// Then we filter out all the observations after the latestCommonDate
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
for
(
WeatherObservation
obs:
observations
)
for
(
WeatherObservation
obs:
observations
)
{
{
if
(
obs
.
getTimeMeasured
().
compareTo
(
latestCommonDate
)
<=
0
)
if
(
obs
.
getTimeMeasured
().
compareTo
(
latestCommonDate
)
<=
0
)
...
@@ -1189,8 +1189,8 @@ public class WeatherUtil {
...
@@ -1189,8 +1189,8 @@ public class WeatherUtil {
*/
*/
public
List
<
WeatherObservation
>
truncateToFirstAndLastCommonObservation
(
List
<
WeatherObservation
>
observations
)
{
public
List
<
WeatherObservation
>
truncateToFirstAndLastCommonObservation
(
List
<
WeatherObservation
>
observations
)
{
// Find the earliest and latest date for each parameter
// Find the earliest and latest date for each parameter
Map
<
String
,
Date
>
latestObservations
=
new
HashMap
<
String
,
Date
>();
Map
<
String
,
Date
>
latestObservations
=
new
HashMap
<>();
Map
<
String
,
Date
>
earliestObservations
=
new
HashMap
<
String
,
Date
>();
Map
<
String
,
Date
>
earliestObservations
=
new
HashMap
<>();
for
(
WeatherObservation
obs:
observations
)
for
(
WeatherObservation
obs:
observations
)
{
{
Date
latestDateForParameter
=
latestObservations
.
get
(
obs
.
getElementMeasurementTypeId
());
Date
latestDateForParameter
=
latestObservations
.
get
(
obs
.
getElementMeasurementTypeId
());
...
@@ -1221,7 +1221,7 @@ public class WeatherUtil {
...
@@ -1221,7 +1221,7 @@ public class WeatherUtil {
date
.
compareTo
(
latestCommonDate
)
<
0
?
date
:
latestCommonDate
;
date
.
compareTo
(
latestCommonDate
)
<
0
?
date
:
latestCommonDate
;
}
}
// Then we filter out all the observations before the earliestCommonDate and after the latestCommonDate
// Then we filter out all the observations before the earliestCommonDate and after the latestCommonDate
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
for
(
WeatherObservation
obs:
observations
)
for
(
WeatherObservation
obs:
observations
)
{
{
if
(
obs
.
getTimeMeasured
().
compareTo
(
earliestCommonDate
)
>=
0
||
obs
.
getTimeMeasured
().
compareTo
(
latestCommonDate
)
<=
0
)
if
(
obs
.
getTimeMeasured
().
compareTo
(
earliestCommonDate
)
>=
0
||
obs
.
getTimeMeasured
().
compareTo
(
latestCommonDate
)
<=
0
)
...
@@ -1240,7 +1240,7 @@ public class WeatherUtil {
...
@@ -1240,7 +1240,7 @@ public class WeatherUtil {
* @return
* @return
*/
*/
public
List
<
WeatherObservation
>
filterWeatherObservationsByParameter
(
List
<
WeatherObservation
>
observations
,
Set
<
String
>
parameters
){
public
List
<
WeatherObservation
>
filterWeatherObservationsByParameter
(
List
<
WeatherObservation
>
observations
,
Set
<
String
>
parameters
){
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
for
(
WeatherObservation
obs:
observations
)
for
(
WeatherObservation
obs:
observations
)
{
{
if
(
parameters
.
contains
(
obs
.
getElementMeasurementTypeId
()))
if
(
parameters
.
contains
(
obs
.
getElementMeasurementTypeId
()))
...
@@ -1267,7 +1267,7 @@ public class WeatherUtil {
...
@@ -1267,7 +1267,7 @@ public class WeatherUtil {
return
null
;
return
null
;
}
}
// First we organize the less-than-hourly values into one bucket per hour
// First we organize the less-than-hourly values into one bucket per hour
Map
<
Date
,
Map
>
hourBucket
=
new
HashMap
<
Date
,
Map
>();
Map
<
Date
,
Map
>
hourBucket
=
new
HashMap
<>();
String
expectedParameter
=
observations
.
get
(
0
).
getElementMeasurementTypeId
();
String
expectedParameter
=
observations
.
get
(
0
).
getElementMeasurementTypeId
();
Date
lastDate
=
null
;
Date
lastDate
=
null
;
for
(
WeatherObservation
observation:
observations
)
for
(
WeatherObservation
observation:
observations
)
...
@@ -1281,7 +1281,7 @@ public class WeatherUtil {
...
@@ -1281,7 +1281,7 @@ public class WeatherUtil {
Map
<
Date
,
Double
>
hourValuesForDate
=
hourBucket
.
get
(
theDate
);
Map
<
Date
,
Double
>
hourValuesForDate
=
hourBucket
.
get
(
theDate
);
if
(
hourValuesForDate
==
null
)
if
(
hourValuesForDate
==
null
)
{
{
hourValuesForDate
=
new
HashMap
<
Date
,
Double
>();
hourValuesForDate
=
new
HashMap
<>();
hourBucket
.
put
(
theDate
,
hourValuesForDate
);
hourBucket
.
put
(
theDate
,
hourValuesForDate
);
}
}
...
@@ -1300,7 +1300,7 @@ public class WeatherUtil {
...
@@ -1300,7 +1300,7 @@ public class WeatherUtil {
}
}
// Then we iterate the buckets, do the aggregation and create return values
// Then we iterate the buckets, do the aggregation and create return values
List
<
WeatherObservation
>
aggregatedObservations
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
aggregatedObservations
=
new
ArrayList
<>();
WeatherObservation
templateObservation
=
observations
.
get
(
0
);
WeatherObservation
templateObservation
=
observations
.
get
(
0
);
Double
aggregateValue
;
Double
aggregateValue
;
for
(
Date
anHour:
hourBucket
.
keySet
())
for
(
Date
anHour:
hourBucket
.
keySet
())
...
@@ -1382,7 +1382,7 @@ public class WeatherUtil {
...
@@ -1382,7 +1382,7 @@ public class WeatherUtil {
public
List
<
WeatherObservation
>
getIncrementalValuesFromAccumulated
(
List
<
WeatherObservation
>
accumulatedValues
,
TimeZone
timeZone
,
Integer
incrementalLogIntervalId
)
public
List
<
WeatherObservation
>
getIncrementalValuesFromAccumulated
(
List
<
WeatherObservation
>
accumulatedValues
,
TimeZone
timeZone
,
Integer
incrementalLogIntervalId
)
{
{
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<
WeatherObservation
>();
List
<
WeatherObservation
>
retVal
=
new
ArrayList
<>();
// We always start on the whole hour
// We always start on the whole hour
Calendar
cal
=
Calendar
.
getInstance
(
timeZone
);
Calendar
cal
=
Calendar
.
getInstance
(
timeZone
);
Collections
.
sort
(
accumulatedValues
);
Collections
.
sort
(
accumulatedValues
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment