Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSLogic
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
VIPSLogic
Commits
81dda06d
Commit
81dda06d
authored
7 months ago
by
Lene Wasskog
Browse files
Options
Downloads
Patches
Plain Diff
feat: Use openmeteo for BarleyNetBlotchModel (hardcoded url)
parent
057e983d
No related branches found
No related tags found
1 merge request
!191
Add map module and Open-Meteo support
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/nibio/vips/logic/modules/barleynetblotch/BarleyNetBlotchModelService.java
+78
-45
78 additions, 45 deletions
.../modules/barleynetblotch/BarleyNetBlotchModelService.java
with
78 additions
and
45 deletions
src/main/java/no/nibio/vips/logic/modules/barleynetblotch/BarleyNetBlotchModelService.java
+
78
−
45
View file @
81dda06d
...
...
@@ -19,11 +19,8 @@
package
no.nibio.vips.logic.modules.barleynetblotch
;
import
com.webcohesion.enunciate.metadata.Facet
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.TimeZone
;
import
java.util.*
;
import
javax.ejb.EJB
;
import
javax.persistence.EntityManager
;
import
javax.persistence.NoResultException
;
...
...
@@ -38,10 +35,7 @@ import no.nibio.vips.entity.ModelConfiguration;
import
no.nibio.vips.entity.Result
;
import
no.nibio.vips.entity.WeatherObservation
;
import
no.nibio.vips.logic.controller.session.ForecastBean
;
import
no.nibio.vips.logic.entity.Organism
;
import
no.nibio.vips.logic.entity.Organization
;
import
no.nibio.vips.logic.entity.PointOfInterestWeatherStation
;
import
no.nibio.vips.logic.entity.Preparation
;
import
no.nibio.vips.logic.entity.*
;
import
no.nibio.vips.logic.util.RunModelException
;
import
no.nibio.vips.logic.util.SystemTime
;
import
no.nibio.vips.observation.ObservationImpl
;
...
...
@@ -140,6 +134,9 @@ public class BarleyNetBlotchModelService {
public
Response
runModel
(
@PathParam
(
"organizationId"
)
Integer
organizationId
,
@QueryParam
(
"timeZone"
)
String
timeZoneStr
,
@QueryParam
(
"weatherdataType"
)
String
weatherdataType
,
@QueryParam
(
"latitude"
)
Double
latitude
,
@QueryParam
(
"longitude"
)
Double
longitude
,
@QueryParam
(
"weatherStationId"
)
Integer
weatherStationId
,
@QueryParam
(
"sowingDate"
)
String
sowingDateStr
,
@QueryParam
(
"cropId"
)
Integer
cropOrganismId
,
...
...
@@ -173,47 +170,57 @@ public class BarleyNetBlotchModelService {
ModelConfiguration
config
=
new
ModelConfiguration
();
config
.
setModelId
(
"BARLEYNETB"
);
// Get weather data from weather station
PointOfInterestWeatherStation
weatherStation
=
em
.
find
(
PointOfInterestWeatherStation
.
class
,
weatherStationId
);
WeatherDataSourceUtil
wsdUtil
=
new
WeatherDataSourceUtil
();
// End date for weather data depends on season
// We try to add 5 months to the sowing date. If thats in the future,
// We add 10 days to today
Date
dateOfLastWeatherData
;
Calendar
cal
=
Calendar
.
getInstance
(
timeZone
);
cal
.
setTime
(
sowingDate
);
cal
.
add
(
Calendar
.
MONTH
,
5
);
Date
fiveMonthsAfterSowingDate
=
cal
.
getTime
();
if
(
fiveMonthsAfterSowingDate
.
after
(
SystemTime
.
getSystemTime
()))
{
cal
.
setTime
(
SystemTime
.
getSystemTime
());
cal
.
add
(
Calendar
.
DATE
,
10
);
dateOfLastWeatherData
=
cal
.
getTime
();
}
else
{
dateOfLastWeatherData
=
fiveMonthsAfterSowingDate
;
}
WeatherDataSourceUtil
wsdUtil
=
new
WeatherDataSourceUtil
();
Date
endDateForWeatherData
=
calculateEndDateForWeatherData
(
timeZone
,
sowingDate
);
List
<
WeatherObservation
>
observations
;
try
{
observations
=
wsdUtil
.
getWeatherObservations
(
if
(
"weatherstation"
.
equals
(
weatherdataType
))
{
PointOfInterestWeatherStation
weatherStation
=
em
.
find
(
PointOfInterestWeatherStation
.
class
,
weatherStationId
);
try
{
observations
=
wsdUtil
.
getWeatherObservations
(
weatherStation
,
WeatherObservation
.
LOG_INTERVAL_ID_1H
,
new
String
[]{
new
String
[]
{
WeatherElements
.
TEMPERATURE_MEAN
,
WeatherElements
.
PRECIPITATION
},
sowingDate
,
dateOfLastWeatherData
);
}
catch
(
WeatherDataSourceException
ex
)
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
).
entity
(
ex
.
getMessage
()).
build
();
}
if
(
observations
==
null
||
observations
.
isEmpty
())
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
).
entity
(
"Could not find weather data for weather station with id="
+
weatherStationId
).
build
();
sowingDate
,
endDateForWeatherData
);
}
catch
(
WeatherDataSourceException
ex
)
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
).
entity
(
ex
.
getMessage
()).
build
();
}
if
(
observations
==
null
||
observations
.
isEmpty
())
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
)
.
entity
(
"Could not find weather data for weather station with id="
+
weatherStationId
).
build
();
}
}
else
{
PointOfInterest
coordinates
=
new
PointOfInterest
();
coordinates
.
setLatitude
(
latitude
);
coordinates
.
setLongitude
(
longitude
);
try
{
observations
=
wsdUtil
.
getWeatherObservations
(
"https://weather.vips.nibio.no/rest/grid/openmeteo/"
+
coordinates
.
getLongitude
()
+
"_"
+
coordinates
.
getLatitude
(),
WeatherObservation
.
LOG_INTERVAL_ID_1H
,
new
String
[]
{
WeatherElements
.
TEMPERATURE_MEAN
,
WeatherElements
.
PRECIPITATION
},
sowingDate
,
endDateForWeatherData
,
timeZone
,
Boolean
.
FALSE
,
new
HashSet
<>(
Collections
.
singletonList
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
))
);
}
catch
(
WeatherDataSourceException
ex
)
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
).
entity
(
ex
.
getMessage
()).
build
();
}
if
(
observations
==
null
||
observations
.
isEmpty
())
{
return
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
)
.
entity
(
"Could not find weather data for weather station with id="
+
weatherStationId
).
build
();
}
}
// Mandatory parameters
...
...
@@ -257,6 +264,32 @@ public class BarleyNetBlotchModelService {
}
return
Response
.
ok
().
entity
(
results
).
build
();
}
/**
* End date for weather data depends on season. We try to add 5 months to the sowing date.
* If the resulting date is in the future, we add 10 days to today.
*
* @param timeZone The current timezone
* @param sowingDate The sowing date
* @return The end date for weather data
*/
private
static
Date
calculateEndDateForWeatherData
(
TimeZone
timeZone
,
Date
sowingDate
)
{
Date
dateOfLastWeatherData
;
Calendar
cal
=
Calendar
.
getInstance
(
timeZone
);
cal
.
setTime
(
sowingDate
);
cal
.
add
(
Calendar
.
MONTH
,
5
);
Date
fiveMonthsAfterSowingDate
=
cal
.
getTime
();
if
(
fiveMonthsAfterSowingDate
.
after
(
SystemTime
.
getSystemTime
()))
{
cal
.
setTime
(
SystemTime
.
getSystemTime
());
cal
.
add
(
Calendar
.
DATE
,
10
);
dateOfLastWeatherData
=
cal
.
getTime
();
}
else
{
dateOfLastWeatherData
=
fiveMonthsAfterSowingDate
;
}
return
dateOfLastWeatherData
;
}
}
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