Heya Daniweb,
I've been working on Regular Expressions, thanks to cghtkh who told me about them. I've used resources from:
NewThinkTank.com
Python Regular Expression Documentation
and Daniweb.com!
I figured I'd share my code, ask a few questions, and get some feedback on what I did if I can. Feedback helps me improve my programming skills, Hopefully I won't be a pest to anyone.
import re #Imports the Regular Expression Library
f = open('randomcharacters.txt') #Opens "randomcharacters.txt" from same directory as the script
lineToSearch = ""
for line in f:
lineToSearch += line #Goes through all the lines in the data one by one
pingFinderPattern = re.compile('time=([0-9.]+) ms')
Pattern1 = re.search('time=([0-9.]+) ms', line)
Pattern1 = re.findall('time=([0-9.]+) ms',lineToSearch)
for i in Pattern1: #Question: Is the i in this mean anything special such as Iterations? I couldn't get an answer for that.
print(i)
This code took ~4000 pings and compiled it into some numbers which I then pasted to Google Docs and generated these graphs.
Google Docs Graphs Link
I'm interested in hearing feedback on this, I removed a few Outliers in the ~400ms range for Google, however StackOverflow that 5+ High Ping times per spike so I kept it.
Question:
for i in Pattern1: #Question: Is the i in this mean anything special such as Iterations? I couldn't get an answer for that.
print(i)
I'm looking to use matplotlib to plot data as an all in one tool so I don't have to copy and paste and how I think this would work potentially would be to get the data in a csv form and just put the variable into the plot.
Example:
import re
import matplotlib.pyplot as plt
f = open('randomcharacters.txt')
lineToSearch = ""
for line in f:
lineToSearch += line
pingFinderPattern = re.compile('time=([0-9.]+) ms')
Pattern1 = re.search('time=([0-9.]+) ms', line)
Pattern1 = re.findall('time=([0-9.]+) ms',lineToSearch)
for i in Pattern1:
print(i)
plt.plot(i)
plt.ylabel('Ping Time')
plt.show
However this returns one value per line I believe, and I'm not sure how to go about this. I've spent some time searching around and watching tutorial videos.
Thanks for your time everyone, I truly appreciate each and every response and all criticism, I hope one day to be a skilled programmer who can give wise advice to others learning. :)
Respectfully,
BombShock.