Skip to content

Commit

Permalink
use named JSON keys instead of numeric ones. Fixes jiang-hang#5
Browse files Browse the repository at this point in the history
  • Loading branch information
pcdi committed Jan 21, 2021
1 parent 467da1f commit ee98376
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions R/rstatscn.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ dataJson2df<-function(rawObj,rowcode,colcode)
#dataStructure
#jj is a list
#jj[[1]] = 200 #return code
#jj[[2]] is datanode
#jj[[2]][[1]] is data
#jj[[2]][[2]] is description
#jj[[2]][[2]][,"nodes"][[1]] is row description , it is a dataframe
#jj[[2]][[2]][,"nodes"][[2]] is col description , it is a dataframe
desList=ret[[2]][[2]][,'nodes']
rowWdIdx = which(ret[[2]][[2]]$wdcode == rowcode)
colWdIdx = which(ret[[2]][[2]]$wdcode == colcode)
#jj[[2]] is returndata
returnData = "returndata"
#jj[[2]][[1]] is datanodes
dataNodes = "datanodes"
#jj[[2]][[2]] is freshsort
#jj[[2]][[3]] is data
#jj[[2]][[4]] is wdnodes (description)
descriptionNodes = "wdnodes"
#jj[[2]][[4]][,"nodes"][[1]] is row description , it is a dataframe
#jj[[2]][[4]][,"nodes"][[2]] is col description , it is a dataframe
desList=ret[[returnData]][[descriptionNodes]][,'nodes']
rowWdIdx = which(ret[[returnData]][[descriptionNodes]]$wdcode == rowcode)
colWdIdx = which(ret[[returnData]][[descriptionNodes]]$wdcode == colcode)
rowDes=desList[[rowWdIdx]]
colDes=desList[[colWdIdx]]

Expand Down Expand Up @@ -119,7 +124,7 @@ dataJson2df<-function(rawObj,rowcode,colcode)
myret=as.data.frame(matrix(rep(NA,rowNum*colNum),nrow=rowNum))
rownames(myret)=rowCodes
colnames(myret)=colCodes
dfdata=ret[[2]][[1]]
dfdata=ret[[returnData]][[dataNodes]]
for (k in seq(1,nrow(dfdata))) {
wddf=dfdata[k,"wds"][[1]]
myret[wddf[rowWdIdx,'valuecode'],wddf[colWdIdx,'valuecode']] = dfdata[k,'data'][1,'data']
Expand Down

0 comments on commit ee98376

Please sign in to comment.