mirror of
https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java.git
synced 2026-11-28 14:38:08 -08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3e5e81500 | ||
|
|
a2791ddd91 | ||
|
|
dbe9b0964d |
No files matched your search
@@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>WS3000</groupId>
|
||||
<artifactId>weatherstar3000</artifactId>
|
||||
<version>1.6.0</version>
|
||||
<version>1.7.0</version>
|
||||
|
||||
<name>weatherstar3000</name>
|
||||
<url>https://github.com/MistWeatherMedia/WeatherSTAR-3000-Java</url>
|
||||
@@ -586,6 +586,12 @@
|
||||
<artifactId>joml</artifactId>
|
||||
<version>${joml.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.locationtech.jts</groupId>
|
||||
<artifactId>jts-core</artifactId>
|
||||
<version>1.19.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -99,10 +99,9 @@ public class Main {
|
||||
}
|
||||
*/
|
||||
//things to add:
|
||||
//airport conditions
|
||||
//air quality
|
||||
//optimized LookAndFeels?
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.6.0");
|
||||
//multiple ad crawls (up to 7)
|
||||
System.out.println("WeatherSTAR 3000 Simulator Version 1.7.0");
|
||||
|
||||
String userDir = System.getProperty("user.dir");
|
||||
if (userDir != null && !userDir.isEmpty()) {
|
||||
@@ -387,7 +386,7 @@ public class Main {
|
||||
|
||||
//tides
|
||||
JPanel tPanel = new JPanel(new GridLayout(0, 1, 0, 0));
|
||||
tPanel.setBorder(BorderFactory.createTitledBorder("Tides Locations"));
|
||||
tPanel.setBorder(BorderFactory.createTitledBorder("Tides Locations (OPTIONAL)"));
|
||||
|
||||
JPanel t1Panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
t1Panel.add(new JLabel("Station ID"));
|
||||
|
||||
@@ -1,47 +1,239 @@
|
||||
package WS3000.weatherstar3000;
|
||||
|
||||
//import java.net.URI;
|
||||
//import java.net.http.HttpClient;
|
||||
//import java.net.http.HttpRequest;
|
||||
//import java.net.http.HttpResponse;
|
||||
import org.locationtech.jts.geom.Coordinate;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.Point;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.Month;
|
||||
import java.util.ArrayList;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import util.Utilities;
|
||||
|
||||
//import org.json.JSONObject;
|
||||
|
||||
public class Outlook extends Thread {
|
||||
static Utilities utl = new Utilities();
|
||||
String month;
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
String getMonth() {
|
||||
String precipitation;
|
||||
String temperature;
|
||||
|
||||
private static final GeometryFactory geometryFactory = new GeometryFactory();
|
||||
|
||||
String getOutlook(String type, String lat, String lon) {//type prcp or temp
|
||||
try {
|
||||
ZonedDateTime cdate = ZonedDateTime.now(Main.timeZone);
|
||||
Month cmonth = cdate.getMonth();
|
||||
|
||||
return cmonth.name().toUpperCase();
|
||||
String zipFile = "https://ftp.cpc.ncep.noaa.gov/GIS/us_tempprcpfcst/monthlyupdate/monthupd_" + type + "_latest.zip";
|
||||
|
||||
try {
|
||||
InputStream kmlStream = getKmlStreamFromUrl(zipFile);
|
||||
if (kmlStream == null) {
|
||||
System.err.println("No .kml file found inside the ZIP archive.");
|
||||
return utl.ljust("NO REPORT", 17, " ");
|
||||
}
|
||||
|
||||
List<NamedPolygon> polygons = parseKmlPolygons(kmlStream);
|
||||
|
||||
Point userPoint = geometryFactory.createPoint(new Coordinate(Double.parseDouble(lon), Double.parseDouble(lat)));
|
||||
|
||||
String matchedPolygonName = findContainingPolygon(polygons, userPoint);
|
||||
|
||||
if (matchedPolygonName != null) {
|
||||
if (matchedPolygonName.contains("Above")) {
|
||||
return utl.ljust("ABOVE NORMAL", 17, " ");
|
||||
} else if (matchedPolygonName.contains("Below")) {
|
||||
return utl.ljust("BELOW NORMAL", 17, " ");
|
||||
} else {
|
||||
return utl.ljust("NORMAL", 17, " ");
|
||||
}
|
||||
} else {
|
||||
return utl.ljust("NO REPORT", 17, " ");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return utl.ljust("NO REPORT", 17, " ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
return utl.ljust("NO REPORT", 17, " ");
|
||||
}
|
||||
}
|
||||
|
||||
private InputStream getKmlStreamFromUrl(String zipUrl) {
|
||||
try {
|
||||
URL url = URI.create(zipUrl).toURL();
|
||||
|
||||
ZipInputStream zis = new ZipInputStream(url.openStream());
|
||||
ZipEntry entry;
|
||||
|
||||
while ((entry = zis.getNextEntry()) != null) {
|
||||
if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".kml")) {
|
||||
return zis;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
ArrayList<String> getOutlook() {
|
||||
ArrayList<String> outlook = new ArrayList<>();
|
||||
|
||||
private List<NamedPolygon> parseKmlPolygons(InputStream kmlStream) throws Exception {
|
||||
List<NamedPolygon> result = new ArrayList<>();
|
||||
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document doc = builder.parse(kmlStream);
|
||||
|
||||
NodeList placemarks = doc.getElementsByTagName("Placemark");
|
||||
|
||||
for (int i = 0; i < placemarks.getLength(); i++) {
|
||||
Element placemark = (Element) placemarks.item(i);
|
||||
|
||||
NodeList nameNodes = placemark.getElementsByTagName("name");
|
||||
String name = nameNodes.getLength() > 0 ? nameNodes.item(0).getTextContent().trim() : "Unnamed";
|
||||
|
||||
NodeList polygonNodes = placemark.getElementsByTagName("Polygon");
|
||||
|
||||
for (int j = 0; j < polygonNodes.getLength(); j++) {
|
||||
Element polygonEl = (Element) polygonNodes.item(j);
|
||||
NodeList coordsNodes = polygonEl.getElementsByTagName("coordinates");
|
||||
|
||||
if (coordsNodes.getLength() > 0) {
|
||||
String rawCoords = coordsNodes.item(0).getTextContent();
|
||||
Polygon polygon = buildJtsPolygon(rawCoords);
|
||||
if (polygon != null) {
|
||||
result.add(new NamedPolygon(name, polygon));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Polygon buildJtsPolygon(String rawCoords) {
|
||||
String[] pointsStr = rawCoords.trim().split("\\s+");
|
||||
List<Coordinate> coordsList = new ArrayList<>();
|
||||
|
||||
for (String p : pointsStr) {
|
||||
p = p.trim();
|
||||
if (p.isEmpty()) continue;
|
||||
|
||||
String[] parts = p.split(",");
|
||||
if (parts.length >= 2) {
|
||||
try {
|
||||
double lon = Double.parseDouble(parts[0]);
|
||||
double lat = Double.parseDouble(parts[1]);
|
||||
coordsList.add(new Coordinate(lon, lat));
|
||||
} catch (NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (coordsList.size() < 3) return null;
|
||||
|
||||
if (!coordsList.get(0).equals2D(coordsList.get(coordsList.size() - 1))) {
|
||||
coordsList.add(coordsList.get(0));
|
||||
}
|
||||
|
||||
Coordinate[] coordsArray = coordsList.toArray(new Coordinate[0]);
|
||||
return geometryFactory.createPolygon(coordsArray);
|
||||
}
|
||||
|
||||
private String findContainingPolygon(List<NamedPolygon> polygons, Point point) {
|
||||
for (NamedPolygon np : polygons) {
|
||||
if (np.polygon.covers(point)) {
|
||||
return np.name;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getOutlookTitle() {
|
||||
try {
|
||||
outlook.add("NO");
|
||||
outlook.add("REPORT");
|
||||
return outlook;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
outlook.add("NO");
|
||||
outlook.add("REPORT");
|
||||
return outlook;
|
||||
ZonedDateTime today = ZonedDateTime.now(Main.timeZone);
|
||||
|
||||
String[] monthsShorter = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC", "JAN"};
|
||||
String[] monthsShort = {"JAN", "FEB", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUG", "SEPT", "OCT", "NOV", "DEC", "JAN"};
|
||||
String[] monthsLong = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER", "JANUARY"};
|
||||
|
||||
String zipFile = "https://ftp.cpc.ncep.noaa.gov/GIS/us_tempprcpfcst/monthlyupdate/monthupd_temp_latest.zip";
|
||||
|
||||
int cMonthVal = ZonedDateTime.now(Main.timeZone).getMonthValue()-1;
|
||||
|
||||
String currentMonth = monthsShorter[cMonthVal];
|
||||
String dataMonth = "";
|
||||
|
||||
InputStream kmlStream = getKmlStreamFromUrl(zipFile);
|
||||
if (kmlStream == null) {
|
||||
System.err.println("No .kml file found inside the ZIP archive.");
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(kmlStream);
|
||||
Element root = doc.getDocumentElement();
|
||||
if (root.hasAttribute("id")) {
|
||||
dataMonth = parseMonth(root.getAttribute("id").toUpperCase());
|
||||
}
|
||||
|
||||
if (today.isAfter(today.withDayOfMonth(1).with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.THURSDAY)))) {
|
||||
if (currentMonth.equals(dataMonth)) {
|
||||
return utl.cjust("MID " + monthsShort[cMonthVal] + " - MID " + monthsShort[cMonthVal+1], 32, " ");
|
||||
} else {
|
||||
return utl.cjust(monthsLong[cMonthVal+1], 32, " ");
|
||||
}
|
||||
} else {
|
||||
return utl.cjust(monthsLong[cMonthVal], 32, " ");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return utl.ljust("", 32, " ");
|
||||
}
|
||||
}
|
||||
|
||||
private String parseMonth(String text) {
|
||||
if (text == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
Pattern pattern = Pattern.compile("Valid\\s+([A-Za-z]{3})", Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
|
||||
if (matcher.find()) {
|
||||
return matcher.group(1).toUpperCase();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Main.outlook.month = getMonth();
|
||||
Main.outlook.outlook = getOutlook();
|
||||
String mainLat = Main.mainLat;
|
||||
String mainLon = Main.mainLon;
|
||||
Main.outlook.month = getOutlookTitle();
|
||||
Main.outlook.temperature = getOutlook("temp", mainLat, mainLon);
|
||||
Main.outlook.precipitation = getOutlook("prcp", mainLat, mainLon);
|
||||
}
|
||||
}
|
||||
|
||||
class NamedPolygon {
|
||||
String name;
|
||||
Polygon polygon;
|
||||
|
||||
NamedPolygon(String name, Polygon polygon) {
|
||||
this.name = name;
|
||||
this.polygon = polygon;
|
||||
}
|
||||
}
|
||||
@@ -1131,24 +1131,14 @@ public class SlidesRunner extends Scene {
|
||||
|
||||
olMainLines.clear();
|
||||
|
||||
olMainLines.add(" NAT'L WEATHER SERVICE OUTLOOK ");
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));//half space
|
||||
olMainLines.add(utl.cjust(oData.month, 32, " "));
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i <= oData.outlook.size()-1; i++) {
|
||||
int cwordlength = oData.outlook.get(i).length();
|
||||
if (cwordlength + sb.length() + 1 <= 32) {
|
||||
if (!sb.isEmpty()) {sb.append(" ");}
|
||||
sb.append(oData.outlook.get(i));
|
||||
} else {
|
||||
i--;
|
||||
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
|
||||
sb.setLength(0);
|
||||
}
|
||||
}
|
||||
olMainLines.add(utl.ljust(sb.toString(), 32, " "));
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add(" 30 DAY OUTLOOK ");
|
||||
olMainLines.add(oData.month);
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add("TEMPERATURES: " + oData.temperature);
|
||||
olMainLines.add(utl.ljust(" ", 32, " "));
|
||||
olMainLines.add("PRECIPITATION: " + oData.precipitation);
|
||||
|
||||
slideInit = true;
|
||||
}
|
||||
@@ -1158,7 +1148,7 @@ public class SlidesRunner extends Scene {
|
||||
int poolIdx = 0;
|
||||
|
||||
for (int row = 0; row < olMainLines.size(); row++) {
|
||||
int lineHeight = row == 1 ? 22 : 40;
|
||||
int lineHeight = 40;
|
||||
String line = olMainLines.get(row);
|
||||
for (int i = 0; i < line.length(); i ++) {
|
||||
if (poolIdx >= olPool.length) break;
|
||||
@@ -1246,15 +1236,6 @@ public class SlidesRunner extends Scene {
|
||||
}
|
||||
}
|
||||
|
||||
public void airportDelays() {
|
||||
slideRounds = 0;
|
||||
this.addGameObjectToScene(bg);
|
||||
|
||||
if (!slideInit) {
|
||||
slideInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void travelForecast() {
|
||||
travelForecastActive = true;
|
||||
this.addGameObjectToScene(travelBg);
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
"Flash Flood Warning": { "headline": false, "scroll": true, "severity": "Warning" },
|
||||
"Excessive Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"Excessive Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" },
|
||||
"Extreme Heat Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"Extreme Heat Warning": { "headline": true, "scroll": true, "severity": "Warning" },
|
||||
"Heat Advisory": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"Tropical Storm Watch": { "headline": true, "scroll": true, "severity": "Advisory" },
|
||||
"Tropical Storm Warning": { "headline": true, "scroll": true, "severity": "Warning" },
|
||||
|
||||
Reference in new issue
Block a user