получить температуру по точке

This commit is contained in:
2025-02-04 07:47:37 +05:00
parent 487fec663c
commit a07332832a
5 changed files with 104 additions and 40 deletions

View File

@ -21,15 +21,15 @@ custom:
#data_dir: O:\\temp\\CCALM\\
data_dir: /data/
db_all:
url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://92.46.48.43:5444/weather?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://192.168.0.90:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require
url: jdbc:postgresql://127.0.0.1:5432/weather?ApplicationName=kz_mcp_weather&sslmode=require
login: postgres
password: PasSecrKey1
db_ru:
url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://92.46.48.43:5444/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://192.168.0.90:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
#url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
url: jdbc:postgresql://127.0.0.1:5432/weather_ru?ApplicationName=kz_mcp_weather&sslmode=require
login: postgres
password: PasSecrKey1

View File

@ -8,10 +8,8 @@ import java.io.PrintWriter;
import java.sql.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -39,6 +37,7 @@ import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
import org.ccalm.weather.WeatherDownload;
import tctable.Tools;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
@ -169,12 +168,12 @@ public class AirTemperature implements ServletContextAware {
if(!strPos1.isEmpty())
{
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
Tools.CutBeforeFirst(answer1,":");
String posStart = Tools.CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
Tools.CutBeforeFirst(answer2,":");
String posEnd = Tools.CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);
@ -444,23 +443,6 @@ public class AirTemperature implements ServletContextAware {
System.out.println("Done download and save");
return result;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
if(pos==-1)
{
result.concat(str.toString());
str.delete(0,str.length());
}else
{
result=str.substring(0,pos);
str.delete(0,pos+1);
}
return result;
}
//---------------------------------------------------------------------------
//List of "Air temperature" dates from database in JSON
//@CacheControl(maxAge = 300)
@ -524,5 +506,69 @@ public class AirTemperature implements ServletContextAware {
return result;
}
//---------------------------------------------------------------------------
@CrossOrigin
@RequestMapping(value = "/geodatalist/getAirTemperature",method = RequestMethod.GET,produces = "application/json;charset=UTF-8")
@ResponseBody
public Object getAirTemperature(@RequestParam("date") String date,@RequestParam("hours") int hours,@RequestParam("lat") double lat, @RequestParam("lon") double lon,HttpServletResponse response) {
String headerValue = CacheControl.maxAge(60, TimeUnit.SECONDS).getHeaderValue();
response.addHeader("Cache-Control", headerValue);
Map<String, Object> result = new HashMap<>();
float temperature = -999;
Connection conn_all = DBTools.getConn(db_url_all,db_login_all,db_password_all);
Connection conn_ru = DBTools.getConn(db_url_ru,db_login_ru,db_password_ru);
String sql = """
select main.get_air_temperature(?::timestamp,?,?,?)-273.15;
""";
if(conn_all!=null) {
try (Statement st = conn_all.createStatement()) {
PreparedStatement pstmt = st.getConnection().prepareStatement(sql);
pstmt.setString(1, date);
pstmt.setInt(2, hours);
pstmt.setDouble(3, lon);
pstmt.setDouble(4, lat);
try (ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) {
temperature = rs.getFloat(1);
if (rs.wasNull()) {
temperature = -999;
}
}
}
} catch (SQLException ex) {
logger.error("N4:" + ex.getMessage(), ex);
}
}
if(temperature == -999){
if(conn_ru!=null) {
try (Statement st = conn_ru.createStatement()) {
PreparedStatement pstmt = st.getConnection().prepareStatement(sql);
pstmt.setString(1, date);
pstmt.setInt(2, hours);
pstmt.setDouble(3, lon);
pstmt.setDouble(4, lat);
try (ResultSet rs = pstmt.executeQuery()) {
if (rs.next()) {
temperature = rs.getFloat(1);
if (rs.wasNull()) {
temperature = -999;
}
}
}
} catch (SQLException ex) {
logger.error("N4:" + ex.getMessage(), ex);
}
}
}
result.put("error_code", 0);
result.put("temperature", temperature);
return result;
}
}

View File

@ -44,6 +44,7 @@ import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
//import org.ccalm.weather.WeatherDownload;
import tctable.Tools;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
@ -79,7 +80,7 @@ public class Precipitation implements ServletContextAware {
this.context=servletContext;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
/*public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
@ -93,7 +94,7 @@ public class Precipitation implements ServletContextAware {
str.delete(0,pos+1);
}
return result;
}
}*/
//---------------------------------------------------------------------------
/**
* Example https://127.0.0.1:8081/geodatalist/Precipitation or https://127.0.0.1:8081/geodatalist/Precipitation?date=20250531
@ -191,12 +192,12 @@ public class Precipitation implements ServletContextAware {
if(!strPos1.isEmpty())
{
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
Tools.CutBeforeFirst(answer1,":");
String posStart = Tools.CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
Tools.CutBeforeFirst(answer2,":");
String posEnd = Tools.CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);

View File

@ -44,6 +44,7 @@ import org.w3c.dom.NodeList;
//import main.DownloadFromHTTP;
import org.ccalm.weather.WeatherDownload;
import tctable.Tools;
import ucar.ma2.Array;
import ucar.nc2.Dimension;
import ucar.nc2.Variable;
@ -79,7 +80,7 @@ public class SoilTmperature implements ServletContextAware {
this.context=context;
}
//---------------------------------------------------------------------------
public static String CutBeforeFirst(StringBuffer str,String ch)
/*public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
@ -93,7 +94,7 @@ public class SoilTmperature implements ServletContextAware {
str.delete(0,pos+1);
}
return result;
}
}*/
//---------------------------------------------------------------------------
/**
* Example: http://127.0.0.1:8081/geodatalist/DownloadSoil?forecast=000
@ -199,12 +200,12 @@ public class SoilTmperature implements ServletContextAware {
{
//String strPos1 = "250:146339365:d=2017022818:TSOIL:0-0.1 m below ground:anl:"
StringBuffer answer1=new StringBuffer(strPos1);
CutBeforeFirst(answer1,":");
String posStart = CutBeforeFirst(answer1,":");
Tools.CutBeforeFirst(answer1,":");
String posStart = Tools.CutBeforeFirst(answer1,":");
StringBuffer answer2=new StringBuffer(strPos2);
CutBeforeFirst(answer2,":");
String posEnd = CutBeforeFirst(answer2,":");
Tools.CutBeforeFirst(answer2,":");
String posEnd = Tools.CutBeforeFirst(answer2,":");
if(posEnd==null || posEnd.equals("")) posEnd=""; else
{
posEnd=String.valueOf(Long.parseLong(posEnd)-1);

View File

@ -163,6 +163,22 @@ public class Tools {
return "";
}
public static String CutBeforeFirst(StringBuffer str,String ch)
{
int pos=str.indexOf(ch);
String result="";
if(pos==-1)
{
result.concat(str.toString());
str.delete(0,str.length());
}else
{
result=str.substring(0,pos);
str.delete(0,pos+1);
}
return result;
}
//узнать точку пересичений 2х линай если x=0 и y=0 то не пересиклась
public static Point getCrossingLine(Point PHead0, Point PTail0, Point PHead1, Point PTail1)
{