Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
feat(-interface): Prefix dimension names with key position and attrib…
Browse files Browse the repository at this point in the history
…utes names with M.

Closes #50
  • Loading branch information
airosa committed Dec 15, 2016
1 parent 532375f commit 0baa7b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/util/wdc-interface.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/util/wdc-interface.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0baa7b2

Please sign in to comment.