데이터 다운
1. 접속
사이트 : https://www.kwater.or.kr/website/tlight/bbs/BBSMSTR_000000000026/lst.do
알림마당>주간운영계획
Total : 500 [1/50]
www.kwater.or.kr
2. 원하는 일자 선택
3. 엑셀 파일 다운
데이터 구성 & 주의 사항
- 1파일 당 7일 data
- 총 3개의 수문
- 각 수문별 개폐시간
- 각 수문에서 종료시각: 24:00, 시작시각: 00:00 인 경우 두 일자를 붙일 수 있도록 조정
- 시화배수갑문 경우 주수문과 동일한 시간에 개/폐되는 경우 데이터 값이 누락되어 있으니 참고
- 엑셀 입력시, 각 일별로 개폐수가 가장 많은 수문을 기준으로 일별 데이터 수직 길이 설정
코드구성
1. siwha_power_plant
- 날짜, 갑문 개폐 데이터 추출
- 목표 양식 형태로 편집
2. remove_error
- 결과값을 출력하면서 생기는 에러 수정
코드
1. siwha_power_plant
clc; clear; close all;
%% sihwa power plant data extract code %%
% d.o : original data
% d.p_1 : slice
% d.p_2 : table -> cell
% d.p_3 : edit format
% d.time_1 -> 2 : str -> num
% d.all : cell -> double
% d.week : rearrangement
year=[];
%% inp.input control
inp.month = 1:12;
inp.year = 2022;
inp.output = 'output';
if isfolder(inp.output) == 0
mkdir(inp.output)
end
for mm = inp.month
inp.input = ['01__시화호_조력발전소_운영계획/01__Raw_data/',num2str(inp.year),'/',num2str(mm,'%02d')];
%% route
f.list = dir([inp.input,'/*.xlsx']);
f.name = char(f.list.name);
%% load data
for ww = 1:length(f.list)
d.o = readtable([inp.input,'/',f.name(ww,:)]);
d.p_1 = d.o(3:end-1,3:7);
d.p_2 = table2cell(d.p_1);
% make simple
d.p_3 = d.p_2(:,[1,3:5]);
for ii = 1:length(d.p_2)
if isempty(d.p_2{ii,3})
d.p_3(ii,2) = d.p_2(ii,2);
end
end
%% process data
% fill empty value
for ii = 1:length(d.p_3)
switch d.p_3{ii,2}
case '시화배수갑문'
if isempty(d.p_3{ii,3})
d.p_3(ii,3) = d.p_3(ii-1,3);
end
if isempty(d.p_3{ii,4})
d.p_3(ii,4) = d.p_3(ii-1,4);
end
end
end
% split time data
for ii = 1:length(d.p_3)
for jj = 1:2
if length(d.p_3{ii,jj+2}) > 5
d.time_1(ii,jj*2-1:jj*2) = strsplit(d.p_3{ii,jj+2}(1:5),':');
else
d.time_1(ii,jj*2-1:jj*2) = strsplit(d.p_3{ii,jj+2},':');
end
end
end
% trans str to num
d.time_2 = cellfun(@str2num,d.time_1,'UniformOutput',false);
% devide each case
for ii = 1:length(d.p_3)
if isempty(d.p_3{ii,1}) == 0
d.date1 = d.p_3{ii,1}(1:10);
d.date2 = datevec(d.date1,'yyyy-mm-dd');
d.all(ii,1:3) = num2cell(d.date2(1:3));
end
switch d.p_3{ii,2}
case '발전'
d.all(ii,12:15) = d.time_2(ii,:);
case '주수문'
d.all(ii,4:7) = d.time_2(ii,:);
case '시화배수갑문'
d.all(ii,8:11) = d.time_2(ii,:);
end
end
[tp.v,tp.h] = size(d.all);
% cell -> double
tp.frame_1 = nan(tp.v,tp.h);
for ii = 1:tp.v
for jj = 1:tp.h
if isempty(d.all{ii,jj})==0
tp.frame_1(ii,jj) = d.all{ii,jj};
end
end
end
% make time list
tp.date_index = find(isnan(tp.frame_1(:,1))==0);
tp.date_index = vertcat(tp.date_index,tp.v);
% make frame & insert data
d.week=[];
for ii = 2:length(tp.date_index)
if ii == length(tp.date_index)
tp.a = tp.date_index(ii-1):tp.date_index(ii);
else
tp.a = tp.date_index(ii-1):tp.date_index(ii)-1;
end
tp.case_1 = rmmissing(tp.frame_1(tp.a,4:7));
tp.case_2 = rmmissing(tp.frame_1(tp.a,8:11));
tp.case_3 = rmmissing(tp.frame_1(tp.a,12:15));
m = max([height(tp.case_1),height(tp.case_2),height(tp.case_3)]);
tp.frame_2 = nan(m,15);
tp.frame_2(1:m,1:3) = repmat(tp.frame_1(tp.date_index(ii-1),1:3),[m 1]);
tp.frame_2(1:height(tp.case_1),4:7) = tp.case_1;
tp.frame_2(1:height(tp.case_2),8:11) = tp.case_2;
tp.frame_2(1:height(tp.case_3),12:15) = tp.case_3;
d.week = vertcat(d.week,tp.frame_2);
end
% compact week
w.week_all{ww} = d.week;
clear d tp
end % week
% sort
for ii = 1:length(w.week_all)
w.dnum_list(ii) = datenum(w.week_all{ii}(1,1:3));
w.sort_week_list = sort(w.dnum_list);
end
% rearrangement
month=[];
for ii = 1:length(w.sort_week_list)
w.index_list = find(w.sort_week_list(ii) == w.dnum_list);
month = vertcat(month,w.week_all{w.index_list});
end
% compact month
year = vertcat(year,month);
clear w
end % month
save([inp.output,'/',num2str(inp.year),'_year_data.mat'],"year")
|
2. remove_error
clc; clear; %close all;
load('output\2022_year_data.mat')
% devide case
main.open = rmmissing(year(:,1:5));
main.close = rmmissing(year(:,[1:3,6:7]));
sub.open = rmmissing(year(:,[1:3,8:9]));
sub.close = rmmissing(year(:,[1:3,10:11]));
power.open = rmmissing(year(:,[1:3,12:13]));
power.close = rmmissing(year(:,[1:3,14:15]));
% main
for ii = 1:length(main.open)-1
if main.close(ii,4) == 24 && main.open(ii+1,4) == 00
main.close(ii,:) = nan;
main.open(ii+1,:) = nan;
main.close(ii+1,4) = main.close(ii+1,4);
end
end
main.o_dvec = rmmissing(main.open);
main.o_dvec(:,6) = 0;
main.o_dnum = datenum(main.o_dvec);
main.c_dvec = rmmissing(main.close);
main.c_dvec(:,6) = 0;
main.c_dnum = datenum(main.c_dvec);
% sub
for ii = 1:length(sub.open)-1
if sub.close(ii,4) == 24 && sub.open(ii+1,4) == 00
sub.close(ii,[4,5]) = nan;
sub.open(ii+1,[4,5]) = nan;
sub.close(ii+1,4) = sub.close(ii+1,4);
end
end
sub.o_dvec = rmmissing(sub.open);
sub.o_dvec(:,6) = 0;
sub.o_dnum = datenum(sub.o_dvec);
sub.c_dvec = rmmissing(sub.close);
sub.c_dvec(:,6) = 0;
sub.c_dnum = datenum(sub.c_dvec);
% power
for ii = 1:length(power.open)-1
if power.close(ii,4) == 24 && power.open(ii+1,4) == 00
power.close(ii,[4,5]) = nan;
power.open(ii+1,[4,5]) = nan;
power.close(ii+1,4) = power.close(ii+1,4);
end
end
power.o_dvec = rmmissing(power.open);
power.o_dvec(:,6) = 0;
power.o_dnum = datenum(power.o_dvec);
power.c_dvec = rmmissing(power.close);
power.c_dvec(:,6) = 0;
power.c_dnum = datenum(power.c_dvec);
%% combination
comb = nan(height(year),6);
comb(1:length(main.o_dnum),1) = main.o_dnum;
comb(1:length(main.o_dnum),2) = main.c_dnum;
comb(1:length(sub.o_dnum),3)= sub.o_dnum;
comb(1:length(sub.o_dnum),4) = sub.c_dnum;
comb(1:length(power.o_dnum),5) = power.o_dnum;
comb(1:length(power.o_dnum),6) = power.c_dnum;
|
'mini project' 카테고리의 다른 글
[ matlab ] 2048 game (2) | 2023.02.02 |
---|---|
rotation attack (0) | 2023.01.13 |
강화 확률 시뮬레이션_v01 (0) | 2023.01.06 |
숫자 야구 (0) | 2022.12.27 |
지뢰찾기 (0) | 2022.12.26 |