Merge remote-tracking branch 'origin/main'

main
lakefish 3 years ago
commit 068af770ee

2
.gitignore vendored

@ -32,4 +32,4 @@ build/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
/src/main/resources/5963105_www.peteralbus.com.pfx /src/main/resources/5963105_www.peteralbus.com.pfx
/src/main/resources/application.yml /src/main/resources/application.yml.example

@ -26,26 +26,11 @@ import java.util.Map;
@RequestMapping("/earthquakeInfo") @RequestMapping("/earthquakeInfo")
public class EarthquakeInfoController public class EarthquakeInfoController
{ {
/**
* The Estimate util.
*/
EstimateUtil estimateUtil;
/** /**
* The Earthquake info service. * The Earthquake info service.
*/ */
EarthquakeInfoService earthquakeInfoService; EarthquakeInfoService earthquakeInfoService;
/**
* Sets estimate util.
*
* @param estimateUtil the estimate util
*/
@Autowired
public void setEstimateUtil(EstimateUtil estimateUtil)
{
this.estimateUtil = estimateUtil;
}
/** /**
* Sets earthquake info service. * Sets earthquake info service.
* *
@ -82,38 +67,6 @@ public class EarthquakeInfoController
mapParameter.put("earthquakeId",earthquakeId); mapParameter.put("earthquakeId",earthquakeId);
return earthquakeInfoService.queryInfoWithLine(mapParameter).get(0); return earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
} }
/**
* Gets death predict.
*
* @param earthquakeId the earthquake info id
* @return the death predict
*/
@GetMapping("/getDeathPredict")
public double getDeathPredict(int earthquakeId)
{
Map<String, Object> mapParameter = new HashMap<String, Object>();
mapParameter.put("earthquakeId",earthquakeId);
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
int population=3133;
return estimateUtil.deathPredict(population,earthquakeInfo.getMagnitude(),earthquakeInfo.getHighIntensity());
}
/**
* Gets economy predict.
*
* @param earthquakeId the earthquake info id
* @return the economy predict
*/
@GetMapping("/getEconomyPredict")
public double getEconomyPredict(int earthquakeId)
{
Map<String, Object> mapParameter = new HashMap<String, Object>();
mapParameter.put("earthquakeId",earthquakeId);
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
return estimateUtil.economyPredict(earthquakeInfo.getHighIntensity());
}
/** /**
* Add earthquake string. * Add earthquake string.
* *

@ -0,0 +1,107 @@
package com.peteralbus.controller;
import com.peteralbus.entity.Estimate;
import com.peteralbus.entity.EarthquakeInfo;
import com.peteralbus.service.EstimateService;
import com.peteralbus.service.EarthquakeInfoService;
import com.peteralbus.util.EstimateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/estimate")
public class EstimateController {
/**
* The Estimate util.
*/
EstimateUtil estimateUtil;
EstimateService estimateService;
/**
* The Earthquake info service.
*/
EarthquakeInfoService earthquakeInfoService;
/**
* Sets earthquake info service.
*
* @param earthquakeInfoService the earthquake info service
*/
@Autowired
public void setEarthquakeInfoService(EarthquakeInfoService earthquakeInfoService)
{
this.earthquakeInfoService = earthquakeInfoService;
}
/**
* Sets estimate util.
*
* @param estimateUtil the estimate util
*/
@Autowired
public void setEstimateUtil(EstimateUtil estimateUtil)
{
this.estimateUtil = estimateUtil;
}
/**
* Sets estimate service.
*
* @param estimateService
*/
@Autowired
public void setAnalyzeService(EstimateService estimateService) {
this.estimateService = estimateService;
}
/**
* Gets estimate result.
*
* @param earthquakeId the earthquake info id
* @return the estimate result
*/
@GetMapping("/getAnalyzeResult")
public Estimate getPredictResult(long earthquakeId){
System.out.println(earthquakeId);
int count = estimateService.queryAnalyze(earthquakeId);
Estimate estimate = new Estimate();
if(count==0){
Map<String, Object> mapParameter = new HashMap<String, Object>();
mapParameter.put("earthquakeId",earthquakeId);
EarthquakeInfo earthquakeInfo=earthquakeInfoService.queryInfoWithLine(mapParameter).get(0);
double magnitude = earthquakeInfo.getMagnitude(),
highIntensity = earthquakeInfo.getHighIntensity(),
longitude = earthquakeInfo.getLongitude(),
latitude = earthquakeInfo.getLatitude(),
longRadius = earthquakeInfo.getIntensityLineList().get(2).getLongRadius(),
shortRadius = earthquakeInfo.getIntensityLineList().get(2).getShortRadius();
System.out.println(longRadius);
LocalDateTime earthquakeTime = earthquakeInfo.getEarthquakeTime();
double radians = Math.toRadians(latitude);//将角度转换为弧度。
double minLongitude = longitude-shortRadius/(111-Math.cos(radians)),
maxLongitude = longitude+shortRadius/(111-Math.cos(radians)),
minLatitude = latitude-longRadius/111,
maxLatitude = latitude+longRadius/111;
int population=(int)estimateService.getPopulation(minLongitude,maxLongitude,minLatitude,maxLatitude);
estimate.setPredictDeath(estimateUtil.deathPredict(earthquakeInfo.getEarthquakeId(),population,magnitude,highIntensity,earthquakeTime,longitude,latitude));
estimate.setPredictEconomy(estimateUtil.economyPredict(earthquakeInfo.getHighIntensity()));
estimate.setEarthquakeId(earthquakeId);
estimate.setPopulation(population);
Date date = new Date();
estimate.setGmt_time(date);
estimateService.insertAnalyze(estimate);
}
else
{
estimate = estimateService.queryAnalyzeById(earthquakeId);
}
return estimate;
}
}

@ -0,0 +1,25 @@
package com.peteralbus.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.Date;
@ToString
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Estimate {
@TableId(type= IdType.ASSIGN_ID)
private Long analyzeId;
private Long earthquakeId;
private Double predictDeath;
private Double predictEconomy;
private int population;
private Date gmt_time;
}

@ -0,0 +1,14 @@
package com.peteralbus.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.peteralbus.entity.Estimate;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface EstimateMapper extends BaseMapper<Estimate>
{
Double getPopulation(@Param("minLongitude") Double minLongitude, @Param("maxLongitude") Double maxLongitude, @Param("minLatitude") Double minLatitude, @Param("maxLatitude") Double maxLatitude);
Estimate queryAnalyzeById(@Param("earthquakeId") long earthquakeId);
int queryAnalyze(@Param("earthquakeId") long earthquakeId);
}

@ -1,6 +1,7 @@
package com.peteralbus.service; package com.peteralbus.service;
import com.peteralbus.entity.EarthquakeInfo; import com.peteralbus.entity.EarthquakeInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

@ -0,0 +1,20 @@
package com.peteralbus.service;
import com.peteralbus.entity.Estimate;
import org.apache.ibatis.annotations.Param;
public interface EstimateService {
/**
* Get
*
* @param minLongitude the minimum Longitude
* @param maxLongitude the maximum Longitude
* @param minLatitude the minimum Latitude
* @param maxLatitude the maximum Latitude
* @return the double
*/
double getPopulation(@Param("minLongitude") Double minLongitude, @Param("maxLongitude") Double maxLongitude, @Param("minLatitude") Double minLatitude, @Param("maxLatitude") Double maxLatitude);
int insertAnalyze(Estimate estimate);
Estimate queryAnalyzeById(long earthquakeId);
int queryAnalyze(@Param("earthquakeId") long earthquakeId);
}

@ -0,0 +1,41 @@
package com.peteralbus.service.impl;
import com.peteralbus.entity.Estimate;
import com.peteralbus.mapper.EstimateMapper;
import com.peteralbus.service.EstimateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class EstimateServiceImpl implements EstimateService {
EstimateMapper estimateMapper;
@Autowired
public void setAnalyzeMapper(EstimateMapper estimateMapper){
this.estimateMapper = estimateMapper;
}
@Override
public double getPopulation(Double minLongitude, Double maxLongitude, Double minLatitude, Double maxLatitude) {
return estimateMapper.getPopulation(minLongitude,maxLongitude,minLatitude,maxLatitude);
}
@Override
public int insertAnalyze(Estimate analyze){
int result = 0;
result = estimateMapper.insert(analyze);
if (result == 0)
{
return result;
}
return result;
}
@Override
public Estimate queryAnalyzeById(long earthquakeId) {
return estimateMapper.queryAnalyzeById(earthquakeId);
}
@Override
public int queryAnalyze(long earthquakeId) {
return estimateMapper.queryAnalyze(earthquakeId);
}
}

@ -2,6 +2,9 @@ package com.peteralbus.util;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;
/** /**
* The type Estimate util. * The type Estimate util.
* @author PeterAlbus * @author PeterAlbus
@ -14,20 +17,40 @@ public class EstimateUtil
* *
* @param population the population * @param population the population
* @param magnitude the magnitude * @param magnitude the magnitude
* @param earthquakeTime the time of earthquake
* @param longitude the longitude
* @param latitude the latitude
* @return the double * @return the double
*/ */
public double deathPredict(int population,double magnitude,double intensity) public double deathPredict(Long earthquake_id,int population, double magnitude, double intensity, LocalDateTime earthquakeTime,Double longitude,Double latitude)
{ {
double deathPredict = 0; double deathPredict = 0;
/*M为震级 I为震中强度*/ /*M为震级 I为震中强度*/
double mCoefficient = Math.abs((magnitude-4.17)/0.35*intensity-0.97); double mCoefficient = Math.abs((magnitude-4.17)/(0.35*intensity-0.97));
/*population 为人口密度*/ /*population 为人口密度*/
double denCoefficient = 0.05*Math.log(population)+0.74; double denCoefficient = 0.05*Math.log(population)+0.74;
/*白天为1夜晚为0.75*/ /*时间修正系数*/
double timeCoefficient = 0.75; /* 1:00-5:59为2,6:00-8:59为1,9:00-19:59为5/9,20:00-00:59为5/3 */
int hour = earthquakeTime.getHour();
double timeCoefficient = 5.0/3.0;
if(hour>=1 && hour<6){
timeCoefficient = 2.0;
}
else if(hour>=6 && hour < 9){
timeCoefficient = 1.0;
}
else if(hour >= 9 && hour < 20){
timeCoefficient = 5.0/9.0;
}
/*西部强度修正系数 0.3661*/ /*西部强度修正系数 0.3661*/
double strengthCoefficient = 0.4853; double temp_latitude = 0.85 * longitude -64.4;/*黑河-腾冲现模拟方程*/
double bdr = 0.5; double strengthCoefficient = 0.3661;
if(latitude < temp_latitude){
strengthCoefficient = 0.4853;
}
double bdr = (intensity*17.205-101.861)*0.01;
if(bdr <= 0)
bdr = 0.01;
deathPredict = 0.461*mCoefficient*denCoefficient*timeCoefficient*strengthCoefficient*Math.exp(12.285*bdr); deathPredict = 0.461*mCoefficient*denCoefficient*timeCoefficient*strengthCoefficient*Math.exp(12.285*bdr);
return deathPredict; return deathPredict;
// double deathPredict = 0; // double deathPredict = 0;
@ -42,8 +65,7 @@ public class EstimateUtil
* @return the double * @return the double
*/ */
public double economyPredict(double highIntensity) public double economyPredict(double highIntensity)
{ {return Math.pow(10,0.84444*highIntensity-1.831)/10000;
return Math.pow(10,0.84444*highIntensity-1.831)/10000;
} }
} }

@ -30,4 +30,9 @@
limit #{startIndex},#{pageSize} limit #{startIndex},#{pageSize}
</if> </if>
</select> </select>
<select id="getPopulation" resultType="double">
select avg(z) from population
where x>#{minLongitude} and x &lt;#{maxLongitude} and y>#{minLatitude} and y &lt; #{maxLatitude}
</select>
</mapper> </mapper>

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.peteralbus.mapper.EstimateMapper">
<resultMap id="EarthquakeInfoWithLines" type="EarthquakeInfo">
<id property="earthquakeId" column="earthquake_id"/>
<result property="earthquakeName" column="earthquake_name"/>
<result property="magnitude" column="magnitude"/>
<result property="highIntensity" column="high_intensity"/>
<result property="longitude" column="longitude"/>
<result property="latitude" column="latitude"/>
<result property="depth" column="depth"/>
<result property="earthquakeTime" column="earthquake_time"/>
<collection property="intensityLineList" javaType="list" ofType="IntensityLine">
<id property="lineId" column="line_id"/>
<result property="longRadius" column="long_radius"/>
<result property="shortRadius" column="short_radius"/>
<result property="angle" column="angle"/>
<result property="intensity" column="intensity"/>
<result property="earthquakeId" column="earthquake_id"/>
</collection>
</resultMap>
<select id="getPopulation" resultType="double">
select avg(z) from population
where x>#{minLongitude} and x &lt;#{maxLongitude} and y>#{minLatitude} and y &lt; #{maxLatitude}
</select>
<select id="queryAnalyzeById" resultType="Estimate">
select predict_death,predict_economy,population
from estimate
where earthquake_id = #{earthquakeId}
</select>
<select id="queryAnalyze" resultType="int">
select count(*)
from estimate
where earthquake_id = #{earthquakeId}
</select>
</mapper>
Loading…
Cancel
Save