| | |
Query regarding Data mining and plotting graph...
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 11
Reputation:
Solved Threads: 0
I have log file which gives CPU utilization and timestamp value at regular interval.
Logs snippet below:
==========LOGS==============
a:CPU [ 85%]: asdf asd 123 xyz
A: Ts 23086, Netvalue 3286, someothervalues 3456
abc abc
xyz xyz
a:CPU [ 75%]: asdf asd 123 xyz
A: Ts 24088, Netvalue 3266, someothervalues 6576
======End of Logs ===========
What I want to do:
I want to make a graph of CPU load vs timestamp(Ts) value
So I thought if I can create a Dictionary like Dict = {"Timestamp":"CPU Load"} (eg: Dict = {24088:85} for above logs)
then plot a graph somehow using entries in dictionary.
My Queries:
1. How to get a dictionary in above format? I'm weak at data mining...
2. For plotting graph - suggest if this can be a correct approach using dictionary? ..or some other approach would work ...(something like exporting values to MS Excel and creating plot cpu/time.)
Any help appreciated....
Logs snippet below:
==========LOGS==============
a:CPU [ 85%]: asdf asd 123 xyz
A: Ts 23086, Netvalue 3286, someothervalues 3456
abc abc
xyz xyz
a:CPU [ 75%]: asdf asd 123 xyz
A: Ts 24088, Netvalue 3266, someothervalues 6576
======End of Logs ===========
What I want to do:
I want to make a graph of CPU load vs timestamp(Ts) value
So I thought if I can create a Dictionary like Dict = {"Timestamp":"CPU Load"} (eg: Dict = {24088:85} for above logs)
then plot a graph somehow using entries in dictionary.
My Queries:
1. How to get a dictionary in above format? I'm weak at data mining...
2. For plotting graph - suggest if this can be a correct approach using dictionary? ..or some other approach would work ...(something like exporting values to MS Excel and creating plot cpu/time.)
Any help appreciated....
•
•
•
•
Logs snippet below:
==========LOGS==============
a:CPU [ 85%]: asdf asd 123 xyz
A: Ts 23086, Netvalue 3286, someothervalues 3456
abc abc
xyz xyz
a:CPU [ 75%]: asdf asd 123 xyz
A: Ts 24088, Netvalue 3266, someothervalues 6576
======End of Logs ===========
If so you could do something like this:
python Syntax (Toggle Plain Text)
fh = open('my_log.inf') flines = fh.readlines() fh.close() for line in flines: if line[:2\] == 'a:' #get CPU # etc...
•
•
Join Date: May 2009
Posts: 11
Reputation:
Solved Threads: 0
Thanks for the input... I'm able to extract keywords ...but Im stuck at next level:
Now I want to check a condition that
if
"CPU" keyword occurs in line 1 (#I'm able to do this)
then
check for next line for keyword "Ts" (How do I do this ???)
and then only
create an entry in dictionary like D{CPU : timestamp} (#I'm able to do this)
Code Snippet below:
===========
a:CPU [ 75%]: asdf asd 123 xyz
A: Ts 24088,
=========
Now I want to check a condition that
if
"CPU" keyword occurs in line 1 (#I'm able to do this)
then
check for next line for keyword "Ts" (How do I do this ???)
and then only
create an entry in dictionary like D{CPU : timestamp} (#I'm able to do this)
Code Snippet below:
===========
a:CPU [ 75%]: asdf asd 123 xyz
A: Ts 24088,
=========
If you read your lines into a list via
That's an extremely simple solution that you could use. There's many ways to do it, but I hope this at least gets you on a path to answering your query
readlines() you can simply use indexing... something like this: python Syntax (Toggle Plain Text)
my_index = 0 while my_index < len(my_lines): current_line = my_lines[index] if 'CPU' in current_line: #get CPU data index += 1 next_line = my_lines[index] # Get Ts data # Save data index += 1
![]() |
Similar Threads
- Talks on Data Mining (C++)
- in search of patterns (Computer Science)
- Data-mining & Security (Network Security)
- problem plotting graph (Python)
- data-grabbing & mining - need script-help (PHP)
- Opening another software application in runtime (C#)
- PLotting a map/graph (Game Development)
Other Threads in the Python Forum
- Previous Thread: Calling grep from within python
- Next Thread: wxpython - repositioning help
| Thread Tools | Search this Thread |
alarm app beginner cipher cmd coordinates cx-freeze data decimals dictionary directory dynamic error examples file float format ftp function generator getvalue gui halp homework http images import input ip itunes java keycontrol leftmouse line linux list lists logging loop maintain maze millimeter module mouse mysqldb number numbers output parsing path port prime programming projects push py2exe pygame pyglet pymailer pyqt python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation split sqlite ssh string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo verify vigenere web webservice wikipedia windows wxpython






