Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
variety
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
variety
Commits
ef763c8d
Commit
ef763c8d
authored
Mar 17, 2015
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Display ASCII tables' scalars indented to the right #83
parent
c465b9c7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
9 deletions
+19
-9
SampleData.java
test/src/test/java/com/github/variety/test/SampleData.java
+7
-7
variety.js
variety.js
+12
-2
No files found.
test/src/test/java/com/github/variety/test/SampleData.java
View file @
ef763c8d
...
...
@@ -19,13 +19,13 @@ class SampleData {
"+------------------------------------------------------------+\n"
+
"| key | types | occurrences | percents |\n"
+
"| ------------------ | ------------ | ----------- | -------- |\n"
+
"| _id | ObjectId | 5 | 100
|\n"
+
"| name | String | 5 | 100
|\n"
+
"| bio | String | 3 | 60
|\n"
+
"| birthday | String | 2 | 40
|\n"
+
"| pets | Array,String | 2 | 40
|\n"
+
"| someBinData | BinData-old | 1 | 20
|\n"
+
"| someWeirdLegacyKey | String | 1 | 20
|\n"
+
"| _id | ObjectId | 5 | 100.0
|\n"
+
"| name | String | 5 | 100.0
|\n"
+
"| bio | String | 3 | 60.0
|\n"
+
"| birthday | String | 2 | 40.0
|\n"
+
"| pets | Array,String | 2 | 40.0
|\n"
+
"| someBinData | BinData-old | 1 | 20.0
|\n"
+
"| someWeirdLegacyKey | String | 1 | 20.0
|\n"
+
"+------------------------------------------------------------+"
;
/**
...
...
variety.js
View file @
ef763c8d
...
...
@@ -274,15 +274,25 @@ if($outputFormat === 'json') {
printjson
(
varietyResults
);
// valid formatted json output, compressed variant is printjsononeline()
}
else
{
// output nice ascii table with results
var
table
=
[[
'key'
,
'types'
,
'occurrences'
,
'percents'
],
[
''
,
''
,
''
,
''
]];
// header + delimiter rows
var
significantDigits
=
function
(
value
)
{
return
value
.
toExponential
()
.
replace
(
/e
[\+\-
0-9
]
*$/
,
''
)
// remove exponential notation
.
replace
(
/^0
\.?
0*|
\.
/
,
''
)
// remove decimal point and leading zeros
.
length
;
};
var
maxDigits
=
Math
.
max
.
apply
(
null
,
varietyResults
.
map
(
function
(
value
){
return
significantDigits
(
value
.
percentContaining
);}));
varietyResults
.
forEach
(
function
(
key
)
{
table
.
push
([
key
.
_id
.
key
,
key
.
value
.
types
.
toString
(),
key
.
totalOccurrences
.
toString
(),
key
.
percentContaining
.
toString
()]);
table
.
push
([
key
.
_id
.
key
,
key
.
value
.
types
.
toString
(),
key
.
totalOccurrences
.
toString
(),
key
.
percentContaining
.
to
Fixed
(
maxDigits
).
to
String
()]);
});
var
colMaxWidth
=
function
(
arr
,
index
)
{
return
Math
.
max
.
apply
(
null
,
arr
.
map
(
function
(
row
){
return
row
[
index
].
toString
().
length
;}));
};
var
pad
=
function
(
width
,
string
,
symbol
)
{
return
width
<=
string
.
length
?
string
:
pad
(
width
,
string
+
symbol
,
symbol
);
};
var
pad
=
function
(
width
,
string
,
symbol
)
{
return
width
<=
string
.
length
?
string
:
pad
(
width
,
isNaN
(
string
)
?
string
+
symbol
:
symbol
+
string
,
symbol
);
};
var
output
=
''
;
table
.
forEach
(
function
(
row
,
ri
){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment