fwtrash/pages/vermessung.php

76 lines
1.9 KiB
PHP
Raw Normal View History

2022-12-20 11:21:31 +00:00
<?php
2024-03-29 14:47:35 +00:00
$tpl['file'] = 'vermessung.twig';
2022-12-20 11:21:31 +00:00
$tpl['data'] = [];
$tpl['debug'] = false;
$protocol = !empty($_POST['protocol']) ? $_POST['protocol'] : '';
if(!empty($protocol)) {
preg_match_all("/(?<datetime>.*)\t(?<amt>.*) führt mit (?<laeufer>.*) eine.*erwirtschaftet (?<gm>.*) Goldmünzen/m", $protocol, $res);
$dtact = date('m.Y');
$vms = $newest = [];
for($i = 0; $i < count($res['datetime']); $i++) {
$tmpdt = date('m.Y', strtotime($res['datetime'][$i]));
if(!array_key_exists($tmpdt, $vms)) {
$vms[$tmpdt] = [
'user' => [],
'gm' => 0,
'list' => [],
'dtact' => $tmpdt
];
}
$laeufer = explode(', ', str_replace(' und ', ', ', trim($res['laeufer'][$i], ',')));
2024-03-29 14:47:35 +00:00
$pro = (int)str_replace('.', '', $res['gm'][$i]) / (count($laeufer) + 1);
if(!array_key_exists($res['amt'][$i], $vms[$tmpdt]['user'])) {
$vms[$tmpdt]['user'][$res['amt'][$i]] = [
'gold' => $pro,
'count' => 1
];
}
else {
$vms[$tmpdt]['user'][$res['amt'][$i]]['gold'] += $pro;
$vms[$tmpdt]['user'][$res['amt'][$i]]['count'] += 1;
}
2022-12-20 11:21:31 +00:00
foreach($laeufer as $tmp) {
2024-03-29 14:47:35 +00:00
if(!array_key_exists($tmp, $vms[$tmpdt]['user'])) {
$vms[$tmpdt]['user'][$tmp] = [
'gold' => $pro,
'count' => 1
];
}
else {
$vms[$tmpdt]['user'][$tmp]['gold'] += $pro;
$vms[$tmpdt]['user'][$tmp]['count'] += 1;
}
2022-12-20 11:21:31 +00:00
}
arsort($vms[$tmpdt]['user']);
$vms[$tmpdt]['gm'] += (int)str_replace('.', '', $res['gm'][$i]);
$vms[$tmpdt]['list'][] = [
'datum' => $res['datetime'][$i],
'gold' => (int)str_replace('.', '', $res['gm'][$i]),
'amt' => $res['amt'][$i],
2022-12-29 02:59:51 +00:00
'laeufer' => $laeufer,
2024-03-29 14:47:35 +00:00
'a' => $pro
2022-12-20 11:21:31 +00:00
];
}
$tpl['data'] = [
'protocol' => $protocol,
'vms' => $vms,
'newest' => array_shift($vms)
];
}
else {
$tpl['data'] = [
'protocol' => $protocol
];
}