You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/third_party/pagespeed/models/PageSpeedData_model.php

178 lines
7.0 KiB
PHTML

<?php
class PageSpeedData_model extends CI_Model {
var $topnum = false; //返回记录数
var $orderby = false;
var $where = false; //查询条件
function __construct() {
parent::__construct();
$this->HT = $this->load->database('HT', TRUE);
$this->INFO = $this->load->database('INFO', TRUE);
}
public function init() {
$this->topnum = false;
$this->where = false;
$this->orderby = ' ORDER BY psd_Datetime ASC ';
}
public function detail($psd_URL, $psd_SiteCode) {
$this->init();
$this->topnum = 1;
$this->where = ' AND psd.psd_URL=N' . $this->INFO->escape($psd_URL);
$this->where .= ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode);
return $this->get_list();
}
public function add($table, $data) {
if ($this->INFO->insert($table, $data)) {
return $this->INFO->last_id($table);
} else {
return false;
}
}
public function insert_list($psd_SiteCode) {
$sql = "
INSERT INTO PageSpeedData
(
psd_URL
,psd_SiteCode
)
8 years ago
SELECT TOP 200 ic.ic_url
,ic.ic_sitecode
FROM Tourmanager.dbo.infoContents ic
WHERE ic.ic_status = 1
AND ic.ic_url<>''
AND ic.ic_sitecode = ?
AND NOT EXISTS(
SELECT TOP 1 1
FROM PageSpeedData psd
WHERE psd.psd_URL = ic.ic_url
AND psd.psd_SiteCode = ic.ic_sitecode
)
ORDER BY
8 years ago
ic.ic_datetime ASC
";
$this->INFO->query($sql, array($psd_SiteCode));
}
public function get_update_list($psd_SiteCode, $topnum = 3) {
$this->init();
$this->topnum = $topnum;
$this->where = ' AND psd.psd_SiteCode=' . $this->INFO->escape($psd_SiteCode);
$this->where .= ' AND ISNULL(psd.psd_Datetime,1999) < GETDATE()-1 ';
$this->where .= ' AND psd.psd_ErrorCount<=3';
$this->orderby = ' ORDER BY psd_Datetime ASC ';
return $this->get_list();
}
public function update($table, $data, $where) {
$this->INFO->update($table, $data, $where);
}
//记录错误次数
public function update_error($psd_id) {
$sql = "
UPDATE PageSpeedData
SET psd_ErrorCount = psd_ErrorCount+1
, psd_Datetime=GETDATE()
WHERE psd_id = ?
";
$this->INFO->query($sql, array($psd_id));
//删除错误数大于3的数据保持没有冗余数据 ,不删除,很多页面信息平台发布了,但是网前删除了
//$sql = " DELETE FROM PageSpeedData WHERE psd_ErrorCount>3 ";
// $this->INFO->query($sql);
}
//删除数据
// public function delete($psd_id) {
// $sql = " DELETE FROM PageSpeedData WHERE psd_id=? ";
// return $this->INFO->query($sql, array($psd_id));
// }
public function get_list() {
$this->topnum ? $sql = "SELECT TOP " . $this->topnum : $sql = "SELECT ";
$sql .= "
psd.psd_id,
psd.psd_DesktopScore,
psd.psd_MobileScore,
psd.psd_DesktopData,
psd.psd_MobileData,
psd.psd_URL,
psd.psd_Datetime,
psd.psd_SiteCode,
psd.psd_ErrorCount
FROM
PageSpeedData psd
WHERE 1 = 1
";
$this->where ? $sql.=$this->where : false;
$this->orderby ? $sql.=$this->orderby : false;
$query = $this->INFO->query($sql);
//print_r($this->INFO->queries);
if ($this->topnum === 1) {
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
} else {
return $query->result();
}
}
public function search_score_list($start_score, $end_score, $psd_SiteCode, $device = 'moblie') {
$this->init();
$this->topnum = 150;
$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 ';
}
$this->where .= " AND psd.psd_ErrorCount<=3 ";
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=?
AND psd.psd_ErrorCount<=3
";
$query = $this->INFO->query($sql, array($psd_SiteCode));
if ($query->num_rows() > 0) {
$row = $query->row();
return $row;
} else {
return FALSE;
}
}
}