<commit_before>import urllib2
import logging
import json
from random import randrange

from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template.context import RequestContext

from django.core.cache import cache
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect, HttpResponseNotModified, \
                        HttpResponse, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import get_object_or_404
from core.models import TimeSeries

@csrf_exempt
def home(request):
    """
    Try a POST with curl and automatically adds a random value, this updates plot async
    """
    if request.POST and 'model_data' in request.POST.values():
        try:
            last_value = TimeSeries.objects.order_by('-id')[0].value
        except:
            last_value = 50
        if last_value < 5 or last_value > 100:
            last_value = 50
        TimeSeries.objects.create(value=randrange(last_value - 5, last_value + 5))

    if request.POST and 'redis_data' in request.POST.values():
        try:
            import redis
        except ImportError, e:
            logging.error("redis -redis server binding for Python is not installed. \
                                            Try pip install redis")
        try:
            from redis import ConnectionError
            r_inst = redis.Redis('localhost')  # works only on local
            r_inst.ping()
        except ConnectionError:
            logging.error("redis server is not running. Start it to make graphos plot data.")
        #        import redis
        #        r_inst = redis.Redis('localhost')
        r_inst.rpush('graphos', randrange(1, 100))

    c = RequestContext(request, {

    })
    return render_to_response('home.html', context_instance=c)

def tutorial(request):
    """
    Try a POST with curl and automatically adds a random value, this updates plot async
    """
    if request.POST and 'model_data' in request.POST.values():
        try:
            last_value = TimeSeries.objects.order_by('-id')[0].value
        except:
            last_value = 50
        if last_value < 5 or last_value > 100:
            last_value = 50
        TimeSeries.objects.create(value=randrange(last_value - 5, last_value + 5))

    if request.POST and 'redis_data' in request.POST.values():
        try:
            import redis
        except ImportError, e:
            logging.error("redis -redis server binding for Python is not installed. \
                                            Try pip install redis")<commit_msg>added a LineChart with raw data in template context<commit_after>import urllib2
import logging
import json
from random import randrange

from django.core.urlresolvers import reverse
from django.shortcuts import render_to_response
from django.template.context import RequestContext

from django.core.cache import cache
from django.utils.translation import ugettext_lazy as _
from django.http import HttpResponseRedirect, HttpResponseNotModified, \
                        HttpResponse, HttpResponseForbidden
from django.views.decorators.csrf import csrf_exempt
from django.shortcuts import get_object_or_404
from core.models import TimeSeries

from graphos.flot_charts import LineChart

@csrf_exempt
def home(request):
    """
    Try a POST with curl and automatically adds a random value, this updates plot async
    """
    if request.POST and 'model_data' in request.POST.values():
        try:
            last_value = TimeSeries.objects.order_by('-id')[0].value
        except:
            last_value = 50
        if last_value < 5 or last_value > 100:
            last_value = 50
        TimeSeries.objects.create(value=randrange(last_value - 5, last_value + 5))

    if request.POST and 'redis_data' in request.POST.values():
        try:
            import redis
        except ImportError, e:
            logging.error("redis -redis server binding for Python is not installed. \
                                            Try pip install redis")
        try:
            from redis import ConnectionError
            r_inst = redis.Redis('localhost')  # works only on local
            r_inst.ping()
        except ConnectionError:
            logging.error("redis server is not running. Start it to make graphos plot data.")
        #        import redis
        #        r_inst = redis.Redis('localhost')
        r_inst.rpush('graphos', randrange(1, 100))

    model_series = [[1, 2], [2, 2], [3, 2], [4, 4], [5, 6], [6, 7]]
    TimeSeriesChart = LineChart(series=model_series)

    c = RequestContext(request)
    return render_to_response('home.html', {'Chart': TimeSeriesChart}, context_instance=c)

def tutorial(request):
    """
    Try a POST with curl and automatically adds a random value, this updates plot async
    """
    if request.POST and 'model_data' in request.POST.values():
        try:
            last_value = TimeSeries.objects.order_by('-id')[0].value
        except:
            last_value = 50
        if last_value < 5 or last_value > 100:
            last_value = 50
        TimeSeries.objects.create(value=randrange(last_value - 5, last_value + 5))

    if request.POST and 'redis_data' in request.POST.values():
        try:
            import redis
        except ImportError, e:
            logging.error("redis -redis server binding for Python is not installed. \
                                            Try pip install redis")
{'fraction_non_alphanumeric': 0.0792186652197504, 'fraction_numerical': 0.013022246337493217, 'mean_word_length': 2.3843329253365972, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6736236', 'n_tokens_mistral': 1546, 'n_tokens_neox': 1474, 'n_words': 470}