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

Commit

Permalink
added columns to all operations results
Browse files Browse the repository at this point in the history
  • Loading branch information
f-marino committed Nov 9, 2022
1 parent 819bb25 commit 0da33a0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/datasource/explore_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (ds I2b2DataSource) ExploreQueryHandler(userID string, jsonParameters []byt
{
OutputName: outputNameExploreQueryCount,
SharedID: outputDataObjectsSharedIDs[outputNameExploreQueryCount],
Columns: []string{"count"},
IntValue: &count,
}, {
OutputName: outputNameExploreQueryPatientList,
Expand Down
7 changes: 5 additions & 2 deletions pkg/datasource/statistics_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func (ds I2b2DataSource) StatisticsQueryHandler(
valueVector := []int64{}
columns := []string{}

for _, bucket := range statResult.Buckets {
// these are needed to correctly sort the columns during the aggregation
labels := generateColumnsLabels(len(statResult.Buckets))

for i, bucket := range statResult.Buckets {
valueVector = append(valueVector, bucket.Count)
columns = append(columns, "["+fmt.Sprintf("%f", bucket.LowerBound)+", "+fmt.Sprintf("%f", bucket.HigherBound)+"]")
columns = append(columns, "[\""+labels[i]+"\", "+fmt.Sprintf("%f", bucket.LowerBound)+", "+fmt.Sprintf("%f", bucket.HigherBound)+"]")
}
values = append(values, valueVector)

Expand Down
1 change: 1 addition & 0 deletions pkg/datasource/survival_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (ds I2b2DataSource) SurvivalQueryHandler(userID string, jsonParameters []by
{
OutputName: outputNameSurvivalQueryResult,
SharedID: outputDataObjectsSharedIDs[outputNameSurvivalQueryResult],
Columns: generateColumnsLabels(len(survivalQueryResult)),
IntVector: survivalQueryResult,
},
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/datasource/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package datasource

import (
"fmt"
"math"
)

// generateColumnsLabels generates a list containing the string representations of the numbers from 0 to n-1, with the right number of leading 0s.
// e.g., for n=16 -> ["00", "01, ..., "15"], for n=106 -> ["000", "001", ..., "115"]
func generateColumnsLabels(n int) []string {

labels := make([]string, n)
figures := int(math.Ceil(math.Log10(float64(n))))

for i := 0; i < n; i++ {
labels[i] = fmt.Sprintf(fmt.Sprintf("%%0%dd", figures), i)
}

return labels
}

0 comments on commit 0da33a0

Please sign in to comment.