데이터 XML을 JMP로 가져오기안녕하세요. 사용자가 시간을 정의할 수 있는 방식으로 날씨 데이터 형식 XML(핀란드 기상 서비스 - https://en.ilmatieteenlaitos.fi/open-data-manual-fmi-wfs-services )을 JMP로 가져오려고 합니다. 기간. 내 코드가 작동하지 않고 항상 "잘못된 HTTP 요청 상태" 오류 메시지가 나타납니다.
// User-defined start and end dates (modify as needed)
startDate = "2024-07-10";
endDate = "2024-07-24";
// Construct the URL with user-defined dates and parameters
url = "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=helsinki-vantaa_airport×tep=1&starttime=" || startDate || "T00:00:00Z&endtime=" || endDate || "T23:59:59Z¶meters=temperature%2Chumidity%2Cpressure";
// Create HTTP request object
httpRequest = New HTTP Request();
// Send HTTP GET request
response = httpRequest << Send("GET", url);
// Check if the request was successful
If(response << Get Status Code == 200,
// Parse the XML response
xmlResponse = response << Get As XML,
// Extract data from XML response
dataNodes = xmlResponse << XPath("//wml2:MeasurementTVP"),
// Initialize lists to store data
temperatureList = {},
humidityList = {},
pressureList = {},
// Loop through each data node and extract values
ForEach(node in dataNodes,
// Extract timestamp
timestamp = node << XPath("wml2:time"),
// Extract temperature value
temperature = node << XPath("wml2:value[@parameter='temperature']"),
temperatureValue = temperature << NodeText,
// Extract humidity value
humidity = node << XPath("wml2:value[@parameter='humidity']"),
humidityValue = humidity << NodeText,
// Extract pressure value
pressure = node << XPath("wml2:value[@parameter='pressure']"),
pressureValue = pressure << NodeText,
// Convert timestamp to JMP DateTime format
timestampDT = Parse DateTime(timestamp, "YYYY-MM-DDThh:mm:ssZ"),
// Append data to lists
Append(temperatureList, {timestampDT, As Number(temperatureValue)}),
Append(humidityList, {timestampDT, As Number(humidityValue)}),
Append(pressureList, {timestampDT, As Number(pressureValue)})
);
// Create a new JMP data table and add columns
dt = New Table("Helsinki-Vantaa Weather Data",
Add Rows(Num Rows(temperatureList)),
New Column("Timestamp", Numeric, "DateTime"),
New Column("Temperature (°C)", Numeric, "Continuous", Format(3)),
New Column("Relative Humidity (%)", Numeric, "Continuous", Format(3)),
New Column("Pressure (hPa)", Numeric, "Continuous", Format(3))
);
// Populate the data table with values
dt:"Timestamp" << Set Values(temperatureList);
dt:"Temperature (°C)" << Set Values(humidityList);
dt:"Relative Humidity (%)" << Set Values(pressureList);
dt:"Pressure (hPa)" << Set Values(pressureList);
// Show the data table
dt << Show;
,
// Display error if request failed
Throw("Failed to fetch data. HTTP status code: " || Char(response << Get Status Code))
);자동화 및 스크립팅데이터 접근Re: 데이터 XML을 JMP로 가져옵니다.새 HTTP 요청 구문이 올바르지 않습니다. 다음은 일부 데이터를 반환해야 하는 작은 예입니다.
Names Default To Here(1);
startDate = "2024-07-10";
endDate = "2024-07-11";
// Construct the URL with user-defined dates and parameters
url = "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=helsinki-vantaa_airport×tep=1&starttime=" || startDate || "T00:00:00Z&endtime=" || endDate || "T23:59:59Z¶meters=temperature%2Chumidity%2Cpressure";
// Create HTTP request object
request = New HTTP Request(
Method("GET"),
URL(url)
);
data = request << send;
/*
Show(request << Get MIME Type);
*/Re: 데이터 XML을 JMP로 가져옵니다.@jthi에게 감사드립니다. 이제 HTTP 요청이 작동하지만 나머지 스크립트에도 결함이 있는 것 같습니다. XML에서 데이터를 가져오려는 것은 이번이 처음입니다.
Re: 데이터 XML을 JMP로 가져옵니다.LLM 생성 코드를 사용하고 있는 것 같나요? 그렇다면 내 생각에는 JSL이 끔찍합니다.
결과 데이터를 xml 파일로 저장하고 JMP 미리보기를 사용하여 소스 스크립트를 가져오는 것이 좋습니다.

이를 위해서는 약간의 조작이 필요하지만 이것으로 구문 분석할 수 있습니다(또는 XPath Query() 또는 Parse XML() 을 사용할 수 있음)

그런 다음 소스 스크립트를 사용하여 프로세스를 더욱 자동화할 수 있으며 다음과 같은 결과를 얻을 수 있습니다.


Re: 데이터 XML을 JMP로 가져옵니다.
Re: 데이터 XML을 JMP로 가져옵니다.다음은 제가 사용한 스크립트입니다(이전에 JMP에서 Ilmatieteenlaitos 공개 데이터를 사용했지만 다른 데이터를 사용했거나 약간 다른 방식으로 구문 분석한 것 같습니다). open(char to blob(), "text")와 같은 몇 가지 고급 기술을 사용하지만 먼저 파일을 텍스트 파일로 저장하면 이를 피할 수 있습니다. 또한 데이터 정리 및 그래프 생성 기능도 있습니다(생성한 데이터가 올바른지 확인하세요. 이에 대한 확인은 전혀 하지 않았습니다).
더보기...
Names Default To Here(1);
/*
https://en.ilmatieteenlaitos.fi/open-data
https://en.ilmatieteenlaitos.fi/open-data-manual-accessing-data
*/
location = "helsinki-vantaa_airport";
start_date = "2024-07-10";
end_date = "2024-07-11";
fmi_url = "https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=getFeature&storedquery_id=fmi::observations::weather::timevaluepair&place=^location^×tep=1&starttime=^start_date^T00:00:00Z&endtime=^end_date^T23:59:59Z¶meters=temperature%2Chumidity%2Cpressure";
// Create HTTP request object
request = New HTTP Request(
Method("GET"),
URL(Eval Insert(fmi_url))
);
data = request << send;
dt = Open(
Char to blob(data),
XML Settings(
Stack(0),
Row(
"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point"
),
Col(
"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/@gml:id",
Column Name(
"MeasurementID"
),
Fill("Use Forever"),
Type("Character"),
Format({"Best"}),
Modeling Type("Continuous")
),
Col(
"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP/wml2:time",
Column Name(
"Timestamp"
),
Fill("Use Once"),
Type("Character"),
Format({"Best"}),
Modeling Type("Continuous")
),
Col(
"/wfs:FeatureCollection/wfs:member/omso:PointTimeSeriesObservation/om:result/wml2:MeasurementTimeseries/wml2:point/wml2:MeasurementTVP/wml2:value",
Column Name(
"Value"
),
Fill("Use Once"),
Type("Numeric"),
Format({"Best"}),
Modeling Type("Continuous")
)
),
XML Wizard(0),
"text"
);
For Each Row(dt,
:MeasurementID = Word(-1, :MeasurementID, "-");
:Timestamp = Substitute(:Timestamp, "Z", "");
);
Column(dt, "Timestamp") << Data Type(Numeric) << Modeling Type(Continuous) << Format("yyyy-mm-ddThh:mm:ss", 19, 0);
dt_split = dt << Split(
Split By(:MeasurementID),
Split(:Value),
Group(:Timestamp),
Output Table("FMI " || location),
Sort by Column Property
);
Close(dt, no save);
dt_split << Delete Scripts(dt_split << Get Table Script Names);
gb = dt_split << Graph Builder(
Size(857, 524),
Show Control Panel(0),
Variables(X(:Timestamp), Y(:humidity), Y(:pressure), Y(:temperature)),
Elements(Position(1, 1), Line(X, Y, Legend(15))),
Elements(Position(1, 2), Line(X, Y, Legend(16))),
Elements(Position(1, 3), Line(X, Y, Legend(17)))
);
gb << Save Script to Data Table("Plot");
If you wish to see how I filled XML Wizard, you can change the XML Wizard(0), to XML Wizard(1), and run code until that point. You can then see the settings in the GUI I used. And here is some sort of explanation of what those mean

Tall Guess를 사용하면 꽤 멀리 갈 수 있습니다.

하지만 측정 유형이 누락되므로 모든 행에서 반복하기 위해 몇 가지 변경 작업을 수행해야 합니다(JMP 테이블에서 한 번 채울 수도 있고 나머지를 채울 수도 있음).
Re: 데이터 XML을 JMP로 가져옵니다.이전에 JMP에서 가져오기 XML 추가 기능을 사용해 보았지만 이 기능에 대해 헤매었습니다. 하지만 이제 귀하의 설명을 바탕으로 어떻게 작동하는지 이해하게 되었습니다! @jthi 감사합니다! 또한 open(char to blob(), "text")를 사용하여 이 데이터를 가져오는 방법을 공유해 주셔서 정말 감사합니다!