<commit_before>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseServerError, Http404
from django.template import RequestContext
from apps.reporters.models import Location, LocationType
from apps.supply.models import Shipment, Transaction, Stock, PartialTransaction
from rapidsms.webui.utils import render_to_response
from django.db import models
# The import here newly added for serializations
from django.core import serializers
from django.core.paginator import *
from random import randrange, seed
import time
import sys

#Parameter for paging reports outputs
ITEMS_PER_PAGE = 20

#This is required for ***unicode*** characters***
# do we really need to reload it?  TIM to check
reload(sys)
sys.setdefaultencoding('utf-8')

#Views for handling summary of Reports Displayed as Location Tree
def index(req, locid=None):
    reload(sys)
    sys.setdefaultencoding('utf-8')
    # TODO (better) ajax this
    if not locid:
        locid = 1
    try:
        location = Location.objects.get(id=locid)
    except Location.DoesNotExist:
        location= None
    print "location: %s" % location
    return render_to_response(req, "nigeria/index.html",{'location':location })


#Views for handling Reports Summary Displayed as Locations Tree (State -> LGA -> Wards -> DPs -> MTs)
#def index(req):
#    
#    #Variable to hold LGA dictionary
#    lga_dict={}
#    
#    #TODO: Line below should be replaced by a for loop to iterate through objects for state retrieval through code="<statecode>" parameter to .get() method
#    state = Location.objects.get(code="20")
#   
#    # Retrieves all LGAs in the states. TODO: This will be shifted in the forloop for state
#    lgas = state.children.all()[0:9]
#
#    for lga in lgas:
#        #Obtains list of wards from the model
#        wards = lga.children.all()
#        
#        #Builds a dictionary of wards with LGA as keys
#        lga_dict[lga] = wards
#        
#    #TODO: This list should be removed after creating a for loop to retrieve states  from model (above)
#    states = ['Abia','Adamawa','Akwa-Ibom','Anambra','Bauchi','Bayelsa',
#        'Benue','Borno','Cross River','Delta','Ebonyi','Edo','Ekiti','Enugu','FCT','Gombe','Imo','Jigawa','Kaduna','Kano','Katsina','Kebbi','Kogi','Kwara','Lagos','Nasarawa','Niger','Ogun','Ondo','Osun','Oyo','Plateau','Rivers','Sokoto','Taraba','Yobe','Zamfara']
#    
#    
#    return render_to_response(req, "nigeria/index.html",{'st':state, 'states':states,'lgas':lga_dict})

def logistics_summary(req, locid):
    # Get the location we are going to work with.
    # If there is no location set, this will default to the first
    # one in the database.  If there are no locations in the
    # database we are S.O.L.
    if not locid:
        locid = 1
    try: 
        location = Location.objects.get(pk=locid)
    except Location.DoesNotExist:
        location = None

    # get all the transactions that this location was involved in 
    transactions_from_loc = Transaction.objects.all().filter(shipment__origin=location) <commit_msg>cleaning up the nigeria views file<commit_after>#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4

from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseServerError, Http404
from django.template import RequestContext
from apps.reporters.models import Location, LocationType
from apps.supply.models import Shipment, Transaction, Stock, PartialTransaction
from rapidsms.webui.utils import render_to_response
from django.db import models
# The import here newly added for serializations
from django.core import serializers
from django.core.paginator import *
from random import randrange, seed
import time
import sys

#Parameter for paging reports outputs
ITEMS_PER_PAGE = 20

#This is required for ***unicode*** characters***
# do we really need to reload it?  TIM to check
reload(sys)
sys.setdefaultencoding('utf-8')

#Views for handling summary of Reports Displayed as Location Tree
def index(req, locid=None):
    if not locid:
        locid = 1
    try:
        location = Location.objects.get(id=locid)
    except Location.DoesNotExist:
        location= None
    print "location: %s" % location
    return render_to_response(req, "nigeria/index.html",{'location':location })


def logistics_summary(req, locid):
    # Get the location we are going to work with.
    # If there is no location set, this will default to the first
    # one in the database.  If there are no locations in the
    # database we are S.O.L.
    if not locid:
        locid = 1
    try: 
        location = Location.objects.get(pk=locid)
    except Location.DoesNotExist:
        location = None

    # get all the transactions that this location was involved in 
    transactions_from_loc = Transaction.objects.all().filter(shipment__origin=location) 
{'fraction_non_alphanumeric': 0.10069872585285655, 'fraction_numerical': 0.005548705302096177, 'mean_word_length': 3.9311043566362716, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '3464438', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1439, 'n_words': 489}