<commit_before>#!/usr/bin/env python

import unicodecsv
from jinja2 import Environment, FileSystemLoader

from lib.filters import number_as_grouped_number, number_as_financial_magnitude, number_as_magnitude, number_as_percentage, number_as_percentage_change, period_as_text
from lib.service import Service
from lib.slugify import slugify

jinja = Environment(
    loader=FileSystemLoader(searchpath='templates', encoding='utf-8'),
    trim_blocks=True,
    lstrip_blocks=True,
    extensions=['jinja2.ext.with_'],
)

jinja.filters['as_magnitude'] = number_as_magnitude
jinja.filters['as_financial_magnitude'] = number_as_financial_magnitude
jinja.filters['as_percentage'] = number_as_percentage
jinja.filters['as_percentage_change'] = number_as_percentage_change
jinja.filters['as_grouped_number'] = number_as_grouped_number
jinja.filters['period_as_text'] = period_as_text
jinja.filters['slugify'] = slugify

SERVICES_DATA = 'data/services.csv'

data = open(SERVICES_DATA)
reader = unicodecsv.DictReader(data)
services = [ Service(details=row) for row in reader ]

for service in services:
    print service.name

    if service.high_volume:
        template = jinja.get_template('service_detail.html')
        page = template.render(service=service)

        output_filename = '%s/%s.html' % (
            'output/service-details/',
            slugify( '%s-%s' % (service.abbr, service.name) ),
        )
        output = open(output_filename, 'w')
        output.write( page.encode('utf8') )


high_volume_services = [service for service in services if service.high_volume]

template = jinja.get_template('high_volume_transactions.html')
page = template.render(services=high_volume_services)

output_filename = '%s/%s.html' % (
    'output/',
    'high-volume-transactions',
)
output = open(output_filename, 'w')
output.write(page.encode('utf8'))

# get the list of services
# filter high volume services
# render a template<commit_msg>Filter high volume transactions only once<commit_after>#!/usr/bin/env python

import unicodecsv
from jinja2 import Environment, FileSystemLoader

from lib.filters import number_as_grouped_number, number_as_financial_magnitude, number_as_magnitude, number_as_percentage, number_as_percentage_change, period_as_text
from lib.service import Service
from lib.slugify import slugify

jinja = Environment(
    loader=FileSystemLoader(searchpath='templates', encoding='utf-8'),
    trim_blocks=True,
    lstrip_blocks=True,
    extensions=['jinja2.ext.with_'],
)

jinja.filters['as_magnitude'] = number_as_magnitude
jinja.filters['as_financial_magnitude'] = number_as_financial_magnitude
jinja.filters['as_percentage'] = number_as_percentage
jinja.filters['as_percentage_change'] = number_as_percentage_change
jinja.filters['as_grouped_number'] = number_as_grouped_number
jinja.filters['period_as_text'] = period_as_text
jinja.filters['slugify'] = slugify

SERVICES_DATA = 'data/services.csv'

data = open(SERVICES_DATA)
reader = unicodecsv.DictReader(data)

services = [ Service(details=row) for row in reader ]
high_volume_services = [service for service in services if service.high_volume]

for service in high_volume_services:
    print service.name

    template = jinja.get_template('service_detail.html')
    page = template.render(service=service)

    output_filename = '%s/%s.html' % (
        'output/service-details/',
        slugify( '%s-%s' % (service.abbr, service.name) ),
    )
    output = open(output_filename, 'w')
    output.write( page.encode('utf8') )

template = jinja.get_template('high_volume_transactions.html')
page = template.render(services=high_volume_services)

output_filename = '%s/%s.html' % (
    'output/',
    'high-volume-transactions',
)
output = open(output_filename, 'w')
output.write(page.encode('utf8'))

# get the list of services
# filter high volume services
# render a template
{'fraction_non_alphanumeric': 0.111427831044312, 'fraction_numerical': 0.002591344908007256, 'mean_word_length': 5.52027027027027, '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': '4176837', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1220, 'n_words': 232}