populate.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:LL1-Academy 作者: H-Huang 项目源码 文件源码
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']



        if options['silent']:
            sys.stdout = open(os.devnull, "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)))

        if options['silent']:
            sys.stdout = sys.__stdout__

        print("Grammar objects finally in database: {}".format(Grammar.objects.count()))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号