This is my 100th post to this blog! And there’s a lot more where that came from!
Token graphage:
A domain change (formerly: assistedsilicon.blogspot.com), a platform change (Blogger to WordPress), 805.5 themes, and coming on two years later, the topics are mostly the same:
- Linux: vim config, bash aliases, useful scripts, hidden options, and lots more
- MySQL: How to do things you will likely need to do, and do them better
- Python: Resources, recipes, and tricks for using this incredible language
- Vista: How to live with it, partially
- Occasional other tech/geek items
On the graph:
- The nine month lacuna in 2007-08 is to be blamed on World of Warcraft.
- The spike near the end of 2008 corresponded to when I started using Windows Vista (at work, under duress). Discoveries do seem to increase in wartime…
For some reason I couldn’t wrangle my data into a graph I liked in OO Spreadsheet. So, of course, I made the graph in Python! To get the post data, I ran this against my WordPress MySQL DB:
1 2 3 4 | mysql -u root -p -e "use WORDPRESS_DB; \ select date(post_date) as date, post_title as title from wp_posts \ where post_type='post' and post_status='publish' \ group by post_date order by date(post_date) asc;" > posts.csv |
This grabs the dates and titles for all actual published posts, grouping and ordering them on the date. Then I put that output file into a short ugly script for graphing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #!/usr/bin/env python try: from pylab import * except: graphing = False import pprint import datetime # Read in the file of titles and dates: f = open('posts.csv') flines = [] for line in f: flines.append(line.split('\t')) # Create dict of year-month and counts therein: date_counts = {} for line in flines: if date_counts.has_key(line[0][0:7]): date_counts[line[0][0:7]] += 1 else: date_counts[line[0][0:7]] = 1 # Make a list of the counts, dates and sort them: counts = date_counts.items() counts.sort() # Turn the partial date strings into date objects for graphing: dates = [key for key, value in counts] dated_days = [] for day in dates: year = int(day[0:4]) month = int(day[5:7]) day = 1 date = datetime.date(year, month, day) dated_days.append(date) counts = [ value for key, value in counts] # Set labels x = xlabel('Date') setp(x, fontweight='bold') y = ylabel('Posts') setp(y, fontweight='bold') # Subplot to handle date positioning ax = subplot(111) labels = ax.get_xticklabels() setp(labels, fontweight='bold', rotation=30, fontsize=10) # Plot as dates plotted = plot(dated_days, counts, '--') setp(plotted, marker='s') title('Posts over time') grid(True) |
Latest version in my Code Trac.
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.








