This commit is contained in:
邓皓元 2019-10-23 18:06:28 +08:00
parent 420ecb8b3d
commit 3ad17f9d0c

View File

@ -4,181 +4,181 @@ use Illuminate\Support\Carbon;
require_once realpath(dirname(__FILE__) . '/TestCase.php');
function stat_echo_total($sql)
{
$start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01');
// function stat_echo_total($sql)
// {
// $start = Carbon::parse('2018-01-01');
// $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start);
// $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Y-m-d H:i:s')]);
foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// break 2;
}
}
}
// for ($i=0; $i < $j; $i++) {
// $month = $start->copy()->addMonths($i)->endOfMonth();
// $res = DB::select($sql, [$month->format('Y-m-d H:i:s')]);
// foreach ($res as $key => $value) {
// echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// // break 2;
// }
// }
// }
// 总用户数
echo "总用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
where
c.deleted_at is null and
c.refunded_at is null and
c.created_at < ?
group by
p.vehicle
";
// // 总用户数
// echo "总用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.created_at < ?
// group by
// p.vehicle
// ";
stat_echo_total($sql);
// stat_echo_total($sql);
// 2G用户数
echo "2G用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and
pack.flows <= 100
group by
p.vehicle
";
// // 2G用户数
// echo "2G用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.service_start_at < ? and
// pack.flows <= 100
// group by
// p.vehicle
// ";
stat_echo_total($sql);
// stat_echo_total($sql);
// 4G用户数
echo "4G用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
c.deleted_at is null and
c.refunded_at is null and
c.created_at < ? and
pack.flows > 100
group by
p.vehicle
";
// // 4G用户数
// echo "4G用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.created_at < ? and
// pack.flows > 100
// group by
// p.vehicle
// ";
stat_echo_total($sql);
// stat_echo_total($sql);
function stat_echo_service($sql)
{
$start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01');
// function stat_echo_service($sql)
// {
// $start = Carbon::parse('2018-01-01');
// $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start);
// $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Y-m-d H:i:s'), $month->format('Y-m-d H:i:s')]);
foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// break 2;
}
}
}
// for ($i=0; $i < $j; $i++) {
// $month = $start->copy()->addMonths($i)->endOfMonth();
// $res = DB::select($sql, [$month->format('Y-m-d H:i:s'), $month->format('Y-m-d H:i:s')]);
// foreach ($res as $key => $value) {
// echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// // break 2;
// }
// }
// }
// 活跃用户数
echo "活跃用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ?
group by
p.vehicle
";
// // 活跃用户数
// echo "活跃用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.service_start_at < ? and c.service_end_at > ?
// group by
// p.vehicle
// ";
stat_echo_service($sql);
// stat_echo_service($sql);
// 活跃2G用户数
echo "活跃2G用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and
pack.flows <= 100
group by
p.vehicle
";
// // 活跃2G用户数
// echo "活跃2G用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.service_start_at < ? and c.service_end_at > ? and
// pack.flows <= 100
// group by
// p.vehicle
// ";
stat_echo_service($sql);
// stat_echo_service($sql);
// 活跃4G用户数
echo "活跃4G用户数,类型,数量" . PHP_EOL;
$sql = "
select
count(distinct sim),
p.vehicle
from
virtual_order_cards_partition c
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and
pack.flows > 100
group by
p.vehicle
";
// // 活跃4G用户数
// echo "活跃4G用户数,类型,数量" . PHP_EOL;
// $sql = "
// select
// count(distinct sim),
// p.vehicle
// from
// virtual_order_cards_partition c
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// c.deleted_at is null and
// c.refunded_at is null and
// c.service_start_at < ? and c.service_end_at > ? and
// pack.flows > 100
// group by
// p.vehicle
// ";
stat_echo_service($sql);
// stat_echo_service($sql);
@ -217,7 +217,8 @@ join virtual_packages pack on
where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ?
c.service_start_at < ? and c.service_end_at > ? and
pack.flowed = 0
group by
p.vehicle
";
@ -243,7 +244,8 @@ where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and
pack.flows <= 100
pack.flows <= 100 and
pack.flowed = 0
group by
p.vehicle
";
@ -269,7 +271,8 @@ where
c.deleted_at is null and
c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and
pack.flows > 100
pack.flows > 100 and
pack.flowed = 0
group by
p.vehicle
";
@ -277,94 +280,94 @@ group by
stat_echo_price($sql);
function stat_echo_flow($sql)
{
$start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01');
// function stat_echo_flow($sql)
// {
// $start = Carbon::parse('2018-01-01');
// $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start);
// $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Ym')]);
foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . sprintf("%.02f", $value->avg) . PHP_EOL;
// break 2;
}
}
}
// for ($i=0; $i < $j; $i++) {
// $month = $start->copy()->addMonths($i)->endOfMonth();
// $res = DB::select($sql, [$month->format('Ym')]);
// foreach ($res as $key => $value) {
// echo $month->format('Y-m') . ',' . $value->vehicle . ',' . sprintf("%.02f", $value->avg) . PHP_EOL;
// // break 2;
// }
// }
// }
// 用户平均使用流量
echo "用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = "
select
avg(f.mebibyte),
p.vehicle
from
virtual_flow_pool_months f
join virtual_order_cards c on
f.sim = c.sim
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
f.month = ?
group by
p.vehicle
";
// // 用户平均使用流量
// echo "用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
// $sql = "
// select
// avg(f.mebibyte),
// p.vehicle
// from
// virtual_flow_pool_months f
// join virtual_order_cards c on
// f.sim = c.sim
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// f.month = ?
// group by
// p.vehicle
// ";
stat_echo_flow($sql);
// stat_echo_flow($sql);
// 2G用户平均使用流量
echo "2G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = "
select
avg(f.mebibyte),
p.vehicle
from
virtual_flow_pool_months f
join virtual_order_cards c on
f.sim = c.sim
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
f.month = ? and
pack.flows <= 100
group by
p.vehicle
";
// // 2G用户平均使用流量
// echo "2G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
// $sql = "
// select
// avg(f.mebibyte),
// p.vehicle
// from
// virtual_flow_pool_months f
// join virtual_order_cards c on
// f.sim = c.sim
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// f.month = ? and
// pack.flows <= 100
// group by
// p.vehicle
// ";
stat_echo_flow($sql);
// stat_echo_flow($sql);
// 4G用户平均使用流量
echo "4G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = "
select
avg(f.mebibyte),
p.vehicle
from
virtual_flow_pool_months f
join virtual_order_cards c on
f.sim = c.sim
join virtual_properties p on
p.company_id = c.company_id and
p.package_id = c.package_id
join virtual_packages pack on
pack.id = c.package_id and
pack.deleted_at is null
where
f.month = ? and
pack.flows > 100
group by
p.vehicle
";
// // 4G用户平均使用流量
// echo "4G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
// $sql = "
// select
// avg(f.mebibyte),
// p.vehicle
// from
// virtual_flow_pool_months f
// join virtual_order_cards c on
// f.sim = c.sim
// join virtual_properties p on
// p.company_id = c.company_id and
// p.package_id = c.package_id
// join virtual_packages pack on
// pack.id = c.package_id and
// pack.deleted_at is null
// where
// f.month = ? and
// pack.flows > 100
// group by
// p.vehicle
// ";
stat_echo_flow($sql);
// stat_echo_flow($sql);