Skip to content

Commit

Permalink
Attack / defense ratio added to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JJGlezTorres committed Nov 29, 2023
1 parent 65a7cf9 commit 4010d7f
Showing 1 changed file with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const stpData = useSTPDataStore()
Defensive counter:
{{defensive_counter}}
</div>
<div>
Effective game time:
{{(total_time/1000).toFixed(2)}}
</div>
</template>

<script lang="ts">
Expand All @@ -36,30 +40,36 @@ export default defineComponent({
stpData: useSTPDataStore(),
offensive_plays: ['Attack', 'AttackingPass', 'KeeperKickBall'],
defensive_plays: ['Defend Shot', 'Defend Pass', 'Keeper Kick Ball'],
neutral_plays: ['Halt', 'BallPlacementUs', 'BallPlacementThem', 'PenaltyThemPrepare', 'PenaltyUsPrepare', 'PenaltyThem', 'DefensiveStopFormation', 'AggressiveStopFormation',
'PenaltyUs', 'KickOffUsPrepare', 'KickOffThemPrepare', 'FreeKickThem', 'FreeKickUsAtGoal', 'FreeKickUsPass', 'KickOffUs', 'KickOffThem'],
/*neutral_plays: ['Halt', 'BallPlacementUs', 'BallPlacementThem', 'PenaltyThemPrepare', 'PenaltyUsPrepare', 'PenaltyThem', 'DefensiveStopFormation', 'AggressiveStopFormation',
'PenaltyUs', 'KickOffUsPrepare', 'KickOffThemPrepare', 'FreeKickThem', 'FreeKickUsAtGoal', 'FreeKickUsPass', 'KickOffUs', 'KickOffThem'],*/
offensive_counter: 0,
defensive_counter: 0,
neutral_counter: 0,
offensive_timer: 0,
defensive_timer: 0,
//neutral_counter: 0,
possession: 0,
current_play: 'Halt',
last_time: 0,
interval_time: 0
interval_time: 0,
total_time: 0
};
},
methods: {
increment_counters() {
const playName = this.stpData.latest?.currentPlay?.playName;
this.current_play = String(playName);
if (this.defensive_plays.includes(String(playName))) {
this.defensive_counter++;
this.defensive_timer = this.defensive_timer + this.interval_time;
} else if (this.offensive_plays.includes(String(playName))) {
this.offensive_counter++;
} else if (this.neutral_plays.includes(String(playName))) {
this.neutral_counter++;
this.offensive_timer = this.offensive_timer + this.interval_time;;
}
this.possession = this.offensive_counter / (this.offensive_counter + this.defensive_counter) * 100
this.possession = this.offensive_timer / (this.offensive_timer + this.defensive_timer) * 100
}
Expand All @@ -69,13 +79,19 @@ export default defineComponent({
},
watch: {
'stpData.latest.currentPlay.playName'() {
this.increment_counters();
if (this.last_time === 0) {
this.last_time = Date.now();
} else {
this.interval_time = Date.now() - this.last_time;
if (this.defensive_plays.includes(this.current_play) ||
this.offensive_plays.includes(this.current_play)) {
this.total_time = this.total_time + this.interval_time; // ms!
}
this.last_time = Date.now();
}
this.increment_counters();
}
}
});
Expand Down

0 comments on commit 4010d7f

Please sign in to comment.