|
|
@ -4,7 +4,8 @@ import com.aliyun.tablestore.grid.consts.AttributionEnum;
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSet;
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSet;
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSetMeta;
|
|
|
|
import com.aliyun.tablestore.grid.model.GridDataSetMeta;
|
|
|
|
import com.aliyun.tablestore.grid.model.grid.Grid4D;
|
|
|
|
import com.aliyun.tablestore.grid.model.grid.Grid4D;
|
|
|
|
import com.htfp.weather.griddata.common.GfsVariableNameEnum;
|
|
|
|
import com.htfp.weather.griddata.common.GfsVariableHeightEnum;
|
|
|
|
|
|
|
|
import com.htfp.weather.griddata.common.GfsVariableIsobaricEnum;
|
|
|
|
import com.htfp.weather.griddata.common.TableConfigBean;
|
|
|
|
import com.htfp.weather.griddata.common.TableConfigBean;
|
|
|
|
import com.htfp.weather.griddata.operation.GfsDataFetcher;
|
|
|
|
import com.htfp.weather.griddata.operation.GfsDataFetcher;
|
|
|
|
import com.htfp.weather.griddata.operation.QueryMeta;
|
|
|
|
import com.htfp.weather.griddata.operation.QueryMeta;
|
|
|
@ -13,6 +14,7 @@ import com.htfp.weather.utils.DateTimeUtils;
|
|
|
|
import com.htfp.weather.utils.NdArrayUtils;
|
|
|
|
import com.htfp.weather.utils.NdArrayUtils;
|
|
|
|
import com.htfp.weather.web.exception.AppExcpetion;
|
|
|
|
import com.htfp.weather.web.exception.AppExcpetion;
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
import com.htfp.weather.web.exception.ErrorCode;
|
|
|
|
|
|
|
|
import com.htfp.weather.web.pojo.response.NowWeatherStatus;
|
|
|
|
import com.htfp.weather.web.pojo.response.PlaneResponse;
|
|
|
|
import com.htfp.weather.web.pojo.response.PlaneResponse;
|
|
|
|
import com.htfp.weather.web.pojo.response.ProfileResponse;
|
|
|
|
import com.htfp.weather.web.pojo.response.ProfileResponse;
|
|
|
|
import com.htfp.weather.web.pojo.response.TimeSeriesDataset;
|
|
|
|
import com.htfp.weather.web.pojo.response.TimeSeriesDataset;
|
|
|
@ -37,6 +39,7 @@ import java.util.stream.Collectors;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service("tablestore-gfs") @Slf4j
|
|
|
|
@Service("tablestore-gfs") @Slf4j
|
|
|
|
public class GfsDataServiceImpl implements IDataService {
|
|
|
|
public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
|
|
|
private static final int SURFACE_LEVEL = 9999;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
GfsDataFetcher gfsDataFetcher;
|
|
|
|
GfsDataFetcher gfsDataFetcher;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
@ -46,7 +49,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ProfileResponse getProfile(OffsetDateTime targetTime, String variableName, double latitude, double longitude) {
|
|
|
|
public ProfileResponse getProfile(OffsetDateTime targetTime, String variableName, double latitude, double longitude) {
|
|
|
|
String targetVariable = GfsVariableNameEnum.getGfsVariableName(variableName);
|
|
|
|
String targetVariable = GfsVariableIsobaricEnum.getGfsVariableName(variableName);
|
|
|
|
|
|
|
|
|
|
|
|
if (targetVariable == null) {
|
|
|
|
if (targetVariable == null) {
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
@ -58,12 +61,12 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int iTime = getTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLon = getLongitudeIndex(longitude);
|
|
|
|
int iLon = getLongitudeIndex(longitude);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String gridDataSetId = lastGridDataSetMeta.getGridDataSetId();
|
|
|
|
String gridDataSetId = lastGridDataSetMeta.getGridDataSetId();
|
|
|
|
int[] pressureLevels = tableConfigBean.getLevList();
|
|
|
|
int[] pressureLevels = tableConfigBean.getPressureList();
|
|
|
|
Array array = gfsDataFetcher.getProfile(gridDataSetId, targetVariable, iTime, iLat, iLon);
|
|
|
|
Array array = gfsDataFetcher.getProfile(gridDataSetId, targetVariable, iTime, iLat, iLon);
|
|
|
|
float[] values = (float[]) array.getStorage();
|
|
|
|
float[] values = (float[]) array.getStorage();
|
|
|
|
return new ProfileResponse(pressureLevels, values);
|
|
|
|
return new ProfileResponse(pressureLevels, values);
|
|
|
@ -73,52 +76,94 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TimeSeriesDataset getForecastSeries(double latitude, double longitude, int pressureLevel) {
|
|
|
|
public TimeSeriesDataset getForecastSeries(double latitude, double longitude, int level) {
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
Map<String, List> params = getFutureTimeIndexList(lastGridDataSetMeta);
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
List<Integer> iTimeList = params.get("iTimeList");
|
|
|
|
OffsetDateTime currentTime = DateTimeUtils.getUTCDateTime(OffsetDateTime.now());
|
|
|
|
List<String> timeList = params.get("timeList");
|
|
|
|
if (currentTime.isBefore(refTime)) {
|
|
|
|
int[] iTimes = iTimeList.stream().mapToInt(Integer::valueOf).toArray();
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
}
|
|
|
|
int iLon = getLongitudeIndex(longitude);
|
|
|
|
int startHour = getForecastHourFromTargetTime(currentTime, refTime);
|
|
|
|
int iLev = getLevelIndex(level);
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(level);
|
|
|
|
List<Integer> iTimeList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> timeList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < forecastHours.size(); i++) {
|
|
|
|
try {
|
|
|
|
int hour = Integer.parseInt(forecastHours.get(i));
|
|
|
|
String gridDataSetId = lastGridDataSetMeta.getGridDataSetId();
|
|
|
|
if (hour >= startHour) {
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getSeries(gridDataSetId, variableNames, iTimes, iLev, iLat, iLon);
|
|
|
|
iTimeList.add(i);
|
|
|
|
if (level == SURFACE_LEVEL) {
|
|
|
|
String timeStr = DateTimeUtils.getLocalZoneDateTime(refTime.plusHours(hour))
|
|
|
|
return buildTimeSeriesDatasetSurface(timeList, gridDataSet);
|
|
|
|
.format(DateTimeFormatter.ofPattern(Constant.API_TIME_STRING));
|
|
|
|
} else {
|
|
|
|
timeList.add(timeStr);
|
|
|
|
return buildTimeSeriesDatasetPressure(timeList, gridDataSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iTimeList.size() >= 24) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int[] iTimes = iTimeList.stream().mapToInt(Integer::valueOf).toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NowWeatherStatus getNowWeather(double latitude, double longitude, int level) {
|
|
|
|
|
|
|
|
GridDataSetMeta lastGridDataSetMeta = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
lastGridDataSetMeta = queryMeta.getLastGridDataSetMeta();
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int iTime = getTargetTimeIndex(OffsetDateTime.now(), lastGridDataSetMeta);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLat = getLatitudeIndex(latitude);
|
|
|
|
int iLon = getLongitudeIndex(longitude);
|
|
|
|
int iLon = getLongitudeIndex(longitude);
|
|
|
|
int iLev = getLevelIndex(pressureLevel);
|
|
|
|
int iLev = getLevelIndex(level);
|
|
|
|
List<String> variableNames = GfsVariableNameEnum.getVariableNamesInFile();
|
|
|
|
List<String> variableNames = getVariableNamesInDatabase(level);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
String gridDataSetId = lastGridDataSetMeta.getGridDataSetId();
|
|
|
|
String gridDataSetId = lastGridDataSetMeta.getGridDataSetId();
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getSeries(gridDataSetId, variableNames, iTimes, iLev, iLat, iLon);
|
|
|
|
GridDataSet gridDataSet = gfsDataFetcher.getSinglePoint(gridDataSetId, variableNames, iTime, iLev, iLat, iLon);
|
|
|
|
return buildTimeSeriesDataset(timeList, gridDataSet);
|
|
|
|
if (level == SURFACE_LEVEL) {
|
|
|
|
|
|
|
|
return buildNowWeatherSurface(gridDataSet);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return buildNowWeatherPressure(gridDataSet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getVariableNamesInDatabase(int level) {
|
|
|
|
|
|
|
|
List<String> variableNames = new ArrayList<>();
|
|
|
|
|
|
|
|
if (level == SURFACE_LEVEL) {
|
|
|
|
|
|
|
|
for (String e: tableConfigBean.getVariableList()){
|
|
|
|
|
|
|
|
String gfsVariableName = GfsVariableHeightEnum.getGfsVariableName(e);
|
|
|
|
|
|
|
|
if (gfsVariableName != null){
|
|
|
|
|
|
|
|
variableNames.add(gfsVariableName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
for (String e: tableConfigBean.getVariableList()){
|
|
|
|
|
|
|
|
String gfsVariableName = GfsVariableIsobaricEnum.getGfsVariableName(e);
|
|
|
|
|
|
|
|
if (gfsVariableName != null){
|
|
|
|
|
|
|
|
variableNames.add(gfsVariableName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return variableNames;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public PlaneResponse getPlane(OffsetDateTime targetTime, String variableName, int level, double minLat, double maxLat, double minLon, double maxLon) {
|
|
|
|
public PlaneResponse getPlane(OffsetDateTime targetTime, String variableName, int level, double minLat, double maxLat, double minLon, double maxLon) {
|
|
|
|
String targetVariable = GfsVariableNameEnum.getGfsVariableName(variableName);
|
|
|
|
int iLev;
|
|
|
|
|
|
|
|
String targetVariable;
|
|
|
|
|
|
|
|
if (level == SURFACE_LEVEL) {
|
|
|
|
|
|
|
|
iLev = 0; // NOTE 2024/5/20: 0 表示地面,风速对应10m高度,其他变量对应2m高度
|
|
|
|
|
|
|
|
targetVariable = GfsVariableHeightEnum.getGfsVariableName(variableName);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
iLev = getPressureIndex(level);
|
|
|
|
|
|
|
|
targetVariable = GfsVariableIsobaricEnum.getGfsVariableName(variableName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (targetVariable == null) {
|
|
|
|
if (targetVariable == null) {
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
|
throw new AppExcpetion(ErrorCode.VALIDATE_ERROR, variableName + "变量在数据库中不存在");
|
|
|
@ -130,8 +175,7 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
throw new AppExcpetion(ErrorCode.DATA_SET_EMPTY, ": e.getMessage()");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int iTime = getTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iTime = getTargetTimeIndex(targetTime, lastGridDataSetMeta);
|
|
|
|
int iLev = getLevelIndex(level);
|
|
|
|
|
|
|
|
int iMinLat = getLatitudeIndex(minLat);
|
|
|
|
int iMinLat = getLatitudeIndex(minLat);
|
|
|
|
int iMaxLat = getLatitudeIndex(maxLat);
|
|
|
|
int iMaxLat = getLatitudeIndex(maxLat);
|
|
|
|
int iMinLon = getLongitudeIndex(minLon);
|
|
|
|
int iMinLon = getLongitudeIndex(minLon);
|
|
|
@ -159,30 +203,92 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
return planeResponse;
|
|
|
|
return planeResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TimeSeriesDataset buildTimeSeriesDataset(List<String> timeList, GridDataSet gridDataSet) {
|
|
|
|
private TimeSeriesDataset buildTimeSeriesDatasetPressure(List<String> timeList, GridDataSet gridDataSet) {
|
|
|
|
TimeSeriesDataset timeSeriesDataset = new TimeSeriesDataset(timeList.size());
|
|
|
|
TimeSeriesDataset timeSeriesDataset = new TimeSeriesDataset(timeList.size());
|
|
|
|
timeSeriesDataset.setTime(timeList);
|
|
|
|
timeSeriesDataset.setTime(timeList);
|
|
|
|
Grid4D grid4D;
|
|
|
|
Grid4D grid4D;
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableNameEnum.getGfsVariableName(GfsVariableNameEnum.TEMP));
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.TEMP));
|
|
|
|
if (grid4D != null) {
|
|
|
|
if (grid4D != null) {
|
|
|
|
timeSeriesDataset.setTemp((float[]) grid4D.toArray().getStorage());
|
|
|
|
timeSeriesDataset.setTemp((float[]) grid4D.toArray().getStorage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableNameEnum.getGfsVariableName(GfsVariableNameEnum.WIND_SPEED));
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.WIND_SPEED));
|
|
|
|
if (grid4D != null) {
|
|
|
|
if (grid4D != null) {
|
|
|
|
timeSeriesDataset.setWindSpeed((float[]) grid4D.toArray().getStorage());
|
|
|
|
timeSeriesDataset.setWindSpeed((float[]) grid4D.toArray().getStorage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableNameEnum.getGfsVariableName(GfsVariableNameEnum.WIND360));
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.WIND360));
|
|
|
|
if (grid4D != null) {
|
|
|
|
if (grid4D != null) {
|
|
|
|
timeSeriesDataset.setWind360((float[]) grid4D.toArray().getStorage());
|
|
|
|
timeSeriesDataset.setWind360((float[]) grid4D.toArray().getStorage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableNameEnum.getGfsVariableName(GfsVariableNameEnum.CLOUD));
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.CLOUD));
|
|
|
|
if (grid4D != null) {
|
|
|
|
if (grid4D != null) {
|
|
|
|
timeSeriesDataset.setCloud((float[]) grid4D.toArray().getStorage());
|
|
|
|
timeSeriesDataset.setCloud((float[]) grid4D.toArray().getStorage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return timeSeriesDataset;
|
|
|
|
return timeSeriesDataset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getTimeIndex(OffsetDateTime targetTime, GridDataSetMeta lastGridDataSetMeta) {
|
|
|
|
private TimeSeriesDataset buildTimeSeriesDatasetSurface(List<String> timeList, GridDataSet gridDataSet) {
|
|
|
|
|
|
|
|
TimeSeriesDataset timeSeriesDataset = new TimeSeriesDataset(timeList.size());
|
|
|
|
|
|
|
|
timeSeriesDataset.setTime(timeList);
|
|
|
|
|
|
|
|
Grid4D grid4D;
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.TEMP));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
timeSeriesDataset.setTemp((float[]) grid4D.toArray().getStorage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.WIND_SPEED));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
timeSeriesDataset.setWindSpeed((float[]) grid4D.toArray().getStorage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.WIND360));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
timeSeriesDataset.setWind360((float[]) grid4D.toArray().getStorage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeSeriesDataset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NowWeatherStatus buildNowWeatherPressure(GridDataSet gridDataSet) {
|
|
|
|
|
|
|
|
String timeStr = OffsetDateTime.now().withMinute(0).withNano(0).format(DateTimeFormatter.ofPattern(Constant.API_TIME_STRING));
|
|
|
|
|
|
|
|
NowWeatherStatus nowWeatherStatus = new NowWeatherStatus();
|
|
|
|
|
|
|
|
nowWeatherStatus.setTime(timeStr);
|
|
|
|
|
|
|
|
Grid4D grid4D;
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.TEMP));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setTemp(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.WIND_SPEED));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setWindSpeed(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.WIND360));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setWind360(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableIsobaricEnum.getGfsVariableName(GfsVariableIsobaricEnum.CLOUD));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setCloud(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nowWeatherStatus;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NowWeatherStatus buildNowWeatherSurface(GridDataSet gridDataSet) {
|
|
|
|
|
|
|
|
String timeStr = OffsetDateTime.now().withMinute(0).withNano(0).format(DateTimeFormatter.ofPattern(Constant.API_TIME_STRING));
|
|
|
|
|
|
|
|
NowWeatherStatus nowWeatherStatus = new NowWeatherStatus();
|
|
|
|
|
|
|
|
nowWeatherStatus.setTime(timeStr);
|
|
|
|
|
|
|
|
Grid4D grid4D;
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.TEMP));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setTemp(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.WIND_SPEED));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setWindSpeed(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
grid4D = gridDataSet.getVariable(GfsVariableHeightEnum.getGfsVariableName(GfsVariableHeightEnum.WIND360));
|
|
|
|
|
|
|
|
if (grid4D != null) {
|
|
|
|
|
|
|
|
nowWeatherStatus.setWind360(((float[]) grid4D.toArray().getStorage())[0]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nowWeatherStatus;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getTargetTimeIndex(OffsetDateTime targetTime, GridDataSetMeta lastGridDataSetMeta) {
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
if (targetTime.isBefore(refTime)) {
|
|
|
|
if (targetTime.isBefore(refTime)) {
|
|
|
@ -198,6 +304,38 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
return iTime;
|
|
|
|
return iTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, List> getFutureTimeIndexList(GridDataSetMeta lastGridDataSetMeta) {
|
|
|
|
|
|
|
|
long milli = (long) lastGridDataSetMeta.getAttributes().get(AttributionEnum.REFERENCE_TIME.getName());
|
|
|
|
|
|
|
|
OffsetDateTime refTime = OffsetDateTime.ofInstant(Instant.ofEpochMilli(milli), ZoneOffset.ofHours(0));
|
|
|
|
|
|
|
|
OffsetDateTime currentTime = DateTimeUtils.getUTCDateTime(OffsetDateTime.now());
|
|
|
|
|
|
|
|
if (currentTime.isBefore(refTime)) {
|
|
|
|
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int startHour = getForecastHourFromTargetTime(currentTime, refTime);
|
|
|
|
|
|
|
|
List<String> forecastHours = lastGridDataSetMeta.getForecastHours();
|
|
|
|
|
|
|
|
List<Integer> iTimeList = new ArrayList<>();
|
|
|
|
|
|
|
|
List<String> timeList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < forecastHours.size(); i++) {
|
|
|
|
|
|
|
|
int hour = Integer.parseInt(forecastHours.get(i));
|
|
|
|
|
|
|
|
if (hour >= startHour) {
|
|
|
|
|
|
|
|
iTimeList.add(i);
|
|
|
|
|
|
|
|
String timeStr = DateTimeUtils.getLocalZoneDateTime(refTime.plusHours(hour))
|
|
|
|
|
|
|
|
.format(DateTimeFormatter.ofPattern(Constant.API_TIME_STRING));
|
|
|
|
|
|
|
|
timeList.add(timeStr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iTimeList.size() >= 24) {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(iTimeList) || CollectionUtils.isEmpty(timeList)) {
|
|
|
|
|
|
|
|
throw new AppExcpetion(ErrorCode.QUERY_TIME_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, List> map = new HashMap<>(2);
|
|
|
|
|
|
|
|
map.put("iTimeList", iTimeList);
|
|
|
|
|
|
|
|
map.put("timeList", timeList);
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
}
|
|
|
|
private int getLongitudeIndex(double lon) {
|
|
|
|
private int getLongitudeIndex(double lon) {
|
|
|
|
double[] lonList = tableConfigBean.getLonList();
|
|
|
|
double[] lonList = tableConfigBean.getLonList();
|
|
|
|
if (lonList.length == 0) {
|
|
|
|
if (lonList.length == 0) {
|
|
|
@ -233,12 +371,24 @@ public class GfsDataServiceImpl implements IDataService {
|
|
|
|
return nearestIndex;
|
|
|
|
return nearestIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getLevelIndex(int pressureLevel) {
|
|
|
|
private int getPressureIndex(int pressureLevel) {
|
|
|
|
List<Integer> levList = Arrays.stream(tableConfigBean.getLevList()).boxed().collect(Collectors.toList());
|
|
|
|
List<Integer> levList = Arrays.stream(tableConfigBean.getPressureList()).boxed().collect(Collectors.toList());
|
|
|
|
if (CollectionUtils.isEmpty(levList)) {
|
|
|
|
if (CollectionUtils.isEmpty(levList)) {
|
|
|
|
throw new AppExcpetion(ErrorCode.LEVEL_INDEX_ERROR, "经度列表为空, 无法查找索引");
|
|
|
|
throw new AppExcpetion(ErrorCode.LEVEL_INDEX_ERROR, "气压列表为空, 无法查找索引");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = levList.indexOf(pressureLevel);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
|
|
throw new AppExcpetion(ErrorCode.LATITUDE_INDEX_ERROR, "找不到" + pressureLevel + "的气压高度索引");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getLevelIndex(int level) {
|
|
|
|
|
|
|
|
if (level == SURFACE_LEVEL) {
|
|
|
|
|
|
|
|
return 0; // NOTE 2024/5/20: 0 表示地面,风速对应10m高度,其他变量对应2m高度
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return getPressureIndex(level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return levList.indexOf(pressureLevel);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getForecastHourFromTargetTime(OffsetDateTime targetTime, OffsetDateTime refTime) {
|
|
|
|
private int getForecastHourFromTargetTime(OffsetDateTime targetTime, OffsetDateTime refTime) {
|
|
|
|