-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Never store data with multiple values like this '$week_ending', '$staff_name', '$monday_start', '$monday_finish', '$tuesday_start', '$tuesday_finish', '$wednesday_start', '$wednesday_finish', '$thursday_start', '$thursday_finish', '$friday_start', '$friday_finish', '$saturday_start', '$saturday_finish', '$sunday_start', '$sunday_finish', '$total_hours', '$timesheet_comment' You should always normalize your data when using an RDBMS. Once that's done, the processing can become a whole lot simpler. For example, if you table were like this... TABLE: driver TABLE: driver_timesheet +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | driver_id | firstname | lastname | | timesheet_id | driver_id | week_ending | timesheet_comment | +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | 1 | Peter | Dowt | | 1 | 1 | 2021-09-05 | 4-day week | | 2 | Laura | Norder | ----------------------------------------------------------------< | 2 | 2 | 2021-09-05 | No Saturday work | | 3 | Tom | DiCanari | | 3 | 3 | 2021-09-05 | No Sunday work | +-----------+-----------+----------+ +--------------+-----------+-------------+-------------------+ | | +------------------------------------------------------------------------------------+ TABLE: driver_time | +----------------+--------------+-------------+------------+----------+------------+ | driver_time_id | timesheet_id | driver_date | time_start | time_end | break_time | +----------------+--------------+-------------+------------+----------+------------+ | 1 | 1 | 2021-08-30 | 08:15:00 | 18:05:00 | 01:20:00 | | 2 | 1 | 2021-08-31 | 08:30:00 | 17:35:00 | 01:10:00 | | 3 | 1 | 2021-09-01 | 08:20:00 | 18:00:00 | 01:00:00 | | 4 | 1 | 2021-09-05 | 08:00:00 | 17:55:00 | 01:10:00 | | 19 | 2 | 2021-08-30 | 08:16:00 | 17:17:00 | 01:19:00 | | 20 | 2 | 2021-08-31 | 08:19:00 | 17:25:00 | 01:06:00 | | 21 | 2 | 2021-09-01 | 08:18:00 | 17:41:00 | 01:24:00 | | 22 | 2 | 2021-09-02 | 08:07:00 | 17:26:00 | 01:20:00 | | 23 | 2 | 2021-09-03 | 08:09:00 | 17:21:00 | 01:01:00 | | 25 | 2 | 2021-09-05 | 08:06:00 | 17:46:00 | 01:24:00 | | 26 | 3 | 2021-08-30 | 08:23:00 | 17:38:00 | 01:02:00 | | 27 | 3 | 2021-08-31 | 08:04:00 | 17:23:00 | 01:21:00 | | 28 | 3 | 2021-09-01 | 08:21:00 | 17:30:00 | 01:13:00 | | 29 | 3 | 2021-09-02 | 08:22:00 | 17:36:00 | 01:01:00 | | 30 | 3 | 2021-09-03 | 08:23:00 | 17:32:00 | 01:09:00 | | 31 | 3 | 2021-09-04 | 08:21:00 | 17:05:00 | 01:00:00 | +----------------+--------------+-------------+------------+----------+------------+ then all you need to do is write the data from your input form to the tables. To get the daily hours worked ... SELECT concat(firstname,' ', lastname) as name , dayname(driver_date) as day , date_format(driver_date, '%b %d') as date , time_start , time_end , break_time , timediff(timediff(time_end, time_start), break_time) as hrs_worked FROM driver_time JOIN driver_timesheet USING (timesheet_id) JOIN driver USING (driver_id) WHERE week_ending = '2021-09-05' ORDER BY driver_id, driver_date; +--------------+-----------+--------+------------+----------+------------+------------+ | name | day | date | time_start | time_end | break_time | hrs_worked | +--------------+-----------+--------+------------+----------+------------+------------+ | Peter Dowt | Monday | Aug 30 | 08:15:00 | 18:05:00 | 01:20:00 | 08:30:00 | | Peter Dowt | Tuesday | Aug 31 | 08:30:00 | 17:35:00 | 01:10:00 | 07:55:00 | | Peter Dowt | Wednesday | Sep 01 | 08:20:00 | 18:00:00 | 01:00:00 | 08:40:00 | | Peter Dowt | Sunday | Sep 05 | 08:00:00 | 17:55:00 | 01:10:00 | 08:45:00 | | Laura Norder | Monday | Aug 30 | 08:16:00 | 17:17:00 | 01:19:00 | 07:42:00 | | Laura Norder | Tuesday | Aug 31 | 08:19:00 | 17:25:00 | 01:06:00 | 08:00:00 | | Laura Norder | Wednesday | Sep 01 | 08:18:00 | 17:41:00 | 01:24:00 | 07:59:00 | | Laura Norder | Thursday | Sep 02 | 08:07:00 | 17:26:00 | 01:20:00 | 07:59:00 | | Laura Norder | Friday | Sep 03 | 08:09:00 | 17:21:00 | 01:01:00 | 08:11:00 | | Laura Norder | Sunday | Sep 05 | 08:06:00 | 17:46:00 | 01:24:00 | 08:16:00 | | Tom DiCanari | Monday | Aug 30 | 08:23:00 | 17:38:00 | 01:02:00 | 08:13:00 | | Tom DiCanari | Tuesday | Aug 31 | 08:04:00 | 17:23:00 | 01:21:00 | 07:58:00 | | Tom DiCanari | Wednesday | Sep 01 | 08:21:00 | 17:30:00 | 01:13:00 | 07:56:00 | | Tom DiCanari | Thursday | Sep 02 | 08:22:00 | 17:36:00 | 01:01:00 | 08:13:00 | | Tom DiCanari | Friday | Sep 03 | 08:23:00 | 17:32:00 | 01:09:00 | 08:00:00 | | Tom DiCanari | Saturday | Sep 04 | 08:21:00 | 17:05:00 | 01:00:00 | 07:44:00 | +--------------+-----------+--------+------------+----------+------------+------------+ and to get the weekly hours for each driver for payroll ... SELECT date_format(week_ending, '%d %b %Y') as wk_ending , concat(firstname,' ', lastname) as name , round(sum(time_to_sec( timediff(timediff(time_end, time_start), break_time) ))/3600, 2) as tot_hrs_dec FROM driver_time JOIN driver_timesheet USING (timesheet_id) JOIN driver USING (driver_id) WHERE week_ending = '2021-09-05' GROUP BY week_ending, driver_id +-------------+--------------+-------------+ | wk_ending | name | tot_hrs_dec | +-------------+--------------+-------------+ | 05 Sep 2021 | Peter Dowt | 33.83 | | 05 Sep 2021 | Laura Norder | 48.12 | | 05 Sep 2021 | Tom DiCanari | 48.07 | +-------------+--------------+-------------+ All your calculations done with a couple of queries.
- 19 replies
-
- php
- time calculations
-
(and 1 more)
Tagged with:
-
NOTE: the win_percentage in $win = percent_win(20); ^^ (100 / $odds) should be equal to 100/$odds
-
Yes. So in answer to your 60% question... If you have an array of 10 elements and 6 of them are 1's, there is a 60% chance of selecting a 1. $win = percent_win(60); // $win will be 1 (true) approx 60% of the time function percent_win($pc) { $lose = 100 - $pc; $a1 = array_fill(0, $lose, 0); $a2 = array_fill(0, $pc, 1); $a1 = array_merge($a1, $a2); shuffle($a1); return $a1[array_rand($a1)]; } To test... $w = $l = 0; for ($i=0; $i<1000; $i++) { $win = percent_win(20); if ($win) ++$w; else ++$l; } printf ('%d - %d - %0.3f', $w, $l, $w/($w + $l) );
-
@ginerjm That was my argument too, but I relented when I ran the simulation over 500 runs If I took out the - $bet from a winning payout (so you weren't losing your stake money) but keeping the odds = 2 and the chance of win = rand(0, 1) then the accumulated bankroll would have made Elon Musk green with envy. EG Thinking about it, the odds of winning are even but you are being paid out at 2-1. So not surprising the gains are exponential. To get it back on an even keel I then changed the chance of a win to $win = rand(0, $odds)==1 so the chance matched the odds. Going back to the original method I decided was a matter of interpretation. The OP's odds of "2", I guess, is actually 1 in 2 (evens) so the OP's formaula works if the stake is lost but double is paid back.
-
I still have no idea what you mean by "PROFIT for each winning unit"
-
Define "unit". Count the wins, multiply by 100 and divide by number of bets (which may be less than 500 if you run out of funds).
-
Something like this? <?php const BETS = 500; $bankroll = 500; $pcent = 0.1; $odds = 2; function betting(&$bankroll, $betPerc, $odds) { for ($i=1; $i <= BETS; $i++) { if ($bankroll < 0.5) break; $win = rand(0,1); $bet = $bankroll * $betPerc; $bankroll += ($win ? $bet * $odds - $bet : - $bet); printf("| %3d | %20.2f | %s | %20s |<br>", $i, $bet, $win ? '✓' : '×', number_format($bankroll,2)); } } echo '<pre>'; printf("| %54.2f |<br>", $bankroll); betting($bankroll, $pcent, $odds); ?>
-
No - in that case you have won your bet but still lost your 50.00 stake. If you lose you pay them If you win, they pay you You are doing both at the same time
-
But if you win, you get your stake back + winnings.
-
The bankroll would become 450 only if you lost.
-
If you win the first bet, you should then have 600. If you win, they pay you.
-
return $bankroll = $bet * $odds - $bet + $bankroll; ^^^^^^ Are you sure you should be losing your stake when you win?
-
One more question - is there a minimum bet? If it's 10% of the current bankroll and you keep losing, you could, at some point, be betting 0.0000000001 euros
-
Clarification required. Your bet is 10%. Does that mean that, if you start with 500.00, you will always bet 50.00, or will your next bet be 10% of your current bankroll? You say 500 times, but what if you are unlucky and run out of cash?
-
PHP v8 doesn't let you mix indeterminate types, such as adding an empty string to an int. $a = 1; $b = '2'; $c = ''; echo $a + $b; // 3 OK echo $a + $c; // Unsupported operand types: int + string echo $a + (int)$c; // 1 OK Use a cast to int. $this->hou += (int)$split[0]; That said, you really are doing the calculations the hard way $t1 = '09:30:00'; $t2 = '17:15:00'; $dt1 = new DateTime($t1); $dt2 = new DateTime($t2); echo $dt2->diff($dt1)->format('%H:%I:%S'); // 07:45:00
-
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
The correct fix would be to use prepared queries. CSV files are expected to have "..." around some string values and fgetcsv() should allow for them. Perhaps there is something weird regarding their placement in your data. -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
If you want to use silly names like that with the "." at the end then you need the column name inside backticks. SELECT `KNr.` FROM .... From MySQL manual -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
Sorry. Not used to mysqli (I always use PDO). It should be fetch_row(); -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
I'd create and array of KNr's from the CSV and a second array of KNr's from your table then compare the arrays for differencess (array_diff() ) EDIT: Something like this $array1 = []; $array2 = []; $file = fopen($filename, "r"); while (($column = fgetcsv($file, 10000, ";")) !== FALSE) { $array1[] = $column[0]; } $res = $con->query("SELECT KN2 from adressen_neu"); while ($row = $res->fetch_num() ) { $array2[] = $row[0]; } echo '<pre>' . print_r(array_diff($array1, $array2), 1) . '</pre>'; -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
I've just spotted the "key" icon next to KNr ( I was expecting a separated to column to say which columns were keys) so it looks like that is the primary key. That makes your checking for missing records simple. You just need to see which KNr values are not in the db table but are in the csv file. -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
Those ... tell us sweet FA (Why is phpmyadmin so useless?). What about my other question about unique identifiers> -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
I was hoping to see which column was the primary key and if you had any other keys defined on any columns. That was why I requested the the output from SHOW CREATE TABLE. I can't see anything defined there, so is there anything in those records that uniquly identifies a record? -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
What is your table's structure? SHOW CREATE TABLE adressen_neu; -
PHP CSV Upload - Some rows in CSV file aren't in database
Barand replied to KN1V3S's topic in PHP Coding Help
You are inserting using the slowest method possible. Are the missing rows always from the end of the CSV file, or is it skipping rows from the middle? -
Perhaps... <link rel='stylesheet' href='https://www.w3schools.com/w3css/4/w3.css'> <form id="form1"> <div class='w3-container w3-display-topright w3-light-gray w3-third' > <div class='w3-cell-row w3-padding-small'> <div class='w3-container w3-cell' style='width:120px'>Email</div> <div class='w3-container w3-cell'> <input class='w3-input w3-card w3-tiny' type='text' name='email'> </div> </div> <div class='w3-cell-row w3-padding-small'> <div class='w3-container w3-cell' style='width:120px'>Password</div> <div class='w3-container w3-cell'> <input class='w3-input w3-card w3-tiny' type='text' name='password'> </div> </div> <div class='w3-cell-row w3-padding-small'> <div class='w3-container w3-cell w3-right' style='width: 60%'> <button class='w3-btn w3-small w3-light-grey w3-border w3-right'>LogIn</button> </div> </div> </div> </form> Laptop... Mobile...