fo: 지하수 유입량 추정
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getFetch } from "@/app/components/api";
|
||||
import { getFetch, postFetch } from "@/app/components/api";
|
||||
import DataForm, { roundNumber } from "@/app/components/common/DataForm";
|
||||
import type { TableUpperProps } from "../dashboard";
|
||||
import type { ExcelType, UnderWaterInputModalProps, UnderWaterProps } from "./types";
|
||||
@@ -203,11 +203,22 @@ const fetchUnderWaterList = async (pageNo: number, pageSize: number, searchYear:
|
||||
//return { data: underWaterList, count: 2 };
|
||||
}*/
|
||||
|
||||
const fetchUnderWaterListFlow = async(fcltyCd : string, searchYear : string) => {
|
||||
const url = '/fclt/flow/' + fcltyCd + '/' + searchYear;
|
||||
const res = await getFetch('fo', url);
|
||||
return res;
|
||||
}
|
||||
// const fetchUnderWaterListFlow = async(fcltyCd : string, searchYear : string) => {
|
||||
// const url = '/fclt/flow/' + fcltyCd + '/' + searchYear;
|
||||
// const res = await getFetch('fo', url);
|
||||
// return res;
|
||||
// }
|
||||
|
||||
// 시설들 유량 정보 조회
|
||||
export const fetchDetailListFlow = async (searchYear: string|undefined, fcltCdList: string[]): Promise<UnderWaterProps | null> => {
|
||||
try {
|
||||
const res = await postFetch('fo', '/fclt/flow/'+searchYear, fcltCdList);
|
||||
return res;
|
||||
} catch (error) {
|
||||
console.error('시설정보 오수발생량 상세 데이터를 가져오는데 실패했습니다:', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**====================================
|
||||
* Store - expaort
|
||||
@@ -274,15 +285,15 @@ const dataFormSetting=(item : UnderWaterProps)=> {
|
||||
}
|
||||
|
||||
// 병렬 처리 제한용 헬퍼
|
||||
async function processInBatches(items, batchSize, callback) {
|
||||
const results :any = [];
|
||||
for (let i = 0; i < items.length; i += batchSize) {
|
||||
const batch = items.slice(i, i + batchSize);
|
||||
const batchResults = await Promise.all(batch.map(callback));
|
||||
results.push(...batchResults);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
// async function processInBatches(items, batchSize, callback) {
|
||||
// const results :any = [];
|
||||
// for (let i = 0; i < items.length; i += batchSize) {
|
||||
// const batch = items.slice(i, i + batchSize);
|
||||
// const batchResults = await Promise.all(batch.map(callback));
|
||||
// results.push(...batchResults);
|
||||
// }
|
||||
// return results;
|
||||
// }
|
||||
|
||||
export type UnderWaterStore = UnderWaterType & UnderWaterActions;
|
||||
|
||||
@@ -313,68 +324,100 @@ export const underWaterReducer:(set:(fn: (state: UnderWaterType) => UnderWaterTy
|
||||
}
|
||||
|
||||
const fcltylist = facilityInitData.data;
|
||||
|
||||
const calData = await processInBatches(fcltylist, 20, async (item: any, index: number) => {
|
||||
const bscFctCd = item.bscFctCd;
|
||||
const res = await fetchUnderWaterListFlow(bscFctCd, searchYear).catch((error) => {
|
||||
console.log('Error fetching flow data for facility code:', bscFctCd, error);
|
||||
return { data: [], count: 0 }; // 에러 발생 시 빈 데이터 반환
|
||||
const fcltCdList : string[] = []; // 시설코드목록
|
||||
const underWaterPropsList : UnderWaterProps[] = []; // 오수발생량시설목록
|
||||
fcltylist.forEach(item => {
|
||||
fcltCdList.push(item.bscFctCd);
|
||||
underWaterPropsList.push({
|
||||
bscFctCd : item.bscFctCd,
|
||||
sidoNm : item.sido,
|
||||
sggNm : item.gugun,
|
||||
lclgvrnmntNm : '',
|
||||
bscFctNm : item.bscFctNm,
|
||||
daddr : item.daddr,
|
||||
fctCpc : parseFloat(item.fctCpc.toString().replace(/,/g, '')),
|
||||
inflAmnt : 0,
|
||||
waterUsage : 0,
|
||||
underWaterInputYear : 0,
|
||||
underWaterInputSummer : 0,
|
||||
underWaterInputWinter : 0,
|
||||
properYn : '',
|
||||
infoRnDay : 0,
|
||||
rgnNm : item.rgnNm,
|
||||
rvbsn : item.rvbsn,
|
||||
lgbsn : item.lgbsn,
|
||||
mdmbsn : item.mdmbsn,
|
||||
msrDt : '',
|
||||
});
|
||||
|
||||
item.sidoNm = item.sido || '';
|
||||
item.sggNm = item.gugun || '';
|
||||
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
|
||||
});
|
||||
|
||||
const soccurDetailRes : any = await fetchDetailListFlow(searchYear, fcltCdList);
|
||||
|
||||
for (const item of underWaterPropsList) {
|
||||
|
||||
let chungcunSumFlow = 0;
|
||||
const detailList = soccurDetailRes?.data[item.bscFctCd]
|
||||
|
||||
let chungcunSumFlow = 0; // 청천유입량
|
||||
let sumChungcunDay = 0; // 청천일수
|
||||
let sumSummerChungcunDay = 0; // 하절기 청천일수
|
||||
let sumSummerChungcunFlow = 0; // 하절기 청천유입량
|
||||
|
||||
let sumSummerChungcunDay = 0;
|
||||
let sumSummerChungcunFlow = 0;
|
||||
let sumWinterChungcunDay = 0; // 동절기 청천일수
|
||||
let sumWinterChungcunFlow = 0; // 동절기 청천유입량
|
||||
let totWaterUsage = 0; // 연간 하수유입량
|
||||
detailList?.forEach(item2 => {
|
||||
|
||||
let sumWinterChungcunDay = 0;
|
||||
let sumWinterChungcunFlow = 0;
|
||||
|
||||
const rainEffectData = CalcRainEffect(res.data, 'SUNNY');
|
||||
rainEffectData.forEach((flowItem: FlowDataItem) => {
|
||||
chungcunSumFlow += flowItem.inflAmnt && flowItem.inflAmnt !== 'x' ? Number(flowItem.inflAmnt.toString().trim()) : 0;
|
||||
|
||||
if(flowItem.msrDt.substring(4,6) ==='06' || flowItem.msrDt.substring(4,6) ==='07' || flowItem.msrDt.substring(4,6) ==='08'){
|
||||
sumSummerChungcunDay += 1;
|
||||
sumSummerChungcunFlow += flowItem.inflAmnt && flowItem.inflAmnt !== 'x' ? Number(flowItem.inflAmnt.toString().trim()) : 0;
|
||||
}else if(flowItem.msrDt.substring(4,6) ==='01' || flowItem.msrDt.substring(4,6) ==='02'){
|
||||
sumWinterChungcunDay += 1;
|
||||
sumWinterChungcunFlow += flowItem.inflAmnt && flowItem.inflAmnt !== 'x' ? Number(flowItem.inflAmnt.toString().trim()) : 0;
|
||||
let rainEffectDay = 0;
|
||||
if (item2.infoRnDay == null) item2.infoRnDay = 0;
|
||||
if(item2.infoRnDay >= 3) {
|
||||
rainEffectDay = 2;
|
||||
}else{
|
||||
rainEffectDay--;
|
||||
}
|
||||
if(rainEffectDay<0){ //청천시
|
||||
chungcunSumFlow += Number(item2.inflAmnt);
|
||||
sumChungcunDay += 1;
|
||||
|
||||
if(item2.msrDt.substring(4,6) ==='06' || item2.msrDt.substring(4,6) ==='07' || item2.msrDt.substring(4,6) ==='08'){
|
||||
// 하절기 6,7,8월
|
||||
sumSummerChungcunDay += 1;
|
||||
sumSummerChungcunFlow += Number(item2.inflAmnt); //item2.inflAmnt && item2.inflAmnt !== 'x' ? Number(item2.inflAmnt.toString().trim()) : 0;
|
||||
}else if(item2.msrDt.substring(4,6) ==='01' || item2.msrDt.substring(4,6) ==='02'){
|
||||
// 동절기 1,2월
|
||||
sumWinterChungcunDay += 1;
|
||||
sumWinterChungcunFlow += Number(item2.inflAmnt); //item2.inflAmnt && item2.inflAmnt !== 'x' ? Number(item2.inflAmnt.toString().trim()) : 0;
|
||||
}
|
||||
}
|
||||
totWaterUsage += Number(item2.inflAmnt);
|
||||
});
|
||||
|
||||
let totWaterInflow = 0
|
||||
const count = detailList ? detailList.length : 0;
|
||||
const avg = count == 0 ? 0 : totWaterUsage / count; // 일평균 유입량
|
||||
// 지하수 유입량 추정에는 수용가의 물사용량을 사용할 수 없음 : 청천시의 물사용량을 구하여야 하기 때문임.
|
||||
// if(wtrUsgMap && wtrUsgMap[item.bscFctCd]) {
|
||||
// item.waterUsage = wtrUsgMap[item.bscFctCd] ?? 0;
|
||||
// } else {item.waterUsage = parseFloat((avg * 0.65).toFixed(2));} // 물사용량 = 일평균 유입량 * 65%
|
||||
|
||||
const rainEffectTot = CalcRainEffect(res.data);
|
||||
rainEffectTot.forEach((flowItem: FlowDataItem) => {
|
||||
totWaterInflow += flowItem.inflAmnt && flowItem.inflAmnt !== 'x' ? Number(flowItem.inflAmnt.toString().trim()) : 0;
|
||||
});
|
||||
|
||||
|
||||
const avg = res.count === 0 ? 0 : totWaterInflow / res.count;
|
||||
|
||||
const usage = chungcunSumFlow&&chungcunSumFlow>0?chungcunSumFlow / rainEffectData.length:0;
|
||||
const usage = chungcunSumFlow&&chungcunSumFlow>0?chungcunSumFlow / sumChungcunDay:0;
|
||||
const summerUsage = sumSummerChungcunFlow?sumSummerChungcunFlow / sumSummerChungcunDay:0;
|
||||
const winterUsage = sumWinterChungcunFlow?sumWinterChungcunFlow / sumWinterChungcunDay:0;
|
||||
|
||||
|
||||
item.inflAmnt = roundNumber(avg, 0);
|
||||
item.underWaterInputYear = Math.round((usage-(usage*0.65*OSU_PERCENT)) * 1) / 1;
|
||||
item.underWaterInputSummer = Math.round((summerUsage-(summerUsage*0.65*OSU_PERCENT)) * 1) / 1;
|
||||
item.underWaterInputWinter = Math.round((winterUsage-(winterUsage*0.65*OSU_PERCENT)) * 1) / 1;
|
||||
item.properYn = Math.round( (Number(usage-(usage*0.65*OSU_PERCENT)) / Number(item.inflAmnt)) * 100 * 1 ) / 1 > 20?'초과유입':'적정';
|
||||
return {...item, index:index};
|
||||
});
|
||||
item.underWaterInputYear = Math.round((usage-(usage*0.65*OSU_PERCENT)) * 1) / 1; // 연간지하수유입량(m³/일)
|
||||
item.underWaterInputSummer = Math.round((summerUsage-(summerUsage*0.65*OSU_PERCENT)) * 1) / 1; // 하절기지하수유입량(m³/일)
|
||||
item.underWaterInputWinter = Math.round((winterUsage-(winterUsage*0.65*OSU_PERCENT)) * 1) / 1; // 동절기지하수유입량(m³/일)
|
||||
item.properYn = Math.round( (Number(usage-(usage*0.65*OSU_PERCENT)) / Number(item.inflAmnt)) * 100 * 1 ) / 1 > 20?'초과유입':'적정'; // 적정여부
|
||||
// 반올림 처리
|
||||
// ["fctCpc", "inflAmnt", "underWaterInputYear", "underWaterInputSummer", "underWaterInputWinter"].forEach(
|
||||
// (key) => (item[key] = roundNumber(item[key], 0))
|
||||
// );
|
||||
}
|
||||
|
||||
if(pageSize>= 5000){
|
||||
const excelDownList: ExcelType[] = [];
|
||||
calData.forEach((item : any) => {
|
||||
underWaterPropsList.forEach((item : any) => {
|
||||
dataFormSetting(item)
|
||||
item.fctCpc = parseFloat(item.fctCpc.toString().replace(/,/g, ''));
|
||||
/* item.sidoNm = item.lclgvrnmntNm.split(' ')[0]?.toString() || '';
|
||||
item.sggNm = item.lclgvrnmntNm.split(' ')[1]?.toString() || ''; */
|
||||
excelDownList.push({
|
||||
시설코드: item.bscFctCd,
|
||||
권역: item.rvbsn,
|
||||
@@ -406,7 +449,7 @@ export const underWaterReducer:(set:(fn: (state: UnderWaterType) => UnderWaterTy
|
||||
...state,
|
||||
UnderWater: {
|
||||
...state.UnderWater,
|
||||
underWaterList: calData,
|
||||
underWaterList: underWaterPropsList,
|
||||
underWaterCount: facilityInitData.count,
|
||||
excelList: [],
|
||||
isLoading : false,
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
export type UnderWaterProps = {
|
||||
bscFctCd : string,
|
||||
bscFctCd : string, // 처리구역시설코드
|
||||
lclgvrnmntNm : string,
|
||||
sidoNm : string,
|
||||
sggNm : string,
|
||||
bscFctNm : string,
|
||||
daddr : string,
|
||||
fctCpc : number,
|
||||
underWaterInputYear : number,
|
||||
underWaterInputSummer : number,
|
||||
underWaterInputWinter : number,
|
||||
sidoNm : string, // 시도
|
||||
sggNm : string, // 시군구
|
||||
bscFctNm : string, // 시설명
|
||||
daddr : string, // 주소
|
||||
fctCpc : number, // 시설용량
|
||||
waterUsage : number, // 물사용량(m³/일)
|
||||
underWaterInputYear : number, // 연간 지하수유입량 추정(m³/일)
|
||||
underWaterInputSummer : number, // 하절기 지하수유입량 추정(m³/일)
|
||||
underWaterInputWinter : number, // 동절기 지하수유입량 추정(m³/일)
|
||||
infoRnDay : number,
|
||||
rgnNm : string,
|
||||
rvbsn : string,
|
||||
lgbsn : string,
|
||||
mdmbsn : string,
|
||||
inflAmnt : number | '',
|
||||
properYn : string | '',
|
||||
inflAmnt : number, // 연평균유입하수량(m³/일)
|
||||
properYn : string | '', // 적정여부
|
||||
msrDt : string, // 측정일자
|
||||
}
|
||||
export interface UnderWaterInterface {
|
||||
bscFctCd : string,
|
||||
|
||||
Reference in New Issue
Block a user