No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emgen.py 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. from django.core.management.base import BaseCommand, CommandError
  2. from optparse import make_option
  3. from EditorialModel.randomem import RandomEm
  4. from EditorialModel.backend.json_backend import EmBackendJson
  5. from EditorialModel.backend.dummy_backend import EmBackendDummy
  6. from EditorialModel.backend.graphviz import EmBackendGraphviz
  7. class Command(BaseCommand):
  8. option_list = BaseCommand.option_list + (
  9. make_option('--no-classes',
  10. action='store',
  11. dest='classtype',
  12. default = 0,
  13. help='Chances for a classtype to be empty',
  14. type="int",
  15. metavar="INT",
  16. ),
  17. make_option('--max-classes',
  18. action='store',
  19. dest='nclass',
  20. default = 3,
  21. help='Maximum number of classes per classtype',
  22. type="int",
  23. metavar="INT",
  24. ),
  25. make_option('--no-fieldgroup',
  26. action='store',
  27. dest='nofg',
  28. default = 10,
  29. help='Chances for a class to have no fieldgroup',
  30. type="int",
  31. metavar="INT",
  32. ),
  33. make_option('--no-types',
  34. action='store',
  35. dest='notype',
  36. default = 10,
  37. help='Chances for a class to have no types',
  38. type="int",
  39. metavar="INT",
  40. ),
  41. make_option('--max-types',
  42. action='store',
  43. dest='ntype',
  44. default = 8,
  45. help='Maximum number of types in a class',
  46. type="int",
  47. metavar="INT",
  48. ),
  49. make_option('--sel-opt-field',
  50. action='store',
  51. dest='seltype',
  52. default = 2,
  53. help='Chances for type to select an optionnal field',
  54. type="int",
  55. metavar="INT",
  56. ),
  57. make_option('--superiors',
  58. action='store',
  59. dest='ntypesuperiors',
  60. default = 2,
  61. help='Chances for a type to link with other types (superiors)',
  62. type="int",
  63. metavar="INT",
  64. ),
  65. make_option('--no-fields',
  66. action='store',
  67. dest='nofields',
  68. default = 10,
  69. help='Chances for a fieldgroup to be empty',
  70. type="int",
  71. metavar="INT",
  72. ),
  73. make_option('--max-fields',
  74. action='store',
  75. dest='nfields',
  76. default = 8,
  77. help='Maxmimum number of fields per fieldgroup',
  78. type="int",
  79. metavar="INT",
  80. ),
  81. make_option('--rel-to-type-attr',
  82. action='store',
  83. dest='rfields',
  84. default = 5,
  85. help='Maximum number of relation-to-type attribute fields',
  86. type="int",
  87. metavar="INT",
  88. ),
  89. make_option('--opt-field',
  90. action='store',
  91. dest='optfield',
  92. default = 2,
  93. help='Chances for a field to be optionnal',
  94. type="int",
  95. metavar="INT",
  96. ),
  97. make_option('-o',
  98. '--output',
  99. action='store',
  100. dest='output',
  101. default = 'random_me.json',
  102. help='json output file for the me',
  103. type="string",
  104. metavar="FILENAME",
  105. ),
  106. make_option('-d',
  107. '--output-dot',
  108. action='store',
  109. dest='dotout',
  110. default = False,
  111. help='graphviz output file for the me',
  112. type="string",
  113. metavar="FILENAME",
  114. ),
  115. )
  116. help = 'Randomly generate an EditorialModel'
  117. def handle(self, *args, **options):
  118. anames = ['classtype','nclass', 'nofg', 'notype', 'ntype', 'seltype', 'ntypesuperiors', 'nofields', 'nfields', 'optfield']
  119. chances = dict()
  120. for n in anames:
  121. chances[n] = options[n]
  122. bj = EmBackendJson(options['output'])
  123. em = RandomEm.random_em(EmBackendDummy())
  124. bj.save(em)
  125. if options['dotout']:
  126. gvb = EmBackendGraphviz(options['dotout'])
  127. gvb.save(em)