From db4fac819945b51a057d9a468491e205a26ada2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B9=E8=AF=9A=E8=AF=9A?= Date: Mon, 19 Jun 2017 15:42:01 +0800 Subject: [PATCH] =?UTF-8?q?pagespeed=E5=88=86=E6=95=B0=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=92=8C=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pagespeed/controllers/index.php | 30 +++++- .../pagespeed/models/PageSpeedData_model.php | 49 ++++++++- .../third_party/pagespeed/views/search.php | 43 ++++++++ .../third_party/pagespeed/views/welcome.php | 102 ++++++++++++++---- application/views/bootstrap/header.php | 3 +- application/views/bootstrap3/header.php | 1 + 6 files changed, 201 insertions(+), 27 deletions(-) create mode 100644 application/third_party/pagespeed/views/search.php diff --git a/application/third_party/pagespeed/controllers/index.php b/application/third_party/pagespeed/controllers/index.php index c3ffcc6c..84e81a3f 100644 --- a/application/third_party/pagespeed/controllers/index.php +++ b/application/third_party/pagespeed/controllers/index.php @@ -11,7 +11,27 @@ class Index extends CI_Controller { } public function index() { + $this->permission->is_admin(); + $data = array(); + $data['score_data'] = $this->PageSpeedData_model->score_chart($this->config->item('site_code')); + $this->load->view('bootstrap3/header', $data); $this->load->view('welcome'); + $this->load->view('bootstrap3/footer'); + } + + //根据分数段来查询页面 + public function search_score() { + $this->permission->is_admin(); + $data = array(); + $device = $this->input->post('device'); + $start_score = $this->input->post('start_score'); + $end_score = $this->input->post('end_score'); + $data['score_data_list'] = $this->PageSpeedData_model->search_score_list($start_score, $end_score, $device, $this->config->item('site_code')); + if (empty($data['score_data_list'])) { + echo json_encode('没有找到数据'); + } else { + echo json_encode($this->load->view('search', $data, true)); + } } //自动抓取分数和排名 @@ -20,11 +40,13 @@ class Index extends CI_Controller { $this->PageSpeedData_model->insert_list($sitecode); $update_list = $this->PageSpeedData_model->get_update_list($sitecode, 2); if (empty($update_list)) { - echo 'all done!'; + echo'all done!'; return; } + foreach ($update_list as $item) { - $this->run($item->psd_URL, $item->psd_SiteCode); + $this->run($item->psd_URL, $item-> + psd_SiteCode); } } @@ -37,7 +59,8 @@ class Index extends CI_Controller { } $pagespeed_data = $this->PageSpeedData_model->detail($psd_URL, $psd_SiteCode); if (!empty($pagespeed_data)) { - echo json_encode(array('result' => 'ok', 'data' => 'M:' . $pagespeed_data->psd_MobileScore . ',D:' . $pagespeed_data->psd_DesktopScore)); + echo json_encode(array('result' => 'ok', 'data' => 'M:' . $pagespeed_data->psd_MobileScore . ',D:' . $pagespeed_data-> + psd_DesktopScore)); } } @@ -47,6 +70,7 @@ class Index extends CI_Controller { $psd_SiteCode = $this->input->get_post('psd_SiteCode'); if (empty($psd_URL) || empty($psd_SiteCode)) { echo json_encode(array('result' => 'error', 'data' => 'url或站点为空')); + return false; } } diff --git a/application/third_party/pagespeed/models/PageSpeedData_model.php b/application/third_party/pagespeed/models/PageSpeedData_model.php index 5ba8e070..e8008b85 100644 --- a/application/third_party/pagespeed/models/PageSpeedData_model.php +++ b/application/third_party/pagespeed/models/PageSpeedData_model.php @@ -56,7 +56,7 @@ class PageSpeedData_model extends CI_Model { ORDER BY ic.ic_datetime ASC "; - $this->INFO->query($sql,array($psd_SiteCode)); + $this->INFO->query($sql, array($psd_SiteCode)); } public function get_update_list($psd_SiteCode, $topnum = 3) { @@ -124,4 +124,51 @@ class PageSpeedData_model extends CI_Model { } } + public function search_score_list($start_score, $end_score, $psd_SiteCode, $device = 'moblie') { + $this->init(); + $this->topnum = 50; + $this->where = ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode); + if ($device == 'moblie') { + $this->where = " AND psd.psd_MobileScore BETWEEN $start_score AND $end_score "; + $this->orderby = ' ORDER BY psd_MobileScore ASC '; + } else { + $this->where = " AND psd.psd_DesktopScore BETWEEN $start_score AND $end_score "; + $this->orderby = ' ORDER BY psd_DesktopScore ASC '; + } + return $this->get_list(); + } + + //分数段统计 + public function score_chart($psd_SiteCode) { + $sql = " + SELECT COUNT(psd.psd_id) AS [page_count] + ,AVG(psd.psd_DesktopScore)AS [d_avg] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 96 AND 100 THEN 1 END) AS [d96_100] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 90 AND 95 THEN 1 END) AS [d90_95] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 86 AND 89 THEN 1 END) AS [d86_89] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 80 AND 85 THEN 1 END) AS [d80_85] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 70 AND 79 THEN 1 END) AS [d70_79] + ,COUNT(CASE WHEN psd.psd_DesktopScore BETWEEN 60 AND 69 THEN 1 END) AS [d60_69] + ,COUNT(CASE WHEN psd.psd_DesktopScore<60 THEN 1 END) AS [d60_0] + ,AVG(psd.psd_MobileScore)AS [m_avg] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 96 AND 100 THEN 1 END) AS [m96_100] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 90 AND 95 THEN 1 END) AS [m90_95] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 86 AND 89 THEN 1 END) AS [m86_89] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 80 AND 85 THEN 1 END) AS [m80_85] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 70 AND 79 THEN 1 END) AS [m70_79] + ,COUNT(CASE WHEN psd.psd_MobileScore BETWEEN 60 AND 69 THEN 1 END) AS [m60_69] + ,COUNT(CASE WHEN psd.psd_MobileScore<60 THEN 1 END) AS [m60_0] + FROM PageSpeedData psd + WHERE 1=1 + AND psd.psd_SiteCode=? + "; + $query = $this->INFO->query($sql, array($psd_SiteCode)); + if ($query->num_rows() > 0) { + $row = $query->row(); + return $row; + } else { + return FALSE; + } + } + } diff --git a/application/third_party/pagespeed/views/search.php b/application/third_party/pagespeed/views/search.php new file mode 100644 index 00000000..1d4dac44 --- /dev/null +++ b/application/third_party/pagespeed/views/search.php @@ -0,0 +1,43 @@ + $item) { + +} +?> + + +
+ + + + + + + + + + + + + config->item('site_url'), '/'); + if (!empty($score_data_list)) { + foreach ($score_data_list as $key => $item) { + ?> + + + + + + + + + + + +
#页面移动端桌面端更新时间操作
psd_URL; ?>psd_MobileScore; ?>psd_DesktopScore; ?>psd_Datetime)); ?> + 查看页面 | Google insights +
+
\ No newline at end of file diff --git a/application/third_party/pagespeed/views/welcome.php b/application/third_party/pagespeed/views/welcome.php index e18468fd..b709651e 100644 --- a/application/third_party/pagespeed/views/welcome.php +++ b/application/third_party/pagespeed/views/welcome.php @@ -1,22 +1,80 @@ - - - - - - - - HTML-Compressor - - - -

页面样式精简

-
-

- - -
- - - + + + +
+ +根据分数搜索页面 + + +
+ + \ No newline at end of file diff --git a/application/views/bootstrap/header.php b/application/views/bootstrap/header.php index 6b471097..0789cad2 100644 --- a/application/views/bootstrap/header.php +++ b/application/views/bootstrap/header.php @@ -73,11 +73,12 @@ 更多 diff --git a/application/views/bootstrap3/header.php b/application/views/bootstrap3/header.php index 8d164b96..c5ef8df2 100644 --- a/application/views/bootstrap3/header.php +++ b/application/views/bootstrap3/header.php @@ -77,6 +77,7 @@ 更多