|
@@ -1,39 +1,92 @@
|
|
|
#!/usr/bin/python
|
|
|
# -*- coding=utf-8 -*-
|
|
|
# @Create Time: 2024-01-18 09:47:28
|
|
|
-# @Last Modified time: 2024-01-23 11:53:14
|
|
|
+# @Last Modified time: 2024-02-02 13:37:27
|
|
|
|
|
|
-import re
|
|
|
+import re, json
|
|
|
import datetime
|
|
|
import dmPython
|
|
|
+import numpy as np
|
|
|
import pandas as pd
|
|
|
+import requests
|
|
|
from pandas import DataFrame
|
|
|
from threading import Thread
|
|
|
from .preprocess import parse_url
|
|
|
from .UserActivateDegreeAnalyze import UserActivateDegreeAnalyzeSpace
|
|
|
|
|
|
+
|
|
|
+class ResultJson:
|
|
|
+ def __init__(self, time, user_id, domain, title1, title2, title3, device_id=None, text=None, is_op=True, is_bus=False, is_bias=False, status="正常"):
|
|
|
+ # 执行时间
|
|
|
+ self.time = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
+ # 执行用户
|
|
|
+ self.user_id = user_id
|
|
|
+ # 执行域
|
|
|
+ self.domain = domain
|
|
|
+ self.title1 = title1
|
|
|
+ self.title2 = title2
|
|
|
+ # 业务项
|
|
|
+ self.title3 = title3
|
|
|
+ # 设备
|
|
|
+ self.device_id = device_id
|
|
|
+ # 操作步骤
|
|
|
+ self.text = text
|
|
|
+ # 是否用户操作
|
|
|
+ self.is_op = is_op
|
|
|
+ # 是否业务
|
|
|
+ self.is_bus = is_bus
|
|
|
+ # 是否偏离
|
|
|
+ self.is_bias = is_bias
|
|
|
+ # 执行结果
|
|
|
+ self.status = status
|
|
|
+
|
|
|
+ def to_json(self):
|
|
|
+ return {
|
|
|
+ "real": { # 实时信息
|
|
|
+ "time": self.time, # 记录时间
|
|
|
+ "userId": self.user_id, # 用户ID
|
|
|
+ "deviceId": self.device_id, # 设备ID
|
|
|
+ "domain": self.domain, # 访问域
|
|
|
+ "business": self.title3, # 业务类型
|
|
|
+ "option": self.text, # 执行操作
|
|
|
+ "isOp": self.is_op, # 是否是一条操作
|
|
|
+ "isBus": self.is_bus, # 是否是一项业务
|
|
|
+ "isBias": self.is_bias, # 是否偏离
|
|
|
+ "status": self.status # 执行结果
|
|
|
+ },
|
|
|
+ "base": { # 定时信息
|
|
|
+ "用户ID": self.user_id,
|
|
|
+ "常用时段": "",
|
|
|
+ "所在部门": "",
|
|
|
+ "使用设备": "",
|
|
|
+ "操作系统": "",
|
|
|
+ "常用业务": ""
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
def func(item):
|
|
|
print(item)
|
|
|
session = DM8Session()
|
|
|
try:
|
|
|
- result = session.insert("""INSERT INTO FRAGMENT("Time", "User_Id", "Method", "Has_Form", "Dom", "Title1", "Title2", "Title3", "Title4", "Behavior", "Stay") VALUES(?,?,?,?,?,?,?,?,?,?,?)""",
|
|
|
- (item['time'],item['user'],item['method'],item['hasform'],item['domain'],item['一级标题'],item['二级标题'],item['三级标题'],item['四级标题'],item['text'], item['stay']))
|
|
|
+ result = session.execute("""INSERT INTO FRAGMENT("Time", "User_Id", "Method", "Has_Form", "Dom", "Title1", "Title2", "Title3", "Title4", "Behavior", "Stay") VALUES(?,?,?,?,?,?,?,?,?,?,?)""",
|
|
|
+ (item['time'], item['user'], item['method'], item['hasform'], item['domain'], item['一级标题'], item['二级标题'], item['三级标题'], item['四级标题'], item['text'], item['stay']))
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
-# class filteredRealTimeLogDStream(object):
|
|
|
-# time: str
|
|
|
-# user_id: str
|
|
|
-# method: str
|
|
|
-# hasform: bool
|
|
|
-# domain: str
|
|
|
-# title1: str
|
|
|
-# title2: str
|
|
|
-# title3: str
|
|
|
-# title4: str
|
|
|
-# behavior: str
|
|
|
-# stay: int = 0
|
|
|
+def postback(json_data: dict) -> None:
|
|
|
+ url = 'http://192.168.1.166:8080/statistics/algorithm'
|
|
|
+ data = ResultJson(time=datetime.datetime.now(), user_id="fuli@mz.gd.csg.cn", domain="财务域",
|
|
|
+ title1="计划预算管理", title2="预算查询分析", title3="编制过程查询", text="69", is_op=True, is_bus=True)
|
|
|
+
|
|
|
+ print(data.to_json())
|
|
|
+ response = requests.post(url, json={'parameter': data.to_json()})
|
|
|
+
|
|
|
+ if response.status_code == 200:
|
|
|
+ print('success')
|
|
|
+ else:
|
|
|
+ print(response.text())
|
|
|
|
|
|
|
|
|
class DM8Session(object):
|
|
@@ -57,7 +110,7 @@ class DM8Session(object):
|
|
|
self.cursor.close()
|
|
|
return df
|
|
|
|
|
|
- def insert(self, sql_cmd: str, args):
|
|
|
+ def execute(self, sql_cmd: str, args):
|
|
|
try:
|
|
|
self.cursor = self.conn.cursor()
|
|
|
# 执行sql语句
|
|
@@ -73,20 +126,6 @@ class DM8Session(object):
|
|
|
self.cursor.close()
|
|
|
return status
|
|
|
|
|
|
- def update(self, sql_cmd: str, args):
|
|
|
- try:
|
|
|
- self.cursor = self.conn.cursor()
|
|
|
- self.cursor.execute(sql_cmd, args)
|
|
|
- self.conn.commit()
|
|
|
- status = True
|
|
|
- except Exception as e:
|
|
|
- self.conn.rollback()
|
|
|
- print(e)
|
|
|
- status = False
|
|
|
- finally:
|
|
|
- self.cursor.close()
|
|
|
- return status
|
|
|
-
|
|
|
def __del__(self):
|
|
|
self.conn.close()
|
|
|
|
|
@@ -107,14 +146,60 @@ class UrlParser(object):
|
|
|
|
|
|
def process_record(self, item: dict):
|
|
|
i = item['Current_Url']
|
|
|
- j = item['Target_Url']
|
|
|
|
|
|
- # result = item
|
|
|
result = None
|
|
|
|
|
|
if i[1] == '10.10.21.23':
|
|
|
result = {'domain': '人资域'}
|
|
|
- if i[5].get("appCode"):
|
|
|
+ if i[2] == '/gmp/login.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '人资域',
|
|
|
+ '一级标题': '人资域登录',
|
|
|
+ '二级标题': '人资域登录',
|
|
|
+ '三级标题': '人资域登录',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ elif i[2] == '/gmp/static/gmpweb/hrIndex.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '人资域',
|
|
|
+ '一级标题': '人资域首页',
|
|
|
+ '二级标题': '人资域首页',
|
|
|
+ '三级标题': '人资域首页',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ elif i[2] == '/gmp/static/gmpweb/workbench/todo/TodoCenter.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '人资域',
|
|
|
+ '一级标题': '人资域',
|
|
|
+ '二级标题': '公共应用',
|
|
|
+ '三级标题': '代办中心',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ elif i[2] == 'hrcore_web/labormanagement/contractagreementview/myAgreement.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '人资域',
|
|
|
+ '一级标题': '人资域',
|
|
|
+ '二级标题': '个人应用',
|
|
|
+ '三级标题': '我的协议',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ elif i[5].get("appCode"):
|
|
|
task = self.rzdf.query(f'''path == "{i[2]}" & appCode == "{i[5]['appCode'][0]}"''')
|
|
|
result = {
|
|
|
'time': item['Record_Time'],
|
|
@@ -127,9 +212,23 @@ class UrlParser(object):
|
|
|
'三级标题': task['三级标题'].values[0],
|
|
|
'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
}
|
|
|
+ else: # 后续使用 iframe 处理
|
|
|
+ pass
|
|
|
elif i[1] == '10.10.21.28':
|
|
|
result = {'domain': '资产域'}
|
|
|
- if i[5].get('appCode'):
|
|
|
+ if i[2] == '/gmp/static/gmpweb/index.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '资产域',
|
|
|
+ '一级标题': '资产域首页',
|
|
|
+ '二级标题': '资产域首页',
|
|
|
+ '三级标题': '资产域首页',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ elif i[5].get('appCode'):
|
|
|
task = self.zcdf.query(f'''path == "{i[2]}" & appCode == "{i[5]['appCode'][0]}"''')
|
|
|
result = {
|
|
|
'time': item['Record_Time'],
|
|
@@ -144,7 +243,43 @@ class UrlParser(object):
|
|
|
}
|
|
|
elif i[1] == 'fms.gmp.cloud.hq.iv.csg':
|
|
|
result = {'domain': '财务域'}
|
|
|
- if i[5].get('appCode'):
|
|
|
+ if i[2] == '/gmp/login.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '财务域',
|
|
|
+ '一级标题': '登录财务域',
|
|
|
+ '二级标题': '登录财务域',
|
|
|
+ '三级标题': '登录财务域',
|
|
|
+ 'text': item['Button_Text']
|
|
|
+ }
|
|
|
+ elif i[2] == '/gmp/index.html':
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '财务域',
|
|
|
+ '一级标题': '财务域首页',
|
|
|
+ '二级标题': '财务域首页',
|
|
|
+ '三级标题': '财务域首页',
|
|
|
+ 'text': item['Button_Text']
|
|
|
+ }
|
|
|
+ elif i[2] == '/gmp/': # 待确认
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '财务域',
|
|
|
+ '一级标题': '财务域认证',
|
|
|
+ '二级标题': '财务域认证',
|
|
|
+ '三级标题': '财务域认证',
|
|
|
+ 'text': item['Button_Text']
|
|
|
+ }
|
|
|
+ elif i[5].get('appCode'):
|
|
|
task = self.cwdf.query(f'''path == "{i[2]}" & appCode == "{i[5]['appCode'][0]}"''')
|
|
|
result = {
|
|
|
'time': item['Record_Time'],
|
|
@@ -155,73 +290,95 @@ class UrlParser(object):
|
|
|
'一级标题': task['一级标题'].values[0],
|
|
|
'二级标题': task['二级标题'].values[0],
|
|
|
'三级标题': task['三级标题'].values[0],
|
|
|
- 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ 'text': item['Button_Text']
|
|
|
}
|
|
|
elif i[1] == '10.150.23.1:8010':
|
|
|
result = {'domain': '营销域'}
|
|
|
- fd = item['Form_Data']
|
|
|
- if item['Form_Data'] and item['Form_Data'] != 'None':
|
|
|
- try:
|
|
|
- if item['Form_Data'][0] != "{":
|
|
|
- item["Params_Data"] = item['Form_Data']
|
|
|
- form_data = None
|
|
|
- else:
|
|
|
- item['Form_Data'] = item['Form_Data'].replace("\"remark\":\"[", "\"remark\":\"\"[")
|
|
|
- item['Form_Data'] = item['Form_Data'].replace("\"[", "[").replace("]\"", "]").replace("\"{", "{").replace("}\"", "}")
|
|
|
- item['Form_Data'] = item['Form_Data'].replace("object HTMLInputElement", "").replace("[null]", "[]").replace("\"null\"", "\"\"")
|
|
|
- item['Form_Data'] = item['Form_Data'].replace("\n", "")
|
|
|
- form_data = json.loads(item['Form_Data'])
|
|
|
- except Exception as e:
|
|
|
- logging.error(item['Form_Data'])
|
|
|
- logging.error(fd)
|
|
|
- form_data = None
|
|
|
- raise e
|
|
|
- else:
|
|
|
- form_data = None
|
|
|
-
|
|
|
- if form_data and '_INVOKE_FUNC_TITLE_' in form_data:
|
|
|
- title = form_data['_INVOKE_FUNC_TITLE_'][0]
|
|
|
- appcontext = form_data['_INVOKE_FUNC_URL_'][0].split('/')[1]
|
|
|
- logging.debug(appcontext)
|
|
|
- task = self.yxdf.query(f'''四级标题 == "{title}" & appcontext == "{appcontext}"''')
|
|
|
- if task.empty:
|
|
|
- task = self.yxdf.query(f'''三级标题 == "{title}" & appcontext == "{appcontext}"''')
|
|
|
- if task.empty:
|
|
|
- task = self.yxdf.query(f'''四级标题 == "{title}"''')
|
|
|
- if task.empty:
|
|
|
- task = self.yxdf.query(f'''三级标题 == "{title}"''')
|
|
|
- try:
|
|
|
- result = {
|
|
|
- 'time': item['Record_Time'],
|
|
|
- 'user': item['User_Id'],
|
|
|
- 'method': item['Request_Method'],
|
|
|
- 'hasform': True,
|
|
|
- 'domain': '营销域',
|
|
|
- '一级标题': task['一级标题'].values[0],
|
|
|
- '二级标题': task['二级标题'].values[0],
|
|
|
- '三级标题': task['三级标题'].values[0],
|
|
|
- '四级标题': task['四级标题'].values[0],
|
|
|
- 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
- }
|
|
|
- except Exception as e:
|
|
|
- logging.error(task)
|
|
|
- logging.error(item['Form_Data'])
|
|
|
- logging.error(title)
|
|
|
- logging.error(e)
|
|
|
- logging.error(form_data['_INVOKE_FUNC_URL_'][0])
|
|
|
- else:
|
|
|
+ if i[2] == '/PMS/login.do':
|
|
|
result = {
|
|
|
'time': item['Record_Time'],
|
|
|
'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
'domain': '营销域',
|
|
|
- 'hasform': False,
|
|
|
+ '一级标题': '营销域登录',
|
|
|
+ '二级标题': '营销域登录',
|
|
|
+ '三级标题': '营销域登录',
|
|
|
'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
}
|
|
|
+ else:
|
|
|
+ fd = item['Form_Data']
|
|
|
+ if item['Form_Data'] and item['Form_Data'] != 'None':
|
|
|
+ try:
|
|
|
+ if item['Form_Data'][0] != "{":
|
|
|
+ item["Params_Data"] = item['Form_Data']
|
|
|
+ form_data = None
|
|
|
+ else:
|
|
|
+ item['Form_Data'] = item['Form_Data'].replace("\"remark\":\"[", "\"remark\":\"\"[")
|
|
|
+ item['Form_Data'] = item['Form_Data'].replace("\"[", "[").replace("]\"", "]").replace("\"{", "{").replace("}\"", "}")
|
|
|
+ item['Form_Data'] = item['Form_Data'].replace("object HTMLInputElement", "").replace("[null]", "[]").replace("\"null\"", "\"\"")
|
|
|
+ item['Form_Data'] = item['Form_Data'].replace("\n", "")
|
|
|
+ form_data = json.loads(item['Form_Data'])
|
|
|
+ except Exception as e:
|
|
|
+ logging.error(item['Form_Data'])
|
|
|
+ logging.error(fd)
|
|
|
+ form_data = None
|
|
|
+ raise e
|
|
|
+ else:
|
|
|
+ form_data = None
|
|
|
+ if form_data and '_INVOKE_FUNC_TITLE_' in form_data:
|
|
|
+ title = form_data['_INVOKE_FUNC_TITLE_'][0]
|
|
|
+ appcontext = form_data['_INVOKE_FUNC_URL_'][0].split('/')[1]
|
|
|
+ logging.debug(appcontext)
|
|
|
+ task = self.yxdf.query(f'''四级标题 == "{title}" & appcontext == "{appcontext}"''')
|
|
|
+ if task.empty:
|
|
|
+ task = self.yxdf.query(f'''三级标题 == "{title}" & appcontext == "{appcontext}"''')
|
|
|
+ if task.empty:
|
|
|
+ task = self.yxdf.query(f'''四级标题 == "{title}"''')
|
|
|
+ if task.empty:
|
|
|
+ task = self.yxdf.query(f'''三级标题 == "{title}"''')
|
|
|
+ try:
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True,
|
|
|
+ 'domain': '营销域',
|
|
|
+ '一级标题': task['一级标题'].values[0],
|
|
|
+ '二级标题': task['二级标题'].values[0],
|
|
|
+ '三级标题': task['三级标题'].values[0],
|
|
|
+ '四级标题': task['四级标题'].values[0],
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
+ except Exception as e:
|
|
|
+ logging.error(task)
|
|
|
+ logging.error(item['Form_Data'])
|
|
|
+ logging.error(title)
|
|
|
+ logging.error(e)
|
|
|
+ logging.error(form_data['_INVOKE_FUNC_URL_'][0])
|
|
|
+ else:
|
|
|
+ result = {
|
|
|
+ 'time': item['Record_Time'],
|
|
|
+ 'user': item['User_Id'],
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': False,
|
|
|
+ 'domain': '营销域',
|
|
|
+ '一级标题': '登录门户',
|
|
|
+ '二级标题': '登录门户',
|
|
|
+ '三级标题': '登录门户',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
+ }
|
|
|
elif i[1] == '4a.gd.csg.local':
|
|
|
result = {
|
|
|
'time': item['Record_Time'],
|
|
|
'user': item['User_Id'],
|
|
|
- '域': '登录门户'
|
|
|
+ 'method': item['Request_Method'],
|
|
|
+ 'hasform': True if item['Form_Data'] else False,
|
|
|
+ 'domain': '登录门户',
|
|
|
+ '一级标题': '登录门户',
|
|
|
+ '二级标题': '登录门户',
|
|
|
+ '三级标题': '登录门户',
|
|
|
+ 'text': item['Button_Text'] if item['Button_Text'] else None
|
|
|
}
|
|
|
return result
|
|
|
|
|
@@ -290,7 +447,7 @@ class UserVisitAnalyzeSpace(object):
|
|
|
# index += 1
|
|
|
# dt.iloc[index] = d2
|
|
|
# session = DM8Session()
|
|
|
- # result = session.insert("""INSERT INTO FRAGMENT("Time", "User_Id", "Dom", "Title1", "Title2", "Title3", "Title4", "Behavior", "Stay") VALUES(?,?,?,?,?,?,?,?)""",
|
|
|
+ # result = session.execute("""INSERT INTO FRAGMENT("Time", "User_Id", "Dom", "Title1", "Title2", "Title3", "Title4", "Behavior", "Stay") VALUES(?,?,?,?,?,?,?,?)""",
|
|
|
# args=(d1['time'], d1['user'], d1['domain'], d1['一级标题'], d1['二级标题'], d1['三级标题'], d1.get('四级标题'), d1['text'], d1['stay']))
|
|
|
# else:
|
|
|
# dt.iloc[index] = d1
|
|
@@ -331,7 +488,7 @@ class UserVisitAnalyzeSpace(object):
|
|
|
"""
|
|
|
pass
|
|
|
|
|
|
- def getClickCategory2Count(self):# -> DataFrame
|
|
|
+ def getClickCategory2Count(self) -> DataFrame:
|
|
|
"""获取各分类点击次数
|
|
|
1、过滤出点击行为数据,点击数据只占总数据的一小部分,所以过滤后数据可能不均匀
|
|
|
"""
|
|
@@ -392,7 +549,7 @@ class BusinessClickRealTimeSpace(object):
|
|
|
session = DM8Session()
|
|
|
for row in self.aggregatedDStream.itertuples():
|
|
|
try:
|
|
|
- result = session.insert("""INSERT INTO TOTALVISIT("Name", "Count") VALUES(?,?)""", (row.word, row.count))
|
|
|
+ result = session.execute("""INSERT INTO TOTALVISIT("Name", "Count") VALUES(?,?)""", (row.word, row.count))
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
return self.aggregatedDStream
|
|
@@ -408,36 +565,36 @@ class BusinessClickRealTimeSpace(object):
|
|
|
"""
|
|
|
pass
|
|
|
|
|
|
+# 字典键首字母大写
|
|
|
+# def capital_to_higher(dict_info):
|
|
|
+# new_dict = {}
|
|
|
+# for i, j in dict_info.items():
|
|
|
+# new_dict[re.sub("([a-zA-Z])", lambda x: x.groups()[0].upper(), i, 1)] = j
|
|
|
+# return new_dict
|
|
|
|
|
|
-# class PageOneStepSpace(object):
|
|
|
-# def __init__(self):
|
|
|
-# pass
|
|
|
-
|
|
|
-# def getSession2Action(self):
|
|
|
-# """获取<session,用户访问行为>格式的数据
|
|
|
-# """
|
|
|
-# pass
|
|
|
-
|
|
|
-# def persistConvertRate(self):
|
|
|
-# """持久转化率
|
|
|
-# """
|
|
|
-# pass
|
|
|
-
|
|
|
-
|
|
|
-def capital_to_higher(dict_info):
|
|
|
+# 字典键全改小写
|
|
|
+def capital_to_lower(dict_info):
|
|
|
new_dict = {}
|
|
|
for i, j in dict_info.items():
|
|
|
- new_dict[re.sub("([a-zA-Z])", lambda x: x.groups()[0].upper(), i, 1)] = j
|
|
|
+ new_dict[i.lower()] = j
|
|
|
return new_dict
|
|
|
|
|
|
-
|
|
|
def predict(g: dict, item: dict):
|
|
|
- item = capital_to_higher(item)
|
|
|
- if g.get(item['User_Id']):
|
|
|
- g[item['User_Id']].push(item)
|
|
|
+ # 字典键全改小写
|
|
|
+ item = capital_to_lower(item)
|
|
|
+ # 放入全局
|
|
|
+ if g.get(item['user_id']):
|
|
|
+ g[item['user_id']].push(item)
|
|
|
else:
|
|
|
- g[item['User_Id']] = UserActivateDegreeAnalyzeSpace(item['User_Id'])
|
|
|
- g[item['User_Id']].push(item)
|
|
|
+ g[item['user_id']] = UserActivateDegreeAnalyzeSpace(item['user_id'])
|
|
|
+ g[item['user_id']].push(item)
|
|
|
+
|
|
|
+ # item = capital_to_higher(item)
|
|
|
+ # if g.get(item['User_Id']):
|
|
|
+ # g[item['User_Id']].push(item)
|
|
|
+ # else:
|
|
|
+ # g[item['User_Id']] = UserActivateDegreeAnalyzeSpace(item['User_Id'])
|
|
|
+ # g[item['User_Id']].push(item)
|
|
|
|
|
|
|
|
|
# session = DM8Session()
|
|
@@ -446,7 +603,7 @@ def predict(g: dict, item: dict):
|
|
|
# try:
|
|
|
# df = session.query("""SELECT "ID", "Count" FROM TOTALCOUNT WHERE "Name" = ?""", args="采集量")
|
|
|
# if df.shape[0] == 1:
|
|
|
- # result = session.update("""UPDATE TOTALCOUNT SET "Count"=? WHERE TOTALCOUNT.ID = ?""", (int(df['Count'])+1, int(df['ID'])))
|
|
|
+ # result = session.execute("""UPDATE TOTALCOUNT SET "Count"=? WHERE TOTALCOUNT.ID = ?""", (int(df['Count'])+1, int(df['ID'])))
|
|
|
# except Exception as e:
|
|
|
# print(e)
|
|
|
|