recover_offline_coins_stats.py 935 B

123456789101112131415161718192021222324252627282930313233
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. """
  4. 从事件表里恢复线下投币数据
  5. """
  6. import os
  7. import sys
  8. # : current_dir - 2
  9. PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
  10. sys.path.insert(0, PROJECT_ROOT)
  11. from script.base import init_env, get_logger
  12. logger = get_logger(__name__)
  13. init_env(interactive = True)
  14. from apps.web.device.models import DeviceEvent
  15. from apps.web.constant import Const
  16. from apilib.utils_datetime import date_to_datetime_floor, date_to_datetime_ceiling, dt_to_timestamp
  17. DATE_FMT = Const.DATE_FMT
  18. start_time_timestamp = dt_to_timestamp(date_to_datetime_floor('2018-09-30'))
  19. end_time_timestamp = dt_to_timestamp(date_to_datetime_ceiling('2018-10-03'))
  20. all_offline_coin_events = DeviceEvent.get_collection().find({
  21. 'cmd': 205,
  22. 'time': {'$gte': start_time_timestamp, '$lte': end_time_timestamp}
  23. })