Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace downloader.sh with multiprocessing.Pool #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions bashplotlib/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,23 @@
import sys
import math
import optparse
import requests
from os.path import dirname
from multiprocessing import Pool

from .utils.helpers import *
from .utils.commandhelp import hist

sample_files = [('exp.txt', 'yuxlaj8okcjta9t', ''),
('lower48.txt', 'cbf5skx34grlwy6', ''),
('x_test.txt', 'gsu2y9vqnx5ps5i', ''),
('y_test.txt', 'mlt4gfqr6n24kxj', ''),
('texas.txt', 'gsu2y9vqnx5ps5i', ''),
('million.txt', 'jjeubxlxuqkzkeq/5W6zkUZXww/', 'h')]

download_base = 'https://dl.dropbox.com/s{}/{}/{}?dl=1'
download_dir = os.path.join(os.environ['HOME'], 'bashplotlib/examples/data')


def calc_bins(n, min_val, max_val, h=None, binwidth=None):
"""
Expand Down Expand Up @@ -46,12 +59,22 @@ def read_numbers(numbers):
yield float(number.strip())


def sample_data_downloader(filename, fileid, prefix):
req = requests.get(download_base.format(prefix, fileid, filename))
filepath = os.path.join(download_dir, filename)
with open(filepath, 'w') as f:
f.write(req.text)


def run_demo():
"""
Run a demonstration
"""
module_dir = dirname(dirname(os.path.realpath(__file__)))
demo_file = os.path.join(module_dir, 'examples/data/exp.txt')
if not os.path.exists(download_dir):
os.mkdir(download_dir)
with Pool() as pool:
pool.starmap(sample_data_downloader, sample_files)
demo_file = os.path.join(download_dir, 'exp.txt')

if not os.path.isfile(demo_file):
sys.stderr.write("demo input file not found!\n")
Expand Down
4 changes: 1 addition & 3 deletions bin/texas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@
from __future__ import print_function
import os

_ROOT = os.path.abspath(os.path.dirname(__file__))

texas = os.path.join(_ROOT, "../bashplotlib", "data", "texas.txt")
texas = os.path.join(os.environ["HOME"], "bashplotlib/examples/data/texas.txt")
print(open(texas).read().strip())
14 changes: 0 additions & 14 deletions examples/downloaddata.sh

This file was deleted.

5 changes: 3 additions & 2 deletions examples/sample.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
dir=$(dirname "$0")

if [ ! -d "${dir}/data" ]; then
echo 'downloading data'
"${dir}/downloaddata.sh"
echo 'Sample data is needed'
echo 'Run "hist --demo" to download'
exit 1
fi

echo 'plotting coordinates'
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
install_requires={'requests':'examples'},
dependency_links=['https://github.com/kennethreitz/requests'],
)