<commit_before>import re
from django.utils import simplejson
from django.shortcuts import render_to_response
from djangomako import shortcuts
from django.db.models import Avg, Max, Min, Count
from django.http import HttpResponse
from odk_dropbox import utils
from odk_dropbox.models import Form
from .models import ParsedInstance, Phone
import datetime

def map_data(request, stamp):
    """
    Returns JSON with a stamp to ensure most recent data is sent.
    pis = ParsedInstance.objects.exclude(location__gps=None)
    for ps in pis:
        pcur = {}
        if ps.location.gps:
            pcur['images'] = [x.image.url for x in ps.instance.images.all()]
            pcur['phone'] = ps.phone.__unicode__()
            pcur['date'] = ps.end.strftime("%Y-%m-%d %H:%M")
            pcur['survey_type'] = ps.survey_type.name
            pcur['gps'] = ps.location.gps.to_dict()
            pcur['title'] = ps.survey_type.name
        psubs.append(pcur)
    cur_stamp = model_stamp(ParsedInstance)
    """
    psubs = []
    return stamped_json_output(cur_stamp, psubs, True)

from ipdb import set_trace as debug

def activity_list(request, stamp):
    if stamp_up_to_date(ParsedInstance, stamp):
        return HttpResponse(simplejson.dumps("OK"))
    else:
        try:
            stamp_data = simplejson.loads(stamp)
            latest = stamp_data['latest']
            instance_list = ParsedInstance.objects.exclude(location__gps=None).filter(id__gte=latest)
            flush = False
        except:
            instance_list = ParsedInstance.objects.exclude(location__gps=None)
            flush = True

        return stamped_json_output(stamp=model_stamp(ParsedInstance), \
                data=[pi.to_dict() for pi in instance_list], \
                flush=flush)

def stamp_up_to_date(model, stamp):
    return model_stamp(model)==stamp

def model_stamp(model):
    latest_id = model.objects.order_by('-id')[0].id
    count = model.objects.count()
    return "{'count':%s,'latest':%s}" % (count, latest_id)

def stamped_json_output(stamp, data, flush):
    return HttpResponse(simplejson.dumps({'stamp':stamp, \
                        'data':data, 'flush':flush }))<commit_msg>took out ipdb import<commit_after>import re
from django.utils import simplejson
from django.shortcuts import render_to_response
from djangomako import shortcuts
from django.db.models import Avg, Max, Min, Count
from django.http import HttpResponse
from odk_dropbox import utils
from odk_dropbox.models import Form
from .models import ParsedInstance, Phone
import datetime

def map_data(request, stamp):
    """
    Returns JSON with a stamp to ensure most recent data is sent.
    pis = ParsedInstance.objects.exclude(location__gps=None)
    for ps in pis:
        pcur = {}
        if ps.location.gps:
            pcur['images'] = [x.image.url for x in ps.instance.images.all()]
            pcur['phone'] = ps.phone.__unicode__()
            pcur['date'] = ps.end.strftime("%Y-%m-%d %H:%M")
            pcur['survey_type'] = ps.survey_type.name
            pcur['gps'] = ps.location.gps.to_dict()
            pcur['title'] = ps.survey_type.name
        psubs.append(pcur)
    cur_stamp = model_stamp(ParsedInstance)
    """
    psubs = []
    return stamped_json_output(cur_stamp, psubs, True)

def activity_list(request, stamp):
    if stamp_up_to_date(ParsedInstance, stamp):
        return HttpResponse(simplejson.dumps("OK"))
    else:
        try:
            stamp_data = simplejson.loads(stamp)
            latest = stamp_data['latest']
            instance_list = ParsedInstance.objects.exclude(location__gps=None).filter(id__gte=latest)
            flush = False
        except:
            instance_list = ParsedInstance.objects.exclude(location__gps=None)
            flush = True

        return stamped_json_output(stamp=model_stamp(ParsedInstance), \
                data=[pi.to_dict() for pi in instance_list], \
                flush=flush)

def stamp_up_to_date(model, stamp):
    return model_stamp(model)==stamp

def model_stamp(model):
    latest_id = model.objects.order_by('-id')[0].id
    count = model.objects.count()
    return "{'count':%s,'latest':%s}" % (count, latest_id)

def stamped_json_output(stamp, data, flush):
    return HttpResponse(simplejson.dumps({'stamp':stamp, \
                        'data':data, 'flush':flush }))

{'fraction_non_alphanumeric': 0.11302549965541006, 'fraction_numerical': 0.00045945325063174823, 'mean_word_length': 2.9871794871794872, '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': '5186389', 'n_tokens_mistral': 1392, 'n_tokens_neox': 1366, 'n_words': 295}