本文整理汇总了Python中DBUtil.select_log_count_by_ip方法的典型用法代码示例。如果您正苦于以下问题:Python DBUtil.select_log_count_by_ip方法的具体用法?Python DBUtil.select_log_count_by_ip怎么用?Python DBUtil.select_log_count_by_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBUtil
的用法示例。
在下文中一共展示了DBUtil.select_log_count_by_ip方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simple_features
# 需要导入模块: import DBUtil [as 别名]
# 或者: from DBUtil import select_log_count_by_ip [as 别名]
def simple_features():
log_list = DBUtil.select_all_logs()
count_dict = DBUtil.select_log_count_by_ip()
mysql_conn = DBUtil.get_mysql_conn()
cur = mysql_conn.cursor()
index = 0
for log in log_list:
index = index + 1
if index % 1000 == 0:
print index
visitDuration = int(log.time_taken_ms)
bytesTransfer = int(log.sc_bytes) + int(log.cs_bytes)
urlLength = 0
space_index = log.cs_uri.find(" ")
if space_index != -1:
urlLength = len(log.cs_uri[space_index:])
if log.c_ip == "":
numIP = 0
else:
numIP = count_dict[log.c_ip]
cur.execute(
"INSERT INTO Features (id, c_ip, visitDuration, numIP, bytesTransfer, urlLength) VALUES (%s, %s, %s, %s, %s, %s) ON DUPLICATE KEY UPDATE visitDuration=VALUES(visitDuration), numIP=VALUES(numIP), bytesTransfer=VALUES(bytesTransfer), urlLength=VALUES(urlLength)",
(log.id, log.c_ip, visitDuration, numIP, bytesTransfer, urlLength))
mysql_conn.commit()
cur.close()
mysql_conn.close()