Commits

Neil Muller committed 5644e30

Rework superstar logic. Add total decks and percentages to superstars by year

  • Participants
  • Parent commits 652ad60

Comments (0)

Files changed (1)

File TWDA/twd_stats.py

     oNonUnique = IKeyword('non-unique')
     aCrypt = [x.abstractCard for x in oCardSet.cards
             if is_crypt_card(x.abstractCard)]
+    iCrypt = len(aCrypt)
     dCrypt = {}
     for oCard in aCrypt:
         sName = oCard.name
         dCrypt[sName] += 1
     aTotals = sorted(dCrypt.items(), key=lambda x: -x[1])
     iMax = aTotals[0][1]
-    if iMax < iSuper:
+    fSuper = float(iSuper)/ 12.0
+    fMax = float(iMax)/iCrypt
+    if (iMax < iSuper) or (fMax < fSuper):
+        # We check both to ensure illegal crypts don't screw the numbers
         return None
     if len(aTotals) > 1 and aTotals[1][1] == iMax:
         # Not superstar, multiple vampires have that number
 def find_super_stars_by_year(aParCS, iSuper):
     """Divide super star decks by year"""
     dSuperStarByYear = {}
+    dYears = {}
     for oCS in card_sets_with_progress(79):
         if oCS.parent.id not in aParCS:
             continue
+        sYear = oCS.parent.name.replace(sTWDParPrefix, '')
+        dYears.setdefault(sYear, 0)
+        dYears[sYear] += 1
         sName = get_super_star(oCS, iSuper)
         if sName:
-            sYear = oCS.parent.name.replace(sTWDParPrefix, '')
             dSuperStarByYear.setdefault(sYear, 0)
             dSuperStarByYear[sYear] += 1
-    return dSuperStarByYear
+    for sYear in sorted(dSuperStarByYear):
+        print sYear, ':', '%d / %d (%2.5f %%)' % (dSuperStarByYear[sYear], dYears[sYear], 100.0*float(dSuperStarByYear[sYear]) / dYears[sYear])
 
 
 def find_super_star_stats(aParCS, iSuper, bDetails, bUrls):
                 sPlural = 'decks'
             else:
                 sPlural = 'deck'
-            print ' %45s : %3d %s' % (sName, iNum, sPlural)
+            print ' %45s : %3d %s' % (sName.encode('utf8'), iNum, sPlural)
     except TypeError:
         for sName, aDetails in sorted(dInfo.items()):
             print ' %40s :' % sName
     dSuperStars, dDetails, dUrls = \
             find_super_star_stats(aParCS, int(oOpts.sup), oOpts.details,
             oOpts.urls)
-    dSuperStarsByYear = find_super_stars_by_year(aParCS, int(oOpts.sup))
     print_dict(dClans, 'Clans')
     print_dict(dMulti, 'Multi-clan')
     print_dict(dSuperStars, 'Superstars')
         print_dict(dDetails, 'Superstar card set names')
     if dUrls:
         print_dict(dUrls, 'Superstar card set urls')
-    print_dict(dSuperStarsByYear, 'Superstars by Year')
+    find_super_stars_by_year(aParCS, int(oOpts.sup))