Archived
1
0
Fork 0

change time range

This commit is contained in:
yzhh 2022-07-28 23:53:15 +08:00
parent ee4a066d08
commit 9e0a93c487
3 changed files with 9 additions and 6 deletions

View file

@ -87,7 +87,7 @@ async def download_to_cache(url: str) -> Union[str, bool]:
:param url: 需要获取的url
:returns: 文件的相对路径若获取失败则返回False'''
if not Config('allow_request_localhost'):
hostname = urllib.parse.urlparse(url).hostname
check = private_ip_check(hostname)

View file

@ -329,7 +329,7 @@ class BotDBUtil:
@staticmethod
def get_count_by_times(new, old, module_name=None):
filter_ = [AnalyticsData.timestamp <= new, AnalyticsData.timestamp >= old]
filter_ = [AnalyticsData.timestamp < new, AnalyticsData.timestamp > old]
if module_name is not None:
filter_.append(AnalyticsData.moduleName == module_name)
return session.query(AnalyticsData).filter(*filter_).count()

View file

@ -556,6 +556,7 @@ async def _(msg: MessageSession):
else:
await msg.finish('机器人未开启命令统计功能。')
@ana.handle('days [<name>]')
async def _(msg: MessageSession):
if Config('enable_analytics'):
@ -565,12 +566,14 @@ async def _(msg: MessageSession):
module_ = msg.parsed_msg['<name>']
data_ = {}
for d in range(30):
new = datetime.now() - timedelta(days=30 - d - 1)
old = datetime.now() - timedelta(days=30 - d)
print(old.day)
new = datetime.now().replace(hour=0, minute=0, second=0) - timedelta(days=30 - d - 1)
old = datetime.now().replace(hour=0, minute=0, second=0) - timedelta(days=30 - d)
get_ = BotDBUtil.Analytics.get_count_by_times(new, old, module_)
print(get_)
data_[new.day] = get_
today = datetime.now().replace(hour=0, minute=0, second=0)
now = datetime.now()
data_.update({now.day: BotDBUtil.Analytics.get_count_by_times(now, today, module_)})
print(data_)
data_x = []
data_y = []
for x in data_: