Browse Source

Added a random methods to EmModel to generate a random EM

Yann Weber 9 years ago
parent
commit
d405f0b41e
1 changed files with 30 additions and 4 deletions
  1. 30
    4
      EditorialModel/model.py

+ 30
- 4
EditorialModel/model.py View File

@@ -267,7 +267,26 @@ class Model(object):
267 267
 
268 268
     @classmethod
269 269
     ## @brief Generate a random editorial model
270
-    def random(cls, backend):
270
+    # 
271
+    # The random generator can be tuned with integer parameters
272
+    # that represent probability or maximum numbers of items.
273
+    # The probability (chances) works like 1/x chances to append
274
+    # with x the tunable parameter
275
+    # Tunable generator parameters :
276
+    # - classtype : Chances for a classtype to be empty (default 0)
277
+    # - nclass : Maximum number of classes per classtypes (default 5)
278
+    # - nofg : Chances for a classe to have no fieldgroup associated to it (default 10)
279
+    # - notype : Chances for a classe to have no type associated to it (default 5)
280
+    # - seltype : Chances for a type to select an optionnal field (default 2)
281
+    # - ntypesuperiors : Chances for a type to link with a superiors (default 3)
282
+    # - nofields : Chances for a fieldgroup to be empty (default 10)
283
+    # - nfields : Maximum number of field per fieldgroups (default 8)
284
+    # - rfields : Maximum number of relation_to_type attributes fields (default 5)
285
+    # - optfield : Chances for a field to be optionnal (default 2)
286
+    # @param backend : A backend to use with the new EM
287
+    # @param **chances dict : Provide tunable generation parameter
288
+    # @return A randomly generate EM
289
+    def random(cls, backend, **chances):
271 290
         em = Model(backend)
272 291
 
273 292
         chances = {
@@ -361,14 +380,20 @@ class Model(object):
361 380
     @staticmethod
362 381
     ## @brief Generate a random string
363 382
     # @warning dirty cache trick with globals()
364
-    def _rnd_str():
365
-        if '_words' not in globals():
366
-            with open('/usr/share/dict/words', 'r') as fpw:
383
+    # @return a randomly selected string
384
+    def _rnd_str(words_src='/usr/share/dict/words'):
385
+        if '_words' not in globals() or globals()['_words_fname'] != words_src:
386
+            globals()['_words_fname'] = words_src
387
+            with open(words_src, 'r') as fpw:
367 388
                 globals()['_words'] = [ l for l in fpw ]
368 389
         words = globals()['_words']
369 390
         return words[random.randint(0,len(words)-1)]
370 391
         
371 392
     @classmethod
393
+    ## @brief Generate a random MlString
394
+    # @param nlng : Number of langs in the MlString
395
+    # @return a random MlString with nlng translations
396
+    # @todo use a dict to generated langages
372 397
     def _rnd_mlstr(cls, nlng):
373 398
         ret = MlString()
374 399
         for _ in range(nlng):
@@ -377,6 +402,7 @@ class Model(object):
377 402
 
378 403
     @classmethod
379 404
     ## @brief returns randomly generated datas for an EmComponent
405
+    # @return a dict with name, string and help_text
380 406
     def _rnd_component_datas(cls):
381 407
         mlstr_nlang = 5;
382 408
         ret = {}

Loading…
Cancel
Save