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
// if last card was deleted, only that card is removed from server and Redux store | |
// If non last card was deleted, remaining cards are updated to reflect their | |
// updated position_ids received from the server | |
export const deleteCard = (column_id, id) => { | |
return dispatch => { | |
dispatch(toggleSpinner(id, true)); | |
axios | |
.delete(`/api/cards/${id}/`) | |
.then(res => { | |
dispatch(cardDeleted(column_id, id)); |
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
class CardListSerializer(serializers.ListSerializer): | |
def update(self, instance, validated_data): | |
""" | |
Update multiple existing cards | |
""" | |
card_mapping = {card.id: card for card in instance} | |
data_mapping = {item['id']: item for item in validated_data} | |
cards = [] |
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
def delete(self, request, pk): | |
""" | |
If last column card is deleted, return response without extra data, | |
else update remaining card position_ids and return them in | |
the response. | |
""" | |
try: | |
card = Card.objects.get(pk=pk) | |
except Card.DoesNotExist: | |
return Response(status=status.HTTP_404_NOT_FOUND) |
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
def calc_correlation(self, months, data, time_span): | |
""" | |
Calculate pair wise correlations for stocks in 'data' over | |
specified 'time_span'. | |
Remove duplicates from resulting matrix. | |
Stack the data to create columns: symbol_01, symbol_02, time_span | |
""" | |
df.reset_index(inplace=True) | |
df.set_index(['date', 'symbol'], inplace=True) | |
df.sortlevel(inplace=True) |
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 django.contrib.auth.models import User | |
from django.core.cache import cache | |
from paypal.standard.ipn.signals import valid_ipn_received | |
import redis | |
def paypal_notification(sender, **kwargs): | |
""" | |
sender contains all the transaction information received from paypal. | |
Determine the nature of the paypal transaction by accessing sender |
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
def get_portfolio_analysis(user, portfolio_id): | |
cache_key = '{}:{}:portfolio'.format(user, portfolio_id) | |
analysis_results = None | |
try: | |
analysis_results = cache.get(cache_key) | |
except redis.exceptions.ConnectionError: | |
logger.warn('relevant info is logged here') | |
# perform analysis on a cache miss or redis connection error | |
if analysis_results is None: |
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
-- select 1 year worth of daily data for the top 1500 symbols | |
-- with the highest average volume over the last 3 months | |
SELECT core_daily.date, core_daily.close, core_daily.symbol | |
WHERE ( | |
core_daily.symbol_id IN ( | |
SELECT symbol_id FROM core_daily | |
WHERE date > current_date - INTERVAL'3' month | |
GROUP BY symbol_id ORDER BY AVG(volume) DESC | |
LIMIT 1500 |
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 tests.mixins import BaseTestMixins | |
class QuestionCreateAndDetailTest(TestCase, BaseTestMixins): | |
@classmethod | |
def setUpTestData(cls): | |
# create_test_data is made available through the BaseTestMixins mixin | |
# it is only run once at the beginning of QuestionCreateAndDetailTest | |
cls.create_test_data() |
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
user = self.request.user | |
voted_flag = (Question.objects | |
.filter(votes__voter=user, | |
votes__object_id=OuterRef('pk'))) | |
query = (Question.objects | |
.select_related('user') | |
.annotate(voted=Exists(voted_for_question))) | |
question = get_object_or_404(question_query, slug=kwargs['slug']) |
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 django.db import models | |
from django.conf import settings | |
from django.contrib.contenttypes.fields import GenericRelation | |
from votes.models import Vote | |
from comments.models import Comment | |
from questions.models import Question | |
class Answer(models.Model): | |
user = models.ForeignKey(settings.AUTH_USER_MODEL, |
NewerOlder