<commit_before>from django.shortcuts import render_to_response
from django.template import RequestContext as OriginalRequestContext
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.forms.models import model_to_dict
from display_defs.models import FacilityTable, MapLayerDescription
from nga_districts.models import LGA, Zone, State
from django.db.models import Count
from django.conf import settings
import json
from facilities.models import FacilityRecord, Variable, LGAIndicator

from uis_r_us.indicators.gap_analysis import all_gap_indicators
from uis_r_us.indicators.overview import tmp_variables_for_sector
from uis_r_us.indicators.mdg import tmp_get_mdg_indicators
from uis_r_us.indicators.facility import tmp_facility_indicators

class RequestContext(OriginalRequestContext):
    def __init__(self, *args, **kwargs):
        self.css_debug_mode = settings.CSS_DEBUG_MODE
        self.active_districts = active_districts()
        OriginalRequestContext.__init__(self, *args, **kwargs)

def _get_state_lga_from_first_two_items(arr):
    try:
        state = State.objects.get(slug=arr[0])
        full_id = '_'.join([arr[0], arr[1]])
        lga = state.lgas.get(unique_slug=full_id)
    except Exception, e:
        return (False, False, False)
    return (state, lga, True)

@login_required
def nmis_view(request, state_id, lga_id, reqpath=""):
    context = RequestContext(request)
    context.jsmodules = ['facility_tables', 'tabulations']
    context.url_root = "/nmis~/"
    context.reqpath = reqpath
    context.include_sectors = \
                ['overview', 'health', 'education', 'water']
    context.sector_data = json.dumps(sector_data())
    try:
        context.state = State.objects.get(slug=state_id)
        full_id = '_'.join([state_id, lga_id])
        context.lga = context.state.lgas.get(unique_slug=full_id)
    except Exception, e:
        return HttpResponseRedirect("/")
    lga_data = context.lga.get_latest_data(for_display=True)
    data_for_display = context.lga.get_latest_data(for_display=True, display_options={
                'num_skilled_health_providers_per_1000': {'decimal_places': 3},
                'num_chews_per_1000': {'decimal_places': 3},
            })

    def g(slug):
        return lga_data.get(slug, None)
    context.profile_data = _profile_variables(g)
    context.facility_indicators = tmp_facility_indicators(context.lga, data_for_display)
    context.mdg_indicators = tmp_get_mdg_indicators(lga_data, g)
    def _gap_variables(sector_slug, lga_data):
        def j(slug):
            value_dict = lga_data.get(slug, None)
            if value_dict:
                return value_dict.get('value', None)
            else:
                return 'N/A'
        def plug_in_values(row):
            for key in ['current', 'gap', 'target']:
                if key in row:
                    row[key] = j(row[key])
            return row
        return [plug_in_values(r) \
                        for r in all_gap_indicators().get(sector_slug, [])]
    context.sectors = [ \
        [s, tmp_variables_for_sector(s, lga_data, {}), _gap_variables(s, lga_data)] \
            for s in ['health', 'education', 'water']]
    return render_to_response("nmis_view.html", context_instance=context)

def summary_views(request, lga_id, sector_id=""):
    context = RequestContext(request)
    try:
        lga = LGA.objects.get(unique_slug=lga_id)
    except Exception, e:
        return HttpResponseBadRequest("Not cool")
    context.lga = lga
    return render_to_response("summary_view.html")

@login_required<commit_msg>taking out lga_data<commit_after>from django.shortcuts import render_to_response
from django.template import RequestContext as OriginalRequestContext
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.forms.models import model_to_dict
from display_defs.models import FacilityTable, MapLayerDescription
from nga_districts.models import LGA, Zone, State
from django.db.models import Count
from django.conf import settings
import json
from facilities.models import FacilityRecord, Variable, LGAIndicator

from uis_r_us.indicators.gap_analysis import all_gap_indicators
from uis_r_us.indicators.overview import tmp_variables_for_sector
from uis_r_us.indicators.mdg import tmp_get_mdg_indicators
from uis_r_us.indicators.facility import tmp_facility_indicators

class RequestContext(OriginalRequestContext):
    def __init__(self, *args, **kwargs):
        self.css_debug_mode = settings.CSS_DEBUG_MODE
        self.active_districts = active_districts()
        OriginalRequestContext.__init__(self, *args, **kwargs)

def _get_state_lga_from_first_two_items(arr):
    try:
        state = State.objects.get(slug=arr[0])
        full_id = '_'.join([arr[0], arr[1]])
        lga = state.lgas.get(unique_slug=full_id)
    except Exception, e:
        return (False, False, False)
    return (state, lga, True)

@login_required
def nmis_view(request, state_id, lga_id, reqpath=""):
    context = RequestContext(request)
    context.jsmodules = ['facility_tables', 'tabulations']
    context.url_root = "/nmis~/"
    context.reqpath = reqpath
    context.include_sectors = \
                ['overview', 'health', 'education', 'water']
    context.sector_data = json.dumps(sector_data())
    try:
        context.state = State.objects.get(slug=state_id)
        full_id = '_'.join([state_id, lga_id])
        context.lga = context.state.lgas.get(unique_slug=full_id)
    except Exception, e:
        return HttpResponseRedirect("/")
    data_for_display = context.lga.get_latest_data(for_display=True, display_options={
                'num_skilled_health_providers_per_1000': {'decimal_places': 3},
                'num_chews_per_1000': {'decimal_places': 3},
            })

    def g(slug):
        return data_for_display.get(slug, None)
    context.profile_data = _profile_variables(g)
    context.facility_indicators = tmp_facility_indicators(context.lga, data_for_display)
    context.mdg_indicators = tmp_get_mdg_indicators(data_for_display, g)
    def _gap_variables(sector_slug):
        def j(slug):
            value_dict = data_for_display.get(slug, None)
            if value_dict:
                return value_dict.get('value', None)
            else:
                return 'N/A'
        def plug_in_values(row):
            for key in ['current', 'gap', 'target']:
                if key in row:
                    row[key] = j(row[key])
            return row
        return [plug_in_values(r) \
                        for r in all_gap_indicators().get(sector_slug, [])]
    context.sectors = [ \
        [s, tmp_variables_for_sector(s, data_for_display, {}), _gap_variables(s)] \
            for s in ['health', 'education', 'water']]
    return render_to_response("nmis_view.html", context_instance=context)

def summary_views(request, lga_id, sector_id=""):
    context = RequestContext(request)
    try:
        lga = LGA.objects.get(unique_slug=lga_id)
    except Exception, e:
        return HttpResponseBadRequest("Not cool")
    context.lga = lga
    return render_to_response("summary_view.html")

@login_required
{'fraction_non_alphanumeric': 0.09905595840744288, 'fraction_numerical': 0.003557258174852921, 'mean_word_length': 3.4901719901719903, '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': '871253', 'n_tokens_mistral': 2359, 'n_tokens_neox': 2297, 'n_words': 467}