mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
742714fbac | ||
|
|
a29f4d0829 | ||
|
|
02e0a7cf1f | ||
|
|
5177d0fead | ||
|
|
1cc60fe38c |
No files matched your search
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>WS3000</groupId>
|
||||
<artifactId>weatherstar3000</artifactId>
|
||||
<version>1.5.3</version>
|
||||
<version>1.6.0</version>
|
||||
|
||||
<name>weatherstar3000</name>
|
||||
<url>https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java</url>
|
||||
|
||||
@@ -248,7 +248,7 @@ public class Almanac extends Thread {
|
||||
String getPrecip(String icaoCode, String key, String month, String day) {
|
||||
try {
|
||||
if (Objects.equals(month, "error") || Objects.equals(day, "error")) {
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
@@ -260,24 +260,25 @@ public class Almanac extends Thread {
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
String[] monthNames = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
float precip = JSONResponse.getJSONArray("precipitationAverage").getFloat(0);
|
||||
|
||||
String precip = JSONResponse.getJSONArray("precipitationAverage").isNull(0) ? "NO REPORT" : String.valueOf(JSONResponse.getJSONArray("precipitationAverage").getFloat(0));
|
||||
|
||||
String precipString = utl.rjust(precip + " IN", 8, " ");
|
||||
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 23, " ");
|
||||
String precipString = precip.equals("NO REPORT") ? "NO REPORT" : utl.rjust(precip + " IN", 9, " ");
|
||||
String cmonth = utl.ljust("NORMAL " + monthNames[Integer.parseInt(month)] + " PRECIP", 22, " ");
|
||||
|
||||
return utl.ljust(cmonth + precipString, 31, " ") + " ";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return " ";
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
//import java.text.DecimalFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Month;
|
||||
|
||||
public class CurrentConditions extends Thread {
|
||||
@@ -349,7 +349,7 @@ public class CurrentConditions extends Thread {
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
|
||||
LocalDate cdate = LocalDate.now();
|
||||
ZonedDateTime cdate = ZonedDateTime.now(Main.timeZone);
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,9 @@ package WS3000.weatherstar3000;
|
||||
|
||||
public class DataRunner extends Thread {
|
||||
public void run() {
|
||||
if (Main.ztOption.equals("Location Time")) {
|
||||
Main.timeZone = Main.getTimeZone(Main.mainIcao);
|
||||
}
|
||||
//System.out.println("Data collection");
|
||||
Main.currentConditions = new CurrentConditions();
|
||||
Main.hourlyObservations = new HourlyObservations();
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ExtendedForecast extends Thread {
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
JSONObject dpData = JSONResponse.getJSONArray("daypart").getJSONObject(0);
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 5 : 4;
|
||||
int bump = dpData.getJSONArray("dayOrNight").isNull(0) ? 6 : dpData.getJSONArray("dayOrNight").getString(0).equals("N") ? 6 : 4;
|
||||
int ex = day*2;
|
||||
|
||||
values.add(utl.getForecastEx(dpData.getJSONArray("iconCodeExtend").getInt(ex + bump), 0));
|
||||
|
||||
@@ -28,6 +28,10 @@ import java.awt.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URISyntaxException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Main {
|
||||
static String selectedFlavor;
|
||||
@@ -58,6 +62,9 @@ public class Main {
|
||||
static Bulletin bulletin;
|
||||
static Tides tides;
|
||||
|
||||
static String ztOption;
|
||||
static ZoneId timeZone;
|
||||
|
||||
static JFrame settingsWindow;
|
||||
|
||||
static ArrayList<String> nearNames = new ArrayList<>();
|
||||
@@ -94,8 +101,8 @@ public class Main {
|
||||
//things to add:
|
||||
//airport conditions
|
||||
//air quality
|
||||
//timezone switch?
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.5.2");
|
||||
//optimized LookAndFeels?
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.6.0");
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
if (userDir != null && !userDir.isEmpty()) {
|
||||
@@ -445,6 +452,12 @@ public class Main {
|
||||
ldlDropdown.setSelectedIndex(0);
|
||||
r2Panel.add(ldlDropdown);
|
||||
|
||||
r2Panel.add(new JLabel("Time Zone"));
|
||||
String[] timeZoneOptions = {"Location Time", "System Time", "US/Eastern", "US/Central", "US/Mountain", "US/Arizona", "US/Pacific", "US/Alaska", "US/Aleutian", "US/Hawaii", "US/Samoa"};
|
||||
JComboBox timeZoneDropdown = new JComboBox(timeZoneOptions);
|
||||
timeZoneDropdown.setSelectedIndex(0);
|
||||
r2Panel.add(timeZoneDropdown);
|
||||
|
||||
rPanel.add(r2Panel);
|
||||
|
||||
JPanel r3Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
@@ -869,6 +882,16 @@ public class Main {
|
||||
break;
|
||||
}
|
||||
|
||||
ztOption = timeZoneDropdown.getSelectedItem().toString();
|
||||
|
||||
if (ztOption.equals("Location Time")) {
|
||||
timeZone = getTimeZone(mainIcao);
|
||||
} else if (ztOption.equals("System Time")) {
|
||||
timeZone = ZoneId.systemDefault();
|
||||
} else {
|
||||
timeZone = ZoneId.of(timeZoneDropdown.getSelectedItem().toString());
|
||||
}
|
||||
|
||||
selectedFlavor = (String) flavorDropdown.getSelectedItem();
|
||||
|
||||
simWidth = Integer.parseInt(widthField.getText());
|
||||
@@ -887,28 +910,31 @@ public class Main {
|
||||
|
||||
settingsWindow.setVisible(true);
|
||||
}
|
||||
|
||||
static String checkIcaoCode(String code, String key) {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/location/point?icaoCode=" + code
|
||||
+ "&language=en-US&format=json&apiKey=" + key))
|
||||
.GET() // Or .POST(HttpRequest.BodyPublishers.ofString("your_json_body"))
|
||||
.header("Accept", "application/json").build();
|
||||
|
||||
static ZoneId getTimeZone(String icaoCode) {
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
if (Response.statusCode() == 401) {
|
||||
return "API Key error";
|
||||
} else {
|
||||
return "Invalid ICAO Code";
|
||||
}
|
||||
}
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.weather.com/v3/wx/forecast/daily/7day?icaoCode=" + icaoCode + "&units=e&language=en-US&format=json&apiKey=" + key))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
try {
|
||||
HttpResponse<String> Response = Client.send(Request, HttpResponse.BodyHandlers.ofString());
|
||||
if (Response.statusCode() != 200) {
|
||||
return ZoneId.systemDefault();
|
||||
}
|
||||
String ResponseBody = Response.body();
|
||||
JSONObject JSONResponse = new JSONObject(ResponseBody);
|
||||
String time = JSONResponse.getJSONArray("validTimeLocal").getString(0);
|
||||
|
||||
return "noerror";
|
||||
return ZonedDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")).getZone();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return ZoneId.systemDefault();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "Server Error";
|
||||
return ZoneId.systemDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package WS3000.weatherstar3000;
|
||||
//import java.net.http.HttpClient;
|
||||
//import java.net.http.HttpRequest;
|
||||
//import java.net.http.HttpResponse;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Outlook extends Thread {
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
String getMonth() {
|
||||
try {
|
||||
LocalDate cdate = LocalDate.now();
|
||||
ZonedDateTime cdate = ZonedDateTime.now(Main.timeZone);
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
return cmonth.name().toUpperCase();
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegionalForecast extends Thread {
|
||||
@@ -121,7 +121,7 @@ public class RegionalForecast extends Thread {
|
||||
Main.regionalForecast.low.add(getLow(regForIcaos.get(i), key));
|
||||
Main.regionalForecast.high.add(getHigh(regForIcaos.get(i), key));
|
||||
}
|
||||
int hr = LocalTime.now().getHour();
|
||||
int hr = ZonedDateTime.now(Main.timeZone).getHour();
|
||||
Main.regionalForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,8 @@ public class SlidesRunner extends Scene {
|
||||
GameObject cBumperTwo;
|
||||
Utilities utl = new Utilities();
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
ZonedDateTime today = ZonedDateTime.now();
|
||||
final String prefix = today.format(DateTimeFormatter.ofPattern("E MMM"));
|
||||
ZonedDateTime now = ZonedDateTime.now(Main.timeZone);
|
||||
final String prefix = now.format(DateTimeFormatter.ofPattern("E MMM"));
|
||||
|
||||
//slide line variables
|
||||
ArrayList<String> ccMainLines = new ArrayList<>();
|
||||
@@ -547,8 +546,7 @@ public class SlidesRunner extends Scene {
|
||||
}
|
||||
|
||||
public void dateTime() {
|
||||
now = LocalDateTime.now();
|
||||
today = ZonedDateTime.now();
|
||||
now = ZonedDateTime.now(Main.timeZone);
|
||||
|
||||
dateLine = utl.ljust(String.format("%s %2d", prefix, now.getDayOfMonth()).toUpperCase(), 10, " ") + utl.ljust(" ", 11, " ") + utl.rjust(now.format(formatter), 11, " ");
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
@@ -35,7 +35,7 @@ public class Tides extends Thread {
|
||||
try {
|
||||
HttpClient Client = HttpClient.newBuilder().build();
|
||||
HttpRequest Request = HttpRequest.newBuilder()
|
||||
.uri(URI.create("https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date=" + LocalDate.now().format(tideDateFormatter) + "&end_date=" + LocalDate.now().plusDays(1).format(tideDateFormatter) + "&station=" + station + "&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=json"))
|
||||
.uri(URI.create("https://api.tidesandcurrents.noaa.gov/api/prod/datagetter?begin_date=" + ZonedDateTime.now(Main.timeZone).format(tideDateFormatter) + "&end_date=" + ZonedDateTime.now(Main.timeZone).plusDays(1).format(tideDateFormatter) + "&station=" + station + "&product=predictions&datum=MLLW&time_zone=lst_ldt&interval=hilo&units=english&application=DataAPI_Sample&format=json"))
|
||||
.GET()
|
||||
.header("Accept", "application/json")
|
||||
.build();
|
||||
|
||||
@@ -4,7 +4,7 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -121,7 +121,7 @@ public class TravelForecast extends Thread {
|
||||
Main.travelForecast.low.add(getLow(tForIcaos.get(i), key));
|
||||
Main.travelForecast.high.add(getHigh(tForIcaos.get(i), key));
|
||||
}
|
||||
int hr = LocalTime.now().getHour();
|
||||
int hr = ZonedDateTime.now(Main.timeZone).getHour();
|
||||
Main.travelForecast.first = hr >= 4 && hr < 16 ? "H" : "L";
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
{"segment":"localForecast", "duration": 600.0},
|
||||
{"segment":"regionalForecast", "duration": 600.0},
|
||||
{"segment":"almanac", "duration": 600.0},
|
||||
{"segment":"regionalConditions", "duration": 600.0}
|
||||
{"segment":"hourlyObservations", "duration": 600.0}
|
||||
],
|
||||
"I": [
|
||||
{"segment":"currentConditions", "duration": 600.0},
|
||||
|
||||
Reference in new issue
Block a user