Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
7.9 kB
1
Indexable
Never
public void checkAndSetAllParams() throws CalculateAnalysisException{
		Config cfg = CalculateAnalysisRPC.getCfg();
		this.mapTitle = cfg.mapTitle;
		checkRequiredParams();
		setStationIDsList();
		setCurrentProfile(cfg);
		checkCldbSources();
		setMapName();
		checkFunction();
		setCldbVariables();
		setCurrentColorGradient();
		if(requestResults.contains(CalculateAnalysisRPC.RESULT_ACTUAL) || requestResults.contains(CalculateAnalysisRPC.RESULT_ACTUAL_VS_HISTORY) || requestResults.contains(CalculateAnalysisRPC.RESULT_ACTUAL_VS_NORMAL)){
			actualTimeReference = new TimeReference(this, CalculateAnalysisRPC.RESULT_ACTUAL);
			if(funct.equals(CalculateAnalysisRPC.FUN_SPI)){
				if(!TermInterval.TERM_MONTHYEARINTERVAL.equals(selectedTermInterval.term) //v tomto pripade by bol timeRangeUnit = YEAR, ale jednem mesiac pre N rokov nepodporujeme
						&& (actualTimeReference.timeRangeUnit.equals(CodeTable4.MONTH) || actualTimeReference.timeRangeUnit.equals(CodeTable4.YEAR))){
					Integer scaleN;
					if(actualTimeReference.timeRangeUnit.equals(CodeTable4.YEAR)){
						scaleN = actualTimeReference.periodOfTime * 12;
					}else{
						scaleN = actualTimeReference.periodOfTime;
					}
					actualStationsData = DBDataRPC.getMapSPIStationsData(stationIDsList, variables.varIDsList, currentProfile.sources, toTime, scaleN);
				}else{
					throw new CalculateAnalysisException("Not supported time range for SPI.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_05)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.8);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod05.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_10)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.9);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod10.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_25)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.96);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod25.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_50)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.98);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod50.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_75)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.98666);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod75.");
				}
			}
			else if (funct.equals(CalculateAnalysisRPC.FUN_RETURNPERIOD_100)) {
				if(TermInterval.TERM_YEARINTERVAL.equals(selectedTermInterval.term) && TermInterval.PERIOD_YEAR.equals(selectedTermInterval.period)){
					actualStationsData = DBDataRPC.getMapPeriodStationsData(stationIDsList, variables.varIDsList, 0.99);
				}
				else {
					throw new CalculateAnalysisException("Not supported time range for ReturnPeriod100.");
				}
			}
			else{
				try {
					if(TermInterval.TERM_MONTHYEARINTERVAL.equals(selectedTermInterval.term)){
						JTime jt = JTime.getDefault();
						oneMonth = jt.format(fromTime, "MM");
					}
					actualStationsData = DBDataRPC.getMapStationsData( (ArrayList<Integer>)stationIDsList, variables.varIDsList , fromTime, toTime, currentProfile.sources, funct, timeZone, oneMonth);
				} catch (SQLException e) {
					throw new CalculateAnalysisException("Cannot read actual data from database.", e);
				}
			}
			if(actualStationsData==null){
				throw new CalculateAnalysisException("Cannot read actual data from database.");
			}
		}
		if(requestResults.contains(CalculateAnalysisRPC.RESULT_HISTORY) || requestResults.contains(CalculateAnalysisRPC.RESULT_ACTUAL_VS_HISTORY) || requestResults.contains(CalculateAnalysisRPC.RESULT_NORMAL_VS_HISTORY)){
			historyTimeReference = new TimeReference(this, CalculateAnalysisRPC.RESULT_HISTORY);
			try {
				historyStationsData = DBDataRPC.getMapStationsHistoryData((ArrayList<Integer>)stationIDsList, variables.varIDsList, (ArrayList<Integer>)histDateTime.getYearList(), (ArrayList<Integer>)histDateTime.getMonthsList(), 
						(ArrayList<Integer>)histDateTime.getDaysList(), (ArrayList<Integer>)histDateTime.getHoursList(), (ArrayList<Integer>)histDateTime.getMinutesList() , (ArrayList<Integer>)histDateTime.getSecondsList(),
						currentProfile.sources, funct, timeZone);
			} catch (SelectException e) {
				throw new CalculateAnalysisException(e.getMessage(), e);
			}
			if(historyStationsData==null){
				throw new CalculateAnalysisException("Cannot read history data from database.");
			}
		}
		if(requestResults.contains(CalculateAnalysisRPC.RESULT_NORMAL) || requestResults.contains(CalculateAnalysisRPC.RESULT_NORMAL_VS_HISTORY) || requestResults.contains(CalculateAnalysisRPC.RESULT_ACTUAL_VS_NORMAL)){
			setAndCheckNormalVariablesAndFunction();
			normalPeriod = NormalsRPC.getNormalPeriod(normalParams.periodId);
			if(normalPeriod==null){
				throw new CalculateAnalysisException("Fail to get normal period from DB.");
			}
			normalTimeReference = new TimeReference(this, CalculateAnalysisRPC.RESULT_NORMAL);
			if(NormalsRPC.ANNUAL_NORMAL.equals(normalParams.type)){
				normalStationsData = NormalsRPC.getAnnualMapStationsData(stationIDsList, normalVariables.varIDsList, normalParams.periodId, funct);
			}else{
				if(NormalsRPC.MONTHLY_NORMAL.equals(normalParams.type)){
					List<Integer> months = new ArrayList<Integer>();
					months.add(normalParams.month);
					normalStationsData = NormalsRPC.getMonthlyMapStationsData(stationIDsList, normalVariables.varIDsList, normalParams.periodId, months, funct);
				}else{
					if(NormalsRPC.DAILY_NORMAL.equals(normalParams.type)){
						//TODO:
					}else{
						throw new CalculateAnalysisException("Unsupported Normal Type");
					}
				}
			}
			if(normalStationsData==null){
				throw new CalculateAnalysisException("Cannot read normal data from database.");
			}
		}
		if(requestResults.contains(CalculateAnalysisRPC.RESULT_PERCENTILE)){
			if(percentile==null){
				throw new CalculateAnalysisException("Requested Percentile, but missing percentile parameters.");
			}
			percentile.checkAndSetAllParams();
			percentile.timeReference = new TimeReference(this, CalculateAnalysisRPC.RESULT_PERCENTILE);
			percentile.stationsData = DBDataRPC.getMapPercentileStationsData(stationIDsList, variables.varIDsList, percentile.fromTime, percentile.toTime, currentProfile.sources, funct, percentile.rank, percentile.getPeriodType());
			if(percentile.stationsData==null){
				throw new CalculateAnalysisException("Cannot read percentile data from database.");
			}
		}
	}