저는 JSL을 처음 사용하지만 이 커뮤니티의 도움으로 특정 오염 물질 및 기간 동안 URL에서 대기 질 데이터를 수집하는 코드를 작성할 수 있었습니다. URL에 데이터가 없고 For 루프가 중단되는 경우를 제외하고는 코드에서 모든 것이 잘 작동합니다. For 루프가 데이터가 없는 테이블을 무시하도록 조건을 설정하는 방법이 있습니까? 아래 코드를 붙여넣고 있습니다. 2021을 'end_year'로 지정하면 코드가 제대로 작동하지만 2022를 'end_year'로 지정하면 아직 하반기(35행)에 데이터가 없기 때문에 코드가 중단됩니다.
Names Default To Here(1);
//************************************INPUT****************************//
parameter= "SO2"; // 1. Pick from "NO2", "OZONE", "PM25HR", "NOX", "NO", "CO", "SO2"//
start_year= 2019; // 2. Specify start year
end_year= 2021; // 3. specify end year
//--------------------------------------------------------------------------------------------------------------
//This URL downloads data from Jan 1st until June 30
dl_url1= "https://www.arb.ca.gov/aqmis2/display.php?sitelist=All&filefmt=csv&fname=" || parameter || "_PICKDATA_^temp_year^-6-30&datafmt=dvde&download=y&first_date=^temp_year^-1-1¶m=" || parameter || "&units=001&year=^temp_year^&county_name=--COUNTY--&basin=SC-South+Coast&latitude=--PART+OF+STATE--&report=PICKDATA&order=basin%2Ccounty_name%2Cs.name&submit=All+Sites&ptype=aqd&std15=&o3switch=new&hours=all&statistic=&qselect=Screened&start_mon=1&start_day=1&mon=6&day=30&rows=18";
tableList = {};
For(i = start_year, i <= end_year, i++,
temp_year= Char(i);
year_url = Eval Insert(dl_url1);
dt_temp = Open(year_url, columns(
New Column( "site", Character, "Nominal" ),
New Column( "date",
Numeric,
"Continuous",
Format( "yyyy-mm-dd", 10 ),
Input Format( "yyyy-mm-dd" )
)));
dt_temp << delete rows( Index( N Rows(dt_temp) - 11, N Rows( dt_temp) ) ); //this code deletes the last 11 rows of data
Insert Into( tableList, dt_temp << get name );
);
//This URL downloads data from July 1st 1st until Dec 31
dl_url2= "https://www.arb.ca.gov/aqmis2/display.php?sitelist=All&filefmt=csv&fname=" || parameter || "_PICKDATA_^temp_year^-12-31&datafmt=dvde&download=y&first_date=^temp_year^-7-1¶m=" || parameter || "&units=001&year=^temp_year^&county_name=--COUNTY--&basin=SC-South+Coast&latitude=--PART+OF+STATE--&report=PICKDATA&order=basin%2Ccounty_name%2Cs.name&submit=All+Sites&ptype=aqd&std15=&o3switch=new&hours=all&statistic=&qselect=Screened&start_mon=7&start_day=1&mon=12&day=31&rows=18";
For(i = start_year, i <= end_year, i++,
temp_year= Char(i);
year_url = Eval Insert(dl_url2);
dt_temp = Open(year_url, columns(
New Column( "site", Character, "Nominal" ),
New Column( "date",
Numeric,
"Continuous",
Format( "yyyy-mm-dd", 10 ),
Input Format( "yyyy-mm-dd" )
)));
dt_temp << delete rows( Index( N Rows(dt_temp) - 11, N Rows( dt_temp) ) );
Insert Into( tableList, dt_temp << get name );
);
//The following code concat all tables
all_dt= new Table("All " || parameter || " Data");
For( i = 1, i <= N Items( tableList ), i++,
Data Table(all_dt) << Concatenate(
Data Table( tableList[i] ),
append to first table(1)
);
Close( Data Table( tableList[i] ), No Save );
);
// Create Time (PST) Column
Data Table(all_dt) << New Column( "Column 4",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected
) << Move Selected Columns( {:Column 4}, after( :start_hour ) );
Data Table(all_dt):Column 4 << Input Format( "m/d/y h:m" ) <<
Set Name( "Time (PST)" ) << Format( "m/d/y h:m", 19 ) <<
Set Formula( :date + :start_hour * 3600 );
// Create Month Column
Data Table(all_dt) << New Column( "Month",
Character,
"Nominal",
Formula( Substr( Format( :"Time (PST)"n, "Monddyyyy" ), 1, 3 ) )
) << Move Selected Columns( {:"Month"n}, after( :"Time (PST)"n ) );
// Create Year Column
Data Table(all_dt) << New Column( "Year",
Character,
"Nominal",
Formula( Substr( Format( :"Time (PST)"n, "Monddyyyy" ), 6, 4 ) )
) << Move Selected Columns( {:"Year"n}, after( :"Month"n ) );다음과 같이 데이터 행이 0개인 URL을 건너뛸 수 있습니다.
If(N Rows(dt_temp) > 0,
dt_temp << delete rows(Index(N Rows(dt_temp) - 11, N Rows(dt_temp)));
Insert Into(tableList, dt_temp << get name);
,
Close(dt_temp, no save);
);
데이터가 없는 첫 번째 테이블에서 for 루프를 중지(중단)하려면 for 루프 내에서 Break()를 사용할 수 있습니다.
If(N Rows(dt_temp) == 0,
Close(dt_temp, no save);
break();
);