Skip to content

Commit

Permalink
add windowMove monitorer
Browse files Browse the repository at this point in the history
  • Loading branch information
vdvibhu20 committed May 16, 2024
1 parent 6d0f642 commit a379a12
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
6 changes: 6 additions & 0 deletions app/models/contest-attempt.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export default Model.extend({
windowResizeTimePenaltyMinutes: Ember.computed('monitorerData', function() {
return this.monitorerData && this.monitorerData['window-resizes-penalty'] || 0
}),
windowMoveCount: Ember.computed('monitorerData', function() {
return this.monitorerData && this.monitorerData['window-move-count'] || 0
}),
windowMoveTimePenaltyMinutes: Ember.computed('monitorerData', function() {
return this.monitorerData && this.monitorerData['window-moves-penalty'] || 0
}),
noFaceCount: Ember.computed('monitorerData', function() {
return this.monitorerData && this.monitorerData['no-face-count'] || 0
}),
Expand Down
5 changes: 4 additions & 1 deletion app/models/contest.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,18 @@ export default Model.extend({
allowPaste: DS.attr(),
disallowTabSwitch: DS.attr(),
disallowWindowResize: DS.attr(),
disallowWindowMove: DS.attr(),
disallowNoFace: DS.attr(),
disallowMultipleFaces: DS.attr(),
disallowNoise: DS.attr(),
enforceFullscreen: DS.attr(),
allowedTabSwitchesNumber: DS.attr(),
allowedNoFacesNumber: DS.attr(),
allowedMultipleFacesNumber: DS.attr(),
allowedWindowMovesNumber: DS.attr(),
tabSwitchPenalty: DS.attr(),
noFacePenalty: DS.attr(),
multipleFacesPenalty: DS.attr(),
windowResizePenalty: DS.attr()
windowResizePenalty: DS.attr(),
windowMovePenalty: DS.attr()
});
12 changes: 12 additions & 0 deletions app/pods/components/full-screen-contest-view/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@
<span>{{contest.windowResizePenalty}} minutes deducted.</span>
{{/if}}
</li>
<li>
{{#if monitorer.faultMessages.windowMove}}
<span><i class="fas fa-info-circle font-sm"></i> You moved browser window {{attempt.windowMoveCount}} {{if (eq attempt.windowMoveCount 1) 'time' 'times'}}.</span>
{{#if (gPt attempt.windowMoveCount contest.allowedWindowMovesNumber)}}
<span>{{contest.windowMovePenalty}} minutes deducted.</span>
{{/if }}
{{/if}}
</li>
<li>
{{#if monitorer.faultMessages.noise}}
<span><i class="fas fa-info-circle font-sm"></i> Noise detected.</span>
Expand All @@ -191,6 +199,10 @@
Total Window Resizes: <span class="red">{{attempt.windowResizeCount}} | {{attempt.windowResizeTimePenaltyMinutes}} mins deducted</span>
{{/if}}
<br>
{{#if contest.disallowWindowMove}}
Total Window Moves: <span class="red">{{attempt.windowMoveCount}} | {{attempt.windowMoveTimePenaltyMinutes}} mins deducted</span>
{{/if}}
<br>
{{#if contest.disallowNoFace}}
Total Face Undetected: <span class="red">{{attempt.noFaceCount}} | {{attempt.noFaceTimePenaltyMinutes}} mins deducted</span>
{{/if}}
Expand Down
6 changes: 6 additions & 0 deletions app/pods/components/intermediate-contest-view/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@
<li>&#8226; Resize the browser window</li>
</ul>
{{/if}}
{{#if contest.disallowWindowMove}}
<i class="fas fa-info-circle font-sm"></i> Browser Window Movement is prohibited on this contest. You will face a penalty of 10 mins every 10 secs in case you :-
<ul>
<li>&#8226; Move the browser window</li>
</ul>
{{/if}}
{{#if contest.disallowNoFace}}
<i class="fas fa-info-circle font-sm"></i> Face detection is enabled on this contest. You will face a penalty of 10 mins every 5 secs after 3 faults in case :-
<ul>
Expand Down
31 changes: 30 additions & 1 deletion app/services/monitorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default Service.extend({
noFace: false,
multipleFaces: false,
windowResize: false,
windowMove: false,
noise: false
},
init() {
Expand Down Expand Up @@ -59,6 +60,10 @@ export default Service.extend({
await this.enableWindowResizeMonitorer()
}

if(this.contest.disallowWindowMove) {
await this.enableWindowMoveMonitorer()
}

if(this.contest.disallowNoFace) {
await this.enableNoFaceMonitorer()
}
Expand All @@ -77,6 +82,7 @@ export default Service.extend({
// this.set('onError', null)
await this.disableTabSwitchMonitorer()
await this.disableWindowResizeMonitorer()
await this.disableWindowMoveMonitorer()
await this.disableNoFaceMonitorer()
await this.disableMultipleFacesMonitorer()

Expand All @@ -91,6 +97,10 @@ export default Service.extend({
await this.monitorer.enable({ windowResize: true })
},

async enableWindowMoveMonitorer() {
await this.monitorer.enable({ windowMove: true })
},

async enableNoFaceMonitorer() {
await this.monitorer.enable({ noFace: true })
if(!this.isLiveFeedEnabled) {
Expand Down Expand Up @@ -126,6 +136,10 @@ export default Service.extend({
async disableWindowResizeMonitorer() {
await this.monitorer.disable({ windowResize: true })
},

async disableWindowMoveMonitorer() {
await this.monitorer.disable({ windowMove: true })
},

async disableNoFaceMonitorer() {
await this.monitorer.disable({ noFace: true })
Expand Down Expand Up @@ -158,10 +172,11 @@ export default Service.extend({
async monitorerFaultEventHandler(e) {
const currentAttempt = await this.contest.currentAttempt
if(!!!currentAttempt.id) return

switch(e.detail.code) {
case "TAB_SWITCHED": await this.handleTabSwitchFault(); break;
case "WINDOW_RESIZED": await this.handleWindowResizeFault(e.detail); break;
case "WINDOW_MOVED": await this.handleWindowMoveFault(); break;
case "NO_FACE_DETECTED": await this.handleNoFaceFault(e.detail);
this.set('oneFaceDetected', false); break;
case "MULTIPLE_FACES_DETECTED": await this.handleMultipleFacesFault(e.detail);
Expand Down Expand Up @@ -216,6 +231,20 @@ export default Service.extend({
await this.store.findRecord('contest-attempt', currentAttempt.id)
}
},
async handleWindowMoveFault(details) {
this.set('faultMessages.windowMove', true)
this.set('faultTrigger', true)

const currentAttempt = await this.contest.currentAttempt
await this.api.request(`/contest-attempts/${currentAttempt.id}/report-monitorer-fault`, {
method: 'POST',
data: {
fault_type: 'window_move'
}
})
await this.store.findRecord('contest-attempt', currentAttempt.id)

},

async handleNoFaceFault(details) {
if(!this.noFaceThrottled) {
Expand Down

0 comments on commit a379a12

Please sign in to comment.