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
6027922b
Commit
6027922b
authored
8 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Bugfix in file parsing and log interval setting
parent
d8e23a3f
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/weather/YrWeatherForecastProvider.java
+41
-6
41 additions, 6 deletions
...no/nibio/vips/util/weather/YrWeatherForecastProvider.java
with
41 additions
and
6 deletions
src/main/java/no/nibio/vips/util/weather/YrWeatherForecastProvider.java
+
41
−
6
View file @
6027922b
...
@@ -49,12 +49,19 @@ import org.xml.sax.SAXException;
...
@@ -49,12 +49,19 @@ import org.xml.sax.SAXException;
*/
*/
public
class
YrWeatherForecastProvider
implements
WeatherForecastProvider
{
public
class
YrWeatherForecastProvider
implements
WeatherForecastProvider
{
private
final
static
String
YR_API_URL
=
"http://api.yr.no/weatherapi/locationforecastlts/1.
2
/?lat={0};lon={1};msl={2}"
;
private
final
static
String
YR_API_URL
=
"http://api.yr.no/weatherapi/locationforecastlts/1.
3
/?lat={0};lon={1};msl={2}"
;
@Override
@Override
public
List
<
WeatherObservation
>
getWeatherForecasts
(
PointOfInterest
location
)
throws
ParseWeatherDataException
public
List
<
WeatherObservation
>
getWeatherForecasts
(
PointOfInterest
location
)
throws
ParseWeatherDataException
{
{
return
this
.
getWeatherForecasts
(
location
.
getGisGeom
().
getCoordinate
().
x
,
location
.
getGisGeom
().
getCoordinate
().
y
,
location
.
getGisGeom
().
getCoordinate
().
z
);
if
(
location
.
getGisGeom
()
!=
null
)
{
return
this
.
getWeatherForecasts
(
location
.
getGisGeom
().
getCoordinate
().
x
,
location
.
getGisGeom
().
getCoordinate
().
y
,
location
.
getGisGeom
().
getCoordinate
().
z
);
}
else
{
return
this
.
getWeatherForecasts
(
location
.
getLongitude
(),
location
.
getLatitude
(),
location
.
getAltitude
());
}
}
}
...
@@ -69,6 +76,8 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
...
@@ -69,6 +76,8 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
altitude
)
altitude
)
);
);
//System.out.println("yrURL=" + yrURL.toString());
// TODO: Parse with DOM parser
// TODO: Parse with DOM parser
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilderFactory
dbf
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
db
=
dbf
.
newDocumentBuilder
();
DocumentBuilder
db
=
dbf
.
newDocumentBuilder
();
...
@@ -113,9 +122,16 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
...
@@ -113,9 +122,16 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
RR
.
setTimeMeasured
(
fromTime
);
RR
.
setTimeMeasured
(
fromTime
);
RR
.
setElementMeasurementTypeId
(
WeatherElements
.
PRECIPITATION
);
RR
.
setElementMeasurementTypeId
(
WeatherElements
.
PRECIPITATION
);
RR
.
setValue
(
Double
.
parseDouble
(
DOMUtils
.
getNodeAttr
(
"precipitation"
,
"value"
,
node2
.
getChildNodes
())));
RR
.
setValue
(
Double
.
parseDouble
(
DOMUtils
.
getNodeAttr
(
"precipitation"
,
"value"
,
node2
.
getChildNodes
())));
//System.out.println("Timediff=" + (toTime.getTime() - fromTime.getTime()));
Date
earliestHourlyObservation
=
null
;
if
(
toTime
.
getTime
()
-
fromTime
.
getTime
()
==
hourDelta
)
if
(
toTime
.
getTime
()
-
fromTime
.
getTime
()
==
hourDelta
)
{
{
//System.out.println("Found 1 hour record at " + fromTime);
RR
.
setLogIntervalId
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
);
RR
.
setLogIntervalId
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
);
if
(
earliestHourlyObservation
==
null
)
{
earliestHourlyObservation
=
RR
.
getTimeMeasured
();
}
}
}
else
if
(
toTime
.
getTime
()
-
fromTime
.
getTime
()
==
threeHoursDelta
)
else
if
(
toTime
.
getTime
()
-
fromTime
.
getTime
()
==
threeHoursDelta
)
{
{
...
@@ -129,13 +145,25 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
...
@@ -129,13 +145,25 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
{
{
continue
;
continue
;
}
}
// The earliest observations may be with 6 or 3 hour resolution
// In order to avoid overestimation of rain in the beginning,
// We skip ahead until we find observations with 1 hour resolution
if
(!
RR
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
)
&&
(
earliestHourlyObservation
==
null
||
earliestHourlyObservation
.
after
(
RR
.
getTimeMeasured
()))
)
{
continue
;
}
// We keep the rain observation with the highest resolution
// We keep the rain observation with the highest resolution
WeatherObservation
obsWithSameTimeStamp
=
RRMap
.
get
(
RR
.
getTimeMeasured
());
WeatherObservation
obsWithSameTimeStamp
=
RRMap
.
get
(
RR
.
getTimeMeasured
());
/
*
System.out.println("Timediff=" + (toTime.getTime() - fromTime.getTime()));
/
/
System.out.println("Timediff=" + (toTime.getTime() - fromTime.getTime()));
System.out.println(RR.getTimeMeasured() + ": " + RR.getValue());
//
System.out.println(RR.getTimeMeasured() + ": " + RR.getValue());
System.out.println(RR.getLogIntervalId());
*/
//
System.out.println(RR.getLogIntervalId());
if
(
obsWithSameTimeStamp
!=
null
)
if
(
obsWithSameTimeStamp
!=
null
)
{
{
// Replace if better resolution
if
(
if
(
(
RR
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_3H
)
&&
obsWithSameTimeStamp
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_6H
))
(
RR
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_3H
)
&&
obsWithSameTimeStamp
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_6H
))
||
(
RR
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
)
&&
obsWithSameTimeStamp
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_3H
))
||
(
RR
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
)
&&
obsWithSameTimeStamp
.
getLogIntervalId
().
equals
(
WeatherObservation
.
LOG_INTERVAL_ID_3H
))
...
@@ -143,9 +171,14 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
...
@@ -143,9 +171,14 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
)
)
{
{
RRMap
.
remove
(
RR
.
getTimeMeasured
());
RRMap
.
remove
(
RR
.
getTimeMeasured
());
RRMap
.
put
(
RR
.
getTimeMeasured
(),
RR
);
}
}
}
}
RRMap
.
put
(
RR
.
getTimeMeasured
(),
RR
);
else
{
// No duplicate, so safely store
RRMap
.
put
(
RR
.
getTimeMeasured
(),
RR
);
}
}
}
}
}
yrValues
.
addAll
(
RRMap
.
values
());
yrValues
.
addAll
(
RRMap
.
values
());
...
@@ -169,6 +202,8 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
...
@@ -169,6 +202,8 @@ public class YrWeatherForecastProvider implements WeatherForecastProvider{
Calendar
cal
=
Calendar
.
getInstance
();
Calendar
cal
=
Calendar
.
getInstance
();
for
(
WeatherObservation
yrValue
:
yrValues
)
for
(
WeatherObservation
yrValue
:
yrValues
)
{
{
// Need to do this in order to make it work properly!
yrValue
.
setLogIntervalId
(
WeatherObservation
.
LOG_INTERVAL_ID_1H
);
switch
(
yrValue
.
getElementMeasurementTypeId
())
switch
(
yrValue
.
getElementMeasurementTypeId
())
{
{
case
WeatherElements
.
TEMPERATURE_INSTANTANEOUS
:
case
WeatherElements
.
TEMPERATURE_INSTANTANEOUS
:
...
...
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