diff --git a/src/util/wdc-interface.coffee b/src/util/wdc-interface.coffee index 2c4e110..d162510 100644 --- a/src/util/wdc-interface.coffee +++ b/src/util/wdc-interface.coffee @@ -16,14 +16,25 @@ submit = (url, dimension) -> getComponents = (structure) -> components = [] + dimPos = 0 for type in ['dimensions', 'attributes'] for level in ['dataSet', 'series', 'observation'] if structure[type]?[level]? components = components.concat structure[type][level].map (c) -> + if type is 'attributes' + prefix = "M" + else + dimPos += 1 + if c.keyPosition? + keyPos = c.keyPosition + 1 # keyPosition is zero-based + else + keyPos = dimPos + # assumes there will always be less than 99 dimensions + prefix = if keyPos < 10 then "0#{keyPos}" else "keyPos" + c.name = "#{prefix} - #{c.name}" c.type = type c.level = level - c.name = "+#{c.name}" if type is 'attributes' c components @@ -39,7 +50,7 @@ processResponse = (response) -> columnNames = for c in components switch when c.values[0]?.start? then [c.name, "#{c.name} start", "#{c.name} end"] - when c.values[0]?.id? then [c.name, "ID #{c.name}"] + when c.values[0]?.id? then [c.name, "#{c.name} ID"] else c.name columnTypes = for c in components diff --git a/test/util/wdc-interface.test.coffee b/test/util/wdc-interface.test.coffee index c821aea..c51e293 100644 --- a/test/util/wdc-interface.test.coffee +++ b/test/util/wdc-interface.test.coffee @@ -13,7 +13,7 @@ describe 'Web Data Connector Interface', -> checkResult = () -> response = wdcInterface.response() response.fieldNames.should.be.an('array').with.lengthOf(42) - response.fieldNames.should.include('Currency') + response.fieldNames.should.include('02 - Currency') response.fieldTypes.should.be.an('array').with.lengthOf(42) response.fieldTypes.should.have.members(['string', 'datetime', 'float']) response.dataToReturn.should.be.an('array').with.lengthOf(4)