J2EE Based Weather Storage and Presentat-开源

  • n4_569631
    了解作者
  • 101.5KB
    文件大小
  • gz
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-26 21:39
    上传日期
一个全 Java J2EE 家庭气象站和网站项目。 当前基于 Davis Weather Monitor II,但将发展为支持其他设备、服务器和数据库。 该项目已发展为完全开发的 Runy on Rails 解决方案。
j2eeweather-core.1.0.0.stable.tar.gz
内容介绍
package org.tom.weather.graph; import java.awt.*; import MSBChart.*; import java.awt.event.*; import java.util.*; import org.tom.weather.*; import java.io.FileInputStream; public class Graph { static Graph app= new Graph(); String filename = "graph.jpg"; String titleString = ""; String createString = ""; static Properties props = new Properties(); static boolean metric = false; public void Grapher(int graphType, Properties props) { //data GraphDataSource m = new JdbcGraphDataSource(props); String[] plotdata = m.getGraphData(graphType); String[] xdatatemp = new String[plotdata.length]; double[] ydata_outtemp = new double[plotdata.length]; double[] ydata_rain = new double[plotdata.length]; double[] ydata_dewpoint = new double[plotdata.length]; double[] ydata_windchill = new double[plotdata.length]; double[] ydata_windspeed = new double[plotdata.length]; double[] ydata_winddirection = new double[plotdata.length]; double[] ydata_windgust = new double[plotdata.length]; double[] ydata_barometer = new double[plotdata.length]; double[] ydata_outhumidity = new double[plotdata.length]; int datateller = 0; for (datateller=0;datateller<plotdata.length;datateller++) { xdatatemp[datateller] = plotdata[datateller].substring(plotdata[datateller].indexOf('|')+1); if (metric) { ydata_outtemp[datateller] = Converter.toCelsius((float)(Double.valueOf(plotdata[datateller].substring(0, plotdata[datateller].indexOf("[T]"))).doubleValue())); ydata_dewpoint[datateller] = Converter.toCelsius((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[T]")+3, plotdata[datateller].indexOf("[X]"))).doubleValue())); ydata_windchill[datateller] = Converter.toCelsius((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[X]")+3, plotdata[datateller].indexOf("[C]"))).doubleValue())); ydata_rain[datateller] = Converter.toMm((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[C]")+3, plotdata[datateller].indexOf("[R]"))).doubleValue())); ydata_windspeed[datateller] = Converter.toMps((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[R]")+3, plotdata[datateller].indexOf("[W]"))).doubleValue())); ydata_winddirection[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[W]")+3, plotdata[datateller].indexOf("[D]"))).doubleValue(); ydata_windgust[datateller] = Converter.toMps((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[D]")+3, plotdata[datateller].indexOf("[G]"))).doubleValue())); ydata_barometer[datateller] = Converter.toHPa((float)(Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[G]")+3, plotdata[datateller].indexOf("[B]"))).doubleValue())); ydata_outhumidity[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[B]")+3, plotdata[datateller].indexOf("[H]"))).doubleValue(); } else { ydata_outtemp[datateller] = Double.valueOf(plotdata[datateller].substring(0, plotdata[datateller].indexOf("[T]"))).doubleValue(); ydata_dewpoint[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[T]")+3, plotdata[datateller].indexOf("[X]"))).doubleValue(); ydata_windchill[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[X]")+3, plotdata[datateller].indexOf("[C]"))).doubleValue(); ydata_rain[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[C]")+3, plotdata[datateller].indexOf("[R]"))).doubleValue(); ydata_windspeed[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[R]")+3, plotdata[datateller].indexOf("[W]"))).doubleValue(); ydata_winddirection[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[W]")+3, plotdata[datateller].indexOf("[D]"))).doubleValue(); ydata_windgust[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[D]")+3, plotdata[datateller].indexOf("[G]"))).doubleValue(); ydata_barometer[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[G]")+3, plotdata[datateller].indexOf("[B]"))).doubleValue(); ydata_outhumidity[datateller] = Double.valueOf(plotdata[datateller].substring(plotdata[datateller].indexOf("[B]")+3, plotdata[datateller].indexOf("[H]"))).doubleValue(); } } String[] xdata = build_needed_Xaxis(xdatatemp,graphType); Date myDate3 = new Date(System.currentTimeMillis()); System.out.println("Step 3: Building graph at "+myDate3); Calculate_Timestamp(); Temp_Graph(xdata, ydata_outtemp, graphType); Dew_Graph(xdata, ydata_dewpoint, graphType); Chill_Graph(xdata, ydata_windchill, graphType); Rain_Graph(xdata, ydata_rain, graphType); Windspeed_Graph(xdata, ydata_windspeed, graphType); Winddirection_Graph(xdata, ydata_winddirection, graphType); Windgust_Graph(xdata, ydata_windgust, graphType); Barometer_Graph(xdata, ydata_barometer, graphType); Outhumidity_Graph(xdata, ydata_outhumidity, graphType); Date myDate5 = new Date(System.currentTimeMillis()); System.out.println("Step 5: Done at "+myDate5); System.exit(0); } public void Calculate_Timestamp() { Calendar newtime = Calendar.getInstance(); int month = newtime.get(newtime.MONTH) + 1; int day = newtime.get(newtime.DAY_OF_MONTH); int hour = newtime.get(newtime.HOUR_OF_DAY); int minute = newtime.get(newtime.MINUTE); String monthStr = ""; if (month==1) {monthStr = "Jan";} if (month==2) {monthStr = "Feb";} if (month==3) {monthStr = "Mar";} if (month==4) {monthStr = "Apr";} if (month==5) {monthStr = "May";} if (month==6) {monthStr = "Jun";} if (month==7) {monthStr = "Jul";} if (month==8) {monthStr = "Aug";} if (month==9) {monthStr = "Sep";} if (month==10) {monthStr = "Oct";} if (month==11) {monthStr = "Nov";} if (month==12) {monthStr = "Dec";} String dayStr = Integer.toString(day); String hourStr = Integer.toString(hour); if (hour < 10) {hourStr = "0" + hourStr;} String minuteStr = Integer.toString(minute); if (minute < 10) {minuteStr = "0" + minuteStr;} createString = "Created at "+monthStr+"-"+dayStr+" "+hourStr+":"+minuteStr; } public void Temp_Graph(String[] xdata, double[] ydata, int graphType) { Date myDate4 = new Date(System.currentTimeMillis()); System.out.println("Step 4: Creating temp-jpg at "+myDate4); // series LineDataSerie data1= new LineDataSerie(ydata, new LineStyle(2f,java.awt.Color.green,LineStyle.LINE_NORMAL)); // create title if (metric) { titleString = "Temperature (C)"; } else { titleString = "Temperature (F)"; } MSBChart.Title title=new Title(titleString); title.color = java.awt.Color.yellow; // create axis MSBChart.Axis XAxis=new Axis(Axis.HORIZONTAL,new Scale(),metric); MSBChart.Axis YAxis=new Axis(Axis.VERTICAL,new Scale(),metric); //X-axis XAxis.gridStyle=new LineStyle(1f,java.awt.Color.lightGray,LineStyle.LINE_DOTS); XAxis.tickLabels=xdata; MSBChart.HAxisLabel XLabel= new HAxisLabel(createString,java.awt.Color.yellow,new Font("Serif",Font.PLAIN,10)); //Y-axis int i=0; double lowest_value=9999.9999; double
评论
    相关推荐