Browse Source

Players Stats finished

Maxim Sokhatsky 11 years ago
parent
commit
90d73f92f8

+ 2 - 1
apps/server/src/game.erl

@@ -507,7 +507,8 @@ get_player_info(_,User) ->
        {ok,#series_log{type=M,speed=S,rounds=R,stats=Res}} ->
             Win = case lists:keyfind(winner,1,Res) of {_,Num1} -> Num1; _ -> 0 end,
             Los = case lists:keyfind(looser,1,Res) of {_,Num2} -> Num2; _ -> 0 end,
-            [{M,S,R,{Win,Los}}];
+            [{lists:concat([wf:to_list(M)," ",wf:to_list(S)," ",wf:to_list(R)]),
+              lists:concat([Win,"/",Los])}];
        _ -> [] end end || M <- Okey:modes(), S <- Okey:speeds(), R <- Okey:rounds() ],
     Games=lists:flatten(Scoring),
     {ok,Reveals}=kvs:get(reveal_log,User),

BIN
apps/web/priv/static/doc/Kakaranet-Scene.sketch/Data


+ 1 - 1
apps/web/priv/static/doc/Kakaranet-Scene.sketch/metadata

@@ -15,7 +15,7 @@
 		<string>LucidaGrande-Bold</string>
 	</array>
 	<key>length</key>
-	<integer>2564442</integer>
+	<integer>2565213</integer>
 	<key>version</key>
 	<integer>36</integer>
 </dict>

+ 12 - 12
apps/web/priv/static/doc/Kakaranet-Scene.svg

@@ -728,31 +728,31 @@
                 <tspan x="814" y="638">Kakush: 722 </tspan>
             </text>
         </g>
-        <g id="Player-Statistics" sketch:type="MSLayerGroup" transform="translate(213.000000, 87.000000)">
+        <g id="Player-Statistics" sketch:type="MSLayerGroup" transform="translate(209.000000, 87.000000)">
             <g id="Dialog-2" sketch:type="MSShapeGroup">
                 <rect id="Rectangle-54" stroke="#48AF5E" stroke-width="10" fill="#FFFFFF" x="0" y="0" width="643" height="515" rx="30"></rect>
                 <rect id="Rectangle-55" stroke="#979797" fill="#48AF5E" x="5" y="4" width="633" height="67"></rect>
-                <path d="M10,170.877714 L10,486.007158 C10,497.048906 18.9566601,506.000011 30.0008497,506.000011 L612.99915,506.000018 C624.045315,506.000018 633,497.050485 633,486.002368 L633,283.000003 C73.6559486,412.100111 648.096463,130.846676 10,170.877714 Z" id="Rectangle-60" fill="#DFF1F4"></path>
+                <path d="M10,149 L10,485.993284 C10,497.042694 18.9566601,506.000011 30.0008497,506.000011 L612.99915,506.000018 C624.045315,506.000018 633,497.050485 633,486.002368 L633,283.000003 C64,486.999987 603,92.0000002 10,149 Z" id="Rectangle-60" fill="#DFF1F4"></path>
             </g>
             <text id="Notes" sketch:type="MSTextLayer" font-family="Exo 2" font-size="20" font-weight="normal" fill="#4A4A4A">
                 <tspan x="24" y="453.5">How good is Player (win/lose) per each game type, and how </tspan>
                 <tspan x="24" y="477.5">player usualy reveals the games.</tspan>
             </text>
             <text id="Stat-Left" sketch:type="MSTextLayer" font-family="Exo 2" font-size="23.586" font-weight="normal" fill="#517ECE">
-                <tspan x="24" y="209">Lucky</tspan>
-                <tspan x="24" y="238">Std Color                       124/23</tspan>
-                <tspan x="24" y="267">Std Even/Odd             234/2</tspan>
-                <tspan x="24" y="296">Std Countdown          20/10</tspan>
-                <tspan x="24" y="325">Tour Color 512             30/100</tspan>
-                <tspan x="24" y="354">Tour Even/Odd 64    44/23</tspan>
+                <tspan x="24" y="183">Lucky</tspan>
+                <tspan x="24" y="212">Std Color                       124/23</tspan>
+                <tspan x="24" y="241">Std Even/Odd             234/2</tspan>
+                <tspan x="24" y="270">Std Countdown          20/10</tspan>
+                <tspan x="24" y="299">Tour Color 512             30/100</tspan>
+                <tspan x="24" y="328">Tour Even/Odd 64    44/23</tspan>
             </text>
             <text id="Stat-Right" sketch:type="MSTextLayer" font-family="Exo 2" font-size="23.586" font-weight="normal" fill="#517ECE">
-                <tspan x="378" y="209">Have 8 Tashes         40</tspan>
-                <tspan x="378" y="238">Normal                      124</tspan>
-                <tspan x="378" y="267">Okey                           234</tspan>
+                <tspan x="341.5" y="182.971549">Have 8 Tashes         40</tspan>
+                <tspan x="341.5" y="211.971549">Normal                      124</tspan>
+                <tspan x="341.5" y="240.971549">Okey                           234</tspan>
             </text>
             <text id="Reveals" sketch:type="MSTextLayer" font-family="Exo 2" font-size="35.1627907" font-weight="normal" fill="#3B5998">
