fixed date trans bugs and added live search

This commit is contained in:
2019-03-04 19:27:42 +01:00
parent 5a3f051e63
commit e18bde2a33

View File

@@ -22,45 +22,48 @@ for($i = 0; $i < 2; $i++) {
natsort($worklists); natsort($worklists);
$checkedLists = $_GET['worklist'];
$monthTrans = ['jan' => 'Jan', 'feb' => 'Feb', 'mrt' => 'Mar', 'apr' => 'Apr', 'mei' => 'May', 'jul' => 'Jul', 'aug' => 'Aug', 'sep' => 'Sep',
'okt' => 'Oct', 'nov' => 'Nov', 'dec' => 'Dec'];
$all_names = []; $all_names = [];
$totalShifted = 0; $totalShifted = 0;
$total = 0; $total = 0;
$checkedLists = [];
foreach ($checkedLists as $site) { if (isset($_GET['worklist'])) {
$site = 'https://old.wina.be/worklists/' . $site; $checkedLists = $_GET['worklist'];
$data = file_get_contents($site);
preg_match_all('/<div id="(data_shift.*?<table.*?>.*?<\/table>)/s', $data, $shiften); $monthTrans = ['jan' => 'Jan', 'feb' => 'Feb', 'mrt' => 'Mar', 'apr' => 'Apr', 'mei' => 'May', 'jun' => 'Jun', 'jul' => 'Jul', 'aug' => 'Aug', 'sep' => 'Sep',
$shiften = $shiften[1]; 'okt' => 'Oct', 'nov' => 'Nov', 'dec' => 'Dec'];
foreach ($shiften as $shift) { foreach ($checkedLists as $site) {
preg_match_all('/data_shift.*?Start<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $start); $site = 'https://old.wina.be/worklists/' . $site;
preg_match_all('/data_shift.*?Einde<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $einde); $data = file_get_contents($site);
$start = explode(' ', $start[1][0]);
$start[1] = $monthTrans[$start[1]];
$start = DateTime::createFromFormat('j M Y - G:i', implode(' ', $start));
$einde = explode(' ', $einde[1][0]);
$einde[1] = $monthTrans[$einde[1]];
$einde = DateTime::createFromFormat('j M Y - G:i', implode(' ', $einde));
$diff = ($einde->getTimestamp() - $start->getTimestamp()) / 3600; preg_match_all('/<div id="(data_shift.*?<table.*?>.*?<\/table>)/s', $data, $shiften);
$shiften = $shiften[1];
preg_match_all('/data_shift.*?Invulling.*?<td.*?>(.*?)<\/td>/s', $shift, $blockNames); foreach ($shiften as $shift) {
if (count($blockNames[1]) !== 0) { preg_match_all('/data_shift.*?Start<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $start);
preg_match_all('/<span.*?>(.*?)<\/span>/s', $blockNames[1][0], $names); preg_match_all('/data_shift.*?Einde<\/td>.*?>.*?(\d.*?)<\/td>/s', $shift, $einde);
$start = explode(' ', $start[1][0]);
$start[1] = $monthTrans[$start[1]];
$start = DateTime::createFromFormat('j M Y - G:i', implode(' ', $start));
$einde = explode(' ', $einde[1][0]);
$einde[1] = $monthTrans[$einde[1]];
$einde = DateTime::createFromFormat('j M Y - G:i', implode(' ', $einde));
foreach ($names[1] as $name) { $diff = ($einde->getTimestamp() - $start->getTimestamp()) / 3600;
if (!array_key_exists($name, $all_names)) {
$all_names[$name] = $diff; preg_match_all('/data_shift.*?Invulling.*?<td.*?>(.*?)<\/td>/s', $shift, $blockNames);
} else { if (count($blockNames[1]) !== 0) {
$all_names[$name] += $diff; preg_match_all('/<span.*?>(.*?)<\/span>/s', $blockNames[1][0], $names);
foreach ($names[1] as $name) {
if (!array_key_exists($name, $all_names)) {
$all_names[$name] = $diff;
} else {
$all_names[$name] += $diff;
}
$totalShifted += $diff;
} }
$totalShifted += $diff;
} }
} }
} }
@@ -73,9 +76,9 @@ $avg = $totalShifted / count($all_names);
<!doctype html> <!doctype html>
<html lang="nl"> <html lang="nl">
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Wina shift counter</title> <title>Wina shift counter</title>
<meta name="author" content="Arthur Bols">
<!-- Bootstrap core CSS --> <!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
@@ -90,7 +93,7 @@ $avg = $totalShifted / count($all_names);
<div class="text-center"> <div class="text-center">
<h1>Wina shift counter</h1> <h1>Wina shift counter</h1>
<form class="mb-2" method="get"> <form class="mb-2" method="get">
<select name="worklist[]" class="selectpicker" data-style="btn-primary" multiple> <select name="worklist[]" class="selectpicker" data-style="btn-primary" data-live-search="true" multiple>
<?php <?php
foreach($worklists as $key => $list) { foreach($worklists as $key => $list) {
echo "<option " . (in_array($key, $checkedLists) ? "selected " : '') . "value='$key'>" . $list . "</option>"; echo "<option " . (in_array($key, $checkedLists) ? "selected " : '') . "value='$key'>" . $list . "</option>";