Statistics
0,
"raindrops" => 0,
"total" => 0,
"end" => strtotime($switch["timestamp"]),
"start" => null
];
if ($week !== $lastWeek) {
if (isset($weeks[$lastWeek])) {
$weeks[$lastWeek]["start"] = strtotime($switch["timestamp"]);
$lastWeek = $week;
}
}
$weeks[$week]["raindrops"]++;
$weeks[$week]["total"]++;
}
$lastWeek = 0;
foreach ($switchesCloudburst as $switch) {
$week = date('YW', strtotime($switch["timestamp"]));
if ($lastWeek === 0) $lastWeek = $week;
if (!isset($weeks[$week])) $weeks[$week] = [
"cloudburst" => 0,
"raindrops" => 0,
"total" => 0,
"end" => strtotime($switch["timestamp"]),
"start" => null
];
if ($week !== $lastWeek) {
if (isset($weeks[$lastWeek])) {
$weeks[$lastWeek]["start"] = strtotime($switch["timestamp"]);
$lastWeek = $week;
}
}
$weeks[$week]["cloudburst"]++;
$weeks[$week]["total"]++;
}
$index = 0;
foreach ($weeks as $id => $week) {
if ($index >= 20) continue;
$weeksRectified[$id] = $week;
$index++;
}
$weeksRectified = array_filter(array_reverse($weeksRectified), function ($i) {
return $i["start"] > 1651363200;
});
$members = [];
$frontersMonth = [];
$fronts = [];
$lastFrontIDs = [];
foreach (array_reverse($switchesRaindrops) as $switch) {
foreach ($lastFrontIDs as $frontID) {
$fronts[$frontID]["end"] = strtotime($switch["timestamp"]);
}
$lastFrontIDs = [];
$index = 0; foreach ($switch["members"] as $member) {
if (strtotime($switch["timestamp"]) - (time() - 86400*30) < 0) continue;
$fronts[$switch["id"] . ":" . $index] = [
"member" => $member,
"start" => strtotime($switch["timestamp"]),
"end" => strtotime(date('c')),
"duration" => null
];
$lastFrontIDs[] = $switch["id"] . ":" . $index;
} $index++;
}
foreach ($fronts as $id => $front) {
$fronts[$id]["duration"] = $front["end"] - $front["start"];
if (!($front["start"] - (time() - 86400*30) < 0)) {
if (!isset($members[$front["member"]])) $members[$front["member"]] = [
"time" => 0,
"name" => getMemberWithoutSystem($front["member"])["display_name"],
"color" => getMemberWithoutSystem($front["member"])["color"],
];
$members[$front["member"]]["time"] += $fronts[$id]["duration"];
}
}
foreach ($fronts as $front) {
if (!isset($frontersMonth[date('Y-m', $front["start"])])) $frontersMonth[date('Y-m', $front["start"])] = [];
if (!isset($frontersMonth[date('Y-m', $front["start"])][$front["member"]])) $frontersMonth[date('Y-m', $front["start"])][$front["member"]] = 0;
$frontersMonth[date('Y-m', $front["start"])][$front["member"]] += $front["duration"];
}
$fronts = [];
$lastFrontIDs = [];
foreach (array_reverse($switchesCloudburst) as $switch) {
foreach ($lastFrontIDs as $frontID) {
$fronts[$frontID]["end"] = strtotime($switch["timestamp"]);
}
$lastFrontIDs = [];
$index = 0; foreach ($switch["members"] as $member) {
$fronts[$switch["id"] . ":" . $index] = [
"member" => $member,
"start" => strtotime($switch["timestamp"]),
"end" => strtotime(date('c')),
"duration" => null
];
$lastFrontIDs[] = $switch["id"] . ":" . $index;
} $index++;
}
foreach ($fronts as $id => $front) {
$fronts[$id]["duration"] = $front["end"] - $front["start"];
if (!($front["start"] - (time() - 86400*30) < 0)) {
if (!isset($members[$front["member"]])) $members[$front["member"]] = [
"time" => 0,
"name" => getMemberWithoutSystem($front["member"])["display_name"],
"color" => getMemberWithoutSystem($front["member"])["color"],
];
$members[$front["member"]]["time"] += $fronts[$id]["duration"];
}
}
foreach ($fronts as $front) {
if (!isset($frontersMonth[date('Y-m', $front["start"])])) $frontersMonth[date('Y-m', $front["start"])] = [];
if (!isset($frontersMonth[date('Y-m', $front["start"])][$front["member"]])) $frontersMonth[date('Y-m', $front["start"])][$front["member"]] = 0;
$frontersMonth[date('Y-m', $front["start"])][$front["member"]] += $front["duration"];
}
$fronts = array_reverse($fronts);
uasort($members, function ($a, $b) {
return $b["time"] - $a["time"];
});
$frontersMonthRectified = [];
foreach ($frontersMonth as $monthID => $month) {
$thisMonth = [];
foreach ($month as $id => $time) {
$thisMonth[$id] = [
"duration" => $time,
"name" => getMemberWithoutSystem($id)["display_name"],
"color" => getMemberWithoutSystem($id)["color"]
];
}
$frontersMonthRectified[$monthID] = $thisMonth;
}
uasort($frontersMonthRectified, function ($a, $b) use ($frontersMonthRectified) {
return strtotime(array_search($a, $frontersMonthRectified) . "-01") - strtotime(array_search($b, $frontersMonthRectified) . "-01");
});
$frontersMonthMembers = [];
foreach ($frontersMonthRectified as $month => $fronters) {
foreach ($fronters as $fronter => $data) {
foreach (scoreOrderGlobal() as $member) {
if (!isset($frontersMonthMembers[$member["id"]])) $frontersMonthMembers[$member["id"]] = [];
}
}
foreach ($frontersMonthMembers as $key => $member) {
$frontersMonthMembers[$key][$month] = $frontersMonthRectified[$month][$key] ?? [
"duration" => 0
];
/*$frontersMonthMembers[$key][$month] = array_map(function ($i) {
return $i["duration"];
}, $frontersMonthMembers[$key][$month]);*/
}
}
?>
Switches per week