This file contains 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
import itertools | |
import matplotlib.pyplot as plt | |
import numpy as np | |
colors = itertools.cycle(['r','g','b','c','y','m','k']) | |
markers = itertools.cycle(['o','s','v']) | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
for i in range(5): |
This file contains 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
y=[2.56422, 3.77284,3.52623,3.51468,3.02199] | |
z=[0.15, 0.3, 0.45, 0.6, 0.75] | |
n=[58,651,393,203,123] | |
fig, ax = plt.subplots() | |
ax.scatter(z, y) | |
for i, txt in enumerate(n): | |
ax.annotate(txt, (z[i],y[i])) |
This file contains 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
def _save_categories(curso_id_in_supplier, category): | |
from shop.models import Category, CourseCategories, Course | |
c_c = CourseCategories() | |
c_c.course = Course.objects.get(id_in_supplier=curso_id_in_supplier, supplier=IOB) | |
try: | |
c_c.category = Category.objects.get(slug=category) | |
except Category.DoesNotExist: | |
ct = Category() | |
ct = category |
This file contains 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
def _save_curso(id_in_supplier, name, description, periodo_acesso): | |
from shop.models import Course | |
from product.models import Price, Product | |
try: | |
return Course.objects.get(id_in_supplier=id_in_supplier, supplier=IOB) | |
except Course.DoesNotExist: | |
try: | |
p = Product.objects.get(name=name) | |
p.delete() | |
except Product.DoesNotExist: |
This file contains 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
common_setup = """ | |
import numpy | |
from crab.metrics import cosine_distances | |
X = numpy.random.uniform(1,5,(1000,)) | |
""" | |
bench = Benchmark(statement, setup_bk1, name="Crab Cosine") | |
suite = BenchmarkSuite() | |
suite.append(bench) |
This file contains 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
import sqlite3 | |
class BenchmarkDb(object): | |
""" | |
Persistence handler for bechmark results | |
""" | |
def _create_tables(self): | |
self._cursor.execute("drop table if exists benchmarksuites") | |
self._cursor.execute("drop table if exists benchmarks") |
This file contains 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
class BenchmarkRepository(object): | |
""" | |
Manage an isolated copy of a repository for benchmarking | |
""" | |
... | |
def _copy_repo(self): | |
if os.path.exists(self.target_dir): | |
print 'Deleting %s first' % self.target_dir | |
# response = raw_input('%s exists, delete? y/n' % self.target_dir) |
This file contains 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
class BenchmarkGitRunner(object): | |
... | |
def run(self): | |
revisions = self._get_revisions_to_run() | |
for rev in revisions: | |
any_succeeded, n_active = self._run_and_write_results(rev) | |
if not any_succeeded and n_active > 0: |
This file contains 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
class GitRepository(Repository): | |
""" | |
Read some basic statistics about a git repository | |
""" | |
def __init__(self, repo_path): | |
self.repo_path = repo_path | |
self.git = _git_command(self.repo_path) | |
(self.shas, self.messages, |
This file contains 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
import re import math | |
def getwords(doc): | |
splitter=re.compile('\\W*') # Split the words by non-alpha characters | |
words=[s.lower() for s in splitter.split(doc) if len(s)>2 and len(s)<20] | |
# Return the unique set of words only | |
return dict([(w,1) for w in words]) |