-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mplus.py
4234 lines (3297 loc) · 150 KB
/
mplus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import webapp2
import logging
import os
import json
import copy
import operator
import time
import pdb
from google.appengine.api import app_identity
from google.appengine.api import urlfetch
from google.appengine.ext import ndb
from google.appengine.ext import deferred
from google.appengine.runtime import DeadlineExceededError
from google.appengine.ext import vendor
# add libraries in lib
vendor.add('lib')
import slugify
import cloudstorage as gcs
import datetime
import pytz
from dragonflight import dungeons, dungeon_slugs, dungeon_short_names, slugs_to_dungeons
from dragonflight import primordial_stones
from warcraft import specs, tanks, healers, melee, ranged, role_titles, regions, pvp_regions, pvp_modes
from warcraft import spec_short_names
from t_interval import t_interval
from talents_to_spells import talents_to_spells
from talent_ids import talent_id_order, talent_id_class, talent_id_spec, talent_id_heights
from models import Run, DungeonAffixRegion, KnownAffixes, PvPLadderStats, PvPCounts
# wcl handling
from models import SpecRankings, SpecRankingsRaid, RaidCounts, DungeonEaseTierList
from auth import api_key
from wcl import wcl_specs
from wcl_dragonflight import dungeon_encounters
# information about dragonflight talent trees
from tree import class_zero, class_eight, class_twenty
from tree import spec_zero, spec_eight, spec_twenty
from tree import talent_order
from priority_talents import priority_talents
from active_talents import class_active, spec_active
from encode_talent_string import encode_talent_string
from dragonflight import tier_items, embellished_items, crafted_items
from enchants import enchant_mapping, enchant_collapse
# cloudflare cache handling
from auth import cloudflare_api_key, cloudflare_zone
# ludus labs api
from auth import ludus_access_key
# internal api
from auth import internal_api
## globals
from config import RIO_MAX_PAGE
from dragonflight import dungeons as DUNGEONS
from warcraft import regions as REGIONS
from config import RIO_MAX_PAGE, RIO_SEASON, RAID_NAME
from config import WCL_SEASON, WCL_PARTITION
from config import MIN_KEY_LEVEL
from config import MAX_RAID_DIFFICULTY
from config import latest_patch_us
from config import latest_patch_eu
from config import latest_patch_kr
from config import latest_patch_tw
last_updated = None
## raid rotation
known_raids = ["amirdrassil"]
from wcl_dragonflight import amirdrassil_encounters
from amirdrassil import amirdrassil_canonical_order, amirdrassil_short_names, amirdrassil_ignore
def get_raid_encounters(active_raid):
return amirdrassil_encounters
def get_raid_canonical_order(active_raid):
return amirdrassil_canonical_order
def get_raid_short_names(active_raid):
return amirdrassil_short_names
def get_raid_ignore(active_raid):
return amirdrassil_ignore
# rotate updating raids every day
def determine_raids_to_update(current_time=None):
raids_to_update = ["amirdrassil"]
return raids_to_update
# rotate updating raids every day
def determine_raids_to_generate(current_time=None):
raids_to_update = ["amirdrassil"]
return raids_to_update
## raider.io handling
def update_known_affixes(affixes, affixes_slug):
'''Update datastore's list of known affixes and their last seen times'''
key = ndb.Key('KnownAffixes', affixes_slug)
known_affix = key.get()
if known_affix is None: # only add it if we haven't seen it before
known_affix = KnownAffixes(id=affixes_slug, affixes=affixes)
known_affix.put()
else:
known_affix.put() # put it back to update last seen
def parse_individual_ranking(ranking):
'''Parse an individual r.io run and return a Run model object for it'''
score = ranking["score"]
run = ranking["run"]
roster = []
ksrid = ""
completed_at = ""
completed_at = datetime.datetime.strptime(run["completed_at"], "%Y-%m-%dT%H:%M:%S.%fZ")
clear_time_ms = run["clear_time_ms"]
mythic_level = run["mythic_level"]
if mythic_level < MIN_KEY_LEVEL: # only track runs at +16 or above
return None
num_chests = run["num_chests"]
keystone_time_ms = run["keystone_time_ms"]
faction = run["faction"]
ksrid = str(run["keystone_run_id"])
for roster_entry in run["roster"]:
character = roster_entry["character"]
spec_class = character["spec"]["name"] + " " + character["class"]["name"]
roster += [spec_class]
return Run(score=score, roster=roster, keystone_run_id=ksrid,
completed_at=completed_at, clear_time_ms=clear_time_ms,
mythic_level=mythic_level, num_chests=num_chests,
keystone_time_ms=keystone_time_ms, faction=faction)
def parse_response(data, dungeon, affixes, region, page):
'''Parse the response from r.io and store it in our datastore'''
dungeon_slug = slugify.slugify(unicode(dungeon))
if affixes == "current":
affixes = ""
affixes += data[0]["run"]["weekly_modifiers"][0]["name"] + ", "
affixes += data[0]["run"]["weekly_modifiers"][1]["name"] + ", "
affixes += data[0]["run"]["weekly_modifiers"][2]["name"]
# R.I.P. Seasonal Affix
# affixes += data[0]["run"]["weekly_modifiers"][3]["name"]
affixes_slug = slugify.slugify(unicode(affixes))
update_known_affixes(affixes, affixes_slug)
key_string = dungeon_slug + "-" + affixes_slug + "-" + region + "-" + str(page)
key = ndb.Key('DungeonAffixRegion',
key_string)
dar = DungeonAffixRegion(key=key)
dar.dungeon = dungeon
dar.affixes = affixes
dar.region = region
dar.page = page
for individual_ranking in data:
parsed_run = parse_individual_ranking(individual_ranking)
if parsed_run is not None:
dar.runs += [parsed_run]
return dar
# update
## @@season update
## also in templates/max_link and templates/by-affix
## also in wcl_ (also marked with @@)
def update_dungeon_affix_region(dungeon, affixes, region, season=RIO_SEASON, page=0):
'''For a given dungeon, affixes, region, season, and page, get top M+ runs'''
dungeon_slug = slugify.slugify(unicode(dungeon))
if region == "cn" and affixes == "current": # not working properly for cn
affixes = current_affixes()
affixes_slug = slugify.slugify(unicode(affixes))
# everbloom handling
if dungeon_slug == "the-everbloom":
dungeon_slug = "everbloom"
req_url = "https://raider.io/api/v1/mythic-plus/runs?"
req_url += "season=%s®ion=%s&affixes=%s&dungeon=%s&page=%d" \
% (season, region, affixes_slug, dungeon_slug, page)
response = {}
try:
result = urlfetch.fetch(req_url, deadline=60)
if result.status_code == 200:
response = json.loads(result.content)["rankings"]
if response == []: # empty rankings, as sometimes happens at week start
logging.info("no rankings found for %s / %s / %s / %s",
dungeon, affixes, region, page)
return
dar = parse_response(response,
dungeon, affixes, region, page)
dar.put()
except DeadlineExceededError:
logging.exception('deadline exception fetching url: %s', req_url)
deferred.defer(update_dungeon_affix_region, dungeon, affixes,
region, season, page)
except urlfetch.Error:
logging.exception('caught exception fetching url: %s', req_url)
def update_current():
'''Query the r.io api across all regions for each dungeon (current affixes)'''
global DUNGEONS, REGIONS, RIO_MAX_PAGE
for region in REGIONS:
for dungeon in DUNGEONS:
for page in range(0, RIO_MAX_PAGE):
deferred.defer(update_dungeon_affix_region,
dungeon,
"current",
region,
page=page)
## end raider.io processing
## data analysis start
## replacements for numpy
def average(data):
return mean(data)
def mean(data):
"""Return the sample arithmetic mean of data."""
n = len(data)
if n < 1:
return 0
return sum(data)/float(n)
def _ss(data):
"""Return sum of square deviations of sequence data."""
c = mean(data)
ss = sum((x-c)**2 for x in data)
return ss
def std(data, ddof=0):
"""Calculates the population standard deviation
by default; specify ddof=1 to compute the sample
standard deviation."""
n = len(data)
if n < 2:
return 0
ss = _ss(data)
pvar = ss/(n-ddof)
return pvar**0.5
from math import sqrt
from ckmeans import ckmeans
def create_package(name):
package = {}
package["name"] = name
package["slug"] = slugify.slugify(unicode(name))
return package
# generate a dungeon tier list
def gen_dungeon_tier_list(dungeons_report):
scores = []
for k in dungeons_report:
scores += [float(k[0])]
if len(dungeons_report) < 6:
# for some reason we're seeing fewer than 6 dungeons
# might be early in the week, etc.
return gen_dungeon_tier_list_small(dungeons_report)
buckets = ckmeans(scores, 6)
added = []
tiers = {}
tm = {}
tm[5] = "S"
tm[4] = "A"
tm[3] = "B"
tm[2] = "C"
tm[1] = "D"
tm[0] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in dungeons_report:
if float(k[0]) in buckets[i]:
if k not in added:
if tm[i] not in tiers:
tiers[tm[i]] = []
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in dungeons_report:
if k not in added:
if tm[0] not in tiers:
tiers[tm[0]] = []
tiers[tm[0]] += [k]
added += [k]
return render_dungeon_tier_list(tiers, tm)
def render_dungeon_tier_list(tiers, tm):
dtl = {}
dtl["S"] = ""
dtl["A"] = ""
dtl["B"] = ""
dtl["C"] = ""
dtl["D"] = ""
dtl["F"] = ""
global dungeon_short_names
template = env.get_template("dungeon-mini-icon.html")
for i in range(0, 6):
for k in tiers[tm[i]]:
rendered = template.render(dungeon_slug = k[4],
dungeon_name = k[1],
dungeon_short_name = dungeon_short_names[k[1]])
dtl[tm[i]] += rendered
return dtl
def icon_spec(dname, prefix="", size=56):
dslug = slugify.slugify(unicode(dname))
return '<a href="%s.html"><img src="images/spec-icons/%s.jpg" width="%d" height="%d" title="%s" alt="%s" /><br/>%s</a>' % (prefix+dslug, dslug, size, size, dname, dname, dname)
import pdb
# generate a specs tier list
def gen_spec_tier_list(specs_report, role, prefix="", api=False):
global role_titles
scores = []
for i in range(0, 4):
for k in specs_report[role_titles[i]]:
if int(k[3]) < 20: # ignore specs with fewer than 20 runs as they would skew the buckets; we'll add them to F later
continue
scores += [float(k[0])]
if len(scores) < 6: # relax the fewer than 20 rule (early scans early in season)
scores = []
for i in range(0, 4):
for k in specs_report[role_titles[i]]:
scores += [float(k[0])]
buckets = ckmeans(scores, 6)
added = []
tiers = {}
tm = {}
tm[5] = "S"
tm[4] = "A"
tm[3] = "B"
tm[2] = "C"
tm[1] = "D"
tm[0] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in specs_report[role]:
if len(buckets) > i:
if float(k[0]) in buckets[i]:
if k not in added:
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in specs_report[role]:
if k not in added:
tiers[tm[0]] += [k]
added += [k]
if api==False:
dtl = {}
dtl["S"] = ""
dtl["A"] = ""
dtl["B"] = ""
dtl["C"] = ""
dtl["D"] = ""
dtl["F"] = ""
global spec_short_names
template = env.get_template("spec-mini-icon.html")
for i in range(0, 6):
for k in tiers[tm[i]]:
rendered = template.render(spec_name = k[1],
spec_short_name = spec_short_names[k[1]],
spec_slug = slugify.slugify(unicode(k[1])))
dtl[tm[i]] += rendered
return dtl
else:
dtl = {}
dtl["S"] = []
dtl["A"] = []
dtl["B"] = []
dtl["C"] = []
dtl["D"] = []
dtl["F"] = []
for i in range(0, 6):
for k in tiers[tm[i]]:
dtl[tm[i]] += [k[1]]
return dtl
def icon_affix(dname, size=28):
dname = affix_rotation_affixes(dname)
dslug = slugify.slugify(unicode(dname))
def miniaffix(aname, aslug, size):
return '<img src="images/affixes/%s.jpg" class="zoom-icon" width="%d" height="%d" title="%s" alt="%s" />' % (aslug, size, size, aname, aname)
affixen = dname.split(", ")
output = []
for af in affixen:
afname = af
afslug = slugify.slugify(af)
output += [miniaffix(afname, afslug, size=size)]
output_string = output[0]
output_string += output[1]
output_string += output[2]
# R.I.P. Seasonal Affix
# output_string += output[3]
return output_string
def render_affix_tier_list_api(tiers, tm):
dtl = {}
dtl["S"] = []
dtl["A"] = []
dtl["B"] = []
dtl["C"] = []
dtl["D"] = []
dtl["F"] = []
for i in range(0, 6):
for k in tiers[tm[i]]:
dtl[tm[i]] += [k[1]]
return dtl
def render_affix_tier_list(tiers, tm, api=False):
if api==True:
return render_affix_tier_list_api(tiers, tm)
dtl = {}
dtl["S"] = ""
dtl["A"] = ""
dtl["B"] = ""
dtl["C"] = ""
dtl["D"] = ""
dtl["F"] = ""
template = env.get_template('affix-mini-icon.html')
template_all = env.get_template('affixes-mini-icons.html')
for i in range(0, 6):
for k in tiers[tm[i]]:
affixen = k[1].split(", ")
current_set = current_affixes()
this_set = k[1]
affix_set = ""
slug_link = slugify.slugify(k[1])
if current_set in this_set:
slug_link = "index"
for each_affix in affixen:
rendered = template.render(affix_slug = slugify.slugify(each_affix),
affix_name = each_affix)
affix_set += rendered
dtl[tm[i]] += template_all.render(affix_link = slug_link,
affix_set = affix_set)
return dtl
# todo: affix tier list (how do affixes compare with each other)
# have this show on all affixes?
# new: generate a dungeon tier list
def gen_affix_tier_list(affixes_report, api=False):
if len(affixes_report) < 6:
return gen_affix_tier_list_small(affixes_report, api=api)
# ckmeans
scores = []
for k in affixes_report:
scores += [float(k[0])]
buckets = ckmeans(scores, 6)
added = []
tiers = {}
tm = {}
tm[5] = "S"
tm[4] = "A"
tm[3] = "B"
tm[2] = "C"
tm[1] = "D"
tm[0] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in affixes_report:
if float(k[0]) in buckets[i]:
if k not in added:
if tm[i] not in tiers:
tiers[tm[i]] = []
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in affixes_report:
if k not in added:
if tm[0] not in tiers:
tiers[tm[0]] = []
tiers[tm[0]] += [k]
added += [k]
return render_affix_tier_list(tiers, tm, api=api)
# use this if there are fewer than 6 affixes scanned
# since we can't cluster into 6 with uh, fewer than 6
def gen_affix_tier_list_small(affixes_report, api=False):
# super simple tier list -- figure out the max and the min, and then bucket tiers
cimax = -1
cimin = -1
for k in affixes_report:
if cimax == -1:
cimax = float(k[0])
if cimin == -1:
cimin = float(k[0])
if float(k[0]) < cimin:
cimin = float(k[0])
if float(k[0]) > cimax:
cimax = float(k[0])
cirange = cimax - cimin
cistep = cirange / 6
added = []
tiers = {}
tm = {}
tm[0] = "S"
tm[1] = "A"
tm[2] = "B"
tm[3] = "C"
tm[4] = "D"
tm[5] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in affixes_report:
if float(k[0]) >= (cimax-cistep*(i+1)):
if k not in added:
if tm[i] not in tiers:
tiers[tm[i]] = []
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in affixes_report:
if k not in added:
if tm[5] not in tiers:
tiers[tm[5]] = []
tiers[tm[5]] += [k]
added += [k]
return render_affix_tier_list(tiers, tm, api=api)
# use this if there are fewer than 6 dungeons scanned
# since we can't cluster into 6 with uh, fewer than 6
def gen_dungeon_tier_list_small(dungeons_report):
# super simple tier list -- figure out the max and the min, and then bucket tiers
cimax = -1
cimin = -1
for k in dungeons_report:
if cimax == -1:
cimax = float(k[0])
if cimin == -1:
cimin = float(k[0])
if float(k[0]) < cimin:
cimin = float(k[0])
if float(k[0]) > cimax:
cimax = float(k[0])
cirange = cimax - cimin
cistep = cirange / 6
added = []
tiers = {}
tm = {}
tm[0] = "S"
tm[1] = "A"
tm[2] = "B"
tm[3] = "C"
tm[4] = "D"
tm[5] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in dungeons_report:
if float(k[0]) >= (cimax-cistep*(i+1)):
if k not in added:
if tm[i] not in tiers:
tiers[tm[i]] = []
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in dungeons_report:
if k not in added:
if tm[5] not in tiers:
tiers[tm[5]] = []
tiers[tm[5]] += [k]
added += [k]
return render_dungeon_tier_list(tiers, tm)
# for background on the analytical approach of using the lower bound of a confidence interval:
# https://www.evanmiller.org/how-not-to-sort-by-average-rating.html
# https://www.evanmiller.org/ranking-items-with-star-ratings.html
def construct_analysis(counts, sort_by="lb_ci", limit=500):
overall = []
all_data = []
for name, runs in counts.iteritems():
for r in runs:
all_data += [r.score]
master_stddev = 1
if len(all_data) >= 2:
master_stddev = std(all_data, ddof=1)
for name, runs in counts.iteritems():
data = []
max_found = 0
max_id = ""
max_level = 0
all_runs = []
for r in runs:
data += [r.score]
all_runs += [[r.score, r.mythic_level, r.keystone_run_id]]
if r.score >= max_found:
max_found = r.score
max_id = r.keystone_run_id
max_level = r.mythic_level
n = len(data)
if n == 0:
overall += [[name, 0, 0, n, [0, 0], [0, "", 0], []]]
continue
mean = average(data)
if n <= 1:
overall += [[name, mean, 0, n, [0, 0], [max_found, max_id, max_level], all_runs]]
continue
# filter to top 500
sorted_data = sorted(data, reverse=True)
sorted_data = sorted_data[:limit]
stddev = std(sorted_data, ddof=1)
sorted_mean = average(sorted_data)
sorted_n = len(sorted_data)
t_bounds = t_interval(n)
ci = [sorted_mean + critval * master_stddev / sqrt(sorted_n) for critval in t_bounds]
# stddev = std(data, ddof=1)
# t_bounds = t_interval(n)
# ci = [mean + critval * master_stddev / sqrt(n) for critval in t_bounds]
maxi = [max_found, max_id, max_level]
all_runs = sorted(all_runs, key=lambda x: x[0], reverse=True)
# restrict the mean just to the runs actually used for lb_ci
overall += [[name, sorted_mean, stddev, n, ci, maxi, all_runs]]
overall = sorted(overall, key=lambda x: x[4][0], reverse=True)
if sort_by == "max":
overall = sorted(overall, key=lambda x: x[5][0], reverse=True)
if sort_by == "n":
overall = sorted(overall, key=lambda x: x[3], reverse=True)
return overall
# construct_analysis for raid, which has per encounter lists of key metrics for a given spec
def construct_analysis_raid(spec_counts):
counts = spec_counts
overall = {}
all_data = []
for encounter, metrics in counts.iteritems():
for m in metrics:
all_data += [m]
master_stddev = 1
if len(all_data) >= 2:
master_stddev = std(all_data, ddof=1)
for encounter, metrics in counts.iteritems():
data = []
for m in metrics:
data += [m]
n = len(data)
if n == 0:
overall[encounter] = [0, 0, 0, []]
continue
mean = average(data)
if n <= 1:
overall[encounter] = [mean, n, mean, data]
continue
# filter to top 100
sorted_data = sorted(data, reverse=True)
sorted_data = sorted_data[:100]
stddev = std(sorted_data, ddof=1)
sorted_mean = average(sorted_data)
sorted_n = len(sorted_data)
t_bounds = t_interval(n)
ci = [sorted_mean + critval * master_stddev / sqrt(sorted_n) for critval in t_bounds]
# stddev = std(data, ddof=1)
# t_bounds = t_interval(n)
# ci = [mean + critval * master_stddev / sqrt(n) for critval in t_bounds]
# lbci, n, mean, data
# restrict the mean just to the runs actually used for lb_ci
overall[encounter]= [ci[0], n, sorted_mean, data]
return overall
# build a spec report for raid
# build for each boss, and overall
# save this to the db for each spec
# read from the db
def gen_raid_spec_analysis(difficulty=MAX_RAID_DIFFICULTY, active_raid=""):
# raid_generate_counts is now a cached call
raid_counts, raid_max_found, raid_max_link = raid_generate_counts(difficulty=difficulty, active_raid=active_raid)
analysis = {}
lb_ci_spec = {}
lb_ci_spec["all"] = {}
for s in specs:
analysis[s] = construct_analysis_raid(raid_counts[s])
scores = []
all_scores = []
n_scores = 0
raid_encounters = get_raid_encounters(active_raid)
for e in raid_encounters:
raid_ignore = get_raid_ignore(active_raid)
if e not in raid_ignore: # ignore certain encounters for the tier list
all_scores += analysis[s][e][3]
scores += [analysis[s][e][0]]
n_scores += analysis[s][e][1]
if e not in lb_ci_spec:
lb_ci_spec[e] = {}
lb_ci_spec[e][s] = [analysis[s][e][0], analysis[s][e][1], analysis[s][e][2]]
# using the average of the lbcis, n, mean of scores
lb_ci_spec["all"][s] = [average(scores), n_scores, mean(all_scores)]
return lb_ci_spec, raid_max_found, raid_max_link
def gen_raid_specs_role_package(encounter, difficulty=MAX_RAID_DIFFICULTY, active_raid=""):
global role_titles, specs
# gen_raid_spec analysis uses the memoized raid_generate_counts
lb_ci_spec, raid_max_found, raid_max_link = gen_raid_spec_analysis(difficulty=difficulty, active_raid=active_raid)
encounter_overall = lb_ci_spec[encounter]
role_package = {}
stats = {}
# go through all the specs, grouped by role
for i, display in enumerate([tanks, healers, melee, ranged]):
role_score = []
stats[role_titles[i]] = {}
n_runs = 0
ids = []
for k in display: # for spec k
rmf = 0
rml = ""
if encounter != "all":
rmf = raid_max_found[k][encounter]
rml = raid_max_link[k][encounter]
else:
maxf = 0
maxe = ""
for ee, mm in raid_max_found[k].iteritems():
if mm > maxf:
maxe = ee
maxf = mm
if maxe != "":
rmf = raid_max_found[k][maxe]
rml = raid_max_link[k][maxe]
role_score += [[str("%.2f" % encounter_overall[k][0]), # lower bound of ci
str(k), # name of the spec
str("%.2f" % encounter_overall[k][2]), # mean
str("%d" % encounter_overall[k][1]).rjust(4), # n
slugify.slugify(unicode(str(k))), # slug name
str("%.2f" % rmf), # maximum run
rml, # id of the maximum run
]]
n_runs += encounter_overall[k][1] # since it's just parses, can add
stats[role_titles[i]]["n"] = n_runs
# sort role_score by lb_ci
role_score = sorted(role_score, key=lambda x: x[0], reverse=True)
role_package[role_titles[i]] = role_score
return role_package, stats
# generate a specs tier list
# placeholder code for now
def gen_raid_spec_tier_list(specs_report, role, encounter_slug="all", prefix="", difficulty=MAX_RAID_DIFFICULTY, active_raid=""):
global role_titles
# for raid, we compare tanks to tanks
# compare healers to healers
# compare dps to dps (grouping melee + ranged)
compare_with = {}
compare_with["Tanks"] = ["Tanks"]
compare_with["Healers"] = ["Healers"]
compare_with["Melee"] = ["Melee", "Ranged"]
compare_with["Ranged"] = ["Melee", "Ranged"]
scores = []
for i in range(0, 4):
if role_titles[i] not in compare_with[role]:
continue
for k in specs_report[role_titles[i]]:
if int(k[3]) < 20: # ignore specs with fewer than 20 parses as they would skew the buckets; we'll add them to F later
continue
scores += [float(k[0])]
if len(scores) < 6: # relax the fewer than 20 rule (early scans)
scores = []
for i in range(0, 4):
if role_titles[i] not in compare_with[role]:
continue
for k in specs_report[role_titles[i]]:
scores += [float(k[0])]
buckets = ckmeans(scores, 6)
added = []
tiers = {}
tm = {}
tm[5] = "S"
tm[4] = "A"
tm[3] = "B"
tm[2] = "C"
tm[1] = "D"
tm[0] = "F"
for i in range(0, 6):
tiers[tm[i]] = []
for i in range(0, 6):
for k in specs_report[role]:
if len(buckets) > i:
if float(k[0]) in buckets[i]:
if k not in added:
tiers[tm[i]] += [k]
added += [k]
# add stragglers to last tier
for k in specs_report[role]:
if k not in added:
tiers[tm[0]] += [k]
added += [k]
dtl = {}
dtl["S"] = ""
dtl["A"] = ""
dtl["B"] = ""
dtl["C"] = ""
dtl["D"] = ""
dtl["F"] = ""
global spec_short_names
template = env.get_template("raid-spec-mini-icon.html")
for i in range(0, 6):
for k in tiers[tm[i]]:
rendered = template.render(spec_name = k[1],
spec_short_name = spec_short_names[k[1]],
spec_slug = slugify.slugify(unicode(k[1])),
encounter_slug = encounter_slug,
difficulty = difficulty,
active_raid = active_raid,
prefix = prefix)
dtl[tm[i]] += rendered
return dtl
def gen_pvp_specs_role_package(mode):
global role_titles, specs
role_package = {}
stats = {}
logging.info(mode)
key_slug = "us-%s" % mode
pc = ndb.Key('PvPLadderStats', key_slug).get()
data = json.loads(pc.data)
proxy_role_titles = {}
proxy_role_titles[0] = "tank"
proxy_role_titles[1] = "healer"
proxy_role_titles[2] = "melee"
proxy_role_titles[3] = "ranged"