Skip to content

Commit

Permalink
Merge 1084797 into 1fdb049
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-stokes committed Feb 18, 2020
2 parents 1fdb049 + 1084797 commit b0f8951
Show file tree
Hide file tree
Showing 2 changed files with 173 additions and 9 deletions.
86 changes: 86 additions & 0 deletions spinn_utilities/bacon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (c) 2017-2018 The University of Manchester
#
# 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/>.
False
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:snake snake bacon bacon bacon bacon bacon bacon bacon bacon:
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:snake snake bacon bacon bacon bacon bacon bacon bacon bacon:
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon:
1:mushroom mushroom bacon bacon bacon bacon bacon bacon bacon:
1:snake snake bacon bacon bacon bacon bacon bacon bacon bacon:
2:This was a triumph! I'm making a note here Huge Success!!! :
2:It's hard to overstate my satisfaction. Aperture Science :
2:We do what we must because we can For the good of all of us:
2:Except the ones who are dead. But there's no sense crying :
2:over every mistake. You just keep on trying till you run :
2:out of cake. And the science gets done. And you make a neat:
2:gun for the people are still alive. I'm not even angry.....:
2:I'm being so sincere right now. Even through you broke my :
2:heart, and killed me. And tore me to pieces. And threw :
2:every piece into a fire. As they burned it hurt because :
2:I was so happy for you! Now, these points of data make a :
2:beautiful line. And we're out of beta. We're releasing on :
2:time! So I'm GLaD I got burned! Think of all the things we :
2:learned! for the people who are still alive. Go ahead and :
2:leave me... I think I'd perfer to stay inside... Maybe you :
2:will find someone else to help you. Maybe Black Mesa? That :
2:was a joke. Ha Ha. Fat Chance! Anyway this cake is great! :
2:It's so delicious and moist! Look at me still talking when:
2:there's science to do! When I look out there, it makes me :
2:glad I'm not you. I've experiments to run. There is :
2:research to be done. On the people who are still alive. And:
2:believe me I am still alive. I'm doing science and I'm :
2:still alive. I feel fantastic and I'm still alive. While :
2:you're dying I'll be still alive. And when you're dead I :
2:will be still alive...... Still alive.....Still alive!!!!!!:
3:There is a flower within my heart, Daisy, Daisy! Planted :
3:one day by a glancing dart, Planted by Daisy Bell! Whether :
3:she loves me or loves me not, Sometimes it's hard to tell; :
3:Yet I am longing to share the lot Of beautiful Daisy Bell! :
3:Daisy, Daisy, Give me your answer, do! I'm half crazy, All :
3:for the love of you! It won't be a stylish marriage, I :
3:can't afford a carriage, But you'll look sweet on the seat :
3:Of a bicycle built for two! We will go "tandem" as man and :
3:wife, Daisy, Daisy! "Ped'ling" away down the road of life, :
3:I and my Daisy Bell! When the road's dark we can both :
3:despise P'liceman and "lamps" as well; There are "bright :
3:lights" in the dazzling eyes Of beautiful Daisy Bell! I :
3:will stand by you in "wheel" or woe, Daisy, Daisy! You'll :
3:be the bell(e) which I'll ring you know! Sweet little Daisy:
3:Bell! You'll take the "lead" in each "trip" we take, Then :
3:if I don't do well; I will permit you to use the brake, My :
3:beautiful Daisy Bell! :
4:On the farm, ev'ry Friday On the farm, it's rabbit pie day :
4:So ev'ry Friday that ever comes along I get up early and :
4:sing this little song Run rabbit, run rabbit, run, run, run:
4:Run rabbit, run rabbit, run, run, run Bang, bang, bang, :
4:bang goes the farmer's gun Run rabbit, run rabbit, run, run:
4:, run, run Run rabbit, run rabbit, run, run, run Don't give:
4:the farmer his fun, fun, fun He'll get by without his :
4:rabbit pie So run rabbit, run rabbit, run, run, run Run :
4:rabbit, run rabbit, run, run, run Run rabbit, run rabbit, :
4:run, run, run Bang, bang, bang, bang goes the farmer's gun :
4:Run rabbit, run rabbit, run, run, run, run Run rabbit, run :
4:rabbit, run, run, run Don't give the farmer his fun, fun, :
4:fun He'll get by without his rabbit pie So run rabbit, run :
4:rabbit, run, run, run :
96 changes: 87 additions & 9 deletions spinn_utilities/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,57 @@
import sys
import math
import os
from collections import defaultdict
from datetime import date
import random

from spinn_utilities.overrides import overrides
from spinn_utilities import logger_utils
import spinn_utilities

logger = logging.getLogger(__name__)

