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
e59f3367
Commit
e59f3367
authored
Nov 16, 2014
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Alphabetical order of results with same occurrences count, cosmetic changes.
parent
51a6994a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
10 deletions
+10
-10
SampleData.java
test/src/test/java/com/github/variety/test/SampleData.java
+1
-1
variety.js
variety.js
+9
-9
No files found.
test/src/test/java/com/github/variety/test/SampleData.java
View file @
e59f3367
...
@@ -22,8 +22,8 @@ class SampleData {
...
@@ -22,8 +22,8 @@ class SampleData {
"| _id | ObjectId | 5 | 100 |\n"
+
"| _id | ObjectId | 5 | 100 |\n"
+
"| name | String | 5 | 100 |\n"
+
"| name | String | 5 | 100 |\n"
+
"| bio | String | 3 | 60 |\n"
+
"| bio | String | 3 | 60 |\n"
+
"| pets | String,Array | 2 | 40 |\n"
+
"| birthday | String | 2 | 40 |\n"
+
"| birthday | String | 2 | 40 |\n"
+
"| pets | String,Array | 2 | 40 |\n"
+
"| someBinData | BinData-old | 1 | 20 |\n"
+
"| someBinData | BinData-old | 1 | 20 |\n"
+
"| someWeirdLegacyKey | String | 1 | 20 |\n"
+
"| someWeirdLegacyKey | String | 1 | 20 |\n"
+
"+------------------------------------------------------------+"
;
"+------------------------------------------------------------+"
;
...
...
variety.js
View file @
e59f3367
...
@@ -69,7 +69,7 @@ log('Using maxDepth of ' + maxDepth);
...
@@ -69,7 +69,7 @@ log('Using maxDepth of ' + maxDepth);
if
(
typeof
sort
===
'undefined'
)
{
var
sort
=
{
_id
:
-
1
};
}
if
(
typeof
sort
===
'undefined'
)
{
var
sort
=
{
_id
:
-
1
};
}
log
(
'Using sort of '
+
tojson
(
sort
));
log
(
'Using sort of '
+
tojson
(
sort
));
if
(
typeof
outputFormat
===
'undefined'
)
{
var
outputFormat
=
"ascii"
;
}
if
(
typeof
outputFormat
===
'undefined'
)
{
var
outputFormat
=
'ascii'
;
}
log
(
'Using outputFormat of '
+
outputFormat
);
log
(
'Using outputFormat of '
+
outputFormat
);
...
@@ -224,14 +224,14 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
...
@@ -224,14 +224,14 @@ resultsDB[resultsCollectionName].find({}).forEach(function(key) {
resultsDB
[
resultsCollectionName
].
save
(
key
);
resultsDB
[
resultsCollectionName
].
save
(
key
);
});
});
var
sortedKeys
=
resultsDB
[
resultsCollectionName
].
find
({}).
sort
({
totalOccurrences
:
-
1
});
var
sortedKeys
=
resultsDB
[
resultsCollectionName
].
find
({}).
sort
({
totalOccurrences
:
-
1
,
'_id.key'
:
1
});
// occurrences count & alphabetical order
if
(
outputFormat
===
'json'
)
{
if
(
outputFormat
===
'json'
)
{
printjson
(
sortedKeys
.
toArray
());
// valid formatted json output, compressed variant is printjsononeline()
printjson
(
sortedKeys
.
toArray
());
// 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
sortedKeys
.
forEach
(
function
(
key
)
{
sortedKeys
.
forEach
(
function
(
key
)
{
table
.
push
([
key
.
_id
.
key
,
key
.
value
.
types
.
toString
(),
key
.
totalOccurrences
,
key
.
percentContaining
]);
table
.
push
([
key
.
_id
.
key
,
key
.
value
.
types
.
toString
(),
key
.
totalOccurrences
.
toString
(),
key
.
percentContaining
.
toString
()
]);
});
});
var
colMaxWidth
=
function
(
arr
,
index
)
{
var
colMaxWidth
=
function
(
arr
,
index
)
{
...
@@ -240,11 +240,11 @@ if(outputFormat === 'json') {
...
@@ -240,11 +240,11 @@ if(outputFormat === 'json') {
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
,
string
+
symbol
,
symbol
);
};
var
output
=
""
;
var
output
=
''
;
table
.
forEach
(
function
(
row
,
ri
){
table
.
forEach
(
function
(
row
,
ri
){
output
+=
(
"| "
+
row
.
map
(
function
(
cell
,
i
)
{
return
pad
(
colMaxWidth
(
table
,
i
),
cell
,
ri
==
1
?
"-"
:
" "
);}).
join
(
" | "
)
+
" |
\
n"
);
output
+=
(
'| '
+
row
.
map
(
function
(
cell
,
i
)
{
return
pad
(
colMaxWidth
(
table
,
i
),
cell
,
ri
==
1
?
'-'
:
' '
);}).
join
(
' | '
)
+
' |
\
n'
);
});
});
var
lineLength
=
output
.
split
(
"
\
n"
)[
0
].
length
-
2
;
// length of first (header) line minus two chars for edges
var
lineLength
=
output
.
split
(
'
\
n'
)[
0
].
length
-
2
;
// length of first (header) line minus two chars for edges
var
border
=
"+"
+
pad
(
lineLength
,
""
,
"-"
)
+
"+"
;
var
border
=
'+'
+
pad
(
lineLength
,
''
,
'-'
)
+
'+'
;
print
(
border
+
"
\
n"
+
output
+
border
);
print
(
border
+
'
\
n'
+
output
+
border
);
}
}
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