на работе
This commit is contained in:
@ -67,15 +67,18 @@ public class AirTemperature implements ServletContextAware {
|
||||
|
||||
private ServletContext context;
|
||||
|
||||
//http://127.0.0.1:8080/AirTemperature
|
||||
|
||||
/**
|
||||
* This function is run every day from CRON, to see the settings call the function: "sudo crontab -e -u tomcat" on PC 127.0.0.1
|
||||
* @param date - If the field is empty, it is filled in automatically with the current day (When running from CRON, this field is empty)
|
||||
* @return HTML string
|
||||
*/
|
||||
@RequestMapping(value = "/geodatalist/AirTemperature",method = RequestMethod.GET,produces = "text/html;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public Object ajaxTamer(/*@RequestParam(required=true,name="forecast") String forecast,*/@RequestParam(required=false,name="date") String date) {
|
||||
String forecast = "000";
|
||||
|
||||
String result="";
|
||||
result+="Start!<br>";
|
||||
result+="Start!!!<br>";
|
||||
|
||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
@ -96,10 +99,10 @@ public class AirTemperature implements ServletContextAware {
|
||||
logger.info("<br>Connect is ERROR<br>");
|
||||
result+="Connect is ERROR!<br>";
|
||||
}
|
||||
}catch(Exception e)
|
||||
}catch(Exception ex)
|
||||
{
|
||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
||||
logger.error("N1:"+ex.getMessage()+"<br>",ex);
|
||||
result+="Connect Exception:"+ex.getMessage()+"<br>";
|
||||
}
|
||||
|
||||
//Example request: http://ccalm.org/AirTemperature?date=20210531
|
||||
@ -145,7 +148,7 @@ public class AirTemperature implements ServletContextAware {
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N2:"+ex.getMessage(),ex);
|
||||
result+=ex.getMessage()+"<br>";
|
||||
}
|
||||
if(!strPos1.equals(""))
|
||||
@ -162,11 +165,14 @@ public class AirTemperature implements ServletContextAware {
|
||||
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
|
||||
}
|
||||
|
||||
wd.download(URL, data_dir+"temp"+File.separator+"air_text.f000", String.valueOf(posStart), String.valueOf(posEnd));
|
||||
if(!wd.download(URL, data_dir+"temp"+File.separator+"air_text.f000", String.valueOf(posStart), String.valueOf(posEnd))){
|
||||
logger.info("Error download file: "+URL);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
result+="Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx"+"<br>";
|
||||
logger.info("Not download "+URL+".idx"+" to "+data_dir+"temp"+File.separator+"air_text.idx");
|
||||
}
|
||||
|
||||
Array dataArrayLat=null;
|
||||
@ -227,36 +233,51 @@ public class AirTemperature implements ServletContextAware {
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N3:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N4:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||
|
||||
//Delete old data
|
||||
System.out.println("Delete old data 1");
|
||||
logger.info("Delete old data 1");
|
||||
try {
|
||||
String sql="delete from main.air_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N5:"+ex.getMessage(),ex);
|
||||
}
|
||||
System.out.println("Delete old data 2");
|
||||
logger.info("Delete old data 2");
|
||||
try {
|
||||
String sql="delete from main.air_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N6:"+ex.getMessage(),ex);
|
||||
}
|
||||
logger.info("Delete old data 3");
|
||||
try {
|
||||
String sql="delete from main.air_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N7:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N7.1:"+ex.getMessage(),ex);
|
||||
}
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N7.2:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
int pos=0;
|
||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||
{
|
||||
@ -278,7 +299,7 @@ public class AirTemperature implements ServletContextAware {
|
||||
String sql="select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1";
|
||||
rs = st.executeQuery(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N8:"+ex.getMessage(),ex);
|
||||
}
|
||||
if (rs != null) {
|
||||
try {
|
||||
@ -286,17 +307,18 @@ public class AirTemperature implements ServletContextAware {
|
||||
country_id=rs.getString(1);
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N9:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
|
||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||
{
|
||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||
try {
|
||||
String sql="insert into main.air_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
|
||||
String sql="insert into main.air_temperature(date,hours,val,geom,country_id,air_temperature_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_air_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N10:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +333,7 @@ public class AirTemperature implements ServletContextAware {
|
||||
String sql="update main.air_temperature w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N11:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
//Delete values where country_id is null
|
||||
@ -319,23 +341,21 @@ public class AirTemperature implements ServletContextAware {
|
||||
String sql="delete from main.air_temperature where country_id is null;";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N12:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N13:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
gid.close();
|
||||
} catch (IOException ex) {
|
||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
System.out.print("ERROR!");
|
||||
logger.error("N14:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
||||
try {conn.close();} catch (SQLException ex) {logger.error("N15:"+ex.getMessage(),ex);}
|
||||
|
||||
result+="End!<br>";
|
||||
return result;
|
||||
@ -385,17 +405,27 @@ public class AirTemperature implements ServletContextAware {
|
||||
result="An error occurred while connecting to the database!";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N16:"+ex.getMessage(),ex);
|
||||
error=true;
|
||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||
}
|
||||
|
||||
|
||||
if(!error)
|
||||
{
|
||||
Statement st;
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
|
||||
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.air_temperature group by date,hours order by date,hours;";
|
||||
String sql = """
|
||||
SELECT
|
||||
to_char(date, 'YYYY-MM-DD') as date,
|
||||
hours as hour,
|
||||
EXTRACT(DAY FROM CURRENT_DATE-date) as day
|
||||
FROM
|
||||
main.air_temperature_dates
|
||||
group by date,hours
|
||||
order by date,hours
|
||||
""";
|
||||
ResultSet rs = st.executeQuery(sql);
|
||||
if(rs!=null)
|
||||
{
|
||||
@ -408,7 +438,7 @@ public class AirTemperature implements ServletContextAware {
|
||||
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||
} catch( Exception ex )
|
||||
{
|
||||
|
||||
logger.error("N17:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
if(exists) {
|
||||
@ -417,12 +447,12 @@ public class AirTemperature implements ServletContextAware {
|
||||
}else {
|
||||
result="[]";
|
||||
}
|
||||
|
||||
}
|
||||
st.close();
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||
logger.error("N18:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -24,9 +24,9 @@ public class MainController {
|
||||
@ResponseBody
|
||||
public String getGeoDataList(Model model) {
|
||||
String html="";
|
||||
html+="<a href=\"./AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
html+="<a href=\"./PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
html+="<a href=\"./SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20210826\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
html+="<a href=\"./AirTemperatureDates\">AirTemperatureDates</a><br><form action=\"./AirTemperature\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
html+="<a href=\"./PrecipitationDates\">PrecipitationDates</a><br><form action=\"./Precipitation\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
html+="<a href=\"./SoilDates\">SoilDates</a><br><form action=\"./DownloadSoil\" method=\"get\"><label for=\"fname\">Date:</label><input type=\"text\" name=\"date\" value=\"\"20240420\"><label for=\"forecast\">Forecast:</label><input type=\"text\" name=\"forecast\" value=\"000\"><input type=\"submit\" value=\"Submit\"></form><br>";
|
||||
return html;
|
||||
}
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
//import main.DownloadFromHTTP;
|
||||
import org.ccalm.weather.WeatherDownload;
|
||||
//import org.ccalm.weather.WeatherDownload;
|
||||
import ucar.ma2.Array;
|
||||
import ucar.nc2.Dimension;
|
||||
import ucar.nc2.Variable;
|
||||
@ -63,7 +63,7 @@ public class Precipitation implements ServletContextAware {
|
||||
@Value("${custom.config.data_dir}")
|
||||
private String data_dir;
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(SoilTmperature.class);
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Precipitation.class);
|
||||
|
||||
private ServletContext context;
|
||||
|
||||
@ -100,7 +100,7 @@ public class Precipitation implements ServletContextAware {
|
||||
}
|
||||
}catch(Exception e)
|
||||
{
|
||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
||||
logger.error("N1:"+e.getMessage()+"<br>",e);
|
||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
||||
}
|
||||
|
||||
@ -147,7 +147,7 @@ public class Precipitation implements ServletContextAware {
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N2:"+ex.getMessage(),ex);
|
||||
result+=ex.getMessage()+"<br>";
|
||||
}
|
||||
if(!strPos1.equals(""))
|
||||
@ -229,35 +229,50 @@ public class Precipitation implements ServletContextAware {
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N3:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N4:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||
|
||||
//Delete old data
|
||||
System.out.println("Delete old data 1");
|
||||
logger.info("Delete old data 1");
|
||||
try {
|
||||
String sql="delete from main.precipitation where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N5:"+ex.getMessage(),ex);
|
||||
}
|
||||
System.out.println("Delete old data 2");
|
||||
logger.info("Delete old data 2");
|
||||
try {
|
||||
String sql="delete from main.precipitation_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N6:"+ex.getMessage(),ex);
|
||||
}
|
||||
logger.info("Delete old data 3");
|
||||
try {
|
||||
String sql="delete from main.precipitation where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N7:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N7.1:"+ex.getMessage(),ex);
|
||||
}
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N7.2:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int pos=0;
|
||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||
@ -279,7 +294,7 @@ public class Precipitation implements ServletContextAware {
|
||||
try {
|
||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N8:"+ex.getMessage(),ex);
|
||||
}
|
||||
if (rs != null) {
|
||||
try {
|
||||
@ -287,17 +302,17 @@ public class Precipitation implements ServletContextAware {
|
||||
country_id=rs.getString(1);
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N9:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||
{
|
||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||
try {
|
||||
String sql="insert into main.precipitation(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
|
||||
String sql="insert into main.precipitation(date,hours,val,geom,country_id,precipitation_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_precipitation_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N10:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,7 +327,7 @@ public class Precipitation implements ServletContextAware {
|
||||
String sql="update main.precipitation w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N11:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
//Delete values where country_id is null
|
||||
@ -320,23 +335,21 @@ public class Precipitation implements ServletContextAware {
|
||||
String sql="delete from main.precipitation where country_id is null;";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N12:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N13:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
gid.close();
|
||||
} catch (IOException ex) {
|
||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
System.out.print("ERROR!");
|
||||
logger.error("N14:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage(),ex);}
|
||||
|
||||
result+="End!<br>";
|
||||
return result;
|
||||
@ -386,7 +399,7 @@ public class Precipitation implements ServletContextAware {
|
||||
result="An error occurred while connecting to the database!";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N15:"+ex.getMessage(),ex);
|
||||
error=true;
|
||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||
}
|
||||
@ -396,7 +409,19 @@ public class Precipitation implements ServletContextAware {
|
||||
Statement st;
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
|
||||
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,DATE_PART('doy',date)-1 as day FROM main.precipitation group by date,hours order by date,hours";
|
||||
String sql = """
|
||||
SELECT
|
||||
to_char(date, 'YYYY-MM-DD') as date,
|
||||
hours as hour,
|
||||
DATE_PART('doy',date)-1 as day
|
||||
FROM
|
||||
main.precipitation_dates
|
||||
group by
|
||||
date,
|
||||
hours
|
||||
order by date,hours
|
||||
""";
|
||||
ResultSet rs = st.executeQuery(sql);
|
||||
if(rs!=null)
|
||||
{
|
||||
@ -409,7 +434,7 @@ public class Precipitation implements ServletContextAware {
|
||||
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||
} catch( Exception ex )
|
||||
{
|
||||
|
||||
logger.error("N16:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
if(exists) {
|
||||
@ -418,12 +443,12 @@ public class Precipitation implements ServletContextAware {
|
||||
}else {
|
||||
result="[]";
|
||||
}
|
||||
|
||||
}
|
||||
st.close();
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||
logger.error("N17:"+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@ -101,10 +101,10 @@ public class SoilTmperature implements ServletContextAware {
|
||||
logger.info("<br>Connect is ERROR<br>");
|
||||
result+="Connect is ERROR!<br>";
|
||||
}
|
||||
}catch(Exception e)
|
||||
}catch(Exception ex)
|
||||
{
|
||||
logger.info("<br>Connect Exception:"+e.getMessage()+"<br>");
|
||||
result+="Connect Exception:"+e.getMessage()+"<br>";
|
||||
logger.error("N1: "+ex.getMessage()+"<br>",ex);
|
||||
result+="Connect Exception:"+ex.getMessage()+"<br>";
|
||||
}
|
||||
|
||||
//Example request: http://ccalm.org/DownloadWeather?forecast=000&date=20210531
|
||||
@ -155,7 +155,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
}
|
||||
br.close();
|
||||
} catch (IOException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N2: "+ex.getMessage(),ex);
|
||||
result+=ex.getMessage()+"<br>";
|
||||
}
|
||||
if(!strPos1.equals(""))
|
||||
@ -245,42 +245,59 @@ public class SoilTmperature implements ServletContextAware {
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N3: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N4: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
result+="Size="+dataArrayLat.getSize()+"<br>";
|
||||
|
||||
//Delete old data
|
||||
System.out.println("Delete old data 1");
|
||||
logger.info("Delete old data 1");
|
||||
try {
|
||||
String sql="delete from main.soil_temperature where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N5: "+ex.getMessage(),ex);
|
||||
}
|
||||
System.out.println("Delete old data 2");
|
||||
logger.info("Delete old data 2");
|
||||
try {
|
||||
String sql="delete from main.soil_temperature_dates where date=cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone) and hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N6: "+ex.getMessage(),ex);
|
||||
}
|
||||
logger.info("Delete old data 3");
|
||||
try {
|
||||
String sql="delete from main.soil_temperature where date<=CURRENT_DATE-'730 days'::INTERVAL";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N7: "+ex.getMessage(),ex);
|
||||
}
|
||||
if(Integer.parseInt(forecast)!=0) {
|
||||
System.out.println("Delete old data 3");
|
||||
logger.info("Delete old data 4");
|
||||
try {
|
||||
String sql="delete from main.soil_temperature where hours="+forecast;
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N8: "+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N8.1:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("BEGIN TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N8.2:"+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
int pos=0;
|
||||
for(int nLat=0;nLat<dataArrayLat.getSize();nLat++)
|
||||
@ -302,7 +319,8 @@ public class SoilTmperature implements ServletContextAware {
|
||||
try {
|
||||
rs = st.executeQuery("select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N9: "+ex.getMessage(),ex);
|
||||
throw new Exception("Failed to select country...");
|
||||
}
|
||||
if (rs != null) {
|
||||
try {
|
||||
@ -310,19 +328,19 @@ public class SoilTmperature implements ServletContextAware {
|
||||
country_id=rs.getString(1);
|
||||
rs.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N10: "+ex.getMessage(),ex);
|
||||
throw new Exception("Failed to select country...");
|
||||
}
|
||||
}
|
||||
if(country_id!=null && !country_id.equals("") && !country_id.equals("null"))
|
||||
{
|
||||
//logger.info(lon + "," + lat +","+dataArrayTmp.getFloat(pos));
|
||||
try {
|
||||
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326));";
|
||||
//String sql="insert into main.soil_temperature(weather_type_id,date,hours,val,geom,country_id)values(1,cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),(select c.id from main.countries c where ST_Contains(c.geom,ST_SetSRID(st_makepoint("+lon+","+lat+"),4326)) limit 1));";
|
||||
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+");";
|
||||
String sql="insert into main.soil_temperature(date,hours,val,geom,country_id,soil_temperature_date_id)values(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+","+dataArrayTmp.getFloat(pos)+",ST_SetSRID(st_makepoint("+lon+","+lat+"),4326),"+country_id+",main.get_soil_temperature_date(cast(to_timestamp('"+date+" "+time+"', 'YYYYMMDD HH24') as timestamp without time zone),"+forecast+"));";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N11: "+ex.getMessage(),ex);
|
||||
throw new Exception("Failed insert soil temperature...");
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,7 +355,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
String sql="update main.soil_temperature w set country_id=null where country_id=7 and not ST_Contains(ST_SetSRID(ST_GeomFromText('POLYGON((10.00 66.00,10.00 40.00,179.00 40.00,179.00 66.00,10.00 66.00))'),4326),w.geom);";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N12: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
//Delete values where country_id is null
|
||||
@ -345,23 +363,24 @@ public class SoilTmperature implements ServletContextAware {
|
||||
String sql="delete from main.soil_temperature where country_id is null;";
|
||||
st.executeUpdate(sql);
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N13: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {
|
||||
st.executeUpdate("END TRANSACTION;");
|
||||
} catch (SQLException ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N14: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
gid.close();
|
||||
} catch (IOException ex) {
|
||||
//Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
System.out.print("ERROR!");
|
||||
}
|
||||
logger.error("N15: "+ex.getMessage(),ex);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.error("N16: "+ex.getMessage(),ex);
|
||||
}
|
||||
|
||||
try {conn.close();} catch (SQLException ex) {logger.info(ex.getMessage());}
|
||||
try {conn.close();} catch (SQLException ex) {logger.error("N16: "+ex.getMessage(),ex);}
|
||||
|
||||
result+="End!<br>";
|
||||
return result;
|
||||
@ -410,7 +429,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
result="An error occurred while connecting to the database!";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.info(ex.getMessage());
|
||||
logger.error("N17: "+ex.getMessage(),ex);
|
||||
error=true;
|
||||
result="<br>SQLException: "+ex.getMessage()+"<br>";
|
||||
}
|
||||
@ -420,8 +439,18 @@ public class SoilTmperature implements ServletContextAware {
|
||||
Statement st;
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
|
||||
|
||||
//String sql = "SELECT to_char(date, 'YYYY-MM-DD') as date,hours as hour,EXTRACT(DAY FROM CURRENT_DATE-date) as day FROM main.soil_temperature group by date,hours order by date,hours";
|
||||
String sql = """
|
||||
SELECT
|
||||
to_char(date, 'YYYY-MM-DD') as date,
|
||||
hours as hour,
|
||||
EXTRACT(DAY FROM CURRENT_DATE-date) as day
|
||||
FROM
|
||||
main.soil_temperature_dates
|
||||
group by date,hours
|
||||
order by date,hours
|
||||
""";
|
||||
|
||||
ResultSet rs = st.executeQuery(sql);
|
||||
if(rs!=null)
|
||||
{
|
||||
@ -434,7 +463,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
result+= "{\"num\":\""+rs.getString("day")+"\", \"hour\":\""+rs.getString("hour")+"\", \"date\":\""+rs.getString("date")+"\"},";
|
||||
} catch( Exception ex )
|
||||
{
|
||||
|
||||
logger.error("N18: "+ex.getMessage(),ex);
|
||||
}
|
||||
}
|
||||
if(exists) {
|
||||
@ -448,6 +477,7 @@ public class SoilTmperature implements ServletContextAware {
|
||||
st.close();
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
logger.error("N19: "+ex.getMessage(),ex);
|
||||
result="<br>SQLException:"+ex.getMessage()+"<br>";
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
package org.ccalm.weather;
|
||||
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@ -18,12 +14,14 @@ import java.net.URL;
|
||||
* @author ivanov.i
|
||||
*/
|
||||
public class WeatherDownload {
|
||||
|
||||
|
||||
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(WeatherDownload.class);
|
||||
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
public boolean download(String strURL,String strFile,String posStart,String posEnd)
|
||||
{
|
||||
boolean result=true;
|
||||
boolean result=false;
|
||||
String rez = null;
|
||||
String inputLine = null;
|
||||
/*try
|
||||
@ -53,13 +51,13 @@ public class WeatherDownload {
|
||||
}
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
result=true;
|
||||
}
|
||||
conn.disconnect();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
//e.printStackTrace();
|
||||
result=false;
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user