📄 webcatlist.java
字号:
package org.trinet.web;
import java.text.*;
import java.util.*;
import java.net.URL;
import java.sql.*;
import java.io.*;
import org.trinet.jdbc.*;
import org.trinet.jdbc.datatypes.*;
import org.trinet.util.*;
import org.trinet.jasi.*;
import org.trinet.jiggle.*;
import org.trinet.util.Format; // CoreJava printf-like Format class
/**
* Make the files necessary to support the TriNet event and waveform review web pages.
*/
public class WebCatList
{
// should be generallized and read from a property file of arg...
static double hoursback = 24.0;
static String htmlOut = "stdout";
static String host;
static String defaulthost = "makalu";
static String defaultdbase = defaulthost+"db";
static double highlightMag = 2.95;
static String highlightColor = "red";
static String thisAppName = "WebCatList";
/** Make an empty WebCat */
public WebCatList ()
{
}
/** Show usage summary */
public static void showUsage () {
System.out.println ("Usage: java "+thisAppName+" [hours-back] [html-output-file] [dbase-host] [dbase-name]");
System.out.println ("Defaults: ["+hoursback +"] ["+ htmlOut+ "] ["+defaulthost+"] [<host>db]");
}
/**
* Main for testing: % WebCat [hours-back] (default = 1)
*/
public static void main (String args[]) {
final int secondsPerHour = 60*60;
// ?
/* Java WIERDNESS note:
<boron>% java WebCat ?
args[0] = /j/
:. must use equalsIgnoreCase("?") else it looks like "j"!!!
*/
if (args.length == 0 || args[0].equalsIgnoreCase("?")) { // no args on command-line value
showUsage();
System.exit (0);
}
// days back
if (args.length > 0) { // translate epoch second on command-line value
try {
Double val = Double.valueOf(args[0]); // convert arg String to 'double'
hoursback = (double) val.doubleValue();
} catch (NumberFormatException ex) {
showUsage();
System.exit (0);
}
}
// check path
if (args.length > 1) {
htmlOut = args[1];
}
host = defaulthost; // default
if (args.length > 2) {
host = args[2];
}
String dbasename = host+"db"; // default
if (args.length > 3) {
dbasename = args[3];
}
System.out.println ("Making connection...");
DataSource init = new TestDataSource(host, dbasename); // make connection
Calendar cal = Calendar.getInstance();
// must distinguish between 'java.util.Date' and 'java.sql.Date'
java.util.Date date = cal.getTime(); // current epoch millisec
long now = date.getTime()/1000; // current epoch sec (millisecs -> seconds)
long then = now - (long) (secondsPerHour * hoursback); // convert to seconds
// add 1000 to now just to be sure we get everything
// System.out.println ("Fetching last "+hoursback+" hours...");
// Solution sol[] = Solution.create().getValidByTime(then, now);
SolutionList sl = new SolutionList();
sl.fetchValidByTime(then, now);
// reverse chronological order
sl = sl.getTimeSortedList(SolutionList.DESCENDING);
Solution sol[] = sl.getArray();
// System.out.println ("Events found: "+sol.length);
// dump the index html file
try {
if (htmlOut.equals("stdout")) {
System.out.println (writeCatBody(sol));
} else {
// FileOutputStream out = new FileOutputStream("catBody.html");
FileOutputStream out = new FileOutputStream(htmlOut);
PrintStream prt = new PrintStream(out);
prt.println (writeCatBody(sol));
// System.out.println (writeCatBody(sol));
prt.close();
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
System.exit(0);
}
public static String writeCatBody(Solution[] sol) {
String str = ("<PRE><FONT SIZE=+1>");
str += catHeader()+"\n";
String clr0, clr1;
for (int i = 0; i < sol.length; i++)
{
if (sol[i].magnitude.value.doubleValue() > highlightMag) {
clr0 = "<FONT COLOR="+highlightColor+">";
clr1 = "</FONT>";
} else {
clr0 = "";
clr1 = "";
}
// str += clr0+htmlString(sol[i])+clr1+"\n";
str += clr0+ SeisFormat.htmlString(sol[i], host, true)+clr1+"\n";
}
str += ("</FONT></PRE>");
return str;
}
public static String catHeader () {
return " ID# MAG DATE TIME(UTC) LAT LON Z # RMS GAP TP C SRC\n"+
" year/mo/dy hr:mn:sc deg deg km PHS";
}
/*
public static String htmlString(Solution sol) {
// ID# mag year/mo/dy hr:mn:sc latitude longitude dep
// 9514285 2.2 Ml 1999/11/22 01:11:22 36.0736 -117.8523 1.8
// 9520825 0.8 Ml 1999/12/01 21:12:12 33.9418 -116.4998 7.0 6 5.81
// ID# MAG DATE TIME(UTC) LAT LON Z # RMS
// year/mo/dy hr:mn:sc deg deg km PHS
// 9520825 0.8 Ml 1999/12/01 21:12:12 33.9418 -116.4998 7.0 6 5.81 360 le H SRC
// ID# MAG DATE TIME(UTC) LAT LON Z # RMS GAP TP C
// year/mo/dy hr:mn:sc deg deg km PHS
String cgi = "cgi-bin/makeView.cgi?EVID="; // the cgi script name
long evid = sol.id.longValue(); // the event #
String target = "zoom"; // target frame
String tag0 = "<a href=\""+cgi+evid+"&HOST="+host+"\" target=\""+target+"\">";
String tag1 = "</a>";
Format df0 = new Format("%8d"); // CORE Java Format class
// Format df1 = new Format("%5.4f");
// Format df2 = new Format("%7.4f");
Format df1 = new Format("%7.4f");
Format df2 = new Format("%9.4f");
Format df3 = new Format("%4.1f");
Format df4 = new Format("%5.2f");
Format df5 = new Format("%3d");
String timeFmt = "yyyy/MM/dd HH:mm:ss";
DateTime dt = new DateTime();
String dtStr = dt.toString(sol.datetime.doubleValue(), timeFmt);
String str = tag0 + df0.form(evid) + tag1+ " " +
df3.form(safeValue(sol.magnitude.value)) + " " +
sol.magnitude.getTypeString() +" "+
dtStr + " " +
df1.form(safeValue(sol.lat)) + " " +
df2.form(safeValue(sol.lon)) + " " +
df3.form(safeValue(sol.depth)) + " "+
df5.form((int)safeValue(sol.usedReadings)) +" "+
df4.form(safeValue(sol.rms))+" "+
df5.form((int)safeValue(sol.gap))+" "+
sol.eventType.toString().concat(" ").substring(0, 3) +" "+
// sol.eventType.toString() +" "+
sol.processingState.toString()+ " "+
sol.source.toString().concat(" ").substring(0, 4); // truncate to 3 chars
return str;
}
static double safeValue(DataObject val) {
if (val.isNull()) return 0.0;
return val.doubleValue();
}
*/
} // end of class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -