<commit_before>from django import template
# from datetime import date, timedelta

from gnowsys_ndf.ndf.views.methods import get_execution_time

register = template.Library()


# @get_execution_time
# @register.filter
# def list_of_dicts_to_dict(list_of_dicts):
	
# 	req_dict = {}
# 	[req_dict.update(d) for d in list_of_dicts]

# 	return req_dict


@get_execution_time
@register.assignment_tag
def get_dict_from_list_of_dicts(list_of_dicts):
	req_dict = {}
	[req_dict.update(d) for d in list_of_dicts]
	return req_dict


@get_execution_time
@register.filter
def split(str, splitter):
    return str.split(splitter)


@get_execution_time
@register.assignment_tag
def get_latest_git_hash():
	"""
	Template tag that returns latest git hash no.

	Returns:
	    str: Returned hash no is 7 digit smaller unique (hash).
	"""
	# import subprocess
	# gitproc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout = subprocess.PIPE)
	# (stdout, _) = gitproc.communicate()
	# return stdout.strip()

	import os
	git_commit_hash = os.popen("git rev-parse --short HEAD").read().strip()
	return git_commit_hash


@get_execution_time
@register.filter
def get_type(value):
    return type(value)

@get_execution_time
@register.filter
def multiply(value,multiply_factor):
	"""
	Simple Filter for multiplication purpose

	How to use:
	value and multiply_factor are first and second argument respectively, passed through multiply filter.

	Ex: ratings.avg|multiply:30 
	    ratings.avg multiply with 30.

	"""
	return value*multiply_factor<commit_msg>Added filter for accessing nested dict<commit_after>from django import template
# from datetime import date, timedelta

from gnowsys_ndf.ndf.views.methods import get_execution_time

register = template.Library()


# @get_execution_time
# @register.filter
# def list_of_dicts_to_dict(list_of_dicts):
	
# 	req_dict = {}
# 	[req_dict.update(d) for d in list_of_dicts]

# 	return req_dict


@get_execution_time
@register.assignment_tag
def get_dict_from_list_of_dicts(list_of_dicts):
	req_dict = {}
	[req_dict.update(d) for d in list_of_dicts]
	return req_dict


@get_execution_time
@register.filter
def split(str, splitter):
    return str.split(splitter)


@get_execution_time
@register.assignment_tag
def get_latest_git_hash():
	"""
	Template tag that returns latest git hash no.

	Returns:
	    str: Returned hash no is 7 digit smaller unique (hash).
	"""
	# import subprocess
	# gitproc = subprocess.Popen(['git', 'rev-parse', '--short', 'HEAD'], stdout = subprocess.PIPE)
	# (stdout, _) = gitproc.communicate()
	# return stdout.strip()

	import os
	git_commit_hash = os.popen("git rev-parse --short HEAD").read().strip()
	return git_commit_hash


@get_execution_time
@register.filter
def get_type(value):
    return type(value)

@get_execution_time
@register.filter
def multiply(value,multiply_factor):
	"""
	Simple Filter for multiplication purpose

	How to use:
	value and multiply_factor are first and second argument respectively, passed through multiply filter.

	Ex: ratings.avg|multiply:30 
	    ratings.avg multiply with 30.

	"""
	return value*multiply_factor


@register.filter
def get_dict_value_from_key(dict, key):    
    try:
        return dict[key]
    except KeyError:
        return ''
{'fraction_non_alphanumeric': 0.10027683789603199, 'fraction_numerical': 0.0030759766225776685, 'mean_word_length': 4.934306569343065, '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': '6611814', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1087, 'n_words': 274}