Skip to content

Commit

Permalink
_Hugs Maths Teacher_
Browse files Browse the repository at this point in the history
  • Loading branch information
eyeballcode committed Sep 30, 2015
1 parent 71f2b6b commit 0bad57d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
58 changes: 58 additions & 0 deletions src/Berserk.java
@@ -0,0 +1,58 @@
import java.util.HashMap;

public class Berserk {

static int tileSize = 256;
static double initialResolution = 2d * Math.PI * 6378137d / (double) tileSize;
// 156543.03392804062 for tileSize 256 PIxels
static double originShift = 2d * Math.PI * 6378137d / 2d;

/**
* Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:900913
*
* @param lat The latitude
* @param lon The longitude
* @return A hashmap containing the x meter and y meter.
*/
public static HashMap<String, Double> latLonToMeters(double lat, double lon) {
HashMap<String, Double> returnVals = new HashMap<String, Double>();

double mx = lon * originShift / 180.0;
double my = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);

my = my * originShift / 180.0;
returnVals.put("mx", mx);
returnVals.put("my", my);
return returnVals;
}

/**
* Converts EPSG:900913 to pyramid pixel coordinates in given zoom level
*
* @param mx The meter x
* @param my The meter y
* @param resolution The resolution
* @return A hashmap containg the x pixel and y pixel.
*/
public static HashMap<String, Double> metersToPixels(double mx, double my, double resolution) {
HashMap<String, Double> returnVals = new HashMap<String, Double>();

double px = (mx + originShift) / resolution;
double py = (my + originShift) / resolution;

returnVals.put("px", px);
returnVals.put("py", py);
return returnVals;
}

public static void main(String[] args) {
double mx = -8237494.4864285; //-73.998672
double my = 4970354.7325767; // 40.714728
double resolution = 12;
HashMap<String, Double> meterValues = metersToPixels(mx, my, resolution);
HashMap<String, Double> pixelValues = latLonToMeters(meterValues.get("px"), meterValues.get("py"));
System.out.println("First val: " + pixelValues.get("my"));
System.out.println("Second val: " + pixelValues.get("mx"));
}

}
11 changes: 7 additions & 4 deletions src/WatcherThread.java
Expand Up @@ -35,6 +35,7 @@ public void run() {
Document document = Jsoup.connect("http://www.haze.gov.sg/haze-updates/psi-readings-over-the-last-24-hours").get();
Element firstHalfOfDay = document.select(".noalter").get(1).children().select("tr").get(1);
Element secondHalfOfDay = document.select(".noalter").get(1).children().select("tr").get(3);
// System.out.println(secondHalfOfDay.html());
firstHalfOfDay.select("*").get(0).remove();
secondHalfOfDay.select("*").get(0).remove();
int hour = GregorianCalendar.getInstance().get(Calendar.HOUR_OF_DAY);
Expand Down Expand Up @@ -84,6 +85,8 @@ public void run() {
14 00 -> 12;
*/

// private static int[] times = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 12, 11, 10, 9, 8, 7, 6};

private static String getPSI(Element firstHalfOfDay, Element secondHalfOfDay, int hour, String currentPSI, int offset) {
if (hour == 12) {
// Noon
Expand All @@ -92,10 +95,10 @@ private static String getPSI(Element firstHalfOfDay, Element secondHalfOfDay, in
// Morning
currentPSI = firstHalfOfDay.select("*").get(hour + offset).text();
} else if (hour >= 13 && hour <= 23) {
// Afternoon - night System.out.println(secondHalfOfDay.select("*").get(hour - (hour - 13) + offset).text());
System.out.println(secondHalfOfDay.select("*").get(hour - Integer.parseInt(String.valueOf(hour).substring(1)) + offset).text());

currentPSI = secondHalfOfDay.select("*").get(hour - (hour - 7) + offset).text();
// Afternoon - night
System.out.println(hour - 12);
currentPSI = secondHalfOfDay.select("*").get(hour - 10).text();
System.out.println(currentPSI);
}
return currentPSI;
}
Expand Down

1 comment on commit 0bad57d

@eyeballcode
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stares at Berserk

Please sign in to comment.