-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mouday
committed
Nov 2, 2024
1 parent
93b66be
commit 25daa79
Showing
7 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : time_unit_enum.py | ||
@Date : 2024-11-02 | ||
@Author : Peng Shiyu | ||
""" | ||
from __future__ import print_function, unicode_literals, absolute_import, division | ||
|
||
|
||
class TimeUnitEnum(object): | ||
""" | ||
时间单位枚举值 | ||
@since v1.6.56 | ||
""" | ||
# 毫秒 | ||
Millisecond = 1 | ||
|
||
# 秒 | ||
Second = 2 | ||
|
||
# 分钟 | ||
Minute = 3 | ||
|
||
# 小时 | ||
Hour = 4 | ||
|
||
# 天 | ||
Day = 5 | ||
|
||
# 周 | ||
Week = 6 | ||
|
||
# 月 | ||
Month = 7 | ||
|
||
# 年 | ||
Year = 8 | ||
|
||
@staticmethod | ||
def get_config(): | ||
return [ | ||
(TimeUnitEnum.Millisecond, '毫秒'), | ||
(TimeUnitEnum.Second, '秒'), | ||
(TimeUnitEnum.Minute, '分钟'), | ||
(TimeUnitEnum.Hour, '小时'), | ||
(TimeUnitEnum.Day, '天'), | ||
(TimeUnitEnum.Week, '周'), | ||
(TimeUnitEnum.Month, '月'), | ||
(TimeUnitEnum.Year, '年'), | ||
] | ||
|
||
@staticmethod | ||
def get_label(value): | ||
mapping = {k: v for k, v in TimeUnitEnum.get_config()} | ||
return mapping.get(value) | ||
|
||
@staticmethod | ||
def get_value(label): | ||
mapping = {k: v for v, k in TimeUnitEnum.get_config()} | ||
return mapping.get(label) | ||
|
||
@staticmethod | ||
def to_millisecond(value, unit=Second): | ||
# 基础单位:毫秒 | ||
mapping = { | ||
TimeUnitEnum.Millisecond: 1, | ||
TimeUnitEnum.Second: 1000, | ||
TimeUnitEnum.Minute: 1000 * 60, | ||
TimeUnitEnum.Hour: 1000 * 60 * 60, | ||
TimeUnitEnum.Day: 1000 * 60 * 60 * 24, | ||
TimeUnitEnum.Week: 1000 * 60 * 60 * 24 * 7, | ||
TimeUnitEnum.Month: 1000 * 60 * 60 * 24 * 30, | ||
TimeUnitEnum.Year: 1000 * 60 * 60 * 24 * 365, | ||
} | ||
|
||
return value * mapping.get(unit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
@File : migrate_1655_to_1656.py | ||
@Date : 2024-08-28 | ||
cmd: | ||
$ python domain_admin/migrate/migrate_1655_to_1656.py | ||
""" | ||
from __future__ import print_function, unicode_literals, absolute_import, division | ||
|
||
from domain_admin.migrate import migrate_common | ||
from domain_admin.model.base_model import db | ||
from domain_admin.model.monitor_model import MonitorModel | ||
|
||
|
||
def execute_migrate(): | ||
""" | ||
版本升级 v1.6.55 => v1.6.56 | ||
:return: | ||
""" | ||
|
||
migrator = migrate_common.get_migrator(db) | ||
|
||
migrate_rows = [ | ||
migrator.add_column( | ||
table=MonitorModel._meta.table_name, | ||
column_name=MonitorModel.interval_unit.name, | ||
field=MonitorModel.interval_unit | ||
) | ||
] | ||
|
||
migrate_common.try_execute_migrate(migrate_rows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters