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
6faf9a1b
Commit
6faf9a1b
authored
Mar 06, 2015
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix documents percentages, if the limit is higher than real count of the documents #76
parent
384ecdf0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
9 deletions
+21
-9
LimitResultsAnalysisTest.java
...ava/com/github/variety/test/LimitResultsAnalysisTest.java
+16
-0
variety.js
variety.js
+5
-9
No files found.
test/src/test/java/com/github/variety/test/LimitResultsAnalysisTest.java
View file @
6faf9a1b
...
...
@@ -35,4 +35,20 @@ public class LimitResultsAnalysisTest {
analysis
.
validate
(
"name"
,
1
,
100
,
"String"
);
analysis
.
validate
(
"someBinData"
,
1
,
100
,
"BinData-old"
);
}
@Test
public
void
verifyLimitOverMaxResults
()
throws
Exception
{
// limit is set to higher number, that the actual number of documents in collection
// analysis should compute percentages based on the real number of documents, not on the
// number provided in the limit var.
final
ResultsValidator
analysis
=
variety
.
withLimit
(
10
).
runDatabaseAnalysis
();
analysis
.
validate
(
"_id"
,
5
,
100
,
"ObjectId"
);
analysis
.
validate
(
"name"
,
5
,
100
,
"String"
);
analysis
.
validate
(
"bio"
,
3
,
60
,
"String"
);
analysis
.
validate
(
"pets"
,
2
,
40
,
"String"
,
"Array"
);
analysis
.
validate
(
"someBinData"
,
1
,
20
,
"BinData-old"
);
analysis
.
validate
(
"someWeirdLegacyKey"
,
1
,
20
,
"String"
);
}
}
variety.js
View file @
6faf9a1b
...
...
@@ -205,7 +205,7 @@ var mergeDocument = function(docResult, interimResults) {
}
};
var
convertResults
=
function
(
interimResults
)
{
var
convertResults
=
function
(
interimResults
,
documentsCount
)
{
var
getKeys
=
function
(
obj
)
{
var
keys
=
[];
for
(
var
key
in
obj
)
{
...
...
@@ -221,7 +221,7 @@ var convertResults = function(interimResults) {
'_id'
:
{
'key'
:
key
},
'value'
:
{
'types'
:
getKeys
(
entry
.
types
)},
'totalOccurrences'
:
entry
[
'totalOccurrences'
],
'percentContaining'
:
entry
[
'totalOccurrences'
]
*
100
/
$limi
t
'percentContaining'
:
entry
[
'totalOccurrences'
]
*
100
/
documentsCoun
t
});
}
return
varietyResults
;
...
...
@@ -255,13 +255,9 @@ DBQuery.prototype.reduce = function(callback, initialValue) {
return
result
;
};
var
interimResults
=
db
[
collection
]
.
find
(
$query
)
.
sort
(
$sort
)
.
limit
(
$limit
)
.
reduce
(
reduceDocuments
,
{});
var
varietyResults
=
convertResults
(
interimResults
)
var
cursor
=
db
[
collection
].
find
(
$query
).
sort
(
$sort
).
limit
(
$limit
);
var
interimResults
=
cursor
.
reduce
(
reduceDocuments
,
{});
var
varietyResults
=
convertResults
(
interimResults
,
cursor
.
size
())
.
filter
(
filter
)
.
sort
(
comparator
);
...
...
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