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
| #! /usr/bin/env python | |
| import logging | |
| """ | |
| I never remember all the steps for setting up logging in python. | |
| This gist goes through the steps so I can copy and paste what I need. | |
| """ | |
| # create logger on the current module and set its level | |
| logger = logging.getLogger(__file__) |
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
| import numpy as np | |
| from scipy import stats | |
| import pandas as pd | |
| def score_for_confidence(alpha, beta, confidence=.95): | |
| """ | |
| alpha: 1 + num_positive | |
| beta: 1 + num_negative | |
| confidence: confidence you can have that positive fraction is greater than this | |
| """ |
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
| #! /usr/bin/env bash | |
| echo "DROP DATABASE IF EXISTS ambition_dev_stash; CREATE DATABASE ambition_dev_stash WITH TEMPLATE ambition_dev OWNER ambition_dev;" | psql |
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
| #! /usr/bin/env bash | |
| echo "DROP DATABASE IF EXISTS ambition_dev; CREATE DATABASE ambition_dev WITH TEMPLATE ambition_dev_stash OWNER ambition_dev;" | psql |
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
| mcqs = MetricConfig.objects.filter(name__in=['lme_order_volume_profit', 'broadsoft_call_incoming_calls']) | |
| qs = Animal(mcqs, 'day').all() | |
| #qs = qs.filter(time__lte=datetime.datetime(2020, 1, 1,1).date()) #, time__gte=datetime.datetime(1970, 1, 2,1)) | |
| print str(qs.query) | |
| cursor = connections[qs.db].cursor() | |
| cursor.execute('explain %s' % str(qs.query)) | |
| for s in cursor.fetchall(): |
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
| #! /usr/bin/env bash | |
| # RUN THIS SCRIPT WITH SUDO ! | |
| # You should add the following the the `dependencies` section of your circle file | |
| # cache_directories: | |
| # - ./Python-2.7.9.tgz | |
| # - ./Python-2.7.9 | |
| set -x |
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
| # from | |
| # http://pandas.pydata.org/pandas-docs/stable/style.html | |
| df.style.background_gradient(cmap='viridis', low=1, high=0).set_precision(1) |
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
| import numbers | |
| import re | |
| def formatter(val, precision=2): | |
| """ | |
| Converts numbers to a have a given precision in a way that nicely displays in UI | |
| elements. | |
| Inputs: | |
| val: input value (either numeric or string) |
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
| import pylab as pl | |
| from statsmodels.distributions.empirical_distribution import ECDF | |
| def ecdf(x, n_out=100, label=None, xlabel=None, ylabel=None): | |
| x_out = np.linspace(min(x), max(x), n_out) | |
| y_out = ECDF(x)(x_out) | |
| # pl.plot(x_out, 1 - y_out, '-', label=label) | |
| pl.fill_between(x_out, 100*(1 - y_out), label=label, alpha=.3) | |
| if label: | |
| pl.legend(loc='best') | |
| if xlabel: |
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
| #! /usr/bin/env python | |
| import logging | |
| import datetime | |
| import fleming | |
| import pytz | |
| import os | |
| from itertools import islice | |
| import sys | |