<commit_before>from django.core.management.base import BaseCommand, CommandError
from LL1_Academy.tools import MassGrammarGenerator
import os
import time

class Command(BaseCommand):
	help = 'This command will add grammars to the database, starting from <num> grammars and gradually filtering them down to a valid set (which may be much less than <num>)'

	def add_arguments(self, parser):
		parser.add_argument('num', type=int)
	
	def handle(self, *args, **options):
		#Number of randomly generated grammars
		num = options['num']

		#Number variables this run will include. 
		#For example [2,3] will run the script to generate
		#grammars with 2 variables and 3 variables
		nVariables = [2, 3]

		nonTerminals = ['A','B','C','D']
		terminals = ['x','y','z','w']

		for n in nVariables:
			start_time = time.time()
			mg = MassGrammarGenerator.MassGrammarGenerator(n)
			mg.run(num,nonTerminals[:n],terminals)
			print("{}Variables: {} seconds---".format(n,(time.time() - start_time)))
<commit_msg>Upgrade functionality of populate command<commit_after>from django.core.management.base import BaseCommand, CommandError
from LL1_Academy.tools import MassGrammarGenerator
from LL1_Academy.models import Grammar
import os
import time
from django.core.management import call_command


class Command(BaseCommand):
	help = 'This command will add grammars to the database, starting from <num> grammars and gradually filtering them down to a valid set (which may be much less than <num>)'

	def add_arguments(self, parser):
		parser.add_argument('num', type=int)
		parser.add_argument('--reset',
				action='store_true',
				dest='reset_db',
				default=False,
				help='Clear database and repopulate it',
				)
	
	def handle(self, *args, **options):
		if (options['reset_db']):
			call_command('cleardatabase')

		print("Grammar objects initially in database: {}".format(Grammar.objects.count()))
		#Number of randomly generated grammars
		num = options['num']

		#Number variables this run will include. 
		#For example [2,3] will run the script to generate
		#grammars with 2 variables and 3 variables
		nVariables = [2, 3]

		nonTerminals = ['A','B','C','D']
		terminals = ['x','y','z','w']

		for n in nVariables:
			start_time = time.time()
			mg = MassGrammarGenerator.MassGrammarGenerator(n)
			mg.run(num,nonTerminals[:n],terminals)
			print("{}Variables: {} seconds---".format(n,(time.time() - start_time)))
		print("Grammar objects finally in database: {}".format(Grammar.objects.count()))

{'fraction_non_alphanumeric': 0.1250501002004008, 'fraction_numerical': 0.006012024048096192, 'mean_word_length': 4.957040572792363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2223874', 'n_tokens_mistral': 844, 'n_tokens_neox': 758, 'n_words': 238}