Created
November 25, 2014 14:10
-
-
Save astynax/3c8aed9f6f2c532fd6bb to your computer and use it in GitHub Desktop.
landscape render for charted.co
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
# -*- coding: utf-8 -*- | |
""" | |
landscape to "charted.co" render :) | |
""" | |
from operator import itemgetter | |
from itertools import groupby | |
land = """ | |
.............................................................................................. | |
................................................................................!............. | |
...............................................................................!!!............ | |
......................................................!.......................!!!!!........... | |
.....................................................!!!.......!.............!!!!!!!.......... | |
.......................!............................!!!!!.....!!!...........!!!!!!!!!......... | |
......................!!!..........................!!$$$$$...$$$$!.........$$$!$$$!$$$........ | |
.....................!!!!!........................$$$$$$$$$.$$$$$$$.......$$$$$$$$$$$$$....... | |
........@...........!@!@@!!..............$.......$$$$$$$$$$$$$$$$$$$.....$$$$$$$$$$$$$$$...... | |
.......@@@.........@@@@@@@@@............$$$.....$$$$$$$$$$$$$$$$$$$$$...$$$$$$$$$$$$$$$$$..... | |
......@@@@@.......@@@@@@@@@@@..........$$$$$...$$$$$$$$$$$$$$$$$$$$$$$.$$$$$$$$$$$$$$$$$$$.... | |
.....@@@@@@@.....@@@@@@@@@@@@@........$$$$$$$.$$$$$$$$$$$$$$$@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$... | |
....@@@@@@@@@...@@@@@@@@@@@@@@@......$$$$$$$$$$$$$$$$$$$$$$$@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.. | |
...@@@@@@@@@@@.@@@@@@@@@@@@@@@@@....$$$$$$$$$$$$$@$$$$$$$$$@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$. | |
..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@..$$$$$$$$$$$$$@@@$$$$$$$@@@@@@@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ | |
.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$$$$$$$$$$$$$@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#####@#####@#####@@@@@@@#####@@@@@@@@@$$$ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#################@@@@@@@#####@@@@@@@@@@$$ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#################@@@@@@@#####@@@@@@@@@@@$ | |
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@@@@@@@#######***#######@@@@@@@#####@@@@@@@@@@@@ | |
@@@@@*@@@*@@@@@@@@@*@@@@@@@*@@@*@@@*@@@@@@@@@*@@@@@@@#######***#######@#@#@#@#####@@@@@@@@@@@@ | |
@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@*@#######***###################@*@*@*@*@*@* | |
********************************************************************************************** | |
""" | |
order = "*#@$!." | |
order_len = len(order) | |
lines = map(str.strip, filter(bool, land.split('\n'))) | |
# check size | |
assert all(len(l) == len(lines[0]) for l in lines) | |
raw_data = map(list, map(reversed, zip(*lines))) | |
# header | |
print '%,' + ','.join(order) | |
for cnt, raw_row in enumerate(raw_data): | |
# consistency check | |
assert all(c in order for c in raw_row) | |
cells = [(g[0], len(list(g[1]))) for g in groupby(map(order.find, raw_row))] | |
assert all(a <= b for ((a,_), (b,_)) in zip(cells, cells[1:])) | |
counts = dict(cells) | |
row = [cnt] + [counts.get(k, 0) for k in range(order_len)] | |
print ','.join(map(str, row)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment