Menu

Coppell Technologies
Fiwareで都市OSを動かしてみよう
NGSI-LDにも挑戦
データ仕様の現状と課題
スマートシティの標準規定(案)
データモデルのユースケース


Column
Link集
用語集


Coppell

Technologies

利用例-8 (Device)


■利用例の概要
 設備の一つひとつを表現するデータモデルである、Deviceをcsvファイルから生成します。

■csvファイル
 本利用例は、設備の一覧をcsvファイルで入手できる事を想定しています。本利用例のcsvはこちら

■拡張JSON Schema
 元となるJSON Schemaは、このリンクから入手します。
 csvからJSONに変換するルールとして、以下の情報を追加します。追加した拡張JSON Schemaはdata配下にDevice.exschema.jsonというファイル名で格納してありります

Attribute 追加ルール 説明
id

dataSource

csvAttr csvの項目名として"製造番号"を指定します
prefix idを作成するために、"urn:ngsi-ld:Device:"を製造番号の前に付加します
dateInstalled

dataSource

csvAttr csvの項目名として"設置日"を指定します
dateManufactured

dataSource

csvAttr csvの項目名として"製造日"を指定します
pricePurchased

dataSource

csvAttr csvの項目名として"購入価格"を指定します
refDeviceModel

dataSource

csvAttr csvの項目名として"型番"を指定します
target 型番からDeviceModelのidを求めるために、検索対象に"DeviceModel"を指定します
targetKey targetに指定したデータモデルで、型番が格納されているAttributeである、"modelName"を指定します
targetAttr idが格納されているAttributeである"id"を指定します
refBuilding

dataSource

csvAttr csvから値を求めるために、csvの項目名として"施設ID"を指定します
target 施設IDからBuildingのidを求めるために、検索対象に"Building"を指定します
targetKey targetに指定したデータモデルで、施設IDが格納されているAttributeである、"facilityID"を指定します
targetAttr idが格納されているAttributeである"id"を指定します
zoneInstalled リスト構造の中に値を最大3っつ登録したいので、itemsの中をリスト構造とし、3っつの指定ができる様にします

0 dataSource

csvAttr csvの項目名として"場所大分類"を指定します
1 dataSource

csvAttr csvの項目名として"場所中分類"を指定します
2 dataSource

csvAttr csvの項目名として"場所小分類"を指定します
zoneRemarks

dataSource

csvAttr csvの項目名として"場所補足"を指定します

これら以外のAttrributeはそのまま残します。消しても残しても無視されます。但し、typeはrequiredに指定してあるので、JSONに変換されます。

■実行
 cドライブ直下にtestというフォルダを作成して、全てのファイルをここに格納して実行しています。


C:\Users\owner>chdir c:/Tools/

c:\Tools>Python ctoj.py dir=c:/Tools/data/ inputfile=Devicecsv.csv outputfile=Devicejson.json schemafile=Device.exschema.json DeviceModelfile=DeviceModeljson.jsonBuildingfile=Buildingjson.json logfile=Devicelog.txt
##### start ctoj converter #####
CSV translated to JSON successfully. output Entity number: 8

■変換結果
 ツール実行結果は以下の通りです。


 [
   {
     "id": "urn:ngsi-ld:Device:RAS-DM28KE801234567XYZ",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/8/27"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2017/6/21"
     },
     "name": {
       "type": "Text",
       "value": "吉浦1F-支所空調1"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 115000
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP7010001008844-RAS-DM28KE8"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-01234567"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "建物内部",
         "1F",
         "吉浦支所"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "西側壁面"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:HH-CG2033A0020ABC",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/8/30"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2017/3/30"
     },
     "name": {
       "type": "Text",
       "value": "吉浦1F-支所照明1"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 12000
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP3120001236504-HH-CG2033A"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-01234567"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "建物内部",
         "1F",
         "吉浦支所"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "天井"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:RAS-DM28KE801234567VVV",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/8/27"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2017/6/21"
     },
     "name": {
       "type": "Text",
       "value": "吉浦2F-図書空調1"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 105000
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP7010001008844-RAS-DM28KE8"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-01234567"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "建物内部",
         "2F",
         "図書室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "北側壁面"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:HH-CG2033A0020ZZZ",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/8/30"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2017/3/30"
     },
     "name": {
       "type": "Text",
       "value": "吉浦2F-図書照明1"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 12500
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP3120001236504-HH-CG2033A"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-01234567"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "建物内部",
         "2F",
         "図書室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "天井"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:RAS-DM28KE801234567WWW",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2015/3/27"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2015/1/15"
     },
     "name": {
       "type": "Text",
       "value": "吉小3F-音楽空調"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 110000
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP7010001008844-RAS-DM28KE8"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-03000012"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "校舎",
         "3F",
         "音楽室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "西側壁面"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:HH-CG2033A0020UUU",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2015/3/27"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2015/2/22"
     },
     "name": {
       "type": "Text",
       "value": "吉小3F-音楽照明"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 12500
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP3120001236504-HH-CG2033A"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-03000012"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "校舎",
         "3F",
         "音楽室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "天井"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:RAS-DM28KE801234567XXX",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/3/15"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2016/2/16"
     },
     "name": {
       "type": "Text",
       "value": "吉中3F-音楽空調"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 100500
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP7010001008844-RAS-DM28KE8"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-04000008"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "校舎",
         "3F",
         "音楽室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "西側壁面"
     }
   },
   {
     "id": "urn:ngsi-ld:Device:HH-CG2033A0020MMM",
     "type": "Device",
     "dateInstalled": {
       "type": "Date",
       "value": "2017/3/15"
     },
     "dateManufactured": {
       "type": "Date",
       "value": "2014/1/18"
     },
     "name": {
       "type": "Text",
       "value": "吉中3F-音楽照明"
     },
     "pricePurchased": {
       "type": "Number",
       "value": 11500
     },
     "refDeviceModel": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:DeviceModel:JP3120001236504-HH-CG2033A"
     },
     "refBuilding": {
       "type": "Relationship",
       "value": "urn:ngsi-ld:Building:JP9000020342025-04000008"
     },
     "zoneInstalled": {
       "type": "Array",
       "value": [
         "校舎",
         "3F",
         "音楽室"
       ]
     },
     "zoneRemarks": {
       "type": "Text",
       "value": "天井"
     }
   }
 ]

ログファイルは以下の通りです。全ての行でエラーは発生していません。

02: inputdir: c:/Tools/Data/, inputfile: Devicecsv.csv
04: directory: Buildingdir, Buildingfile: Buildingfile
04: directory: DeviceModeldir, DeviceModelfile: DeviceModelfile
09: outputdir: c:/Tools/Data/, outputfile: Devicejson.json
10: CSV Line# 2
10: CSV Line# 3
10: CSV Line# 4
10: CSV Line# 5
10: CSV Line# 6
10: CSV Line# 7
10: CSV Line# 8
10: CSV Line# 9
12: CSV translated to JSON successfully. Enity number: 8