-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunKGS.html
1021 lines (850 loc) · 35.5 KB
/
unKGS.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>un-KGS</title>
<style>
.popoverMiddle{
width: 50%;
height:55%;
position:relative;
margin-left: 25%;
margin-top: 5%;
}
.devider{
background: #009de0;
width: 100%;
height: 1pt;
}
.tst { // 1 .8 background-size: cover; }
.img1 {
background: linear-gradient(
rgba(255,255,255,1),
rgba(255,255,255,.8)),
url('img/background.jpg');
background-size: cover;
}
.rating {
margin-left: 2rem !important;
font-size: 2rem !important;
color: gray !important;
}
.reverse {
-ms-transform: rotateX(360deg);
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
-ms-transition:0.8s all;
-webkit-transition:0.8s all;
transition:0.8s all;
}
.hover {
-ms-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
-ms-transition:0.8s all;
-webkit-transition:0.8s all;
transition:0.8s all;
}
</style>
<script
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m,sap.ui.ux3"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="no"
data-sap-ui-resourceroots='{ "sap.ui.demo.wt": "./" }' >
</script>
<!-- ######################################################################### -->
<!-- ######################################################################### -->
<!-- V I E W -->
<!-- ######################################################################### -->
<!-- ######################################################################### -->
<script id="view1" type="sapui5/xmlview">
<mvc:View
controllerName="sap.ui.demo.wt.controller"
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:layout="sap.ui.commons.layout"
displayBlock="true">
<App>
<pages>
<Page id="uTitle" title="{i18n>un-KGS}" class="img1 easterEgg">
<content>
<!-- ###################################################################### -->
<!--<Panel headerText="{i18n>player}" class="sapUiResponsiveMargin" width="auto"> -->
<Panel class="sapUiResponsiveMargin" width="auto">
<content>
<Input
value="{/recipient/username}"
valueLiveUpdate="true"
placeholder="KGS nickname"
width="50%"
submit="onGo"/>
<Button
text="{i18n>Look it up!}"
press="onGo"
class="sapUiSmallMarginEnd"/>
</content>
</Panel>
<!-- ###################################################################### -->
<!-- ############################# PLAYER INFO ############################ -->
<!--<Panel headerText="{i18n>info}" class="sapUiResponsiveMargin" width="auto">-->
<Panel id = "infopanel" class="sapUiResponsiveMargin" width="auto" visible="false">
<content>
<Slider
id="slider"
value="100"
liveChange="onSliderMoved"
visible="false">
</Slider>
<ProgressIndicator
percentValue="30"
displayValue="to be implemented"
showValue="true"
state="None"
visible="false"/>
<layout:MatrixLayout layoutFixed="false" columns="1" width="100%">
<!-- -/-/-/-/-/-/-/-/-/-/Player strength vs average opponent's strength/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<!-- STARS FOR RATING -->
<RatingIndicator
id="rating"
class="sapUiSmallMargin rotatey"
value="0" maxValue="8"
visualMode="Full"
enabled="false"
tooltip="Player rank: {/recipient/rank}" />
<Text
class="text345"
text="{/recipient/rank}"/>
<Text
class="sapUiSmallMargin text345"
text="VS"/>
<!-- STARS FOR OPPONENTS STRENGTH -->
<RatingIndicator
id="ratingOpp"
class="sapUiSmallMargin rotatey"
maxValue="8"
value="0"
visualMode="Full"
enabled="false"
tooltip="Opponents average rank: {/opponents/rank}" />
<Text
class="text345"
text="{/opponents/rank}"/>
<!-- WINRATE -->
<Text
id="winrate"
class="rating"
text="0%"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<!--layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<Text class="devider"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow-->
<!-- -/-/-/-/-/-/-/-/-/-/Escape indicator/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<!-- Escaper if 5 or more escaped games -->
<Image
id="tal"
class="sap"
width='4.5rem'
src="img/nopolite.png"
tooltip="Escape indicator"
visible="false"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<!-- -/-/-/-/-/-/-/-/-/-/Communicative indicator/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<!-- IMAGE IF HE CHATS -->
<Image
id="talkative"
class="sapUiMediumMargin xNoMarginBottom xxcircle "
width='4.5rem'
src="img/smile3.png"
tooltip="Player chats"
visible="false"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<!-- -/-/-/-/-/-/-/-/-/-/Rengo indicator/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<core:Icon
id="rengo"
src="sap-icon://group"
size="4.5rem"
color="#006caa"
class="sapUiMediumMargin xYesMarginBottom xxcircle2 "
visible="false"
tooltip="Rengo player"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<!-- -/-/-/-/-/-/-/-/-/-/Opening style indicator/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<!-- IMAGE WITH MOST USED CORNER STONES (standard) -->
<Image id="style44" class="sapUiSmallMargin" src="img/4-4b.png" visible="false" width="6rem"/>
<Image id="style43" class="sapUiSmallMargin" src="img/4-3b.png" visible="false" width="6rem"/>
<Image id="style33" class="sapUiSmallMargin" src="img/3-3b.png" visible="false" width="6rem"/>
<Image id="style53" class="sapUiSmallMargin" src="img/5-3b.png" visible="false" width="6rem"/>
<Image id="style54" class="sapUiSmallMargin" src="img/5-4b.png" visible="false" width="6rem"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
<!-- -/-/-/-/-/-/-/-/-/-/Avatar/-/-/-/-/-/-/-/-/-/-/ -->
<layout:MatrixLayoutRow>
<layout:cells>
<layout:MatrixLayoutCell>
<!-- AVATAR (why not? ) -->
<Image
id="avatar"
class="sapUiSmallMargin"
src=""
visible="false"/>
</layout:MatrixLayoutCell>
</layout:cells>
</layout:MatrixLayoutRow>
</layout:MatrixLayout>
</content>
</Panel>
<!-- ###################################################################### -->
</content>
</Page>
</pages>
</App>
</mvc:View>
</script> <!-- id="view1" -->
<!-- ######################################################################### -->
<!-- ######################################################################### -->
<!-- C O N T R O L L E R -->
<!-- ######################################################################### -->
<!-- ######################################################################### -->
<script>
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"sap/ui/model/json/JSONModel",
"sap/ui/model/resource/ResourceModel"
], function (Controller, MessageToast, JSONModel, ResourceModel) {
// "use strict"; // gives problem to dayharri
return Controller.extend("sap.ui.demo.wt.controller", {
onInit : function () {
// set data model on view
var oData = {
recipient : {
username : "",
rank : ""
},
opponents : {
rank : ""
}
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel);
// set i18n model on view
var i18nModel = new ResourceModel({
bundleName: "sap.ui.demo.wt.i18n.i18n"
});
this.getView().setModel(i18nModel, "i18n");
},
onAfterRendering : function () {
//$(".easterEgg")
$("header[id*='uTitle-intHeader']")
.click(function(){
// alert('Created by darkronin');
var popover = new sap.ui.ux3.OverlayContainer( {
// var popover = new sap.m.Popover("author123", {
openButtonVisible: false,
"customHeader" : new sap.m.Bar({
"contentMiddle" : [
new sap.m.Label({"text":"test"}).addStyleClass("popoverTitle")
]
}),
//"showHeader" : false,
"placement" : "Auto"
}).addStyleClass("sapUiPopupWithPadding popoverMiddle");
var oLayout1 = new sap.ui.layout.form.ResponsiveGridLayout({
labelSpanL: 12,
labelSpanM: 12,
labelSpanS: 12,
emptySpanL: 0,
emptySpanM: 0,
emptySpanS: 0,
columnsL: 2,
columnsM: 2,
columnsS: 2,
breakpointL: 800,
breakpointM: 400
});
var customerDetailsForm = new sap.ui.layout.form.Form({
layout: oLayout1,
formContainers: [
new sap.ui.layout.form.FormContainer({
formElements: [
new sap.ui.layout.form.FormElement({
label: new sap.m.Label({
text:"Author",
textAlign:"Center"
}),
//fields: [new sap.m.Text({
// text: "12221",
// textAlign:"Center"
//})]
// replacing starts
fields: [new sap.m.Image({
src: "img/20384978.jpg",
width: "95%"
})]
// replacing ends
}),
new sap.ui.layout.form.FormElement({
label: new sap.m.Label({
text:"darkronin",
textAlign:"Center"
}),
fields: [new sap.m.Text({
text: "",
textAlign:"Center",
vAlign:"Center",
class:"rating"
})]
})
]
}),
new sap.ui.layout.form.FormContainer( {
formElements: [
new sap.ui.layout.form.FormElement({
label: new sap.m.Label({
text:"Codeveloper",
textAlign:"Center"
}),
fields: [new sap.m.Image({
src: "img/6212224.png",
width: "95%"
})]
}),
new sap.ui.layout.form.FormElement({
label: new sap.m.Label({
text:"asdk.kgs",
textAlign:"Center"
}),
fields: [new sap.m.Text({
text: "",
textAlign:"Center",
vAlign:"Center",
class:"rating"
})]
})
]
})
]
});
popover.addContent(customerDetailsForm);
// overlay.open();
popover.open();
});
$(".xxcircle")
.mouseover(function(){$(".xxcircle").removeClass("reverse").addClass("hover");})
.mouseout(function(){$(".xxcircle").removeClass("hover").addClass("reverse");});
$(".xxcircle2")
.mouseover(function(){$(".xxcircle2").removeClass("reverse").addClass("hover");})
.mouseout(function(){ $(".xxcircle2").removeClass("hover").addClass("reverse"); });
},
normalizeRank: function ( iRank ) {
var oRank = 0;
if( iRank != "" && iRank != null){
var mRank = iRank.replace('?', '');
if( iRank.match('k') ) {
oRank = parseInt(iRank);
} else if( iRank.match('d') ) {
oRank = -1 * parseInt(iRank);
} else if( iRank.match('p') ) {
oRank = -10;
} else {
// rank undefined?
}
}
return oRank;
},
// mainfunction
mainFunction : function( l, rank, aGames, sRecipient, inModel, iNormalizeRank, unKGS, recursion, mf) {
// obtain individual controls from the unKGS.controls object
var ratingSelf = unKGS.controls.ratingSelf;
var ratingOpp = unKGS.controls.ratingOpp;
var sliderView = unKGS.controls.sliderView;
var style44 = unKGS.controls.style44;
var style43 = unKGS.controls.style43;
var style33 = unKGS.controls.style33;
var style53 = unKGS.controls.style53;
var style54 = unKGS.controls.style54;
var talkative = unKGS.controls.talkative;
var rengo = unKGS.controls.rengo;
var avatar = unKGS.controls.avatar;
var escaperView = unKGS.controls.escaperView;
// get recursive reference to itself
var mainFunction2 = mf;
//============================================================//
//------------------------------------------------------------//
// Loop on array of games:
// - average opponent rank ( cumRank, cumCount ) (avgOppRank) avgOppRank = cumRank * 1.0 / cumCount;
// - winrate (winCount, cumCount) winRate = winCount * 100.0 / cumCount;
// - escape count (escapeCount)
//------------------------------------------------------------//
// opponents average rank
var oppRank = "";
var avgOppRank = 0;
var winRateString = "";
var caseRecipient = "";
if(unKGS.partials.cumCount > 0){
var cumCount = unKGS.partials.cumCount;
var cumRank = unKGS.partials.cumRank;
var winCount = unKGS.partials.winCount ;
var escapeCount = unKGS.partials.escapeCount;
} else {
var cumRank = 0;
var cumCount = 0;
// winrate
var winCount = 0;
var winRate = 0.0;
// escaper
var escapeCount = 0;
}
for( var ig=0; ig<aGames.length; ig++){
// only consider 1vs1 games
if( aGames[ig].black.length > 1 ) continue; // eliminates rengo
if( aGames[ig].type.toUpperCase() == "DEMONSTRATION" ) continue; // eliminates demo
if( aGames[ig].type.toUpperCase() == "REVIEW" ) continue; // eliminates reviews
// understand player colour
oppRank = aGames[ig].black[0].rank;
var pColor = 'W';
if(aGames[ig].black[0].name.toUpperCase() == sRecipient.toUpperCase()){
oppRank = aGames[ig].white[0].rank;
pColor = 'B';
caseRecipient = aGames[ig].black[0].name;
} else {
caseRecipient = aGames[ig].white[0].name;
}
cumRank += iNormalizeRank( oppRank );
cumCount += 1;
// calculate winrate (uses cumCount)
if( pColor == aGames[ig].result.charAt(0) ) winCount += 1;
// calculate escaper count
// TODO
;;;
if( aGames[ig].result.substr(1) == "+Forfeit" ){
// check if winner is not the player -> then escaper
if( pColor != aGames[ig].result.charAt(0) ) escapeCount += 1;
}
}
if( cumCount ) avgOppRank = cumRank * 1.0 / cumCount;
console.log( 'average opponent rank:' + avgOppRank );
if( cumCount ) winRate = winCount * 100.0 / cumCount;
winRateString = parseInt( winRate ).toString() + '%';
console.log ( 'winrate:' + winRateString );
if( sliderView ) sliderView.setText( winRateString );
if( escapeCount > 1 ){ escaperView.setVisible(true); }
var sOppRank = "";
sOppRank = parseInt(avgOppRank);
if( avgOppRank < 0 ) sOppRank = -1.0 * sOppRank + "d";
if( avgOppRank > 0 ) sOppRank = sOppRank + "k";
if( sOppRank == '0d') sOppRank = '1k';
if( sOppRank == '0k') sOppRank = '1d';
inModel.setProperty("/opponents/rank", sOppRank);
if( avgOppRank < -6){
ratingOpp.setValue(8);
} else if( avgOppRank < -4){
ratingOpp.setValue(7);
} else if( avgOppRank < -2){
ratingOpp.setValue(6);
} else if( avgOppRank < 1){
ratingOpp.setValue(5);
} else if( avgOppRank < 5){
ratingOpp.setValue(4);
} else if( avgOppRank < 10){
ratingOpp.setValue(3);
} else if( avgOppRank < 15){
ratingOpp.setValue(2);
} else if( avgOppRank < 20){
ratingOpp.setValue(1);
} else {
ratingOpp.setValue(0);
}
console.log('logging partials at recursion: ' + recursion);
console.log('cumCount (total games considered): ' + cumCount);
console.log('cumRank (sum of opponent ranks): '+ cumRank);
console.log('winCount: '+winCount);
console.log('escapeCount: '+escapeCount);
unKGS.partials.cumCount = cumCount;
unKGS.partials.cumRank = cumRank;
unKGS.partials.winCount = winCount;
unKGS.partials.escapeCount = escapeCount;
// AVATAR
// use caseRecipient
var img = new Image();
img.onload = function(){imageExists(true)};
img.onerror = function(){imageExists(false)};
img.src = "http://goserver.gokgs.com/avatars/" + caseRecipient + ".jpg";
function imageExists(exists) {
if(exists) {
unKGS.controls.avatar.setSrc("http://goserver.gokgs.com/avatars/"+ caseRecipient + ".jpg")
}
else {
unKGS.controls.avatar.setSrc("img/noavatars.png")
}
unKGS.controls.avatar.setVisible(true);
unKGS.controls.avatar.setDensityAware(false);
}
//============================================================//
// if( cumCount > minimum threshold...)
//
// krequest = l.link.prev;
if( cumCount < 10 && !recursion ){
jQuery.get(
l.link.prev, {},
function(l2){
// console.log(l);
var html = "";
// parse rank from response (l)
var rank = '?';
var aGames2 = l2.content.games;
if( aGames2.length > 0 ){
mainFunction2( l2, rank, aGames2, sRecipient, inModel, iNormalizeRank, unKGS, 1);
}
}, 'json'
).fail( function(e){
MessageToast.show("Oops! Recursion call error");
// infopanel.setVisible(false);
} );
}
//
//============================================================//
// avoid recursion
if(recursion) return true;
//============================================================//
//------------------------------------------------------------//
// Get player rank (from last game)
// N.B. this means that, if the player was promoted after winning,
// or demoted after losing, the rank is an OUTDATED rank.
//------------------------------------------------------------//
// 1 time only
for( var ig=0; ig<aGames.length; ig++){
// only consider 1vs1 games
if( aGames[ig].black.length > 1 ) continue;
if( aGames[ig].type.toUpperCase() == "DEMONSTRATION" ) continue;
if( aGames[ig].type.toUpperCase() == "REVIEW" ) continue;
rank = aGames[ig].white[0].rank;
if( aGames[ig].black[0].name.toUpperCase() == sRecipient.toUpperCase() )rank = aGames[ig].black[0].rank;
break;
} // for( var ig=0; ig<aGames.length; ig++)
// show rank as Toast
// MessageToast.show( rank );
// set rank in model
inModel.setProperty("/recipient/rank", rank);
// show rank as RatingIndicator
var rank_n = rank.replace('?', ''); // normalized rank: remove ?...
switch( rank_n ) {
case "20k": case "19k": case "18k": case "17k": case "16k": ratingSelf.setValue(1);
break;
case "15k": case "14k": case "13k": case "12k": case "11k": ratingSelf.setValue(2);
break;
case "10k": case "9k": case "8k": case "7k": case "6k": ratingSelf.setValue(3);
break;
case "5k": case "4k": case "3k": case "2k": ratingSelf.setValue(4);
break;
case "1k": case "1d": case "2d": ratingSelf.setValue(5);
break;
case "3d": case "4d": ratingSelf.setValue(6);
break;
case "5d": case "6d": ratingSelf.setValue(7);
break;
case "7d": case "8d": case "9d": case "1p": case "2p": case "3p": case "4p":
case "5p": case "6p": case "7p": case "8p": case "9p": ratingSelf.setValue(8);
break;
default: ratingSelf.setValue(0);
break;
}
// rengo icon
for( var ig=0; ig<aGames.length; ig++){
if( aGames[ig].type.toUpperCase() == "RENGO" ){
rengo.setVisible(true);
break;
}
}
//============================================================//
//------------------------------------------------------------//
// Look inside games
//------------------------------------------------------------//
// talkative icon
var gicc = 0; // global chat counts
var giccNumGames = 0; // global games considered
var gG = {};
// for(var jx=0; jx<aGames.length; jx++){
// remove all games except 2
//--------------### TWO GAMES LIMIT ###--------------//
for(var i=aGames.length;i>=0;i--){ if(i>2)aGames.pop()}
//--------------### TWO GAMES LIMIT ###--------------//
aGames.forEach(function(gG){
// gG = aGames[jx];
var grequest = gG.sgf_url;
// console.log("jx:" + jx + "//" + grequest + " " + gG.type);
if( grequest != null && gG.type.toUpperCase() != "REVIEW"
&& gG.type.toUpperCase() != "DEMONSTRATION" ){ // can be Free, Rated, Teaching, Rengo
console.log(grequest);
giccNumGames += 1;
// MessageToast.show(giccNumGames + " " + gG.type + " " + gG.sgf_url);
// --------------### TWO GAMES LIMIT ###--------------//
// if( giccNumGames > 2 ) return false;
// --------------### GAMES LIMIT ###--------------//
// jQuery.get(
// call YQL
$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
"q=select%20*%20from%20htmlstring%20where%20url%3D%22"+
encodeURIComponent(grequest)+
"%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys",
// this function gets the data from the successful JSON-P call
function(data){
// if there is data, filter it and render it out
if(data.query.results.result){
var l2 = data.query.results.result;
var icc = -1; // count of chats! (one will be player name)
// OUTPUT example:
// ["[1]", "[4]", "[UTF-8]", "[CGoban:3]", "[2]", "[Japanese]", "[19]", "[0.50]",
// "[900]", "[1x10 byo-yomi]", "[tona]", "[alobar]", "[7k]", "[8k]", "[2017-04-24]",
// "[The KGS Go Server at http://www.gokgs.com/]", "[alobar [8k]", "[7k]", "[W+Resign]",
// "[dd]", "
var s3 = l2.replace(/\[...\]/g, '-').replace(/\[..\]/g, '-').replace(/\[.\]/g, '-');
var re = new RegExp( sRecipient, "gi");
// var a2 = s2.toUpperCase().match(/FIGHTORDIE/g);
var a2 = s3.toUpperCase().match( re );
// console.log(jx);
gicc += a2.length;
gicc -= 1; // remove 1 for each game
// console.log("after finishing gicc is:"+ gicc);
// decide whether to display "Friendly" icon
talkative.setVisible(false);
// var minGames = 2 * jx;
// console.log(jx+' n. of chats is: '+ gicc);
var minChats = 2 * giccNumGames;
console.log('chats detected: ' + gicc + '; ' + 'n. of minimum chats is: '+ minChats.toString());
if( gicc >= minChats ) talkative.setVisible(true);
//----------------------------------------------------------//
// opening style
if( gG.board_size == 19 && gG.handicap == null){
/// var aOs = l2.match(/;[BW].\w\w\]/g);
// consider only positions 0..3 (first 4 moves)
// console.log(aOs[0]+aOs[1]+aOs[2]+aOs[3]);
var aOs = [];
// note: move number depend on player (maybe read it from PW[] / PB[] since i have the SGF here?)
if( gG.black[0].name.toUpperCase() == sRecipient.toUpperCase() ){
// player black
aOs = l2.match(/;B.\w\w\]/g);
} else {
// player white
aOs = l2.match(/;W.\w\w\]/g);
}
var myEval = aOs[0].charAt(3) + aOs[0].charAt(4);
switch(myEval){
case "dd": case "pd": case "dp": case "pp": style44.setVisible(true);// MessageToast.show("4-4");
break;
case "cc": case "qc": case "cq": case "qq": style33.setVisible(true);// MessageToast.show("3-3");
break;
case "dc": case "pc": case "pq": case "dq": case "cd": case "cp":
case "qp": case "qd": style43.setVisible(true);// MessageToast.show("4-3");
break;
case "ec": case "oc": case "oq": case "eq": case "ce": case "co":
case "qo": case "qe": style53.setVisible(true);// MessageToast.show("5-3");
break;
case "ed": case "od": case "op": case "ep": case "de": case "do":
case "po": case "pe": style54.setVisible(true);// MessageToast.show("5-4");
break;
default:
}
var myEval = aOs[1].charAt(3) + aOs[1].charAt(4);
switch(myEval){
case "dd": case "pd": case "dp": case "pp": style44.setVisible(true);// MessageToast.show("4-4");
break;
case "cc": case "qc": case "cq": case "qq": style33.setVisible(true);// MessageToast.show("3-3");
break;
case "dc": case "pc": case "pq": case "dq": case "cd": case "cp":
case "qp": case "qd": style43.setVisible(true);// MessageToast.show("4-3");
break;
case "ec": case "oc": case "oq": case "eq": case "ce": case "co":
case "qo": case "qe": style53.setVisible(true);// MessageToast.show("5-3");
break;
case "ed": case "od": case "op": case "ep": case "de": case "do":
case "po": case "pe": style54.setVisible(true);// MessageToast.show("5-4");
break;
default:
}
}
// otherwise tell the world that something went wrong
} else {
var errormsg = 'Error: cant load the game.';
MessageToast.show(errormsg);
}
});
} ; // if !Review
// }; // $.each aGames[]
});
},
// mainfunction end
onGo : function () {
// define globals
var unKGS = {};
unKGS.controls = {};
unKGS.partials = {};
// read user from input field
var oBundle = this.getView().getModel("i18n").getResourceBundle();
var sRecipient = this.getView().getModel().getProperty("/recipient/username");
// define proxies for jQuery.get call, and set defaults
unKGS.controls.ratingSelf = this.getView().byId("rating");
unKGS.controls.ratingSelf.setValue(0);
unKGS.controls.ratingOpp = this.getView().byId("ratingOpp");
unKGS.controls.ratingOpp.setValue(0);
unKGS.controls.sliderView = this.getView().byId("winrate");
unKGS.controls.escaperView = this.getView().byId("tal");
unKGS.controls.style44 = this.getView().byId("style44");
unKGS.controls.style43 = this.getView().byId("style43");
unKGS.controls.style33 = this.getView().byId("style33");
unKGS.controls.style53 = this.getView().byId("style53");
unKGS.controls.style54 = this.getView().byId("style54");
unKGS.controls.sliderView.setText( "" );
unKGS.controls.escaperView.setVisible(false);
unKGS.controls.style44.setDensityAware(false);
unKGS.controls.style43.setDensityAware(false);
unKGS.controls.style33.setDensityAware(false);
unKGS.controls.style53.setDensityAware(false);
unKGS.controls.style54.setDensityAware(false);
unKGS.controls.style44.setVisible(false);
unKGS.controls.style43.setVisible(false);
unKGS.controls.style33.setVisible(false);
unKGS.controls.style53.setVisible(false);
unKGS.controls.style54.setVisible(false);
unKGS.controls.infopanel = this.getView().byId("infopanel")
unKGS.controls.infopanel.setVisible(false);
//check empty field "KGS nickname"
if(sRecipient == ""){
unKGS.controls.infopanel.setVisible(false);
alert('You didn\'t enter a nickname!');
}
else {
unKGS.controls.infopanel.setVisible(true);
};
unKGS.controls.talkative = this.getView().byId("talkative");
unKGS.controls.talkative.setVisible(false);
unKGS.controls.rengo = this.getView().byId("rengo");
unKGS.controls.rengo.setVisible(false);
var inModel = this.getView().getModel();
inModel.setProperty("/recipient/rank", "");
inModel.setProperty("/opponents/rank", "");
var iNormalizeRank = this.normalizeRank;
// exit if null query
if( sRecipient == "" ) return false;
//check avatars
unKGS.controls.avatar = this.getView().byId("avatar");
// moved inside the GET
// define request
var krequest = 'https://metakgs.org/api/archives/' + sRecipient;
var mainFunction2 = this.mainFunction;
jQuery.get(
krequest, {},
function(l){
// console.log(l);
var html = "";
// console.log(l);
// parse rank from response (l)
var rank = '?';
var aGames = l.content.games;
if( aGames.length > 0 ){
mainFunction2( l, rank, aGames, sRecipient, inModel, iNormalizeRank, unKGS, 0, mainFunction2);
} else { // if( aGames.length > 0 ){
// SCAN PREVIOUS MONTH, SAME LOGIC (mainFunction)
MessageToast.show("No games in last month, scanning previous");
console.log(l.link.prev);
krequest = l.link.prev;
jQuery.get(
krequest, {},
function(l){
// console.log(l);
var html = "";
// parse rank from response (l)
var rank = '?';
var aGames = l.content.games;
if( aGames.length > 0 ){
mainFunction2( l, rank, aGames, sRecipient, inModel, iNormalizeRank, unKGS, 0, mainFunction2);
} else { // if( aGames.length > 0 ){
MessageToast.show("No games in last and next-to-last month");
} // if( aGames.length > 0 ){
}, 'json'
).fail( function(e){
MessageToast.show("Oops! Some error occurred");
infopanel.setVisible(false);
} );
} // if( aGames.length > 0 ){
}, 'json'
).fail( function(e){
MessageToast.show("Oops! Some error occurred");
infopanel.setVisible(false);