WIP RTR Reporting
This commit is contained in:
@@ -47,6 +47,37 @@ class AdminController extends mfBaseController {
|
||||
$this->layout()->set("xinon_active_customers_total", $xinon_active_customers_total);
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function rtrReporting() {
|
||||
require_once(realpath(dirname(__FILE__)."/functions")."/RtrReporting.php");
|
||||
|
||||
$this->layout()->setTemplate("Admin/RtrReporting/Index");
|
||||
|
||||
$rtrreporting = new Admin_RtrReporting($this->request);
|
||||
$response = $rtrreporting->runRequest();
|
||||
|
||||
foreach(["info", "success", "warning", "error"] as $level) {
|
||||
if(array_key_exists($level, $response) && $response[$level]) {
|
||||
$this->layout()->setFlash($response[$level], $level);
|
||||
}
|
||||
}
|
||||
|
||||
if($response["redirect"]) {
|
||||
$this->redirect($response["redirect"]);
|
||||
}
|
||||
|
||||
if($response["template"]) {
|
||||
$this->layout()->setTemplate($response["template"]);
|
||||
}
|
||||
|
||||
if(is_array($response["templateVars"]) && count($response["templateVars"])) {
|
||||
foreach($response["templateVars"] as $key => $value) {
|
||||
$this->layout()->set($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function createNetworkAddressForNetowner() {
|
||||
|
||||
143
application/Admin/functions/RtrReporting.php
Normal file
143
application/Admin/functions/RtrReporting.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
|
||||
class Admin_RtrReporting {
|
||||
private $request;
|
||||
private $db;
|
||||
private $log;
|
||||
private $flash = [];
|
||||
|
||||
public function __construct($request = false) {
|
||||
$this->request = $request;
|
||||
$this->db = FronkDB::singleton();
|
||||
$this->log = mfLoghandler::singleton();
|
||||
|
||||
}
|
||||
|
||||
public function runRequest() {
|
||||
$action = $this->request->do;
|
||||
if(!$action) {
|
||||
return $this->indexAction();
|
||||
} else {
|
||||
$method = $action."Action";
|
||||
if(method_exists($this, $method)) {
|
||||
return $this->$method();
|
||||
} else {
|
||||
throw new Exception("Method not found", "404");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function indexAction() {
|
||||
|
||||
return [
|
||||
"template" => "Admin/RtrReporting/Index",
|
||||
"redirect" => "",
|
||||
"templateVars" => []
|
||||
];
|
||||
}
|
||||
|
||||
public function a10reportAction() {
|
||||
// alle anschlüsse
|
||||
|
||||
$rasterpunkte = [];
|
||||
foreach(BuildingModel::getAll() as $building) {
|
||||
$raster = $building->laea;
|
||||
|
||||
$prod_code = 14310;
|
||||
$bb = "1000,00"; // glas = 1000, funk = 50
|
||||
$user_count = TerminationModel::count(["building_id" => $building->id]);
|
||||
|
||||
|
||||
if(!array_key_exists($raster, $rasterpunkte)) {
|
||||
$rasterpunkte[$raster] = [];
|
||||
}
|
||||
if(!array_key_exists($prod_code, $rasterpunkte[$raster])) {
|
||||
$rasterpunkte[$raster][$prod_code] = [
|
||||
"bb" => $bb,
|
||||
"user_count" => 0
|
||||
];
|
||||
}
|
||||
$rasterpunkte[$raster][$prod_code]["user_count"] += $user_count;
|
||||
}
|
||||
|
||||
$building = new Building();
|
||||
$eigen_product_ids = $this->getEigenProductIds();
|
||||
foreach(ContractModel::search(["product_id" => $eigen_product_ids]) as $contract) {
|
||||
if($contract->termination_id) continue;
|
||||
|
||||
$address = $contract->owner;
|
||||
if(!$address->gps_lat || !$address->gps_long || !$address->laea) {
|
||||
//$address->getCoords();
|
||||
$address->save();
|
||||
}
|
||||
|
||||
$raster = $address->laea;
|
||||
$rtr_code = $contract->product->attributes["rtr_tech_code"]->value;
|
||||
if(substr($rtr_code, 0, 4) == 1431) {
|
||||
$prod_code = 14310;
|
||||
$bb = "1000,00";
|
||||
} elseif(substr($rtr_code, 0, 4) == 1042) {
|
||||
$prod_code = 10420;
|
||||
$bb = "50,00";
|
||||
} else {
|
||||
continue; // incompatible product
|
||||
}
|
||||
$user_count = 1;
|
||||
// get laea
|
||||
|
||||
if(!array_key_exists($raster, $rasterpunkte)) {
|
||||
$rasterpunkte[$raster] = [];
|
||||
}
|
||||
if(!array_key_exists($prod_code, $rasterpunkte[$raster])) {
|
||||
$rasterpunkte[$raster][$prod_code] = [
|
||||
"bb" => $bb,
|
||||
"user_count" => 0
|
||||
];
|
||||
}
|
||||
$rasterpunkte[$raster][$prod_code]["user_count"] += $user_count;
|
||||
|
||||
}
|
||||
|
||||
$csv_header = "rasterid;code;dl_min_max_bb;dl_q25_max_bb;dl_avg_max_bb;dl_max_max_bb;ul_min_max_bb;ul_q25_max_bb;ul_avg_max_bb;ul_max_max_bb;dl_min_n_bb;dl_q25_n_bb;dl_avg_n_bb;dl_avg_n_bb;ul_min_n_bb;ul_q25_n_bb;ul_avg_n_bb;ul_avg_n_bb;anz_anschl_cov";
|
||||
$csv = $csv_header."\n";
|
||||
foreach($rasterpunkte as $rastercode => $raster) {
|
||||
foreach($raster as $prod_code => $data) {
|
||||
$csv .= $rastercode . ";";
|
||||
$csv .= $prod_code . ";";
|
||||
for($i = 0; $i < 16; $i++) {
|
||||
$csv .= $data["bb"] . ";";
|
||||
}
|
||||
$csv .= $data["user_count"];
|
||||
$csv .= "\n";
|
||||
}
|
||||
}
|
||||
|
||||
header("Content-type: text/csv; charset=utf-8");
|
||||
header('Content-disposition: attachment; filename="rtr-A10-report-'.date('Y-m-d_H-i-s').'.csv"');
|
||||
|
||||
echo $csv;
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1042% = radio
|
||||
* 1431% = fiber
|
||||
*/
|
||||
private function getEigenProductIds() {
|
||||
$product_ids = [];
|
||||
|
||||
$sql = "SELECT product_id FROM `ProductAttribute`
|
||||
LEFT JOIN ProducttechAttribute ON (ProductAttribute.producttechattribute_id = ProducttechAttribute.id)
|
||||
WHERE ProducttechAttribute.name='rtr_tech_code'
|
||||
AND (ProductAttribute.value LIKE '1042%' OR ProductAttribute.value LIKE '1431%')";
|
||||
|
||||
$res = $this->db->query($sql);
|
||||
while($data = $this->db->fetch_object($res)) {
|
||||
$product_ids[] = $data->product_id;
|
||||
}
|
||||
|
||||
return $product_ids;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user