Created
November 26, 2015 09:53
-
-
Save averrin/f6936712e0659536b419 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
departments = [] | |
monthes = getMonthList() | |
p = {} | |
pp = {} | |
for m in monthes: | |
pipe = [ | |
{'$group': { | |
'_id': '$department', | |
m: {'$sum': '$' + m} | |
}} | |
] | |
if filter_proj is not None and filter_proj: | |
pipe.insert(0, {'$match': {'project': {'$in': filter_proj}}}) | |
res = db.aggregate(pipe) | |
p[m] = [r for r in res] | |
pipe = [ | |
{'$group': { | |
'_id': '$username', | |
m: {'$sum': '$' + m} | |
}}, | |
] | |
if filter_proj is not None and filter_proj: | |
pipe.insert(0, {'$match': {'project': {'$in': filter_proj}}}) | |
res = db.aggregate(pipe) | |
pp[m] = [r for r in res] | |
for dep in _departments.keys(): | |
dp = {} | |
for m in p: | |
_dp = list(filter(lambda x: x['_id'] == dep, p[m])) | |
if _dp: | |
dp[m] = _dp[0][m] | |
for person in _departments[dep]: | |
_pp = list( | |
filter(lambda x: x['_id'] == person['username'], pp[m])) | |
if _pp: | |
person[m] = _pp[0][m] | |
if not dp or not sum(dp.values()): | |
continue | |
persons = _departments[dep][:] | |
if (filter_proj is not None and filter_proj) or (filter_dep is not None and filter_dep): | |
for person in _departments[dep]: | |
s = 0 | |
print(person) | |
for m in p: | |
print(m, person.get(m, 0)) | |
s += person.get(m, 0) | |
print(s) | |
if not s: | |
persons.remove(person) | |
departments.append({ | |
"title": dep, | |
"persons_count": len(_departments[dep]) - 1, # minus Unknown | |
"persons": persons, | |
"percents": dp | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment