# Path: mod/models/pe_models.py
# class PEUser(Base):
#     __tablename__ = 'pe'
#     cardnum = Column(Integer, primary_key=True)
#     count = Column(String(10), nullable=False)
# 
#     def __repr__(self):
#         return '<PE (%s, %d)' % (self.cardnum, self.count)
# 
# Path: mod/models/tice_cache.py
# class TiceCache(Base):
#     __tablename__ = 'tice'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


from .._config import *
from config import *
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from tornado.tcpclient import TCPClient
from tornado.ioloop import IOLoop
from BeautifulSoup import BeautifulSoup
from ..models.pe_models import PEUser
from ..models.tice_cache import TiceCache
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime,mktime,strptime
from datetime import datetime, timedelta, date
from concurrent.futures import ThreadPoolExecutor
from tornado.concurrent import run_on_executor
import tornado.web
import tornado.gen
import urllib
import random
import json,socket,base64,traceback
import functools
        front_day = 6-current_date
        front_day = front_day if front_day>0 else 0
        back_remain = 5
        all_week = (alldays-5-front_remain)/7
        workday_count = (all_week+1)*5+front_day
        if current_date<=6:
            workday_count = workday_count-1
        return workday_count if workday_count > 0  else 0
        """
#体测信息
class ticeInfoHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        return self.application.db

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        cardnum = self.get_argument('cardnum',default=None)
        retjson = {'code':200,'content':''}
        state = 'fail'
        if not cardnum:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            #read from cache
            try:

# Path: mod/models/pe_models.py
# class PEUser(Base):
#     __tablename__ = 'pe'
#     cardnum = Column(Integer, primary_key=True)
#     count = Column(String(10), nullable=False)
# 
#     def __repr__(self):
#         return '<PE (%s, %d)' % (self.cardnum, self.count)
# 
# Path: mod/models/tice_cache.py
# class TiceCache(Base):
#     __tablename__ = 'tice'
#     cardnum = Column(Integer, primary_key=True)
#     text = Column(String(4096), nullable=False)
#     date = Column(Integer, nullable=False)


# Path: mod/pe/handler.py
from .._config import *
from config import *
from tornado.httpclient import HTTPRequest, AsyncHTTPClient
from tornado.tcpclient import TCPClient
from tornado.ioloop import IOLoop
from BeautifulSoup import BeautifulSoup
from ..models.pe_models import PEUser
from ..models.tice_cache import TiceCache
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.orm.exc import NoResultFound
from time import time, localtime, strftime,mktime,strptime
from datetime import datetime, timedelta, date
from concurrent.futures import ThreadPoolExecutor
from tornado.concurrent import run_on_executor
import tornado.web
import tornado.gen
import urllib
import random
import json,socket,base64,traceback
import functools

        front_day = 6-current_date
        front_day = front_day if front_day>0 else 0
        back_remain = 5
        all_week = (alldays-5-front_remain)/7
        workday_count = (all_week+1)*5+front_day
        if current_date<=6:
            workday_count = workday_count-1
        return workday_count if workday_count > 0  else 0
        """
#体测信息
class ticeInfoHandler(tornado.web.RequestHandler):
    @property
    def db(self):
        return self.application.db

    def get(self):
        self.write('Herald Web Service')

    @tornado.web.asynchronous
    @tornado.gen.engine
    def post(self):
        cardnum = self.get_argument('cardnum',default=None)
        retjson = {'code':200,'content':''}
        state = 'fail'
        if not cardnum:
            retjson['code'] = 400
            retjson['content'] = 'params lack'
        else:
            #read from cache
            try:

                status = self.db.query(TiceCache).filter(TiceCache.cardnum == cardnum).one()