I did some work to the weather page of the blog.
It now outputs exactly what it used to output, but with 33% less code.
I changed four iterations of the code on the left to one of the code on the right and added calls to the new class instead of just brute forcing my way through the images. It doesn’t speed it up measurably because the program spend most of the time waiting for matplotlib.pyplot to generate the images. I more just wanted a task to prove to myself that I’ve still got the skills.
speedTitle = current_time + ' - ' + datalist[3] + ' MPH'
print(speedTitle)
fig, ax = plt.subplots(figsize=(10,8))
df4.plot.line(x='time', y='value',color='crimson', ax=ax)
plt.title(speedTitle)
plt.ylabel("Wind Speed in MPH")
plt.xlabel("Time of reading")
plt.savefig('/var/www/html/image/speed.png')
class ImageOut:
def __init__(self, chartTitle, rawVal, unit, valList, outFile):
self.chartTitle = chartTitle
self.rawVal = rawVal
self.unit = unit
self.valList = valList
self.outFile = outFile
def createImage(self):
now_time = time.ctime()
printTitle = now_time + ' - ' + self.rawVal + self.unit
fig, ax = plt.subplots(figsize=(10,8))
self.valList.plot.line(x='time', y='value',color='crimson', ax=ax)
plt.title(printTitle)
plt.ylabel(self.chartTitle)
plt.xlabel("Time of reading")
plt.savefig(outDir + self.outFile)
You can find the code out on my github if you are curious about it.