rotate the maths

This commit is contained in:
Tyrel Souza 2018-08-28 23:12:00 -04:00
parent 8454fe6aec
commit 7d576552fd

View File

@ -1,9 +1,5 @@
import datetime import datetime
import requests
import json
import os import os
import sys
from selenium import webdriver
from collections import defaultdict from collections import defaultdict
from PIL import ImageFont, Image from PIL import ImageFont, Image
import inkyphat import inkyphat
@ -29,7 +25,7 @@ def print_digit(position, digit):
sprite = text_mask.crop((s_x, 0, s_x + num_width, num_height)) sprite = text_mask.crop((s_x, 0, s_x + num_width, num_height))
inkyphat.paste(inkyphat.WHITE, (o_x, o_y), sprite) inkyphat.paste(inkyphat.BLACK, (o_x, o_y), sprite)
def print_number(position, number): def print_number(position, number):
"""Prints a number using the sprite sheet.""" """Prints a number using the sprite sheet."""
@ -48,6 +44,7 @@ def main():
def get_goodreads_stats(): def get_goodreads_stats():
from selenium import webdriver
payload = { payload = {
'email': os.environ.get('EMAIL'), 'email': os.environ.get('EMAIL'),
'password': os.environ.get('PASSW'), 'password': os.environ.get('PASSW'),
@ -73,47 +70,39 @@ def get_goodreads_stats():
return pages, books return pages, books
def get_stats(pages, books): def get_stats(pages, books):
size = 3 size = 5
coords = defaultdict(list) coords = defaultdict(list)
columns = ["year", "books", "pages"] columns = ["year", "books", "pages"]
start_x, start_y = 12, 25 start_x, start_y = 12, 25
column_offset = [0,70,140] column_offset = [0,78,140]
year_offset = 15 year_offset = 15
for idy, year in enumerate(pages.keys()):
for idx, column in enumerate(columns):
coords[year].append((
start_x + column_offset[idx],
start_y + (year_offset * idy)
))
_stats = [] _stats = []
for idx, year in enumerate(list(reversed(sorted(books.keys())))[:size]):
page_count = pages[year] for idy, year in enumerate(sorted(pages.keys(), key=lambda yr: -int(yr))):
book_count = books[year] row = {}
_stats.append({ col_data = {'year':year, 'pages': pages[year], 'books': books[year]}
'year': [str(year), coords['year'][idx]], y = start_y + (year_offset * idy)
'books': [str(book_count), coords['books'][idx]], for idx, column in enumerate(columns):
'pages': [str(page_count), coords['pages'][idx]], x = start_x + column_offset[idx]
}) row[column] = (col_data[column], (x,y))
_stats.append(row)
return _stats return _stats
def draw(stats): def draw(stats):
colour = 'red' inkyphat.set_colour('red')
inkyphat.set_colour(colour)
inkyphat.set_border(inkyphat.WHITE) inkyphat.set_border(inkyphat.WHITE)
inkyphat.set_image("./background.png") inkyphat.set_image("./background.png")
draw_row('year', stats, 12) draw_row('year', stats)
draw_row('books', stats, 18) draw_row('books', stats)
draw_row('pages', stats, 12) draw_row('pages', stats)
inkyphat.show() inkyphat.show()
def draw_row(row, stats, size): def draw_row(row, stats):
for year in stats: for year in stats:
count = year[row][0] count = year[row][0]
x,y = year[row][1] x,y = year[row][1]