csv 데이터를 IoT Analytics에 넣어 QuickSight로 시각화 (도쿄의 날씨)
11968 단어 IoTCoreawsIoTQuickSightIoTAnalytics
하고 싶은 일
IoT Analytics에서는 AWS IoT Core에서 얻은 데이터 외에 BatchPutMessage
를 사용하여 데이터를 캡처할 수 있습니다.
「실운용에서는 IoT Core로부터의 데이터를 해석하고 싶지만, 이미 있는 과거의 CSV데이터를 받아들여, 어떤 가시화나 해석이 가능한가를 시험해 보고 싶다」라고 할 때에 사용할 수 있습니다.
이번에는 기상청에서 도쿄의 날씨를 CSV로 얻고 QuickSight에서 시각화를 시도합니다.
htps : // / cs. 아 ws. 아마존. 코 m/이오타나 ly 치 cs/아 st/아피레후렌세/아피_바 tch푸t 메사게. HTML
원본 데이터 얻기
이번에는 기상청의 과거 기상 데이터 취득
htps //w w. 했다. j. . jp/gmd/리 sk/오 bsdl/

도쿄에 체크를 넣다

일별 평균 기온

30년분 획득

CSV 다운로드.

sjis처럼 보입니다.

IoT Analytics에 데이터 보내기
채널, 파이프라인, 데이터 스토어 만들기
이번에는 입력 데이터를 그대로 사용하므로 Pipeline에서는 특별히 처리하지 않습니다.


채널 ID : tokyo_temperature

Create Channel을 누릅니다.

채널에서 파이프라인을 만듭니다.


Attribute를 설정합니다. 다음 활동은 그대로.

tokyo_temperature_store
라는 Data store name으로 만들고 Create.
데이터 Post
휴대용 PC에서 다음을 수행합니다.
import csv
import json
import datetime
import boto3
channelName = "tokyo_temperature"
with open('data.csv', encoding='shift_jis') as csvfile:
reader = csv.reader(csvfile)
messages = []
for row in reader:
if len(row) > 3:
format_str = '%Y/%m/%d'
try:
date = datetime.datetime.strptime(row[0], format_str)
temperature = row[1]
blob = {
"date": date.isoformat(),
"temperature": float(row[1])
}
obj = {
"messageId": date.strftime("%Y-%m-%d"),
"payload": json.dumps(blob).encode()
}
messages.append(obj)
except:
continue
client = boto3.client('iotanalytics', region_name='us-east-1')
i = 0
while i < len(messages):
client.batch_put_message(
channelName=channelName,
messages=messages[i:i+99]
)
i += 100
payload의 사이즈 상한이 있으므로, 100개씩 분할해 보내고 있습니다.
또한 region_name
는 적절하게 변경해야합니다.

IoT Analytics의 채널을 보면 메시지가 수신되었음을 알 수 있습니다.
데이터 시각화

Create a data set을 누릅니다.

데이터스토어에서 데이터세트를 만듭니다. 이번에는 모든 데이터를 사용하여 데이터 세트를 만듭니다.

ID는 tokyo_temperature_dataset
라는 이름으로 했습니다.
source는 방금 만든 것을 선택합니다.

모든 것을 얻기 때문에 쿼리는 그대로. 나머지 항목은 모두 기본값으로 유지되며 Data set을 만듭니다.

원하는 데이터 세트를 선택하고 Action⇨Run now를 누릅니다.

잠시 기다렸다가 Content를 누르면 생성된 데이터 세트를 미리 볼 수 있습니다.
데이터 시각화
작성한 데이터 세트를 QuickSight로 그대로 가져옵니다.

서비스에서 QuickSight를 선택합니다.


Standard를 선택.

모든 계정 이름, 메어드를 입력하고 AWS IoT Analytics를 확인한 후 Finish.
QuickSight에서 New Analysis ⇨ New data set ⇨ IoT Analytics를 선택합니다.

작성한 데이터 소스 이름을 선택하고 Visualize.

date, temperature 를 선택하면 그래프가 표시되었습니다.

