# !/usr/bin/python # -*- coding:utf-8 -*- from logger import log_utils from tasks import app from commons import web3_utils from db.models import DriveInfo import traceback import time logger = log_utils.get_logging('tasks_listen_driveInfo_add', 'tasks_listen_driveInfo_add.log') # @app.task(bind=True, queue='listen_driveInfo_add') # def listen_driveInfo_add(self): # logger.info("driveInfo add") # drives_contract, _ = web3_utils.load_via_artifact('DriveInfo', wss=True) # filter = drives_contract.events.newDriveInfo.createFilter(fromBlock=0) # while True: # try: # for event in filter.get_new_entries(): # logger.info('event => {0}'.format(event.event)) # logger.info(event.args) # # # 同步数据到 中心化应用数据库 # init_driveInfos(event.args) # except: # pass # time.sleep(2)
# !/usr/bin/python # -*- coding:utf-8 -*- from logger import log_utils from services.sms_service import send_instant_sms from tasks import app logger = log_utils.get_logging('tasks_send_sms') @app.task(bind=True) def send_sms(self, mobile, content): if mobile and content: status = send_instant_sms(mobile=mobile, msg=content) logger.info('[%s] SEND SMS: status=%s, to=%s, content=%s' % (self.request.id, status, mobile, content)) return status
# !/usr/bin/python # -*- coding:utf-8 -*- from logger import log_utils from services.msg_new_service import send_instant_sms from tasks import app logger = log_utils.get_logging('tasks_send_msg_new', 'tasks_send_msg_new.log') @app.task(bind=True, queue='send_msg_new') def send_msg_new(self, mobile, code, time): print(mobile) print(code) print(time) if mobile and code and time: logger.info('START: Send SMS mobile=%s, code=%s' % (mobile, code)) status = send_instant_sms(mobile=mobile, code=code, time=time) print(status, 'status') logger.info('[%s] SEND SMS: status=%s, to=%s, code=%s' % (self.request.id, status, mobile, code)) return status
import traceback from pymongo import ReadPreference from beans import DimensionRuleO, DimensionConditionO, RaceSubjectFilterO from caches.redis_utils import RedisCache from commons.common_utils import combination from db import STATUS_SUBJECT_CHOICE_RULE_INACTIVE, CATEGORY_SUBJECT_DIMENSION_OPTIONS, \ CATEGORY_SUBJECT_DIMENSION_WEIGHT, CATEGORY_SUBJECT_DIMENSION_NUMERICAL, STATUS_SUBJECT_CHOICE_RULE_ACTIVE from db.models import SubjectDimension, RaceSubjectChoiceRules, RaceSubjectBanks, RaceGameCheckPoint from enums import KEY_PREFIX_EXTRACTING_SUBJECT_RULE, KEY_PREFIX_SUBJECT_BANKS_COUNT, KEY_EXTRACTING_SUBJECT_QUANTITY from logger import log_utils from motorengine.stages import MatchStage, LookupStage from tasks import app logger = log_utils.get_logging('task_race_subject_choice') @app.task(bind=True, queue='race_subject_extract') def start_race_extract_subjects( self, race_cid, race_subject_choice_rule: RaceSubjectChoiceRules): try: logger.info('START(%s): rules_cid=%s' % (self.request.id, race_subject_choice_rule.cid)) cut_off_datetime = datetime.datetime.now() # 抽题 def extract(): extract_subjects(race_cid, race_subject_choice_rule) while True:
KNOWLEDGE_FIRST_LEVEL_DICT, KNOWLEDGE_SECOND_LEVEL_DICT from db.model_utils import update_diamond_reward, get_cache_answer_limit, set_cache_answer_limit, get_cache_share_times, \ set_cache_share_times, do_diamond_reward from db.models import Member, MemberGameHistory, GameDiamondConsume, GameDiamondReward, MemberFriend, MemberNotice, \ GameDanGrade, AdministrativeDivision, MemberStarsAwardHistory, \ MemberExamCertificate, SubjectResolvingViewedStatistics, Subject, SubjectOption, UploadFiles from logger import log_utils from motorengine import DESC, ASC from motorengine.stages import MatchStage, SortStage, LookupStage, LimitStage from settings import SERVER_PROTOCOL, SERVER_HOST, STATIC_URL_PREFIX from web import decorators, WechatAppletHandler from wechat import wechat_utils from wechat.enums import MINI_APP_STATIC_URL_PREFIX from .utils import get_dan_grade_by_index, convert_subject_dimension_dict logger = log_utils.get_logging('a_game') class AppletGameFightQuestionsGetViewHandler(WechatAppletHandler): """ 获取排位赛题目,包括对手答案、给出答案的时间 """ @decorators.render_json @decorators.wechat_applet_authenticated async def post(self): r_dict = {'code': 0} try: open_id = self.get_i_argument('open_id', None) if open_id: member = await find_member_by_open_id(open_id) if member:
import traceback import msgpack from caches.redis_utils import RedisCache from db import STATUS_SUBJECT_DIMENSION_ACTIVE from db.models import SubjectDimension, MemberSubjectStatistics from enums import KEY_CACHE_REPORT_DOING_NOW from logger import log_utils from motorengine.stages import MatchStage, LookupStage from motorengine.stages.group_stage import GroupStage from tasks import app from tasks.instances.task_report_learning_member_quantity import early_warning from tasks.instances.utils import early_warning_empty from tasks.utils import save_cache_condition, get_yesterday logger = log_utils.get_logging('task_report_subject_parameter_radar') @app.task(bind=True, queue='subject_dimension_radar') def start_statistics_subject_parameter_radar(self, cache_key, root_dimension_code, m_city_code_list, province_code_list, city_code_list, gender_list, age_group_list, education_list): """ :param self: :param cache_key: :param root_dimension_code: :param m_city_code_list:
from caches.redis_utils import RedisCache from db import STATUS_USER_ACTIVE, TYPE_DAN_GRADE_ONE, SOURCE_MEMBER_DIAMOND_NOVICE, \ SOURCE_MEMBER_DIAMOND_LOGIN_EVERYDAY, SOURCE_MEMBER_DIAMOND_DICT from db.enums import SOURCE_MEMBER_DIAMOND_VAULT_REWARD from db.model_utils import do_diamond_reward from db.models import Member, MemberGameHistory, VaultDiamondBank, MemberDiamondDetail from enums import KEY_CACHE_WECHAT_AD_DIVISION, KEY_CACHE_APPLET_ONLINE_MEMBER from logger import log_utils from motorengine import DESC from settings import SITE_ROOT from tornado.web import url from web import decorators, WechatAppletHandler from wechat import wechat_utils from .utils import get_dan_grade_by_index logger = log_utils.get_logging('a_mainpage') class AppletMainPageDetailHandler(WechatAppletHandler): """获取主页信息""" @decorators.render_json @decorators.wechat_applet_authenticated async def post(self): r_dict = {'code': 0} open_id = self.get_i_argument('open_id') if not open_id: r_dict['code'] = 1001 return r_dict try: member = await find_member_by_open_id(open_id)
from tornado import gen from tornado.web import url from commons.common_utils import md5 from commons.page_utils import Paging from commons.upload_utils import save_upload_file, drop_disk_file_by_cid from db.models import Present, UploadFiles, DiscountCoupon from db import CATEGORY_PRESENT_DISCOUNT_COUPON, STATUS_PRESENT_ACTIVE, \ STATUS_PRESENT_INACTIVE, CATEGORY_PRESENT_WECHAT_LUCKY_MONEY, STATUS_DISCOUNT_COUPON_UNUSED, \ CATEGORY_UPLOAD_FILE_IMG_PRESENT from enums import PERMISSION_TYPE_INTEGRAL_EXCHANGE_MANAGEMENT from logger import log_utils from web import decorators from web.base import BaseHandler exchange_logger = log_utils.get_logging() class PresentListViewHandler(BaseHandler): """ 兑换商城礼品列表 """ @decorators.permission_required(PERMISSION_TYPE_INTEGRAL_EXCHANGE_MANAGEMENT) @decorators.render_template('backoffice/exchange/list_view.html') async def get(self): # 上下架礼品数量 active_amount = await Present.count(filtered={'record_flag': 1, 'status': STATUS_PRESENT_ACTIVE}) inactive_amount = await Present.count(filtered={'record_flag': 1, 'status': STATUS_PRESENT_INACTIVE}) all_amount = await Present.count(filtered={'record_flag': 1})
# !/usr/bin/python # -*- coding:utf-8 -*- import copy import hashlib import uuid from bson import ObjectId from logger import log_utils from motorengine import ASC, MotorEngineDB from motorengine.base import BaseDocument from motorengine.cache import CacheEngine from motorengine.errors import InvalidDocumentError from pymongo import IndexModel, DeleteOne, ReplaceOne, UpdateOne, ReadPreference logger = log_utils.get_logging('document', 'document.log') class AsyncDocument(BaseDocument): def __init__(self, **kwargs): super(AsyncDocument, self).__init__(**kwargs) @classmethod def switch_async_db(cls, db_name=None): """ 切换数据库 :param db_name: :return: """ if db_name is None or (db_name and isinstance(db_name, str)): setattr(cls, '__db_name', db_name)
# !/usr/bin/python # -*- coding:utf-8 -*- from logger import log_utils from tasks import app from commons import web3_utils from db.models import Cars import time logger = log_utils.get_logging('tasks_listen_car_add', 'tasks_listen_car_add.log') # @app.task(bind=True, queue='listen_car_add') # def listen_car_add(self): # logger.info("car add") # cars_contract, _ = web3_utils.load_via_artifact('Cars', wss=True) # filter = cars_contract.events.newCar.createFilter(fromBlock=0) # while True: # try: # for event in filter.get_new_entries(): # logger.info('event => {0}'.format(event.event)) # logger.info(event.args) # # # 同步数据到 中心化应用数据库 # init_cars(event.args) # except: # pass # time.sleep(2) # @app.task(bind=True, queue='listen_car_add', soft_time_limit=20)
import json import traceback from caches.redis_utils import RedisCache from celery.schedules import crontab from enums import KEY_CACHE_REPORT_ECHARTS_CONDITION from logger import log_utils from tasks import app # 这些是定时任务eval执行的任务,不能删除,删除了eval找不到这些要跑的任务 from tasks.instances.task_report_learning_member_quantity import start_statistics_member_quantity, start_statistics_member_time, start_statistics_member_accuracy from tasks.instances.task_report_learning_situation import start_statistics_learning_situation, start_statistics_quiz_trends, start_statistics_member_active, start_statistics_member_top_n from tasks.instances.task_report_subject_parameter import start_statistics_subject_quantity from tasks.instances.task_report_subject_parameter_cross import start_statistics_subject_parameter_cross from tasks.instances.task_report_subject_parameter_radar import start_statistics_subject_parameter_radar logger = log_utils.get_logging('task_report_schedule') app.register_schedule('task_report_schedule', 'tasks.instances.task_report_schedule.schedule_report_statistics', crontab(hour=1, minute=00)) @app.task(bind=True, queue='task_report_schedule') def schedule_report_statistics(self): """ 定时任务 :param self: :return: """ logger.info( '[SCHEDULE_START] ------ schedule_report_statistics(%s) -----' % self.request.id) task_set = RedisCache.smembers(KEY_CACHE_REPORT_ECHARTS_CONDITION)
from actions.applet import find_member_by_open_id from tornado.web import url from db import STATUS_USER_ACTIVE, STATUS_RACE_ACTIVE from db.models import Member, Race, UploadFiles, RaceMapping, AdministrativeDivision, Company, \ ReportRacePeopleStatistics, RaceMemberEnterInfoStatistic from logger import log_utils from motorengine import DESC, ASC from motorengine.stages import MatchStage, LookupStage, SortStage, GroupStage from settings import SERVER_PROTOCOL, SERVER_HOST from settings import STATIC_URL_PREFIX from web import WechatAppletHandler, decorators from caches.redis_utils import RedisCache logger = log_utils.get_logging('race') class AppletActivityListViewHandler(WechatAppletHandler): """ 获取活动列表 """ @decorators.render_json @decorators.wechat_applet_authenticated async def post(self): r_dict = {'code': 0, 'race_list': []} open_id = self.get_i_argument('open_id', None) auth_address = self.get_i_argument('address_dict') try: member = await find_member_by_open_id(open_id) if not member:
import traceback from pymongo import ReadPreference from caches.redis_utils import RedisCache from db import SEX_LIST, SEX_NONE, SEX_DICT, TYPE_AGE_GROUP_NONE, TYPE_AGE_GROUP_DICT, TYPE_EDUCATION_NONE, \ STATUS_RESULT_GAME_PK_WIN, STATUS_RESULT_GAME_PK_FAILED, STATUS_RESULT_GAME_PK_GIVE_UP, \ STATUS_RESULT_GAME_PK_TIE_BREAK, TYPE_EDUCATION_DICT, TYPE_AGE_GROUP_LIST from db.models import MemberGameHistory, Member, SubjectDimension, Subject, SubjectAccuracyStatistics, \ MemberCheckPointHistory, MemberAccuracyStatistics from enums import KEY_PREFIX_TASK_ACCURATE_STATISTICS, KEY_ALLOW_PROCESS_ACCURATE_STATISTICS from logger import log_utils from tasks import app from tasks.config import task_time_limit logger = log_utils.get_logging('task_accurate_statistics') @app.task(bind=True, queue='accurate_statistics') def start_accurate_statistics(self, history_model, member: Member = None): """ 会员游戏数据精确统计 :param self: 任务对象 :param history_model: 游戏历史 :param member: 会员,默认为None :return: """ result = {'code': 0} if allowed_process(): try: if not isinstance(history_model, (MemberGameHistory, MemberCheckPointHistory)):
STATUS_READPACKET_ISSUE_SUCCESS, CATEGORY_NOTICE_AWARD, STATUS_NOTICE_UNREAD, STATUS_NOTICE_READ, TYPE_MSG_DRAW, \ RESULT_RACE_LOTTERY_OUT_OF_TIME, RESULT_RACE_LOTTERY_LOSE_LATE, STATUS_ACTIVE, STATUS_GAME_CHECK_POINT_ACTIVE, \ CATEGORY_REDPACKET_RULE_LOTTERY, CATEGORY_REDPACKET_RULE_DIRECT, STATUS_RESULT_CHECK_POINT_WIN from db.models import RedPacketItemSetting, RedPacketLotteryHistory, \ RedPacketBasicSetting, MemberNotice, Race, AdministrativeDivision, RedPacketRule, RaceGameCheckPoint, RedPacketBox, \ MemberCheckPointHistory from enums import KEY_RACE_LOTTERY_RESULT from logger import log_utils from pymongo import ReadPreference from settings import REDPACKET_PLATFORM_AUTH_URL, REDPACKET_PLATFORM_HOST from tasks.instances.task_get_lottery_result import get_lottery_result from tasks.instances.task_lottery_queuing import start_lottery_queuing from tornado.web import url from web import WechatAppletHandler, decorators logger = log_utils.get_logging('a_redpacket') class AppletLotteryTurntableGet(WechatAppletHandler): """ 获取抽奖转盘 """ @decorators.render_json @decorators.wechat_applet_authenticated async def post(self): r_dict = {'code': 0, 'lottery_history': False, 'explain': '最终解释权归科普所所有'} open_id = self.get_i_argument('open_id') race_cid = self.get_i_argument('race_cid') checkpoint_cid = self.get_i_argument('checkpoint_cid') if not (open_id and race_cid and checkpoint_cid):
将excel中行政区划信息转为json文件 民政部行政区划信息:http://www.mca.gov.cn/article/sj/xzqh//1980/ """ import copy import json import time from pypinyin import lazy_pinyin import requests import xlrd from logger import log_utils logger = log_utils.get_logging('gene_ad.log') def gene_json(): workbook = xlrd.open_workbook(filename='./ad.xlsx') sheet = workbook.sheet_by_index(0) ad_list = [] location_list = [] for _row in range(sheet.nrows): if _row < 1: continue code = str(int(sheet.cell_value(_row, 0))) name = sheet.cell_value(_row, 1) lng, lat, lev, auth_address = parse_location(name) if not (lng and lat and lev and auth_address):
import msgpack from caches.redis_utils import RedisCache from db import STATUS_SUBJECT_DIMENSION_ACTIVE from db.models import SubjectDimension, MemberSubjectStatistics from enums import KEY_CACHE_REPORT_DOING_NOW from logger import log_utils from motorengine import ASC from motorengine.stages import MatchStage from motorengine.stages.group_stage import GroupStage from tasks import app from tasks.instances.task_report_learning_member_quantity import early_warning from tasks.instances.utils import early_warning_empty from tasks.utils import save_cache_condition, get_yesterday logger = log_utils.get_logging('task_report_subject_parameter_cross') @app.task(bind=True, queue='subject_dimension_cross') def start_statistics_subject_parameter_cross(self, cache_key, main_dimension_code, second_dimension_code, m_city_code_list, province_code_list, city_code_list, gender_list, age_group_list, education_list): """ :param self: :param cache_key: :param main_dimension_code: :param second_dimension_code: :param m_city_code_list: :param province_code_list: :param city_code_list:
# !/usr/bin/python # -*- coding:utf-8 -*- from logger import log_utils from services.email_service import send_instant_mail from tasks import app logger = log_utils.get_logging('tasks_send_mail') @app.task(bind=True) def send_mail(self, mail_to: list = None, subject: str = '提醒', content: str = '', content_images: dict = None, attachments: list = None): status = send_instant_mail(mail_to=mail_to, subject=subject, content=content, content_images=content_images, attachments=attachments) logger.info('[%s] SEND MAIL: status=%s, to=%s, subject=%s' % (self.request.id, status, mail_to, subject)) return status
from db.enums import STATUS_USER_ACTIVE, TYPE_DAN_GRADE_DICT, SOURCE_TYPE_MEMBER_SYSTEM, STATUS_USER_INACTIVE, SEX_NONE, \ CATEGORY_NOTICE_FRIENDS_PLAY, STATUS_NOTICE_UNREAD, STATUS_NOTICE_READ from db.models import Member, MemberAccuracyStatistics, SubjectAccuracyStatistics, MemberFriend, \ MemberNotice, RaceMapping, AdministrativeDivision, Race from db.models import MemberExamHistory, MemberShareStatistics, PersonalCenterViewedStatistics from enums import KEY_INCREASE_MEMBER_CODE from logger import log_utils from motorengine import ASC, UpdateOne from motorengine import DESC from settings import MINI_APP_SECRET, MINI_APP_ID, SERVER_PROTOCOL, SERVER_HOST from tasks.instances.task_member_property_statistics import start_task_member_property_statistics from tasks.instances.task_update_member_info import update_memberinfo_in_other_collections from web import WechatAppletHandler, decorators, json from wechat import API_CODE_EXCHANGE_SESSION_URL logger = log_utils.get_logging('a_member') class AppletMemberAuthViewHandler(WechatAppletHandler): """微信用户首次使用校验""" @decorators.render_json async def post(self): r_dict = {'code': 0} try: args_dict = json.loads(self.request.body) auth_code = args_dict.get('auth_code', None) user_info = args_dict.get('userInfo', {}) if not user_info: user_info = {} source = args_dict.get('source', None)
from db.models import Member, MemberGameHistory, MemberCheckPointHistory, MemberDailyStatistics, Subject, \ MemberSubjectStatistics, MemberDimensionStatistics, MemberLearningDayStatistics, MemberDailyDimensionStatistics, \ MemberLearningDayDimensionStatistics from enums import KEY_PREFIX_TASK_REPORT_DATA_STATISTICS, KEY_ALLOW_TASK_MEMBER_DAILY_STATISTICS, \ KEY_ALLOW_TASK_MEMBER_SUBJECT_STATISTICS, KEY_ALLOW_TASK_MEMBER_DIMENSION_STATISTICS, \ KEY_ALLOW_TASK_MEMBER_LEARNING_DAYS_STATISTICS, KEY_ALLOW_TASK_MEMBER_DAILY_DIMENSION_STATISTICS, \ KEY_ALLOW_TASK_MEMBER_LEARNING_DAY_DIMENSION_STATISTICS from logger import log_utils from motorengine.stages import MatchStage from motorengine.stages.group_stage import GroupStage from motorengine.stages.project_stage import ProjectStage from pymongo import ReadPreference from tasks import app from tasks.config import task_time_limit logger = log_utils.get_logging('task_dashboard_report_statistics') async def start_dashboard_report_statistics(history, member: Member = None, daily_code: str = None, learning_code: str = None): try: if not isinstance(history, MemberGameHistory): raise ValueError( '"member_history" must be a instance of MemberGameHistory or MemberCheckPointHistory.' ) if member: if not isinstance(member, Member): raise ValueError('"member" must be a instance of member.') else:
import os import traceback from datetime import datetime import xlsxwriter from caches.redis_utils import RedisCache from enums import KEY_CACHE_RACE_REPORT_DOWNLOAD from logger import log_utils from settings import SITE_ROOT from tasks import app from tasks.utils import write_sheet_enter_data, write_sheet_daily_increase_people logger = log_utils.get_logging('task_race_export_data') @app.task(bind=True, queue='race_export_data') def start_get_export_data(self, race_cid, title, export_title): """启动任务 :param self: :param race_cid: :param title: :param export_title: :return: """ logger.info('[START] race_export_data(%s), title=(%s)' % (self.request.id, title)) try: # 准备中 RedisCache.hset(KEY_CACHE_RACE_REPORT_DOWNLOAD, export_title, 2)
import traceback from commons.common_utils import RedisCache from db import STATUS_SUBJECT_STATISTICS_IN_PROCESS, STATUS_SUBJECT_STATISTICS_END, STATUS_SUBJECT_INACTIVE, \ CATEGORY_SUBJECT_BENCHMARK, CATEGORY_SUBJECT_GRADUATION from db.models import Subject, SubjectOption, MemberSubjectStatistics, ReportSubjectStatisticsMiddle from enums import KEY_CACHE_REPORT_CONDITION from logger import log_utils from motorengine import ASC, DESC from motorengine.stages import ProjectStage, LookupStage, MatchStage, SortStage, LimitStage, CountStage, SkipStage from motorengine.stages.group_stage import GroupStage from pymongo import ReadPreference from settings import SKIP_NUM from tasks import app logger = log_utils.get_logging('task_subject_statistics') @app.task(bind=True, queue='subject_stat_split') def start_split_subject_stat_task(self, category, task_dt): """ :param self: :param category: :param task_dt: :return: """ logger.info('START(%s): Begin split subject_statistics, condition is %s' % (self.request.id, str(category))) try:
#!/usr/bin/python # -*- coding:utf-8 -*- import datetime import traceback from actions.applet import find_member_by_open_id from actions.applet.utils import do_diamond_reward from db import SOURCE_MEMBER_DIAMOND_DAILY_SHARE_TIMES_LIMIT, SOURCE_MEMBER_DIAMOND_DAILY_SHARE, \ SOURCE_MEMBER_DIAMOND_DICT from db.model_utils import get_cache_share_times, set_cache_share_times from db.models import GameDiamondReward from logger import log_utils from web import decorators, WechatAppletHandler logger = log_utils.get_logging('a_miniapp') class MiniappShareAwardViewHandler(WechatAppletHandler): """ 分享好友奖励会员钻石""" @decorators.render_json @decorators.wechat_applet_authenticated async def post(self): r_dict = {'code': 0} open_id = self.get_i_argument('open_id', None) try: if open_id: member = await find_member_by_open_id(open_id) if member: award_title = '' award_diamonds = ''
import time import traceback from motorengine import DocumentFieldTypeError from pymongo import ReadPreference from caches.redis_utils import RedisCache from commons.common_utils import datetime2str from db import SEX_NONE, TYPE_AGE_GROUP_NONE, TYPE_EDUCATION_NONE, SOURCE_TYPE_MEMBER_SYSTEM from db.models import Member, MemberPropertyStatistics from enums import KEY_ALLOW_TASK_NEW_MEMBER_PROPERTY_STATISTICS from logger import log_utils from tasks import app from tasks.config import task_time_limit logger = log_utils.get_logging('task_member_property_statistics') async def start_task_member_property_statistics(member: Member, orig_member: Member = None): try: if not isinstance(member, Member): raise ValueError('"member" must be a instance of member.') if orig_member and not isinstance(orig_member, Member): raise ValueError('"orig_member" must be a instance of member.') if member == orig_member: raise ValueError( '"member" and "before_member" must be different instance.') # START: 会员属性数据统计 daily_code = _get_daily_code(member.register_datetime)
import msgpack from tornado.web import url from actions.frontsite.report.utils import do_stat_member_times, do_stat_member_count, do_stat_member_accuracy, \ get_drill_district_data, get_cache_key, get_special_cache_key from db import CITY_RACE_CID from db.models import AdministrativeDivision, \ RaceMemberEnterInfoStatistic from enums import PERMISSION_TYPE_MINIAPP_RACE_REPORT_SITUATION, KEY_CACHE_RACE_REPORT_DOWNLOAD from logger import log_utils from motorengine import DESC, RedisCache from motorengine.stages import MatchStage, GroupStage, SortStage from tasks.instances.task_race_export_data import start_get_export_data from web import decorators, BaseHandler, datetime2str logger = log_utils.get_logging() logger_cache = log_utils.get_logging('race_cache') class RaceReportMapHandler(BaseHandler): """ 地方科协地图模块 """ @decorators.render_json @decorators.permission_required( PERMISSION_TYPE_MINIAPP_RACE_REPORT_SITUATION) async def post(self): res_dict = {'code': 0} race_cid = self.get_argument('race_cid') # 0代表人数,1代表人次
# !/usr/bin/python # -*- coding:utf-8 -*- import datetime import json from pymongo.errors import CursorNotFound from logger import log_utils from caches.redis_utils import RedisCache from commons.common_utils import str2datetime from db.models import RaceMapping, AdministrativeDivision, Race, Member, MemberCheckPointHistory, \ RaceGameCheckPoint, Company, RedPacketBox, MemberStatisticInfo from motorengine.stages import MatchStage, ProjectStage, GroupStage logger = log_utils.get_logging('member_stat_schedule', 'member_stat_schedule.log') def daily_member_statistic(race_cid, daily_code): """ 统计每日活动下的会员 :param race_cid: :param daily_code: :return: """ start_date = str2datetime(daily_code, '%Y%m%d').replace(hour=0, minute=0, second=0, microsecond=0) end_date = start_date + datetime.timedelta(days=1) check_point_cids, _checkpoint_map = get_checkpoint_cid_list(race_cid)
import traceback import msgpack from caches.redis_utils import RedisCache from db.models import SubjectChoiceRules, MemberDailyStatistics from enums import KEY_CACHE_REPORT_DOING_NOW from logger import log_utils from motorengine.stages import MatchStage from motorengine.stages.group_stage import GroupStage from tasks import app from tasks.instances.task_report_learning_member_quantity import early_warning from tasks.instances.utils import early_warning_empty from tasks.utils import save_cache_condition, get_yesterday logger = log_utils.get_logging('task_report_learning_member_quantity') @app.task(bind=True, queue='subject_quantity') def start_statistics_subject_quantity(self, cache_key, m_province_code_list, m_city_code_list, s_province_code_list, s_city_code_list, s_gender_list, s_age_group_list, s_education_list): """ :param self: :param cache_key: :param m_province_code_list: :param m_city_code_list: :param s_province_code_list: :param s_city_code_list:
import os import traceback from bson import ObjectId from web import decorators from web.base import BaseHandler from enums.permission import PERMISSION_TYPE_SOURCE_MANAGEMENT from tornado.web import url from commons.page_utils import Paging from db.models import GameMemberSource, UploadFiles from logger import log_utils from commons.common_utils import download_qr_image, md5, drop_disk_file from db import CATEGORY_UPLOAD_FILE_IMG_GAME_MEMBER_SOURCE_QR from settings import STATIC_PATH, SERVER_HOST, SERVER_PROTOCOL logger = log_utils.get_logging() class GameMemberSourceListViewHandler(BaseHandler): @decorators.render_template('backoffice/game_member_source/list_view.html') @decorators.permission_required(PERMISSION_TYPE_SOURCE_MANAGEMENT) async def get(self): per_page_quantity = int(self.get_argument('per_page_quantity', 10)) to_page_num = int(self.get_argument('page', 1)) page_url = '%s?page=$page$per_page_quantity=%s' % ( self.reverse_url('backoffice_source_list'), per_page_quantity) paging = Paging(page_url, GameMemberSource, current_page=to_page_num, items_per_page=per_page_quantity, sort=['-updated_dt'])
#! /usr/bin/python import json import requests from actions.applet.utils import deal_param, generate_rid from db import STATUS_REDPACKET_AWARDED, STATUS_READPACKET_ISSUE_SUCCESS, CATEGORY_NOTICE_AWARD, STATUS_NOTICE_UNREAD, \ STATUS_NOTICE_READ, STATUS_REDPACKET_AWARD_FAILED, STATUS_READPACKET_ISSUE_FAIL from db.models import RedPacketBox, Race, MemberNotice from logger import log_utils from settings import REDPACKET_PLATFORM_QUERY_RESULT_URL, REDPACKET_PLATFORM_HOST logger = log_utils.get_logging('daily_lottery_result_query', 'daily_lottery_result_query.log') def do_query(race_cid): cursor = RedPacketBox.sync_find({ 'member_cid': { '$ne': None }, 'award_cid': { '$ne': None }, 'draw_status': 1, 'race_cid': race_cid }).batch_size(128) index = 0 while True: try:
# !/usr/bin/python # -*- coding:utf-8 -*- import os import settings from logger import log_utils from tornado.template import Template logger = log_utils.get_logging(name='mail_service', file_name='mail_service.log') TEMPLATES_CACHE = {} def render_template(template_name, **kwargs): """ 填充模板 :param template_name: 模板名称 :param kwargs: 填充参数 :return: 填充后的结果 """ if template_name: global TEMPLATES_CACHE if template_name in TEMPLATES_CACHE.keys(): return TEMPLATES_CACHE.get(template_name) else: path = os.path.join(settings.TEMPLATE_PATH, template_name) if os.path.exists(path): template = None try: with open(path) as template:
from db.models import MemberSubjectStatistics, Subject, SubjectOption, SubjectDimension, AdministrativeDivision, \ ReportSubjectStatisticsMiddle from enums import PERMISSION_TYPE_REPORT_SUBJECT_ANALYZE_MANAGEMENT, \ PERMISSION_TYPE_REPORT_SUBJECT_PARAMETER_MANAGEMENT, KEY_CACHE_REPORT_CONDITION, \ PERMISSION_TYPE_REPORT_SUBJECT_ANALYZE_EXPORT, KEY_CACHE_REPORT_DOING_NOW from logger import log_utils from motorengine import ASC from motorengine.stages import LookupStage, SortStage, MatchStage from motorengine.stages.group_stage import GroupStage from motorengine.stages.project_stage import ProjectStage from tasks.instances.task_report_subject_parameter_cross import start_statistics_subject_parameter_cross from tasks.instances.task_report_subject_parameter_radar import start_statistics_subject_parameter_radar from tasks.instances.task_subject_statistics import start_split_subject_stat_task from web import BaseHandler, decorators logger = log_utils.get_logging('subject_analysis') class SubjectAnalysisListViewHandler(BaseHandler): @decorators.render_template('backoffice/reports/subject_analysis_view.html') @decorators.permission_required(PERMISSION_TYPE_REPORT_SUBJECT_ANALYZE_MANAGEMENT) async def get(self): show_export_btn = PERMISSION_TYPE_REPORT_SUBJECT_ANALYZE_EXPORT in self.current_user.permission_code_list s_province = self.get_argument('province', '') s_city = self.get_argument('city', '') s_age_group = self.get_argument('age_group', '') s_gender = self.get_argument('gender', '') s_education = self.get_argument('education', '') sort = int(self.get_argument('sort', 1)) per_page_quantity = int(self.get_argument('per_page_quantity', 50))