<commit_before>from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from django.core import serializers
from django.utils import timezone
from django.contrib.auth import authenticate, login

import datetime
import urllib
import json

from .models import Stock, StockHistory, StockSelection, SectorHistory, StockNews, StockNT
from django.contrib.auth.models import User

sector_names = [s.Sector for s in Stock.objects.distinct('Sector') if s.Sector]

def navRoutes():
    return [{
        'path':reverse('market:index'),
        'isActive':False,
        'icon':'fa-home',
        'label':'Summary',
        'children': []
    },{
        'path':reverse('market:news'),
        'isActive':False,
        'icon':'fa-newspaper-o',
        'label':'Latest News',
        'children': []
    },{
        'path':reverse('market:sectors'),
        'isActive':False,
        'icon':'fa-area-chart',
        'label':'Sectors',
        'children': []
    },{
        'path':reverse('market:account'),
        'isActive':False,
        'icon':'fa-star',
        'label':'Favourite',
        'children': []
    },{
        'path':reverse('market:list'),
        'isActive':False,
        'icon':'fa-table',
        'label':'Stock Table',
        'children': [{
            'path':reverse('market:clist', kwargs={'catagory': 'ftse'}),
            'isActive':False,
            'icon':'fa-table',
            'label':'FTSE ALL',
            'children': []
        },{
            'path':reverse('market:clist', kwargs={'catagory': 'ftseaim'}),
            'isActive':False,
            'icon':'fa-table',
            'label':'FTSE AIM ALL',
            'children': []
        }]
    }]

# helper functions
def common_filter(objects, mcl=49, mch=4000, mp=20, spread=3, liq=2000, dp=3, trend=True, update_date=None):
    query =  objects.filter(MarketCap__gte=mcl).filter(MarketCap__lte=mch).filter(MPRatio__lte=mp).filter(Spread__lte=spread).filter(Liquidity__gte=liq).filter(DPRatio__lte=dp)

    if update_date:
        query = query.filter(pub_date__gte=update_date)

    if trend:
        query = query.filter(ProfitTrend__gte=-0.3).filter(DividendTrend__gte=-0.3).filter(DebtTrend__gte=-0.3)
    return query


def addCORSHeaders(theHttpResponse):
    if theHttpResponse and isinstance(theHttpResponse, HttpResponse):
        theHttpResponse['Access-Control-Allow-Origin'] = '*'
        theHttpResponse['Access-Control-Max-Age'] = '120'
        theHttpResponse['Access-Control-Allow-Credentials'] = 'true'
        theHttpResponse['Access-Control-Allow-Methods'] = 'HEAD, GET, OPTIONS, POST, DELETE'
        theHttpResponse['Access-Control-Allow-Headers'] = 'origin, content-type, accept, x-requested-with'
    return theHttpResponse


# api views
def history(request, symbol):
    return addCORSHeaders(HttpResponse(
        serializers.serialize(
            'json', Stock.objects.get(
                Symbol=symbol
            ).stockhistory_set.all().order_by('-pub_date')[:550]
        )
    ))


def historysector(request, sector):<commit_msg>xorigin problem test<commit_after>from django.shortcuts import render, get_object_or_404
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.views import generic
from django.core import serializers
from django.utils import timezone
from django.contrib.auth import authenticate, login

import datetime
import urllib
import json

from .models import Stock, StockHistory, StockSelection, SectorHistory, StockNews, StockNT
from django.contrib.auth.models import User

sector_names = [s.Sector for s in Stock.objects.distinct('Sector') if s.Sector]

def navRoutes():
    return [{
        'path':reverse('market:index'),
        'isActive':False,
        'icon':'fa-home',
        'label':'Summary',
        'children': []
    },{
        'path':reverse('market:news'),
        'isActive':False,
        'icon':'fa-newspaper-o',
        'label':'Latest News',
        'children': []
    },{
        'path':reverse('market:sectors'),
        'isActive':False,
        'icon':'fa-area-chart',
        'label':'Sectors',
        'children': []
    },{
        'path':reverse('market:account'),
        'isActive':False,
        'icon':'fa-star',
        'label':'Favourite',
        'children': []
    },{
        'path':reverse('market:list'),
        'isActive':False,
        'icon':'fa-table',
        'label':'Stock Table',
        'children': [{
            'path':reverse('market:clist', kwargs={'catagory': 'ftse'}),
            'isActive':False,
            'icon':'fa-table',
            'label':'FTSE ALL',
            'children': []
        },{
            'path':reverse('market:clist', kwargs={'catagory': 'ftseaim'}),
            'isActive':False,
            'icon':'fa-table',
            'label':'FTSE AIM ALL',
            'children': []
        }]
    }]

# helper functions
def common_filter(objects, mcl=49, mch=4000, mp=20, spread=3, liq=2000, dp=3, trend=True, update_date=None):
    query =  objects.filter(MarketCap__gte=mcl).filter(MarketCap__lte=mch).filter(MPRatio__lte=mp).filter(Spread__lte=spread).filter(Liquidity__gte=liq).filter(DPRatio__lte=dp)

    if update_date:
        query = query.filter(pub_date__gte=update_date)

    if trend:
        query = query.filter(ProfitTrend__gte=-0.3).filter(DividendTrend__gte=-0.3).filter(DebtTrend__gte=-0.3)
    return query


def addCORSHeaders(theHttpResponse):
    theHttpResponse['Access-Control-Allow-Origin'] = '*'
    theHttpResponse['Access-Control-Max-Age'] = '120'
    theHttpResponse['Access-Control-Allow-Credentials'] = 'true'
    theHttpResponse['Access-Control-Allow-Methods'] = 'HEAD, GET, OPTIONS, POST, DELETE'
    theHttpResponse['Access-Control-Allow-Headers'] = 'origin, content-type, accept, x-requested-with'
    return theHttpResponse


# api views
def history(request, symbol):
    return addCORSHeaders(HttpResponse(
        serializers.serialize(
            'json', Stock.objects.get(
                Symbol=symbol
            ).stockhistory_set.all().order_by('-pub_date')[:550]
        )
    ))


def historysector(request, sector):
{'fraction_non_alphanumeric': 0.1487577148282956, 'fraction_numerical': 0.00917866751068207, 'mean_word_length': 3.0879689521345406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '101281', 'n_tokens_mistral': 2018, 'n_tokens_neox': 1925, 'n_words': 340}