Generate "array" with time interval and check if place free


#1

Hey,

i have a complex question ^^. I explain,

I have 6 computers.
I have differents tests with differents duration to do on theses computers.
I have 1 person in charge to put the client on the computers.
So i can have only on client subscription every 15minutes, if all computers are free.

So, i thought i could do like this :
a) create an array of slots of 15min from 09:00:00 to 11:45:00.
b) check :

  • the duration of the client test
  • if at least one place is free for that duration
  • be sure no other test on taken places begin at that slot.

I’ve tried for several hours to do it but i’dont find any solution.
If someone would help me to find a solution to this, would be great ^^

thank you very much.


#2

based on what I read, you have 6 computers. Only one can connect at a time to a central server at a given time?


#3

hey,

thank you for your help.

the point is, because only one person will “instal” all the clients, this person can take a new client every 15min,

so we will have one client à 9h00, one à 9h15, 9h30 etc. so maximum 12 clients (inscriptions).

with a table inscriptions, i could easily hide the taken inscriptions, but the point is, if a test is too long, i’ll not have a computer to put the client on it, because i have only 6 computer

you can check this small code i did to test the first part.

  <?php $inscriptions = [
	'1'=> [
		'date' => '05-10-2018',
		'start_time'=>'09:00:00',
		'end_time'=>'11:45:00',
		'state'=>'taken',
	],
	'2'=> [
		'date' => '05-10-2018',
		'start_time'=>'09:15:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],
	'3'=> [
		'date' => '05-10-2018',
		'start_time'=>'09:30:00',
		'end_time'=>'11:00:00',
		'state'=>'taken',
	],
	'4'=> [
		'date' => '05-10-2018',
		'start_time'=>'09:45:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],
	'5'=> [
		'date' => '05-10-2018',
		'start_time'=>'10:00:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],
	'6'=> [
		'date' => '05-10-2018',
		'start_time'=>'10:15:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],

	'11'=> [
		'date' => '06-12-2018',
		'start_time'=>'09:00:00',
		'end_time'=>'11:45:00',
		'state'=>'taken',
	],
	'12'=> [
		'date' => '06-12-2018',
		'start_time'=>'09:15:00',
		'end_time'=>'11:30:00',
		'state'=>'taken',
	],
	'13'=> [
		'date' => '06-12-2018',
		'start_time'=>'09:30:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],
	'14'=> [
		'date' => '06-12-2018',
		'start_time'=>'09:45:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	],
	'15'=> [
		'date' => '06-12-2018',
		'start_time'=>'10:00:00',
		'end_time'=>'11:30:00',
		'state'=>'taken',
	],
	'16'=> [
		'date' => '06-12-2018',
		'start_time'=>'10:15:00',
		'end_time'=>'00:00:00',
		'state'=>'free',
	], 
];
echo '<pre>'; 
$olddate = '';
foreach ($inscriptions as $inscription) {
	# code...
	if($inscription['date'] != $oldate){
		echo '<div style="width:100%; display:block; padding:5px;padding-top:20px; border-bottom: 1px solid">new date: '.$inscription['date'].'</div>';
		$oldate = $inscription['date'];
	}
	if ($inscription['state']=='free') {
		# code...
		echo $inscription['start_time'].' | ';
	}
}
?>

#4

I try to explain it in another way

You have 12 inscriptions to tests max

(9:00-9:15-9:30… 11:45)

You have only six seats to do the tests

Tests have different duration

(15min-60min-90min-150min)

How can we test if a place is free to register the new subscription (client choose his test, so we know the duration)


#5

So, like an appointment based on time?

Or are these computers checking in their availability?


#6

Like an appointment yes


#7

That’s sounds easy enough. Is this to be keep in a database, or just a local page to run by the person placing the clients at their computers? Do you need to keep records of the times?
Since the time-frames are in 15 minutes increments (60 is just four 15 minutes periods), is should be easy to keep a graph of all the available times and have the person overseeing them to fill in as needed.

If no records need to be kept, it’s just an appointment point and click thing. One more question, are these selected by the client to be at various times of day or is it just first-come first-enter type of thing?


#8

It will be stored in a db. The client first select the type of test he wants (so we get the duration) and then we should propose him the different possibilities.


#9

OK,

i think i took the problem in the wrong way,

if i create 12 inscriptions with start_time (9h00 - 9h15… 11h45)
and another table with 6places of 12 ‘15minutes slots’ each, i may be able to “block” the nb of slots equal to the time of the test.

then i can check for each start_time if any place has enough free slots for the new test to register…


#10

Sometimes it is just best to step back and design a solution for the problem.

It appears you have thought it out. Now code it and let us know if you need further help with it. Show us some code when you run into a problem with it.


#11

Thanks, i’ll let you know