Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OpenWeather REST and file connector
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
zalexander2
OpenWeather REST and file connector
Commits
77a56416
Commit
77a56416
authored
3 years ago
by
Christopher Bohn
Browse files
Options
Downloads
Patches
Plain Diff
Added option for custom queries to Demonstration.java
parent
dad36e4a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/unl/cse/soft160/json_connections/Demonstration.java
+120
-89
120 additions, 89 deletions
...a/edu/unl/cse/soft160/json_connections/Demonstration.java
with
120 additions
and
89 deletions
src/main/java/edu/unl/cse/soft160/json_connections/Demonstration.java
+
120
−
89
View file @
77a56416
...
...
@@ -28,7 +28,7 @@ public class Demonstration {
return
dataSets
.
get
(
choice
-
1
);
}
private
static
String
getData
(
OpenWeatherConnector
weather
,
String
dataSet
,
Instant
now
)
{
private
static
String
getData
(
OpenWeatherConnector
weather
,
String
dataSet
,
Instant
now
,
Scanner
scanner
)
{
String
query
;
switch
(
dataSet
)
{
case
"weather"
:
...
...
@@ -51,8 +51,22 @@ public class Demonstration {
query
=
""
;
}
System
.
out
.
println
(
"Requesting data at "
+
now
);
if
(!
query
.
equals
(
""
))
{
System
.
out
.
print
(
"Enter query, or press the ENTER key to accept the example query ("
+
query
+
"): "
);
String
userQuery
=
scanner
.
nextLine
();
if
(!
userQuery
.
equals
(
""
))
{
System
.
out
.
println
(
" "
+
"*"
.
repeat
(
76
));
System
.
out
.
println
(
" *** The following example output strings assume default units. ***"
);
System
.
out
.
println
(
" *** If you specified other units, the values will be correct, but ***"
);
System
.
out
.
println
(
" *** the stated units will be the defaults, not your specified units. ***"
);
System
.
out
.
println
(
" "
+
"*"
.
repeat
(
76
));
query
=
userQuery
;
}
}
String
data
=
null
;
if
(!
query
.
equals
(
""
))
{
System
.
out
.
println
(
"Requesting data at "
+
now
);
try
{
data
=
weather
.
retrieveData
(
query
);
}
catch
(
IOException
ioException
)
{
...
...
@@ -63,6 +77,9 @@ public class Demonstration {
System
.
err
.
println
(
"\t"
+
ioException
.
getCause
().
getMessage
());
}
}
}
else
{
System
.
err
.
println
(
"Not requesting data at "
+
now
+
" due to empty query."
);
}
return
data
;
}
...
...
@@ -133,11 +150,16 @@ public class Demonstration {
System
.
out
.
println
(
"The UV Index is "
+
weather
.
getUltravioletIndex
());
System
.
out
.
println
(
"Precipitation in the last hour has been "
+
weather
.
getOneHourRainfall
()
+
"mm of"
+
" rain and "
+
weather
.
getOneHourSnowfall
()
+
"mm of snow."
);
if
(
weather
.
getTimestamps
(
"minutely"
).
size
()
>
0
)
{
System
.
out
.
println
(
"There is minutely data from "
+
weather
.
getTimestamps
(
"minutely"
).
get
(
0
)
+
" to "
+
weather
.
getTimestamps
(
"minutely"
).
get
(
weather
.
getTimestamps
(
"minutely"
).
size
()
-
1
));
timestamp
=
weather
.
getTimestamps
(
"minutely"
).
get
(
weather
.
getTimestamps
(
"minutely"
).
size
()
/
2
);
System
.
out
.
println
(
"\tAt "
+
timestamp
+
" the 1-hour (?) precipitation total will be "
+
weather
.
getMinutelyPrecipitation
(
timestamp
));
}
else
{
System
.
out
.
println
(
"There is no minutely data."
);
}
if
(
weather
.
getTimestamps
(
"hourly"
).
size
()
>
0
)
{
System
.
out
.
println
(
"There is hourly data from "
+
weather
.
getTimestamps
(
"hourly"
).
get
(
0
)
+
" to "
+
weather
.
getTimestamps
(
"hourly"
).
get
(
weather
.
getTimestamps
(
"hourly"
).
size
()
-
1
));
timestamp
=
weather
.
getTimestamps
(
"hourly"
).
get
(
weather
.
getTimestamps
(
"hourly"
).
size
()
/
2
);
...
...
@@ -158,6 +180,10 @@ public class Demonstration {
"chance of precipitation, resulting in "
+
weather
.
getOneHourRainfall
(
timestamp
)
+
"mm of "
+
"rain and "
+
weather
.
getOneHourSnowfall
(
timestamp
)
+
"mm of snow in the hour before "
+
timestamp
);
}
else
{
System
.
out
.
println
(
"There is no hourly data."
);
}
if
(
weather
.
getTimestamps
(
"daily"
).
size
()
>
0
)
{
System
.
out
.
println
(
"There is daily data from "
+
weather
.
getTimestamps
(
"daily"
).
get
(
0
)
+
" to "
+
weather
.
getTimestamps
(
"daily"
).
get
(
weather
.
getTimestamps
(
"daily"
).
size
()
-
1
));
timestamp
=
weather
.
getTimestamps
(
"daily"
).
get
(
weather
.
getTimestamps
(
"daily"
).
size
()
/
2
);
...
...
@@ -184,6 +210,9 @@ public class Demonstration {
System
.
out
.
println
(
"\tThere will be a "
+
weather
.
getProbabilityOfPrecipitation
(
timestamp
)
*
100
+
"% "
+
"chance of precipitation, resulting in "
+
weather
.
getDailyRainfall
(
timestamp
)
+
"mm of "
+
"rain and "
+
weather
.
getDailySnowfall
(
timestamp
)
+
"mm of snow"
);
}
else
{
System
.
out
.
println
(
"There is no daily data."
);
}
}
private
static
void
reportForecastData
(
OpenWeatherConnector
weather
)
{
...
...
@@ -238,9 +267,10 @@ public class Demonstration {
String
dataSet
=
getDataSet
(
scanner
);
OpenWeatherConnector
weather
=
new
OpenWeatherConnector
(
dataSet
,
apiKey
);
String
data
=
getData
(
weather
,
dataSet
,
now
);
String
data
=
getData
(
weather
,
dataSet
,
now
,
scanner
);
System
.
out
.
println
(
"Raw JSON: "
+
data
);
if
(
data
!=
null
)
{
System
.
out
.
println
(
"Location: "
+
weather
.
getLatitude
()
+
" latitude, "
+
weather
.
getLongitude
()
+
" "
+
"longitude"
);
Date
currentTimeStamp
=
weather
.
getTimestamp
();
...
...
@@ -270,6 +300,7 @@ public class Demonstration {
}
optionallySaveDataToFile
(
data
,
dataSet
,
scanner
);
}
scanner
.
close
();
}
}
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