How should I Arrange my data?
I'd like 开发者_运维技巧to log the CPU percentage of each process in different times. I need a data struct that will allow me to save the data like this:
- Explorer.EXE
- 19:03 | 47%
- 19:05 | 14%
- 19:08 | 24%
- Firefox.EXE
- 19:03 | 21%
- 19:05 | 14%
- 19:08 | 2%
- Messenger.EXE
- 19:03 | 11%
- 19:05 | 12%
- 19:08 | 11%
What's the right way to do it? I thought about tuples inside lists inside a list, but the identifier for a list is not a string but a number.
What about a dictionary that uses the process name as key: http://docs.python.org/library/stdtypes.html#dict
The dictionary value could be a list of tuples.
Something like this?
data = {
'Explorer.EXE': [ ("19:03", 47), ("19:05" , 14), ("19:08" , 24)],
'Firefox.EXE' : [ ("19:03", 21), ("19:05" , 14), ("19:08" , 2) ],
'Messenger.EXE': [ ("19:03" , 11), ("19:05" , 12), ("19:08" , 11)]
}
struct = {
"Explorer.EXE": [
(datetime.time(19, 03), .47),
(datetime.time(19, 05), .14),
...
],
"Firefox.EXE": [
(datetime.time(19, 03), .21),
(datetime.time(19, 05), .14),
...
],
...
}
精彩评论