@@ -210,78 +210,79 @@ def sync_players(clan_id=None):
210
210
:param clan_id:
211
211
:return:
212
212
"""
213
- if config .API_KEY == request .args ['API_KEY' ]:
214
- if clan_id :
215
- clan_ids = [clan_id ]
216
- else :
217
- clan_ids = config .CLAN_IDS .values ()
218
- for clan_id in clan_ids :
219
- logger .info ("Clan member synchronization triggered for " + str (clan_id ))
220
- webapp_data = WebappData .get ()
221
- webapp_data .last_sync_attempt = datetime .datetime .now ()
222
- db_session .add (webapp_data )
223
- db_session .commit ()
224
- db_session .remove ()
225
-
226
- clan_info = wotapi .get_clan (str (clan_id ))
227
- player_ids = clan_info ['data' ][str (clan_id )]['members' ].keys ()
228
- players_info = wotapi .get_players (player_ids )
229
- member_info_data = {}
230
- for i in xrange (0 , len (player_ids ), 20 ):
231
- member_info_data .update (wotapi .get_players_membership_info (player_ids [i :i + 20 ])['data' ])
232
-
233
- processed = set ()
234
- for player_id in player_ids :
235
- player = clan_info ['data' ][str (clan_id )]['members' ][player_id ]
236
- player_data = players_info ['data' ][player_id ]
237
- member_data = member_info_data [player_id ]
238
- p = Player .query .filter_by (wot_id = str (player ['account_id' ])).first ()
239
- if not player_data :
240
- if p :
241
- processed .add (p .id ) # skip this guy later when locking players
242
- logger .info ("Missing player info of " + player ['account_name' ])
243
- continue # API Error?
244
-
245
- since = datetime .datetime .fromtimestamp (
246
- float (member_data ['joined_at' ]))
213
+ if config .API_KEY != request .args ['API_KEY' ]:
214
+ abort (403 )
247
215
216
+ if clan_id :
217
+ clan_ids = [clan_id ]
218
+ else :
219
+ clan_ids = config .CLAN_IDS .values ()
220
+ for clan_id in clan_ids :
221
+ logger .info ("Clan member synchronization triggered for " + str (clan_id ))
222
+ webapp_data = WebappData .get ()
223
+ webapp_data .last_sync_attempt = datetime .datetime .now ()
224
+ db_session .add (webapp_data )
225
+ db_session .commit ()
226
+ db_session .remove ()
227
+
228
+ clan_info = wotapi .get_clan (str (clan_id ))
229
+ player_ids = clan_info ['data' ][str (clan_id )]['members' ].keys ()
230
+ players_info = wotapi .get_players (player_ids )
231
+ member_info_data = {}
232
+ for i in xrange (0 , len (player_ids ), 20 ):
233
+ member_info_data .update (wotapi .get_players_membership_info (player_ids [i :i + 20 ])['data' ])
234
+
235
+ processed = set ()
236
+ for player_id in player_ids :
237
+ player = clan_info ['data' ][str (clan_id )]['members' ][player_id ]
238
+ player_data = players_info ['data' ][player_id ]
239
+ member_data = member_info_data [player_id ]
240
+ p = Player .query .filter_by (wot_id = str (player ['account_id' ])).first ()
241
+ if not player_data :
248
242
if p :
249
- # Player exists, update information
250
- processed .add (p .id )
251
- p .name = player ['account_name' ]
252
- p .openid = 'https://' + config .WOT_SERVER_REGION_CODE + '.wargaming.net/id/' + str (player_id ) + '-' + player ['account_name' ] + '/'
253
- p .locked = False
254
- p .clan = clan_info ['data' ][str (clan_id )]['tag' ]
255
- p .role = player ['role' ] # role might have changed
256
- p .member_since = since # might have rejoined
257
- else :
258
- # New player
259
- p = Player (str (player ['account_id' ]),
260
- 'https://' + config .WOT_SERVER_REGION_CODE + '.wargaming.net/id/' + str (player ['account_id' ]) + '-' + player [
261
- 'account_name' ] + '/' ,
262
- since ,
263
- player ['account_name' ],
264
- clan_info ['data' ][str (clan_id )]['tag' ],
265
- player ['role' ])
266
- logger .info ('Adding player ' + player ['account_name' ])
267
- db_session .add (p )
268
-
269
- # All players of the clan in the DB, which are no longer in the clan
270
- for player in Player .query .filter_by (clan = clan_info ['data' ][str (clan_id )]['tag' ]):
271
- if player .id in processed or player .id is None or player .locked :
272
- continue
273
- logger .info ("Locking player " + player .name )
274
- player .locked = True
275
- player .lock_date = datetime .datetime .now ()
276
- db_session .add (player )
277
-
278
- webapp_data .last_successful_sync = datetime .datetime .now ()
279
- db_session .add (webapp_data )
280
- db_session .commit ()
281
- logger .info ("Clan member synchronization successful" )
243
+ processed .add (p .id ) # skip this guy later when locking players
244
+ logger .info ("Missing player info of " + player ['account_name' ])
245
+ continue # API Error?
246
+
247
+ since = datetime .datetime .fromtimestamp (
248
+ float (member_data ['since' ]))
249
+
250
+ if p :
251
+ # Player exists, update information
252
+ processed .add (p .id )
253
+ p .name = player ['account_name' ]
254
+ p .openid = 'https://' + config .WOT_SERVER_REGION_CODE + '.wargaming.net/id/' + str (player_id ) + '-' + \
255
+ player ['account_name' ] + '/'
256
+ p .locked = False
257
+ p .clan = clan_info ['data' ][str (clan_id )]['abbreviation' ]
258
+ p .role = player ['role' ] # role might have changed
259
+ p .member_since = since # might have rejoined
260
+ else :
261
+ # New player
262
+ p = Player (str (player ['account_id' ]),
263
+ 'https://' + config .WOT_SERVER_REGION_CODE + '.wargaming.net/id/' + str (
264
+ player ['account_id' ]) + '-' + player [
265
+ 'account_name' ] + '/' ,
266
+ since ,
267
+ player ['account_name' ],
268
+ clan_info ['data' ][str (clan_id )]['abbreviation' ],
269
+ player ['role' ])
270
+ logger .info ('Adding player ' + player ['account_name' ])
271
+ db_session .add (p )
272
+
273
+ # All players of the clan in the DB, which are no longer in the clan
274
+ for player in Player .query .filter_by (clan = clan_info ['data' ][str (clan_id )]['abbreviation' ]):
275
+ if player .id in processed or player .id is None or player .locked :
276
+ continue
277
+ logger .info ("Locking player " + player .name )
278
+ player .locked = True
279
+ player .lock_date = datetime .datetime .now ()
280
+ db_session .add (player )
282
281
283
- else :
284
- abort (403 )
282
+ webapp_data .last_successful_sync = datetime .datetime .now ()
283
+ db_session .add (webapp_data )
284
+ db_session .commit ()
285
+ logger .info ("Clan member synchronization successful" )
285
286
286
287
return redirect (url_for ('index' ))
287
288
@@ -641,7 +642,8 @@ def edit_battle(battle_id):
641
642
return redirect (url_for ('battles_list' , clan = g .player .clan ))
642
643
643
644
return render_template ('battles/edit.html' , date = date , map_name = map_name , province = province , battle = battle ,
644
- battle_groups = battle_groups , duration = duration , battle_group_description = battle_group_description ,
645
+ battle_groups = battle_groups , duration = duration ,
646
+ battle_group_description = battle_group_description ,
645
647
battle_commander = battle_commander , enemy_clan = enemy_clan , battle_result = battle_result ,
646
648
battle_group_final = battle_group_final , players = players , description = description ,
647
649
replay = replay , replays = replays , all_players = all_players , sorted_players = sorted_players )
@@ -798,7 +800,7 @@ def create_battle():
798
800
server_tz = timezone (config .SERVER_TIMEZONE )
799
801
user_tz = timezone (usertimezone )
800
802
date = user_tz .localize (date ).astimezone (server_tz )
801
- session ['usertimezone' ] = usertimezone # Remember selected timezone
803
+ session ['usertimezone' ] = usertimezone # Remember selected timezone
802
804
803
805
battle = Battle (date , g .player .clan , enemy_clan , victory = (battle_result == 'victory' ),
804
806
map_name = map_name , map_province = province ,
@@ -861,21 +863,21 @@ def battles_list(clan):
861
863
if not clan in config .CLAN_NAMES :
862
864
abort (404 )
863
865
864
- #enemy_clan = request.args.get('enemy', None)
866
+ # enemy_clan = request.args.get('enemy', None)
865
867
866
- #battles = Battle.query.options(joinedload_all('battle_group.battles')).options(
868
+ # battles = Battle.query.options(joinedload_all('battle_group.battles')).options(
867
869
# joinedload_all('attendances.player')).options(joinedload_all('battle_commander')).filter_by(clan=clan)
868
- #if enemy_clan:
870
+ # if enemy_clan:
869
871
# battles = battles.filter_by(enemy_clan=enemy_clan)
870
- #battles = battles.all()
872
+ # battles = battles.all()
871
873
872
874
return render_template ('battles/battles.html' , clan = clan )
873
875
874
876
875
877
@app .route ('/battles/list/<clan>/json' )
876
878
@require_login
877
879
def battles_list_json (clan ):
878
- if not clan in config .CLAN_NAMES :
880
+ if clan not in config .CLAN_NAMES :
879
881
abort (404 )
880
882
881
883
offset = int (request .args .get ('iDisplayStart' ))
@@ -924,7 +926,7 @@ def battles_list_json(clan):
924
926
and_ (Battle .clan == clan ,
925
927
(or_ (Battle .date == select ([func .max (battle_table .c .date )],
926
928
Battle .battle_group_id == battle_table .c .battle_group_id
927
- ),
929
+ ),
928
930
Battle .battle_group_id == None )),
929
931
search_term ,
930
932
(Battle .enemy_clan == enemy_clan if enemy_clan else True ))) \
@@ -1171,9 +1173,9 @@ def clan_players(clan):
1171
1173
'%i' % (present [player ] / possible [player ] * 100.0 if possible [player ] else 0 ),
1172
1174
'%i' % (present30 [player ] / possible30 [player ] * 100.0 if possible30 [player ] else 0 ),
1173
1175
last_battle_by_player [player ].date .strftime ('%d.%m.%Y %H:%M' ) if
1174
- last_battle_by_player [player ] else '' ,
1176
+ last_battle_by_player [player ] else '' ,
1175
1177
player .gold_earned
1176
- ])
1178
+ ])
1177
1179
1178
1180
headers = Headers ()
1179
1181
headers .add ('Content-Type' , 'text/csv' )
@@ -1318,7 +1320,7 @@ def download_replay(battle_id):
1318
1320
response .headers ['Content-Disposition' ] = 'attachment; filename=' + \
1319
1321
secure_filename (battle .date .strftime (
1320
1322
'%d.%m.%Y_%H_%M_%S' ) + '_' + battle .clan + '_' +
1321
- battle .enemy_clan + '.wotreplay' )
1323
+ battle .enemy_clan + '.wotreplay' )
1322
1324
return response
1323
1325
1324
1326
@@ -1340,7 +1342,7 @@ def download_additional_replay(replay_id):
1340
1342
response .headers ['Content-Disposition' ] = 'attachment; filename=' + \
1341
1343
secure_filename (battle .date .strftime (
1342
1344
'%d.%m.%Y_%H_%M_%S' ) + '_' + battle .clan + '_' +
1343
- battle .enemy_clan + '.wotreplay' )
1345
+ battle .enemy_clan + '.wotreplay' )
1344
1346
return response
1345
1347
1346
1348
@@ -1409,7 +1411,7 @@ def overlapping_battles(battle, ordered_battles, before_dt=timedelta(minutes=0),
1409
1411
[battle.date - before_dt, battle.date + battle.duration + after_dt].
1410
1412
Such battles overlap with the given battle. """
1411
1413
return [b for b in ordered_battles if battle .date - before_dt <= b .date <=
1412
- battle .date + timedelta (seconds = battle .duration or (15 * 60 )) + after_dt ]
1414
+ battle .date + timedelta (seconds = battle .duration or (15 * 60 )) + after_dt ]
1413
1415
1414
1416
# noinspection PyShadowingNames
1415
1417
def get_reserve_conflicts (battles ):
@@ -1545,7 +1547,8 @@ def payout_battles(clan):
1545
1547
return render_template ('payout/payout_battles.html' , battles = battles , clan = clan , fromDate = from_date , toDate = to_date ,
1546
1548
player_played = player_played , player_reserve = player_reserve , players = players ,
1547
1549
player_gold = player_gold , gold = gold , player_defeats = player_defeats ,
1548
- player_fced_win = player_fced_win , victories_only = victories_only , recruit_factor = recruit_factor ,
1550
+ player_fced_win = player_fced_win , victories_only = victories_only ,
1551
+ recruit_factor = recruit_factor ,
1549
1552
player_fced_defeat = player_fced_defeat , player_victories = player_victories ,
1550
1553
player_fced_draws = player_fced_draws , player_draws = player_draws , player_points = player_points ,
1551
1554
player_resources = player_resources , points_per_resource = points_per_resource )
@@ -1645,16 +1648,17 @@ def payout_battles_json():
1645
1648
battle .enemy_clan ,
1646
1649
battle .creator .name ,
1647
1650
battle .outcome_str ()] for battle in battles
1648
- ]
1651
+ ]
1649
1652
})
1650
1653
1651
1654
1652
1655
@app .route ('/players/commanded/<clan>' )
1653
1656
@require_login
1654
1657
@require_role (config .COMMANDED_ROLES )
1655
1658
def players_commanded (clan ):
1656
- commanders = Player .query .filter_by (locked = False , clan = clan ).filter (Player .id .in_ (db_session .query (Battle .battle_commander_id ) \
1657
- .distinct ())).order_by (Player .name ).all ()
1659
+ commanders = Player .query .filter_by (locked = False , clan = clan ).filter (
1660
+ Player .id .in_ (db_session .query (Battle .battle_commander_id ) \
1661
+ .distinct ())).order_by (Player .name ).all ()
1658
1662
1659
1663
return render_template ('players/commanding.html' , commanders = commanders , clan = clan )
1660
1664
@@ -1675,7 +1679,7 @@ def players_commanded_json():
1675
1679
1676
1680
battles = Battle .query .options (joinedload_all ('battle_group.battles' )).options (
1677
1681
joinedload_all ('attendances.player' )).filter (Battle .date >= from_date ).filter (Battle .date <= to_date ) \
1678
- .filter_by (battle_commander = commander )
1682
+ .filter_by (battle_commander = commander )
1679
1683
player_count = defaultdict (int )
1680
1684
for battle in battles :
1681
1685
if use_battle_groups :
@@ -1695,10 +1699,7 @@ def players_commanded_json():
1695
1699
"sEcho" : 1 ,
1696
1700
"iTotalRecords" : len (player_count ),
1697
1701
"iTotalDisplayRecords" : len (player_count ),
1698
- "aaData" : [
1699
- (k .name ,
1700
- v ) for k , v in player_count .iteritems ()
1701
- ]
1702
+ "aaData" : [(k .name , v ) for k , v in player_count .iteritems ()]
1702
1703
})
1703
1704
1704
1705
@@ -1754,7 +1755,7 @@ def clan_statistics(clan):
1754
1755
enemies_by_battle_count = defaultdict (int )
1755
1756
for bc in range (max (battles_by_enemy .values () or [0 ])):
1756
1757
enemies_by_battle_count [bc ] = len ([enemy_clan for enemy_clan in battles_by_enemy if
1757
- battles_by_enemy [enemy_clan ] >= bc ])
1758
+ battles_by_enemy [enemy_clan ] >= bc ])
1758
1759
1759
1760
battle_count_cutoff = 0
1760
1761
for battle_count in range (1 , max (battles_by_enemy .values () or [0 ])):
@@ -1808,7 +1809,7 @@ def player_performance(clan):
1808
1809
to_date = request .form .get ('toDate' , None )
1809
1810
1810
1811
if from_date is None :
1811
- from_date = datetime .datetime .now () - datetime .timedelta (days = 4 * 7 )
1812
+ from_date = datetime .datetime .now () - datetime .timedelta (days = 4 * 7 )
1812
1813
else :
1813
1814
from_date = datetime .datetime .strptime (from_date , '%d.%m.%Y' )
1814
1815
@@ -1817,7 +1818,8 @@ def player_performance(clan):
1817
1818
else :
1818
1819
to_date = datetime .datetime .strptime (to_date , '%d.%m.%Y' ) + datetime .timedelta (days = 1 )
1819
1820
1820
- battles = Battle .query .options (joinedload ('replay' )).filter_by (clan = clan ).filter (Battle .date >= from_date , Battle .date <= to_date ).all ()
1821
+ battles = Battle .query .options (joinedload ('replay' )).filter_by (clan = clan ).filter (Battle .date >= from_date ,
1822
+ Battle .date <= to_date ).all ()
1821
1823
players = Player .query .filter_by (clan = clan , locked = False ).all ()
1822
1824
1823
1825
result = analysis .player_performance (battles , players )
0 commit comments