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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
13 deletions
+23
-13
SampleData.java
test/src/test/java/com/github/variety/test/SampleData.java
+11
-11
variety.js
variety.js
+12
-2
No files found.
test/src/test/java/com/github/variety/test/SampleData.java
View file @
ef763c8d
...
@@ -16,17 +16,17 @@ class SampleData {
...
@@ -16,17 +16,17 @@ class SampleData {
* against this table, to check correct formatting.
* against this table, to check correct formatting.
*/
*/
public
static
final
String
EXPECTED_DATA_ASCII_TABLE
=
public
static
final
String
EXPECTED_DATA_ASCII_TABLE
=
"+------------------------------------------------------------+\n"
+
"+------------------------------------------------------------+\n"
+
"| key | types | occurrences | percents |\n"
+
"| key | types | occurrences | percents |\n"
+
"| ------------------ | ------------ | ----------- | -------- |\n"
+
"| ------------------ | ------------ | ----------- | -------- |\n"
+
"| _id | ObjectId | 5 | 100
|\n"
+
"| _id | ObjectId | 5 | 100.0
|\n"
+
"| name | String | 5 | 100
|\n"
+
"| name | String | 5 | 100.0
|\n"
+
"| bio | String | 3 | 60
|\n"
+
"| bio | String | 3 | 60.0
|\n"
+
"| birthday | String | 2 | 40
|\n"
+
"| birthday | String | 2 | 40.0
|\n"
+
"| pets | Array,String | 2 | 40
|\n"
+
"| pets | Array,String | 2 | 40.0
|\n"
+
"| someBinData | BinData-old | 1 | 20
|\n"
+
"| someBinData | BinData-old | 1 | 20.0
|\n"
+
"| someWeirdLegacyKey | String | 1 | 20
|\n"
+
"| someWeirdLegacyKey | String | 1 | 20.0
|\n"
+
"+------------------------------------------------------------+"
;
"+------------------------------------------------------------+"
;
/**
/**
* Java representation of sample collection provided in variety README:<p>
* Java representation of sample collection provided in variety README:<p>
...
...
variety.js
View file @
ef763c8d
...
@@ -274,15 +274,25 @@ if($outputFormat === 'json') {
...
@@ -274,15 +274,25 @@ if($outputFormat === 'json') {
printjson
(
varietyResults
);
// valid formatted json output, compressed variant is printjsononeline()
printjson
(
varietyResults
);
// valid formatted json output, compressed variant is printjsononeline()
}
else
{
// output nice ascii table with results
}
else
{
// output nice ascii table with results
var
table
=
[[
'key'
,
'types'
,
'occurrences'
,
'percents'
],
[
''
,
''
,
''
,
''
]];
// header + delimiter rows
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
)
{
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
)
{
var
colMaxWidth
=
function
(
arr
,
index
)
{
return
Math
.
max
.
apply
(
null
,
arr
.
map
(
function
(
row
){
return
row
[
index
].
toString
().
length
;}));
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
=
''
;
var
output
=
''
;
table
.
forEach
(
function
(
row
,
ri
){
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