Visual types에서 막대 그래프를 선택하여 X axis에 date(YEAR)를 설정하고 Value에 Temperature(Average)를 설정하여 30년간의 연평균을 내 보았습니다. 큰 기온 변화는 없네요. .
Reference
이 문제에 관하여(csv 데이터를 IoT Analytics에 넣어 QuickSight로 시각화 (도쿄의 날씨)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tatsuhiroiida/items/6467b22492f28ecc296c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
이번에는 기상청의 과거 기상 데이터 취득
htps //w w. 했다. j. . jp/gmd/리 sk/오 bsdl/

도쿄에 체크를 넣다

일별 평균 기온

30년분 획득

CSV 다운로드.

sjis처럼 보입니다.

IoT Analytics에 데이터 보내기
채널, 파이프라인, 데이터 스토어 만들기
이번에는 입력 데이터를 그대로 사용하므로 Pipeline에서는 특별히 처리하지 않습니다.


채널 ID : tokyo_temperature

Create Channel을 누릅니다.

채널에서 파이프라인을 만듭니다.


Attribute를 설정합니다. 다음 활동은 그대로.

tokyo_temperature_store
라는 Data store name으로 만들고 Create.
데이터 Post
휴대용 PC에서 다음을 수행합니다.
import csv
import json
import datetime
import boto3
channelName = "tokyo_temperature"
with open('data.csv', encoding='shift_jis') as csvfile:
reader = csv.reader(csvfile)
messages = []
for row in reader:
if len(row) > 3:
format_str = '%Y/%m/%d'
try:
date = datetime.datetime.strptime(row[0], format_str)
temperature = row[1]
blob = {
"date": date.isoformat(),
"temperature": float(row[1])
}
obj = {
"messageId": date.strftime("%Y-%m-%d"),
"payload": json.dumps(blob).encode()
}
messages.append(obj)
except:
continue
client = boto3.client('iotanalytics', region_name='us-east-1')
i = 0
while i < len(messages):
client.batch_put_message(
channelName=channelName,
messages=messages[i:i+99]
)
i += 100
payload의 사이즈 상한이 있으므로, 100개씩 분할해 보내고 있습니다.
또한 region_name
는 적절하게 변경해야합니다.

IoT Analytics의 채널을 보면 메시지가 수신되었음을 알 수 있습니다.
데이터 시각화

Create a data set을 누릅니다.

데이터스토어에서 데이터세트를 만듭니다. 이번에는 모든 데이터를 사용하여 데이터 세트를 만듭니다.

ID는 tokyo_temperature_dataset
라는 이름으로 했습니다.
source는 방금 만든 것을 선택합니다.

모든 것을 얻기 때문에 쿼리는 그대로. 나머지 항목은 모두 기본값으로 유지되며 Data set을 만듭니다.

원하는 데이터 세트를 선택하고 Action⇨Run now를 누릅니다.

잠시 기다렸다가 Content를 누르면 생성된 데이터 세트를 미리 볼 수 있습니다.
데이터 시각화
작성한 데이터 세트를 QuickSight로 그대로 가져옵니다.

서비스에서 QuickSight를 선택합니다.


Standard를 선택.

모든 계정 이름, 메어드를 입력하고 AWS IoT Analytics를 확인한 후 Finish.
QuickSight에서 New Analysis ⇨ New data set ⇨ IoT Analytics를 선택합니다.

작성한 데이터 소스 이름을 선택하고 Visualize.

date, temperature 를 선택하면 그래프가 표시되었습니다.

Visual types에서 막대 그래프를 선택하여 X axis에 date(YEAR)를 설정하고 Value에 Temperature(Average)를 설정하여 30년간의 연평균을 내 보았습니다. 큰 기온 변화는 없네요. .
Reference
이 문제에 관하여(csv 데이터를 IoT Analytics에 넣어 QuickSight로 시각화 (도쿄의 날씨)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tatsuhiroiida/items/6467b22492f28ecc296c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import csv
import json
import datetime
import boto3
channelName = "tokyo_temperature"
with open('data.csv', encoding='shift_jis') as csvfile:
reader = csv.reader(csvfile)
messages = []
for row in reader:
if len(row) > 3:
format_str = '%Y/%m/%d'
try:
date = datetime.datetime.strptime(row[0], format_str)
temperature = row[1]
blob = {
"date": date.isoformat(),
"temperature": float(row[1])
}
obj = {
"messageId": date.strftime("%Y-%m-%d"),
"payload": json.dumps(blob).encode()
}
messages.append(obj)
except:
continue
client = boto3.client('iotanalytics', region_name='us-east-1')
i = 0
while i < len(messages):
client.batch_put_message(
channelName=channelName,
messages=messages[i:i+99]
)
i += 100

Create a data set을 누릅니다.

데이터스토어에서 데이터세트를 만듭니다. 이번에는 모든 데이터를 사용하여 데이터 세트를 만듭니다.

ID는
tokyo_temperature_dataset
라는 이름으로 했습니다.source는 방금 만든 것을 선택합니다.

모든 것을 얻기 때문에 쿼리는 그대로. 나머지 항목은 모두 기본값으로 유지되며 Data set을 만듭니다.

원하는 데이터 세트를 선택하고 Action⇨Run now를 누릅니다.

잠시 기다렸다가 Content를 누르면 생성된 데이터 세트를 미리 볼 수 있습니다.
데이터 시각화
작성한 데이터 세트를 QuickSight로 그대로 가져옵니다.

서비스에서 QuickSight를 선택합니다.


Standard를 선택.

모든 계정 이름, 메어드를 입력하고 AWS IoT Analytics를 확인한 후 Finish.
QuickSight에서 New Analysis ⇨ New data set ⇨ IoT Analytics를 선택합니다.

작성한 데이터 소스 이름을 선택하고 Visualize.

date, temperature 를 선택하면 그래프가 표시되었습니다.

Visual types에서 막대 그래프를 선택하여 X axis에 date(YEAR)를 설정하고 Value에 Temperature(Average)를 설정하여 30년간의 연평균을 내 보았습니다. 큰 기온 변화는 없네요. .
Reference
이 문제에 관하여(csv 데이터를 IoT Analytics에 넣어 QuickSight로 시각화 (도쿄의 날씨)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/tatsuhiroiida/items/6467b22492f28ecc296c
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(csv 데이터를 IoT Analytics에 넣어 QuickSight로 시각화 (도쿄의 날씨)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tatsuhiroiida/items/6467b22492f28ecc296c텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)