--mode help: improvements, --stat_func=tank

This commit is contained in:
Jylpah committed 2020-11-24 22:49:03 +02:00
1 parent 6651d77ec3
commit b8d9f9125e
1 file changed
+84 -5
+84 -5
View File
@@ -209,6 +209,34 @@ class BattleCategorizationList():
return None
@classmethod
def help(cls):
for cat in cls.get_categorizations_all():
try:
ctitle = cls.get_categorization_title(cat)
ctype = cls.get_categorization_type(cat)
cparams = cls.get_categorization_params(cat)
if ctype == 'number':
cat_tmp = BattleNumberCategorization(cat, ctitle)
elif ctype == 'string':
cat_tmp = BattleStringCategorization(cat, ctitle)
elif ctype == 'category':
cat_tmp = BattleClassCategorization(cat, ctitle, cparams[0])
elif ctype == 'bucket':
cat_tmp = BattleBucketCategorization(cat, ctitle, cparams[0], cparams[1])
else:
cat_tmp = BattleTotals(ctitle)
cat_tmp.help()
except KeyError as err:
bu.error('BattleCategorizationList(): Key not found: Category: ' + cat, exception=err)
except Exception as err:
bu.error('BattleCategorizationList()', exception=err)
def __init__(self, args : argparse.Namespace):
self.urls = collections.OrderedDict()
self.url_title_max_len = 0
@@ -330,6 +358,12 @@ class BattleCategorization():
return 'NONE'
def help(self):
"""Help"""
FORMAT = '\t{:<15s}\t{}. Options:'
print(FORMAT.format(self.category_key, self.title), end=' ')
def record_result(self, result: dict):
try:
cat = self.get_category(result)
@@ -393,6 +427,10 @@ class BattleTotals(BattleCategorization):
def get_categories(self) -> str:
return [ self.TOTAL ]
def help(self):
super().help()
print('-')
class BattleClassCategorization(BattleCategorization):
"""Class for categorization by fixed classes with ID (int)"""
@@ -402,6 +440,14 @@ class BattleClassCategorization(BattleCategorization):
self.category_labels = classes
def help(self):
super().help()
labels = list()
for ndx in range(0, len(self.category_labels)):
labels.append(str(ndx) + '=' + self.category_labels[ndx])
print(', '.join(labels))
def get_category(self, result: dict) -> str:
"""Get category"""
cat_id = -1
@@ -443,6 +489,11 @@ class BattleStringCategorization(BattleCategorization):
return None
def help(self):
super().help()
print(self.title + ' name')
class BattleNumberCategorization(BattleCategorization):
"""Class for categorization by number"""
@@ -466,6 +517,11 @@ class BattleNumberCategorization(BattleCategorization):
return None
def help(self):
super().help()
print('INTEGER')
class BattleBucketCategorization(BattleCategorization):
"""Class for categorization by buckets based on value"""
@@ -478,6 +534,14 @@ class BattleBucketCategorization(BattleCategorization):
except Exception as err:
bu.error('BattleBucketCategorization()', exception=err)
def help(self):
super().help()
labels = list()
for ndx in range(0, len(self.category_labels)):
labels.append(str(ndx) + '=' + self.category_labels[ndx])
print(', '.join(labels))
def get_category(self, result: dict) -> str:
"""Get category"""
cat_id = -1
@@ -1127,7 +1191,7 @@ async def help_extended(db : motor.motor_asyncio.AsyncIOMotorDatabase = None, pa
# Filter usage
print('\n-------------------------------------------------------------------')
print('| Filter usage |')
print('| DB Filter usage |')
print('-------------------------------------------------------------------')
print("Syntax: --filters '{ \"replay.param\": VALUE, \"replay.param2\": { \"$MONGO_OPERATOR\" : VALUE }, ... }'")
@@ -1146,6 +1210,12 @@ async def help_extended(db : motor.motor_asyncio.AsyncIOMotorDatabase = None, pa
except Exception as err:
bu.error(exception=err)
print('\n-------------------------------------------------------------------')
print('| Filter usage |')
print('-------------------------------------------------------------------')
BattleCategorizationList.help()
## move the class PlayerHistogram?
def set_histogram_buckets(json: dict):
global histogram_fields
@@ -1424,6 +1494,8 @@ async def stat_worker(queue : asyncio.Queue, workerID: int, args : argparse.Name
stats[pruned_stat_id] = await stat_wg_func(pruned_stat_id)
stat_id_remap[stat_id] = pruned_stat_id
del stats[stat_id]
bu.debug('get_wg_' + args.stat_func + '_stats returned: account_id=' + str(get_account_id_f_stat_id(pruned_stat_id)) + ': ' + str(stats[pruned_stat_id]), workerID)
except KeyError as err:
bu.error('Key not found', err, id=workerID)
@@ -1479,11 +1551,18 @@ async def get_db_tank_stats(db : motor.motor_asyncio.AsyncIOMotorDatabase, stat_
try:
dbc = db[DB_C_TANK_STATS]
( account_id, tank_id, battletime ) = str2ints(stat_id_str)
time_buffer = 2*7*24*3600
FIX ## find() rather than aggregate!
cursor = dbc.find({ '$and': [ { 'account_id': account_id }, { 'last_battle_time': { '$lte': battletime + time_buffer }}, { 'tank_id' : tank_id } ]}).sort('last_battle_time',-1).limit(1)
hist_stats = [ 'all.' + x for x in histogram_fields.keys() ]
hist_stats.append('tank_id')
hist_stats.append('account_id')
hist_stats.append('last_battle_time')
project = dict()
for stat in hist_stats:
project[stat] = True
project['_id'] = False
cursor = dbc.find({ '$and': [ { 'account_id': account_id }, { 'last_battle_time': { '$gte': battletime - time_buffer }}, { 'tank_id' : tank_id } ] }, projection=project).sort('last_battle_time',-1).limit(1)
# pipeline = [ { '$match': { '$and': [ { 'account_id': account_id }, { 'last_battle_time': { '$lte': battletime + time_buffer }}, { 'tank_id' : tank_id } ]}},
# { '$sort': { 'last_battle_time': -1 }},
@@ -1494,7 +1573,7 @@ async def get_db_tank_stats(db : motor.motor_asyncio.AsyncIOMotorDatabase, stat_
# cursor = dbc.aggregate(pipeline, allowDiskUse=True)
#cursor = dbc.aggregate(pipeline)
return await tank_stats_helper(await cursor.to_list(10))
return await tank_stats_helper(await cursor.to_list(1))
except Exception as err:
bu.error('account_id: ' + str(account_id) + ' Error', err)