<commit_before>#!/usr/bin/python3
"""
Runs logging and visualiserRegistry for available visualisers.
"""
import address_visualisation as AV
from address_visualisation.visualisers import ProfaneStreetsVisualiser, BiggestTownsVisualiser, ExtremeStreetNamesVisualiser, LongestStreetsVisualiser, SquareCountVisualiser, TownWithMostStreetsVisualiser
import logging

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

DEFAULT_VISUALISERS = [
	(ProfaneStreetsVisualiser, 'profane_streets'),
	(BiggestTownsVisualiser, 'biggest_towns'),
	(ExtremeStreetNamesVisualiser, 'extreme_street_names'),
	(LongestStreetsVisualiser, 'longest_streets'),
	(SquareCountVisualiser, 'square_count'),
	(TownWithMostStreetsVisualiser, 'town_with_most_streets')
]

visualisers = DEFAULT_VISUALISERS

visreg = AV.VisualiserRegistry('resources/db.xml')
visreg.register_visualiser_set(visualisers)
visreg.run_visualisers('resources/visualisations')<commit_msg>allow to specify which visualisers are to be run<commit_after>#!/usr/bin/python3
"""
Runs logging and visualiserRegistry for available visualisers.
"""
import address_visualisation as AV
from address_visualisation.visualisers import ProfaneStreetsVisualiser, BiggestTownsVisualiser, ExtremeStreetNamesVisualiser, LongestStreetsVisualiser, SquareCountVisualiser, TownWithMostStreetsVisualiser
import logging
import sys

logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG)

DEFAULT_VISUALISERS = [
	(ProfaneStreetsVisualiser, 'profane_streets'),
	(BiggestTownsVisualiser, 'biggest_towns'),
	(ExtremeStreetNamesVisualiser, 'extreme_street_names'),
	(LongestStreetsVisualiser, 'longest_streets'),
	(SquareCountVisualiser, 'square_count'),
	(TownWithMostStreetsVisualiser, 'town_with_most_streets')
]

visualisers = []
if len(sys.argv) > 1:
	for a in sys.argv[1:]:
		s = a.split('=', 1)
		if len(s) != 2:
			raise Exception('Argument has to be in the form XxxVisualiser=output_name.')
		v = globals()[s[0]]
		if not issubclass(v, AV.Visualiser):
			raise Exception('The class name has to be an instance of visualiser.')
		if s[1].find('/') != -1:
			raise Exception('The output file name cannot contain a forward slash.')

		visualisers.append((v, s[1]))
else:
	visualisers = DEFAULT_VISUALISERS

visreg = AV.VisualiserRegistry('resources/db.xml')
visreg.register_visualiser_set(visualisers)
visreg.run_visualisers('resources/visualisations')
{'fraction_non_alphanumeric': 0.10785123966942149, 'fraction_numerical': 0.004132231404958678, 'mean_word_length': 8.42023346303502, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2676546', 'n_tokens_mistral': 846, 'n_tokens_neox': 773, 'n_words': 156}