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
512f0fdc
Commit
512f0fdc
authored
Mar 23, 2012
by
James Cropcho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
well, that's pretty inefficient, but I have a better idea...
parent
7b6fc8c5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
24 deletions
+61
-24
.gitignore
.gitignore
+1
-0
keys.js
keys.js
+60
-24
No files found.
.gitignore
0 → 100644
View file @
512f0fdc
*~
keys.js
View file @
512f0fdc
use
popplet
;
if
(
typeof
collection
==
"undefined"
)
{
throw
"You have to supply a 'collection' variable, a la
\"
--eval 'var limit = 10'
\"
"
;
}
if
(
typeof
limit
==
"undefined"
)
{
limit
=
db
[
collection
].
count
();
}
print
(
"Using limit of "
+
limit
);
var
alreadyEmitted
=
new
Array
();
// global
schemaAnalyzerKeyIsPresent
=
function
(
toBeEmitted
,
alreadyEmitted
)
{
for
(
key
in
alreadyEmitted
)
{
if
(
key
[
"key"
]
===
toBeEmitted
[
"key"
]
&&
key
[
"type"
]
===
toBeEmitted
[
"type"
])
{
return
true
;
}
}
return
false
;
}
db
.
system
.
js
.
save
(
{
_id
:
"schemaAnalyzerKeyIsPresent"
,
value
:
schemaAnalyzerKeyIsPresent
}
);
c
anHaveChildren
=
function
(
v
)
{
var
isArray
=
(
v
&&
schemaAnalyzerC
anHaveChildren
=
function
(
v
)
{
var
isArray
=
v
&&
typeof
v
===
'object'
&&
typeof
v
.
length
===
'number'
&&
!
(
v
.
propertyIsEnumerable
(
'length'
)));
!
(
v
.
propertyIsEnumerable
(
'length'
));
var
isObject
=
typeof
v
===
'object'
;
return
isArray
||
isObject
;
}
db
.
system
.
js
.
save
(
{
_id
:
"
canHaveChildren"
,
value
:
c
anHaveChildren
}
);
db
.
system
.
js
.
save
(
{
_id
:
"
schemaAnalyzerCanHaveChildren"
,
value
:
schemaAnalyzerC
anHaveChildren
}
);
mapRecursive
=
function
(
parentKey
,
keys
)
{
schemaAnalyzerMapRecursive
=
function
(
parentKey
,
keys
)
{
for
(
var
key
in
keys
)
{
var
value
=
keys
[
key
];
key
=
key
.
replace
(
/
\d
+/g
,
'
XX'
);
key
=
(
parentKey
+
"."
+
key
).
replace
(
/
\.\d
+/g
,
'.
XX'
);
emit
({
"key"
:
parentKey
+
"."
+
key
,
"typee"
:
typeof
value
},
{
occurrences
:
1
})
;
toBeEmitted
=
{
key
:
key
,
type
:
typeof
value
}
;
if
(
canHaveChildren
(
value
))
{
mapRecursive
(
parentKey
+
"."
+
key
,
value
);
if
(
!
schemaAnalyzerKeyIsPresent
(
toBeEmitted
,
alreadyEmitted
))
{
emit
(
toBeEmitted
,
{
occurrences
:
1
});
alreadyEmitted
.
push
(
toBeEmitted
);
}
if
(
schemaAnalyzerCanHaveChildren
(
value
))
{
schemaAnalyzerMapRecursive
(
key
,
value
);
}
}
}
db
.
system
.
js
.
save
({
_id
:
"
mapRecursive"
,
value
:
m
apRecursive
});
db
.
system
.
js
.
save
({
_id
:
"
schemaAnalyzerMapRecursive"
,
value
:
schemaAnalyzerM
apRecursive
});
map
=
function
()
{
var
keys
=
this
;
var
alreadyEmitted
=
new
Array
();
// reset global variable
for
(
var
key
in
keys
)
{
var
value
=
keys
[
key
];
key
=
key
.
replace
(
/
\
d
+/g
,
'
XX'
);
key
=
key
.
replace
(
/
\
.\d
+/g
,
'.
XX'
);
emit
({
"key"
:
key
,
"typee"
:
typeof
value
},
{
occurrences
:
1
});
toBeEmitted
=
{
key
:
key
,
type
:
typeof
value
};
if
(
!
schemaAnalyzerKeyIsPresent
(
toBeEmitted
,
alreadyEmitted
))
{
emit
(
toBeEmitted
,
{
occurrences
:
1
});
alreadyEmitted
.
push
(
toBeEmitted
);
}
if
(
c
anHaveChildren
(
value
))
{
m
apRecursive
(
key
,
value
);
if
(
schemaAnalyzerC
anHaveChildren
(
value
))
{
schemaAnalyzerM
apRecursive
(
key
,
value
);
}
}
}
...
...
@@ -52,16 +79,25 @@ reduce = function(key, values){
}
finalize
=
function
(
key
,
value
)
{
value
.
percentage
=
value
.
occurrences
/
1000
*
100.0
;
value
.
percentage
=
value
.
occurrences
/
limit
*
100.0
;
return
value
;
}
db
.
usersKeyNames
.
drop
();
db
.
users
.
mapReduce
(
map
,
reduce
,
{
finalize
:
finalize
,
out
:
'usersKeyNames'
,
verbose
:
true
,
limit
:
1000
,
sort
:
{
_id
:
-
1
}});
db
.
usersKeyNames
.
find
()
var
resultsCollectionName
=
collection
+
"KeyNames"
;
db
[
collection
].
mapReduce
(
map
,
reduce
,
{
finalize
:
finalize
,
out
:
{
replace
:
resultsCollectionName
,
db
:
"schemaAnalyzerResults"
},
limit
:
limit
,
sort
:
{
_id
:
-
1
},
scope
:
{
limit
:
limit
}});
var
resultsDB
=
db
.
getMongo
().
getDB
(
"schemaAnalyzerResults"
);
var
keyNames
=
resultsDB
[
resultsCollectionName
].
find
().
sort
({
"value.percentage"
:
-
1
});
keyNames
.
forEach
(
function
(
keyName
)
{
print
(
tojson
(
keyName
,
''
,
true
));
});
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