You are not logged in.
Pages: 1
Today I wanted to create a simple script that would graph my pacman activity, and I thought I might as well share it with community. Below you can find a python script that serves that purpose. You will need python2-matplotlib to use it. And here what my version of the graph looks like:
"""
Copyright (C) 2011 Yaşar Arabacı
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import re
import datetime
import time
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from collections import Counter
months = mdates.MonthLocator() # every month
days = mdates.DayLocator() # Every day
monthsFmt = mdates.DateFormatter('%m-%Y')
logfile = "/var/log/pacman.log"
interesting_line = re.compile(
r"\[(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2})\] "
"(?P<action>installed|upgraded|removed)")
installs = Counter()
upgrades = Counter()
removes = Counter()
with open(logfile) as logfile:
for line in logfile:
match = interesting_line.search(line)
if match:
struct = time.strptime(match.group("datetime"),"%Y-%m-%d %H:%S")
date = datetime.date(struct.tm_year, struct.tm_mon, struct.tm_mday)
if match.group("action") == "installed":
installs[date] += 1
elif match.group("action") == "upgraded":
upgrades[date] += 1
elif match.group("action") == "removed":
removes[date] += 1
fig = plt.figure()
ax = fig.add_subplot(111)
insdatenumpairs = zip(installs.keys(), installs.values())
insdatenumpairs = sorted(insdatenumpairs, key = lambda pair: pair[0])
upgdatenumpairs = zip(upgrades.keys(), upgrades.values())
upgdatenumpairs = sorted(upgdatenumpairs, key = lambda pair: pair[0])
remdatenumpairs = zip(removes.keys(), removes.values())
remdatenumpairs = sorted(remdatenumpairs, key = lambda pair: pair[0])
ax.plot([pair[0] for pair in insdatenumpairs],[pair[1] for pair in insdatenumpairs],"b")
ax.plot([pair[0] for pair in upgdatenumpairs],[pair[1] for pair in upgdatenumpairs],"g")
ax.plot([pair[0] for pair in remdatenumpairs],[pair[1] for pair in remdatenumpairs],"y")
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(days)
ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
ax.grid(True)
fig.autofmt_xdate()
plt.legend(("installs","upgrades","removes"))
plt.xlabel("Date")
plt.ylabel("# of packages")
plt.show()
Last edited by yasar11732 (2012-01-08 11:58:35)
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
Neat! Why not make a format package in the AUR? That would simplify the need for deps and make it easier to get to users.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Good idea. I never posted a package to AUR though, and never did a PKGBUILD from scratch. But I will look into it.
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
Here is a little bit different version, only showing total number of packages over time.
"""
Copyright (C) 2011 Yaşar Arabacı
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import re
import datetime
import time
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from collections import Counter
months = mdates.MonthLocator() # every month
days = mdates.DayLocator() # Every day
monthsFmt = mdates.DateFormatter('%m-%Y')
logfile = "/var/log/pacman.log"
interesting_line = re.compile(
r"\[(?P<datetime>\d{4}-\d{2}-\d{2} \d{2}:\d{2})\] "
"(?P<action>installed|removed)")
total = 0
packs = Counter()
with open(logfile) as logfile:
for line in logfile:
match = interesting_line.search(line)
if match:
struct = time.strptime(match.group("datetime"),"%Y-%m-%d %H:%S")
date = datetime.date(struct.tm_year, struct.tm_mon, struct.tm_mday)
if match.group("action") == "installed":
total += 1
elif match.group("action") == "removed":
total -= 1
packs[date] = total
fig = plt.figure()
ax = fig.add_subplot(111)
datenumpairs = zip(packs.keys(), packs.values())
datenumpairs = sorted(datenumpairs, key = lambda pair: pair[0])
ax.plot([pair[0] for pair in datenumpairs],[pair[1] for pair in datenumpairs])
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsFmt)
ax.xaxis.set_minor_locator(days)
ax.format_xdata = mdates.DateFormatter('%Y-%m-%d')
ax.grid(True)
fig.autofmt_xdate()
plt.xlabel("Date")
plt.ylabel("# of packages")
plt.show()
Last edited by yasar11732 (2012-01-08 11:59:09)
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
Here is AUR page: https://aur.archlinux.org/packages.php?ID=55634
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
We already have pacgraph http://www.archlinux.org/packages/?name=pacgraph , not sure if packgraph won't cause confusion.
Offline
Good idea, but doesn't work here:
Traceback (most recent call last):
File "/usr/bin/packgraph", line 73, in <module>
datemin = datetime.datetime(min(installs).year, min(installs).month -1, min(installs).day)
ValueError: month must be in 1..12
Why is there a "-1" behind min(installs)? I set up my system in this January, so "min(installs).month -1" is probably 0.
Offline
Same here
Registed Linux User 608596
Offline
Good idea, but doesn't work here:
Traceback (most recent call last): File "/usr/bin/packgraph", line 73, in <module> datemin = datetime.datetime(min(installs).year, min(installs).month -1, min(installs).day) ValueError: month must be in 1..12
Why is there a "-1" behind min(installs)? I set up my system in this January, so "min(installs).month -1" is probably 0.
I put that to make a left margin on the graph, didn't realize that might cause that error. Fixing now.
Edit : Done
Edit2: You may want to remake the package now.
Last edited by yasar11732 (2012-01-08 12:06:17)
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
We already have pacgraph http://www.archlinux.org/packages/?name=pacgraph , not sure if packgraph won't cause confusion.
Show I remove it from AUR, or rename it perhaps?
Yo Dawg, I heard you likes patches, so I have created a patch for your patch, so you can patch your patches before you patch.
Offline
karol wrote:We already have pacgraph http://www.archlinux.org/packages/?name=pacgraph , not sure if packgraph won't cause confusion.
Show I remove it from AUR, or rename it perhaps?
If you want to do anything at all, renaming sounds more sensible :-)
Offline
@yasar11732 - I like your pacman graphing program. I had no idea what daily -Syus would look like. Cool. Thanks for putting it in AUR. That made it easy for me to get.
I agree with karol that it would be good to rename it. Packgraph is too close in name to pacgraph.
I also tried to run the second version, the one that shows the total number of packages over time, but i had this error:
$ python2 grapher.py
File "grapher.py", line 3
SyntaxError: Non-ASCII character '\xc5' in file grapher.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Offline
Pages: 1