# verify that its either april fools or capocaccia or valantines day
today = date.today()
date_in_string_format = today.strftime("%B %d")
DATES_TO_PLAY_WITH = [
"April 1", "February 14", "April 27", "April 28", "April 29", "April 30",
"May 1", "May 2", "May 3", "May 4", "May 5", "May 6", "May 7", "May 8",
"May 9", "May 10"]
TIME_TO_PLAY = date_in_string_format in DATES_TO_PLAY_WITH

# read in the songs once for performance reasons
CHAR_FILE = "bacon.txt"
line_no = 0
song_id = 0
step_characters = defaultdict(list)
bacon_path = os.path.join(
os.path.dirname(os.path.realpath(spinn_utilities.__file__)), CHAR_FILE)
try:
reader = open(bacon_path)
lines = reader.readlines()

# allow the losing of the distance as well
LICENSE_LINES = 14
replace_distance = lines[LICENSE_LINES] == "True\n"

# turn into array of songs
for line in lines[LICENSE_LINES + 1:-1]:
bits = line.split(":")
step_characters[int(bits[0])].append(bits[1])

# clean up lines so that spaces are still visible
for song_id in step_characters:
for line_no in range(0, len(step_characters[song_id])):
step_characters[song_id][line_no] = (
step_characters[song_id][line_no].replace(" ", "_"))

# reset trackers for start of the first progress bar
song_id = random.randint(1, len(step_characters))
line_no = 0
except IOError:
TIME_TO_PLAY = False


class ProgressBar(object):
""" Progress bar for telling the user where a task is up to
Expand All @@ -35,7 +81,7 @@ class ProgressBar(object):
__slots__ = (
"_number_of_things", "_currently_completed", "_destination",
"_chars_per_thing", "_chars_done", "_string",
"_step_character", "_end_character", "_in_bad_terminal"
"_step_character", "_end_character", "_in_bad_terminal",
)

def __init__(self, total_number_of_things_to_do,
Expand Down Expand Up @@ -95,11 +141,16 @@ def _print_distance_indicator(self, description):
second_space = mid_point - 5

# Print the progress bar itself
print(
"{}0%{}50%{}100%{}".format(
self._end_character, " " * first_space,
" " * second_space, self._end_character),
end="", file=self._destination)
if TIME_TO_PLAY and replace_distance:
print(step_characters[song_id][line_no], end="",
file=self._destination)
self._set_song_line()
else:
print(
"{}0%{}50%{}100%{}".format(
self._end_character, " " * first_space,
" " * second_space, self._end_character),
end="", file=self._destination)
if self._in_bad_terminal:
print("", file=self._destination)
print(" ", end="", file=self._destination)
Expand All @@ -110,16 +161,43 @@ def _print_progress(self, length):
self._print_overwritten_line(self._end_character)
else:
chars_to_print = length - self._chars_done

for _ in range(int(chars_to_print)):
print(self._step_character, end='', file=self._destination)
if TIME_TO_PLAY:
if not self._in_bad_terminal:
print(step_characters[song_id][line_no][
0:self._chars_done + chars_to_print])
else:
print(step_characters[song_id][line_no][
self._chars_done:self._chars_done + 1],
end='', file=self._destination)
self._chars_done += 1
else:
print(self._step_character, end='', file=self._destination)
self._destination.flush()

def _print_progress_done(self):
self._print_progress(ProgressBar.MAX_LENGTH_IN_CHARS)
if not self._in_bad_terminal:
# nothing to see here
if TIME_TO_PLAY:
self._print_overwritten_line(self._end_character)
for _ in range(self.MAX_LENGTH_IN_CHARS):
print(self._step_character, end='', file=self._destination)
print(self._end_character, file=self._destination)
else:
print("", file=self._destination)
if TIME_TO_PLAY:
self._set_song_line()

def _set_song_line(self):
global line_no
global song_id
if line_no + 1 >= len(step_characters[song_id]):
song_id = random.randint(1, len(step_characters))
line_no = 0
else:
line_no += 1

def _create_initial_progress_bar(self, description):
if self._number_of_things == 0:
Expand All @@ -132,8 +210,8 @@ def _create_initial_progress_bar(self, description):
self._check_differences()

def _check_differences(self):
expected_chars_done = math.floor(
self._currently_completed * self._chars_per_thing)
expected_chars_done = int(math.floor(
self._currently_completed * self._chars_per_thing))
if self._currently_completed == self._number_of_things:
expected_chars_done = ProgressBar.MAX_LENGTH_IN_CHARS
self._print_progress(expected_chars_done)
Expand Down

0 comments on commit b0f8951

Please sign in to comment.