gen_dict = {
"item_C_v001" : "jack",
"item_C_v002" : "kris",
"item_A_v003" : "john",
"item_B_v006" : "peter",
"item_A_v005" : "john",
"item_A_v004" : "dave"
}
Item Name | No. of Vers. | User
item_A | 3 | dave, john
item_B | 1 | peter
item_C | 2 | jack, kris
Item Name | No. of Vers. | User
item_A | 3 | dave(1), john(2)
item_B | 1 | peter(1)
item_C | 2 | jack(1), kris(1)
from collections import defaultdict
gen_dict = {
"item_C_v001" : "jack",
"item_C_v002" : "kris",
"item_A_v003" : "john",
"item_B_v006" : "peter",
"item_A_v005" : "john",
"item_A_v004" : "dave"
}
user_dict = defaultdict(set)
count_dict = {}
for item_name, user in gen_dict.iteritems():
user_dict[item_name[:-3]].add(user) # Sure you want -3 not -5?
count_dict[item_name[:-3]] = count_dict.get(item_name[:-3], 0) + 1
for name, num in sorted(count_dict.iteritems()):
print "Version Name : {0}\nNo. of Versions : {1}\nUsers : {2}".format(
name, num, ', '.join(item for item in user_dict[name]))
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/401522d4-a96a-4063-9755-863a93de490c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
(1 MiB) "item_C_v001" : "jack"
(5 MiB) "item_C_v002" : "kris"
(1 MiB) "item_A_v003" : "john",
(1 MiB) "item_B_v006" : "peter",
(2 MiB) "item_A_v005" : "john",
(1 MiB) "item_A_v004" : "dave"Item Name | No. of Vers. | User
item_A | 3 | dave(1, 1MiB), john(2, 3MiB)
item_B | 1 | peter(1, 1MiB)
item_C | 2 | jack(1, 1MiB), kris(1, 5MiB)--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/557625a8-3f4f-412f-aced-e16ce966d37d%40googlegroups.com.
user_ver_count = defaultdict(lambda: defaultdict(int))
user_ver_size = defaultdict(lambda: defaultdict(int))
...
for vers_name, artist_alias in gen_dict.iteritems():
...
user_ver_count[artist_alias[0]][strip_version_name] += 1
user_ver_size[artist_alias[0]][strip_version_name] += artist_alias[1]
users = ', '.join('{0} [{1} ({2}]'.format(alias, convert_size_query(sum(int(i) for i in asset_size_dict.get(alias))), user_ver_count[alias][version_name]) for alias in asset_user_dict[version_name])
It doesn't hurt to break up your logic into individual lines, to help others that can and will end up reading your code. And also to set obscure members of a list into a nicely named local variable :-)Justin--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/705d5dd5-8be5-4449-8149-2f5a9af7b77e%40googlegroups.com.
Untested, but that looks to be almost exactly the same logic as what I gave you for tracking the counts for each user/product. But instead of tracking a counter you would just accumlate the size:user_ver_count = defaultdict(lambda: defaultdict(int)) user_ver_size = defaultdict(lambda: defaultdict(int)) ... for vers_name, artist_alias in gen_dict.iteritems(): ... user_ver_count[artist_alias[0]][strip_version_name] += 1 user_ver_size[artist_alias[0]][strip_version_name] += artist_alias[1]Also, this line is impossible to read:users = ', '.join('{0} [{1} ({2}]'.format(alias, convert_size_query(sum(int(i) for i in asset_size_dict.get(alias))), user_ver_count[alias][version_name]) for alias in asset_user_dict[version_name])It doesn't hurt to break up your logic into individual lines, to help others that can and will end up reading your code. And also to set obscure members of a list into a nicely named local variable :-)Justin
On Fri, Feb 17, 2017 at 1:50 PM likage <dissid...@gmail.com> wrote:
This time round, I tried using tuple like you have mentioned. see,s to be working well but I got an issue, where if there is an existing user, it will collate and summed up the overall data size under 1 user...--In the pastebin, I am expecting item_C to be `kilo [3 (1]` but it seems to add up the values derived from item_B in kilo's case
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Hi Justin,Sorry for the late reply.It works like a charm, thanks!
On Thursday, February 16, 2017 at 8:04:50 PM UTC-8, Justin Israel wrote:
Untested, but that looks to be almost exactly the same logic as what I gave you for tracking the counts for each user/product. But instead of tracking a counter you would just accumlate the size:user_ver_count = defaultdict(lambda: defaultdict(int)) user_ver_size = defaultdict(lambda: defaultdict(int)) ... for vers_name, artist_alias in gen_dict.iteritems(): ... user_ver_count[artist_alias[0]][strip_version_name] += 1 user_ver_size[artist_alias[0]][strip_version_name] += artist_alias[1]Also, this line is impossible to read:users = ', '.join('{0} [{1} ({2}]'.format(alias, convert_size_query(sum(int(i) for i in asset_size_dict.get(alias))), user_ver_count[alias][version_name]) for alias in asset_user_dict[version_name])It doesn't hurt to break up your logic into individual lines, to help others that can and will end up reading your code. And also to set obscure members of a list into a nicely named local variable :-)Justin
On Fri, Feb 17, 2017 at 1:50 PM likage <dissid...@gmail.com> wrote:
This time round, I tried using tuple like you have mentioned. see,s to be working well but I got an issue, where if there is an existing user, it will collate and summed up the overall data size under 1 user...--In the pastebin, I am expecting item_C to be `kilo [3 (1]` but it seems to add up the values derived from item_B in kilo's case
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/705d5dd5-8be5-4449-8149-2f5a9af7b77e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/ccd99399-493e-4616-8c2f-a5ba656e172b%40googlegroups.com.