Add metrika goals
This commit is contained in:
		
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -7926,7 +7926,7 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "predictor": {
 | 
					    "predictor": {
 | 
				
			||||||
      "version": "git+https://github.com/anwinged/predictor.git#4ffca9dcb87bbeb53412aefd2d54ee1d3f71ca08",
 | 
					      "version": "git+https://github.com/anwinged/predictor.git#86e67af488fda6d96c42a5199dc30753e254d338",
 | 
				
			||||||
      "from": "git+https://github.com/anwinged/predictor.git",
 | 
					      "from": "git+https://github.com/anwinged/predictor.git",
 | 
				
			||||||
      "dev": true
 | 
					      "dev": true
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
@@ -9877,9 +9877,9 @@
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "webpack": {
 | 
					    "webpack": {
 | 
				
			||||||
      "version": "4.12.0",
 | 
					      "version": "4.12.1",
 | 
				
			||||||
      "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.12.0.tgz",
 | 
					      "resolved": "https://registry.npmjs.org/webpack/-/webpack-4.12.1.tgz",
 | 
				
			||||||
      "integrity": "sha512-EJj2FfhgtjrTbJbJaNulcVpDxi9vsQVvTahHN7xJvIv6W+k4r/E6Hxy4eyOrj+IAFWqYgaUtnpxmSGYP8MSZJw==",
 | 
					      "integrity": "sha512-7LOKQ+fpPtSvPlP++2rkDRU/8o6pJt00ezGPCksmeIzliOhiz0us4erBmNCW3VeVwH7tLIhv80zFYdOmmqU9BQ==",
 | 
				
			||||||
      "dev": true,
 | 
					      "dev": true,
 | 
				
			||||||
      "requires": {
 | 
					      "requires": {
 | 
				
			||||||
        "@webassemblyjs/ast": "1.5.12",
 | 
					        "@webassemblyjs/ast": "1.5.12",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,7 +22,7 @@
 | 
				
			|||||||
    "vue-loader": "^15.2.4",
 | 
					    "vue-loader": "^15.2.4",
 | 
				
			||||||
    "vue-style-loader": "^4.1.0",
 | 
					    "vue-style-loader": "^4.1.0",
 | 
				
			||||||
    "vue-template-compiler": "^2.5.16",
 | 
					    "vue-template-compiler": "^2.5.16",
 | 
				
			||||||
    "webpack": "^4.12.0",
 | 
					    "webpack": "^4.12.1",
 | 
				
			||||||
    "webpack-cli": "^2.1.5"
 | 
					    "webpack-cli": "^2.1.5"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "scripts": {
 | 
					  "scripts": {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
    <section class="app">
 | 
					    <section class="app">
 | 
				
			||||||
 | 
					        <p class="fact-index">Факт {{ factIndex }}</p>
 | 
				
			||||||
        <p class="note">{{ fact }}</p>
 | 
					        <p class="note">{{ fact }}</p>
 | 
				
			||||||
        <button @click.prevent="next" class="button-next">Узнать чуть лучше</button>
 | 
					        <button @click.prevent="next" class="button-next">Узнать чуть лучше</button>
 | 
				
			||||||
    </section>
 | 
					    </section>
 | 
				
			||||||
@@ -22,12 +23,15 @@ const NOTES = [
 | 
				
			|||||||
    'Хотел бы побывать в горах.',
 | 
					    'Хотел бы побывать в горах.',
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const INTERESTING_GOAL = 'INTERESTING';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default {
 | 
					export default {
 | 
				
			||||||
    data() {
 | 
					    data() {
 | 
				
			||||||
        return {
 | 
					        return {
 | 
				
			||||||
            notes: NOTES,
 | 
					            notes: NOTES,
 | 
				
			||||||
            shown: [],
 | 
					            shown: [],
 | 
				
			||||||
            fact: '',
 | 
					            fact: '',
 | 
				
			||||||
 | 
					            factIndex: null,
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    mounted() {
 | 
					    mounted() {
 | 
				
			||||||
@@ -36,7 +40,7 @@ export default {
 | 
				
			|||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
        next() {
 | 
					        next() {
 | 
				
			||||||
            this.pick();
 | 
					            this.pick();
 | 
				
			||||||
            Metrika.hit(location.href);
 | 
					            Metrika.goal(INTERESTING_GOAL);
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        pick() {
 | 
					        pick() {
 | 
				
			||||||
            let available = _.difference(this.notes, this.shown);
 | 
					            let available = _.difference(this.notes, this.shown);
 | 
				
			||||||
@@ -47,6 +51,7 @@ export default {
 | 
				
			|||||||
            const fact = _.sample(available);
 | 
					            const fact = _.sample(available);
 | 
				
			||||||
            this.shown.push(fact);
 | 
					            this.shown.push(fact);
 | 
				
			||||||
            this.fact = fact;
 | 
					            this.fact = fact;
 | 
				
			||||||
 | 
					            this.factIndex = _.indexOf(NOTES, fact) + 1;
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -58,10 +63,14 @@ export default {
 | 
				
			|||||||
    text-align: center;
 | 
					    text-align: center;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.fact-index {
 | 
				
			||||||
 | 
					    margin-top: 3em;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.note {
 | 
					.note {
 | 
				
			||||||
    display: block;
 | 
					    display: block;
 | 
				
			||||||
    font-size: 160%;
 | 
					    font-size: 160%;
 | 
				
			||||||
    margin: 2em auto;
 | 
					    margin: 0 auto 2em;
 | 
				
			||||||
    min-height: 3em;
 | 
					    min-height: 3em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,23 @@
 | 
				
			|||||||
class Metrika {
 | 
					class Metrika {
 | 
				
			||||||
 | 
					    constructor(counterCb) {
 | 
				
			||||||
 | 
					        this.cb = counterCb;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    get counter() {
 | 
				
			||||||
 | 
					        return this.cb.call();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hit(name) {
 | 
					    hit(name) {
 | 
				
			||||||
        if (window.yaCounter41913764) {
 | 
					        if (this.counter) {
 | 
				
			||||||
            window.yaCounter41913764.hit(name);
 | 
					            this.counter.hit(name);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    goal(name, params = {}) {
 | 
				
			||||||
 | 
					        if (this.counter) {
 | 
				
			||||||
 | 
					            this.counter.reachGoal(name, params);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default new Metrika();
 | 
					export default new Metrika(() => window.yaCounter41913764);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,9 +14,12 @@
 | 
				
			|||||||
            <button class="restart-button" v-on:click.prevent="restart">Заново</button>
 | 
					            <button class="restart-button" v-on:click.prevent="restart">Заново</button>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div v-else>
 | 
					        <div v-else>
 | 
				
			||||||
            <span class="score">
 | 
					            <p class="score">
 | 
				
			||||||
                {{ predictor.score }}
 | 
					                {{ predictor.score }}
 | 
				
			||||||
            </span>
 | 
					            </p>
 | 
				
			||||||
 | 
					            <p class="step">
 | 
				
			||||||
 | 
					                Ход {{ step }}
 | 
				
			||||||
 | 
					            </p>
 | 
				
			||||||
            <div class="buttons">
 | 
					            <div class="buttons">
 | 
				
			||||||
                <button class="pass-button __left" value="0" v-on:click.prevent="click(0)">Нечет</button>
 | 
					                <button class="pass-button __left" value="0" v-on:click.prevent="click(0)">Нечет</button>
 | 
				
			||||||
                <button class="pass-button __right" value="1" v-on:click.prevent="click(1)">Чет</button>
 | 
					                <button class="pass-button __right" value="1" v-on:click.prevent="click(1)">Чет</button>
 | 
				
			||||||
@@ -27,7 +30,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
<script>
 | 
					<script>
 | 
				
			||||||
import Predictor from 'predictor';
 | 
					import Predictor from 'predictor';
 | 
				
			||||||
 | 
					import Metrika from '../common/metrika';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const PREDICTOR_GAME_END_GOAL = 'PREDICTOR_GAME_END';
 | 
				
			||||||
const MAX_SCORE = 50;
 | 
					const MAX_SCORE = 50;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function make_predictor() {
 | 
					function make_predictor() {
 | 
				
			||||||
@@ -56,6 +61,9 @@ export default {
 | 
				
			|||||||
        isRobotWin() {
 | 
					        isRobotWin() {
 | 
				
			||||||
            return this.predictor.score <= -MAX_SCORE;
 | 
					            return this.predictor.score <= -MAX_SCORE;
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        step() {
 | 
				
			||||||
 | 
					            return this.predictor.stepCount() + 1;
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
        click(v) {
 | 
					        click(v) {
 | 
				
			||||||
@@ -67,9 +75,23 @@ export default {
 | 
				
			|||||||
            this.pass(value);
 | 
					            this.pass(value);
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        pass(value) {
 | 
					        pass(value) {
 | 
				
			||||||
            if (Math.abs(this.predictor.score) < MAX_SCORE) {
 | 
					            const oldScore = this.predictor.score;
 | 
				
			||||||
                const prediction = this.predictor.pass(value);
 | 
					            if (Math.abs(oldScore) >= MAX_SCORE) {
 | 
				
			||||||
                // console.log('PREDICTED', prediction, 'PASS', value);
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* const prediction = */ this.predictor.pass(value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const score = this.predictor.score;
 | 
				
			||||||
 | 
					            const absScore = Math.abs(score);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Game over
 | 
				
			||||||
 | 
					            if (absScore === MAX_SCORE) {
 | 
				
			||||||
 | 
					                Metrika.goal(PREDICTOR_GAME_END_GOAL, {
 | 
				
			||||||
 | 
					                    winner: score > 0 ? 'human' : 'robot',
 | 
				
			||||||
 | 
					                    step_count: this.predictor.stepCount(),
 | 
				
			||||||
 | 
					                    score: score,
 | 
				
			||||||
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        restart() {
 | 
					        restart() {
 | 
				
			||||||
@@ -104,8 +126,13 @@ export default {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
.score {
 | 
					.score {
 | 
				
			||||||
    font-size: 400%;
 | 
					    font-size: 400%;
 | 
				
			||||||
    margin-bottom: 0.8em;
 | 
					    margin-top: 0.2em;
 | 
				
			||||||
    display: inline-block;
 | 
					    margin-bottom: 0.2em;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.step {
 | 
				
			||||||
 | 
					    margin-top: 0;
 | 
				
			||||||
 | 
					    margin-bottom: 3em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.buttons {
 | 
					.buttons {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user