Created
October 6, 2010 13:52
-
-
Save serhei/613375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size(850, 1100) | |
# save_footer_row = True # HARDCODE FOR NOW | |
import calendar, datetime | |
start_date = datetime.date(2010, 9, 13) | |
# Compute total_days, days_so_far, numrows, maxpage: | |
total_days, add_date = 0, start_date | |
for i in range(0, 18): | |
add_days = calendar.monthrange(add_date.year, add_date.month)[1] | |
print "%d %d %d %d" % (i, add_date.year, add_date.month, add_days) | |
total_days += add_days | |
if add_date.month == 12: | |
add_date = datetime.date(add_date.year+1, 1, 1) | |
else: | |
add_date = datetime.date(add_date.year, add_date.month+1, 1) | |
if PAGENUM > 1: | |
days_so_far = -34 + PAGENUM*32 | |
else: | |
days_so_far = 0 | |
maxpage = (total_days - 30)/32 + 2 # TODO feh | |
numrows = 35 # ... oops, must have miscalculated 35 | |
#months, add_date = 0, start_date | |
#while months < 18: | |
# add_date += datetime.timedelta(months=1); months++ | |
# Hack so we can find out how many pages to export: | |
if False: | |
font("Helvetica", 48) | |
align(CENTER) | |
text("Please export " + str(maxpage) + "pages.", 0, 50, width=850) | |
# Determine whether to show the header, column headers, or footer: | |
hastitle = PAGENUM == 1 | |
hasheader = True # ... let's draw table headings on every single page. | |
hasfooter = PAGENUM == maxpage | |
stroke(0.1) | |
fill(0.1) | |
# Draw calendar title, if any: | |
if hastitle: | |
font("Helvetica", 48) | |
align(CENTER) | |
text(u"粵語、勝利之道・" + str(total_days) + u"日", 0, 50, width=850) | |
translate(0, 60); numrows -= 2 # ... 2 rows eaten up by the big title. | |
translate(0, 10) # ... offset on all pages for a round # of rows. | |
translate(25, 0) # ... offset to make sure an 800px wide table is centred. | |
font("Helvetica", 18) | |
align(CENTER) | |
# 800px wide area for the table (25px margins); column separators are: | |
header_lines = [0, 200, 400, 525, 650, 800] | |
standard_lines = header_lines + [266, 333] | |
def hr(start = 0, end = 800, draw=True): | |
"""Horizontal line from start to end offset.""" | |
return line(start, 0, end, 0, draw) | |
def draw_vertlines(offsets): | |
"""Series of 30px-high lines at given offsets.""" | |
for offset in offsets: | |
line(offset, 0, offset, 30) | |
# Draw explanatory header, if any: | |
if hasheader: | |
hr(); draw_vertlines(header_lines) | |
text(u"日付", 0, 22, width=200) | |
text(u"インプット活動", 200, 22, width=200) | |
text(u"殘り日数", 400, 22, width=125) | |
text(u"經過日数", 525, 22, width=125) | |
text(u"備考欄", 650, 22, width=150) | |
translate(0, 30) | |
# Lines for the separate SRS usage & tracking categories: | |
hr(200, 400); draw_vertlines(standard_lines) | |
text(u"SRS", 200, 20, width=66) | |
text(u"音声", 266, 22, width=66) | |
text(u"文字", 333, 22, width=67) | |
translate(0, 30) | |
numrows -= 2 # ... 2 more rows eaten by table headers. | |
# Draw a topline for the very first row | |
hr() | |
def format_day(d): | |
s = [u"月", u"火", u"水", u"木", u"金", u"土", u"日"] # Jp days of week | |
return u"%d年%02d月%02d日 (%s)" \ | |
% (d.year, d.month, d.day, s[d.weekday()]) | |
# Draw each row with all boxen except topline: | |
for days_so_far in range(days_so_far, days_so_far+numrows-1): | |
days_remaining = total_days - days_so_far | |
if days_remaining < 1: break # TODO feh | |
date_thisrow = start_date + datetime.timedelta(days=days_so_far) | |
# Draw a light grey background if the day is a Sunday | |
if date_thisrow.weekday() == 6: | |
fill(0,0,0,0.1) | |
stroke(1) | |
rect(1, 1, 799, 29) | |
fill(0.1) | |
stroke(0.1) | |
draw_vertlines(standard_lines) | |
text(format_day(date_thisrow), 0, 22, width=200) | |
days_remaining = total_days - days_so_far | |
text(u"殘り" + str(days_remaining) + u"日", 400, 22, width=125) | |
text(str(days_so_far+1) + u"日目", 525, 22, width=125) | |
translate(0, 30) | |
hr() | |
# Draw congratulatory footer, if any: | |
if hasfooter: | |
hr() | |
align(CENTER) | |
fill(1, 0, 0) | |
font("Helvetica Bold", 24) | |
text(u"目的達成!お疲れ!", 0, 30, width=800) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment