Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If power failure occurs during an online examination, how do we update the time left when the user logs in to the portal again?

I am working on a project Online examination just to gain knowledge. There can be a case of power failure and when a candidate logs in again, then the time wasted during power failure must be given. But in my javascript code, the exam ends after exact 2 hours corresponding to server time(AJAX is used here). After time ends, the student is redirected to home page. I have thought of a solution but I dont find a start to implement it.

As the session is maintained, so I can maintain the time he used from 2 hours and can be stored in database. when he relogin then that particular row which corresponds to him can be checked and the time can be updated.

But I am not able to implement it. Please tell me if there is another solution to it or the direction in which I am thinking is right or wrong.

The exam clock resumes from the start of 2 hours. It doesn't resume from the time which was ticking when the power failure was there. Its the same thing whether a power failure occurs or a candidate logs back again in this case atleast. And I am not asking for any code for this problem. I just want a hint or a direction in which I can think of. I just want to know what can be the concept behind it.

like image 870
Neha Choudhary Avatar asked Oct 08 '22 00:10

Neha Choudhary


1 Answers

Formalizing the problem a bit:

  • A user logins in and begins their exam at t0. Their exam concludes at t120.
  • At some point (x minutes into exam) before the end of the exam (tx) there is a power failure and those being tested must resume the exam.
  • At some point after tx, ty the system comes back online.
  • At some point after or equal to ty, the user logs in again, call it tz. As you've indicated, this is equal to ty.
  • They're entitled to 120 - x more minutes to complete the exam. The point at which the exam concludes is now tz + (120 - x).

Possible Solution:

Originally thought of a very session-oriented approach, but this might be the way to go:

  • Implement a system wide clock (think "heartbeat") with a period p. For every interval p that the system is up, increment a global counter.
  • Record t0 as this global counter for each examination.
  • In another row, update the elapsed time an examination. This is the current value of t0. In your code you'll likely have functionality to save their work in progress, update the elapsed time there. Also update the elapsed time on each page/section load. Note that if some work is lost between the last elapsed time update/in progress save, they'll receive that time 'back' since their last elapsed update was never stored.
  • The interval p will be a policy decision. In theory someone could gain an extra p to complete their exam depending on the timing of the failure. If p is 1 second, it's not a big deal. If it's 5 minutes, it's a bigger deal. Of course there will be performance tradeoffs for different values of p. Also since we're not dealing with real-time systems here, there can be some skew with p.
  • Use transactions for everything. When the system resumes (and before the global clock starts ticking again), any transactions interrupted will need to be rolled back.
like image 98
John Carter Avatar answered Oct 18 '22 10:10

John Carter