-                <tspan x="378" y="134.014225">Reveals</tspan>
+                <tspan x="341.5" y="133">Reveals</tspan>
             </text>
             <text id="Games" sketch:type="MSTextLayer" font-family="Exo 2" font-size="35.1627907" font-weight="normal" fill="#3B5998">
                 <tspan x="24" y="134.014225">Games</tspan>

+ 1 - 0
apps/web/priv/static/doc/svg.htm

@@ -31,6 +31,7 @@
 <label id="player2"> Marie Curie </label><select id="h2"></select>
 <label id="player3"> Ilya Prigogine </label><select id="h3"></select>
 <label id="player4" style="font-weight: bold; color: red;"> Asena Simsek </label><select id="h4"></select><br>
+<button id="logout" type="button">Logout</button>
 <button id="attach" type="button">Attach</button>
 <button id="join" type="button">Join</button>
 <select id="games_ids"></select>

+ 37 - 3
apps/web/priv/static/doc/svg.js

@@ -5,8 +5,32 @@ var transition = {pid: '', port: '8080' };
 
 var players = ["Gabrielo","Mustafa","Alina","Me"];
 
+function statsRow(start_name,i,games) {
+    var start_score = 200;
+    var name = template_engine(
+        '<tspan xmlns="http://www.w3.org/2000/svg" x="{this.x}" y="{this.y}">{this.body}</tspan>',{
+            x: start_name,
+            y: 180+25*i,
+            body: games[i].value[0][0] + " — " + games[i].value[0][1]});
+    var element1 = svg(name);
+    document.getElementById('Stat-Right').appendChild(element1);
+}
+
 function handle_web_socket(body) {
-//    console.log(dec(body).value[0][2].value);
+    console.log(dec(body).value[0][0].value);
+    switch (dec(body).value[0][0].value) {
+        case 'stats_event':
+            document.getElementById('Player-Statistics').style.display = '';
+            var games    = dec(body).value[0][2];
+            var reveals  = dec(body).value[0][3];
+            var protocol = dec(body).value[0][4];
+            removeChilds(document.getElementById('Stat-Left'));
+            removeChilds(document.getElementById('Stat-Right'));
+            for (var i=0;i<games.length;i++) { statsRow(24, i,games); }
+            for (var i=0;i<protocol.length;i++) { statsRow(340,i,protocol); }
+            break;
+    }
+
     switch (dec(body).value[0][2].value) {
         case 'okey_game_info': 
             var a = dec(body).value[0][3][0].value[0][1];
@@ -57,7 +81,7 @@ function handle_web_socket(body) {
                 var c = taken.value[0][1];
                 var v = taken.value[0][2];
                 var pos = findPlace();
-                console.log(pos);
+//                console.log(pos);
                 place_card(pos.x,pos.y,c,v);
             }
             break;
@@ -196,15 +220,25 @@ loadFile('templates/Card.svg', function() {
         document.getElementById("Play")       .setAttribute('onclick', 'onRightMenuDown(evt)');
         document.getElementById("Create")     .setAttribute('onclick', 'onRightMenuDown(evt)');
         document.getElementById("Point-Table").setAttribute('onclick', 'onPlayerInfo(evt)');
+        document.getElementById("Player-Statistics").setAttribute('onclick', 'onPlayerInfoClose(evt)');
         
 //        onRightMenuDown();
 
     });
 });
 
+var removeChilds = function (node) {
+    var last;
+    while (last = node.lastChild) node.removeChild(last);
+};
+
 function onPlayerInfo(evt) {
     ws.send(enc(tuple(atom('client'),
-        tuple(atom('stats_action'),bin('ali_erdem1500001'),atom('game_okey')))));
+        tuple(atom('stats_action'),bin(document.user),atom('game_okey')))));
+    }
+
+function onPlayerInfoClose(evt) {
+    document.getElementById('Player-Statistics').style.display = 'none';
     }
 
 function onRightMenu(evt) {

+ 1 - 0
apps/web/src/logallow.erl

@@ -6,5 +6,6 @@ log_modules() -> [
     n2o_bullet,
     game_session,
     n2o_secret,
+    kvs,
     okey
 ].

+ 1 - 1
apps/web/src/okey.erl

@@ -66,7 +66,6 @@ main() -> #dtl{file="index", bindings=[{title,<<"N2O">>},{body,body()}]}.
 
 body() ->
     wf:wire(#api{name=plusLogin, tag=plus}),
-%    wf:cookie("user",(user())#user.id),
   [ #panel    { id = history },
     #button   { id = pluslogin,  body = "Login",       postback = login_button },
     #label    { id = nothing,    body = " Google"},    #br{}, #br{},
@@ -75,6 +74,7 @@ body() ->
     #label    { id = player2,    body = "Seat 2"},     #dropdown{id=h2,options=[]}, #br{},
     #label    { id = player3,    body = "Seat 3"},     #dropdown{id=h3,options=[]}, #br{},
     #label    { id = player4,    body = "Seat 4"},     #dropdown{id=h4,options=[]}, #br{}, #br{},
+    #button   { id = logout,     body = "Logout",      postback = login_button },
     #button   { id = attach,     body = "Attach",      postback = attach },
     #button   { id = join,       body = "Join",        postback = join, source = [games_ids]},
     #dropdown { id = games_ids,  postback = combo,     options = []}, #br{},