Esempio n. 1
0
def Mom(priceColName, momPrefix, momDaysList, endDate=None):
    if endDate is None:
        dtNow = dt.datetime.now() - dt.timedelta(days=1)
        endDate = dt.datetime(dtNow.year, dtNow.month, dtNow.day)
    else:
        endDate = dt.datetime(endDate.year, endDate.month, endDate.day)
        if endDate.date() >= dt.datetime.now().date():
            endDate = dt.datetime(dt.datetime.now().year, dt.datetime.now().month, dt.datetime.now().day) - \
                      dt.timedelta(days=1)
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    for days in momDaysList:
        facName = momPrefix + '_' + str(days)
        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        tradingDateSet = Public.GetCalendar(lastUpdateDate, endDate)
        currentDate = lastUpdateDate - dt.timedelta(days=days)
        savedDate = lastUpdateDate
        priceDict = {}

        while currentDate + dt.timedelta(days=1) <= endDate:
            currentDate += dt.timedelta(days=1)
            # if currentDate not in tradingDateSet:
            #     continue
            # get data
            record = db[priceColName].find_one({'_id': currentDate})
            if record is None:
                continue
            for symbol, priceList in priceDict.items():
                priceList.append(np.nan)
            for symbol, price in record.items():
                if symbol[0] == '_':
                    continue
                if symbol not in priceDict.keys():
                    priceDict[symbol] = [np.nan]
                priceDict[symbol][-1] = price
            if currentDate <= lastUpdateDate:
                continue

            # evaluate momentum and save to db
            mongoDoc = {
                '_id': currentDate,
                '_updateTime': dt.datetime.now(),
                '_isTrade': (currentDate in tradingDateSet)
            }
            for symbol, priceList in priceDict.items():
                arr = np.array(priceList[max(0, len(priceList) - days):])
                if np.sum(
                        np.isfinite(arr)) < days / 3:  # data is not sufficient
                    continue
                mom = arr[-1] / np.nanmean(arr[0:len(arr) - 1])
                mongoDoc[symbol] = mom
            db[facName].save(mongoDoc)

            savedDate = currentDate
            print(facName + ' ' + str(currentDate))

        db.cfgUpdate.save({'_id': facName, 'lastUpdateDate': savedDate})
Esempio n. 2
0
    def setUp(self):
        self.targetApi= Public.domain()+'/user/publish'
        self.token=Public.getDuetoken('huiyiditou','123123')
        self.uid=Public.getUserid(self.token)
        self.color='39,40,41,42,43,35,37,38,9,10,11,12,13,14,15,16,21,33,34,36,31,32,22,23,24,25,26,27,28,29,30,17,18,19,20,8'#面辅料都有
        self.style='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22'#风格,面辅料都有
        self.season_Fab='1,2,3,4'#季节面料才有
        self.uses_Fab='1,2,3,4,5,6,7,8,9,10'#用途,面料才有
        self.craftwork_Fab='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29'#面料工艺
        self.craftwork_Acc='30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61'#辅料工艺


        self.material_Acc='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15'#材质,辅料才有
Esempio n. 3
0
def Day(facNameList, colList, sql, endDate=None):
    if endDate is None:
        dtNow = dt.datetime.now() - dt.timedelta(days=1)
        endDate = dt.datetime(dtNow.year, dtNow.month, dtNow.day)
    else:
        endDate = dt.datetime(endDate.year, endDate.month, endDate.day)
        if endDate.date() >= dt.datetime.now().date():
            endDate = dt.datetime(dt.datetime.now().year, dt.datetime.now().month, dt.datetime.now().day) - \
                      dt.timedelta(days=1)

    connStr = Public.GetPara('connStr')
    conn = co.connect(connStr)
    cursor = conn.cursor()
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    # for each factor
    for f in range(len(facNameList)):
        facName = facNameList[f]
        col = colList[f]
        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        tradingDateSet = Public.GetCalendar(lastUpdateDate, endDate)
        mongoDoc = db[facName].find_one({'_id': lastUpdateDate})
        mongoDoc = {} if mongoDoc is None else mongoDoc
        # save data day by day.
        currentDate = lastUpdateDate + dt.timedelta(days=1)
        while currentDate <= endDate:
            cursor.execute(
                sql.replace('{TRADE_DATE}', currentDate.strftime('%Y-%m-%d')))
            dataList = cursor.fetchall()
            isTrade = (currentDate in tradingDateSet)
            mongoDoc = {
            }  # if this statement is executed, invalid data will not be filled by previous value
            mongoDoc['_id'] = currentDate
            mongoDoc['_isTrade'] = isTrade
            mongoDoc['_updateTime'] = dt.datetime.now()
            for record in dataList:
                symbol = record[1]
                data = record[col]
                if data is not None:  # and np.isfinite(data):
                    mongoDoc[symbol] = data
            db[facName].save(mongoDoc)
            print(facName + ' ' + str(currentDate))
            currentDate += dt.timedelta(days=1)
        db.cfgUpdate.save({'_id': facName, 'lastUpdateDate': endDate})

    ddd = 0
Esempio n. 4
0
 def test_register(self):
     print u'开始测试登录后的token检查'
     print u'测试项1:正确未过期的token校验'
     par={'token':self.token}
     r=requests.post(self.targetApi,data=par)
     r_info=r.json()['code']
     if(r_info==0 and r.status_code==200):
         print u"Result:Pass"
         print u'接口返回消息:'+ r.json()['msg']
     else:
         print(u'Result:false')
         print u'接口返回code:',r_info,u'状态码:',r.status_code
         print u'接口返回消息:'+ r.json()['msg']
     self.assertEqual(r_info,0)
     print u'______________测试项1测试完毕_________________'
     print u'测试项2:过期的token校验'
     time.sleep(1)
     errorToken='90f0b04a5eaa075770fa13461'
     newtoken= Public.getUserToken('huiyiditou','123123')
     r=requests.post(self.targetApi,data=par)
     r_info=r.json()['code']
     if(r_info==-1 and r.status_code==200):
         print u"Result:Pass"
         print u'接口返回消息:'+ r.json()['msg']
     else:
         print(u'Result:false')
         print u'接口返回code:',r_info,u'状态码:',r.status_code
         print u'接口返回消息:'+ r.json()['msg']
     self.assertEqual(r_info,-1)
     print u'______________测试项1测试完毕_________________'
Esempio n. 5
0
 def test_register(self):
     print u'开始测试登录后的token检查'
     print u'测试项1:正确未过期的token校验'
     par = {'token': self.token}
     r = requests.post(self.targetApi, data=par)
     r_info = r.json()['code']
     if (r_info == 0 and r.status_code == 200):
         print u"Result:Pass"
         print u'接口返回消息:' + r.json()['msg']
     else:
         print(u'Result:false')
         print u'接口返回code:', r_info, u'状态码:', r.status_code
         print u'接口返回消息:' + r.json()['msg']
     self.assertEqual(r_info, 0)
     print u'______________测试项1测试完毕_________________'
     print u'测试项2:过期的token校验'
     time.sleep(1)
     errorToken = '90f0b04a5eaa075770fa13461'
     newtoken = Public.getUserToken('huiyiditou', '123123')
     r = requests.post(self.targetApi, data=par)
     r_info = r.json()['code']
     if (r_info == -1 and r.status_code == 200):
         print u"Result:Pass"
         print u'接口返回消息:' + r.json()['msg']
     else:
         print(u'Result:false')
         print u'接口返回code:', r_info, u'状态码:', r.status_code
         print u'接口返回消息:' + r.json()['msg']
     self.assertEqual(r_info, -1)
     print u'______________测试项1测试完毕_________________'
Esempio n. 6
0
 def __getPath(self):
     op = Public.Public_ConfigOp(self.configPath)
     filePath = op.OldPathReadAndNewPathSave(self.title,
                                             "path",
                                             ifDir=self.ifDir)
     if "" != filePath:
         self.returnPath.emit(filePath)
Esempio n. 7
0
 def __loadConfig(self):
     op = Public.Public_ConfigOp(self.configPath)
     rt = op.ReadConfig(self.title, 'name')
     if True is rt[0]:
         self.lineEdit.setText(rt[1])
     else:
         logger.warn('读取路径失败:{path}'.format(path=self.title))
Esempio n. 8
0
 def __saveHistory(self):
     ipOp = Public.Public_ConfigOp(self.configPath)
     if True is self.HistoryListChanged:
         ipOp.RemoveSection(self.sectionName)
         ipOp.SaveAll()
         for index, item in enumerate(self.inputList):
             ipOp.SaveConfig(self.sectionName, str(index), item)
Esempio n. 9
0
    def __loadConfig(self):
        op = Public.Public_ConfigOp(self.configPath)
        rt = op.ReadConfig(self.title,
                           'maxLogLine',
                           Type='int',
                           defaultValue=self.maxLogLine)
        if True is rt[0]:
            self.maxLogLine = rt[1]

        rt = op.ReadConfig(self.title,
                           'ifRedirect',
                           Type='bool',
                           defaultValue=self.ifRedirect)
        if True is rt[0]:
            self.ifRedirect = rt[1]

        rt = op.ReadConfig(self.title,
                           'ifClearLogAtStart',
                           Type='bool',
                           defaultValue=self.ifClearLogAtStart)
        if True is rt[0]:
            self.ifClearLogAtStart = rt[1]

        rt = op.ReadConfig(self.title,
                           'logLevel',
                           Type='int',
                           defaultValue=self.logLevel)
        if True is rt[0]:
            self.logLevel = rt[1]

        rt = op.ReadConfig(self.title,
                           'ifAddTime',
                           Type='bool',
                           defaultValue=self.ifAddTime)
        if True is rt[0]:
            self.ifAddTime = rt[1]

        rt = op.ReadConfig(self.title, 'logDir', defaultValue=self.logDir)
        if True is rt[0]:
            self.logDir = rt[1]

        rt = op.ReadConfig(self.title,
                           'colorInfo',
                           defaultValue=self.colorInfo)
        if True is rt[0]:
            self.colorInfo = rt[1]

        rt = op.ReadConfig(self.title,
                           'colorWarning',
                           defaultValue=self.colorWarning)
        if True is rt[0]:
            self.colorWarning = rt[1]

        rt = op.ReadConfig(self.title,
                           'colorError',
                           defaultValue=self.colorError)
        if True is rt[0]:
            self.colorError = rt[1]
Esempio n. 10
0
 def __loadHistory(self):
     historyList = self.inputList
     historyOp = Public.Public_ConfigOp(self.configPath)
     rt = historyOp.ReadAllBySection(self.sectionName)
     if True is rt[0]:
         for item in rt[1]:
             if (item[1] not in historyList) and ("" != item[1]):
                 historyList.append(item[1])
     else:
         logger.info(rt[1])
Esempio n. 11
0
 def dropEvent(self, e):
     fileNameList = []
     fileList = e.mimeData().urls()
     for file in fileList:
         fileName = file.toString()
         if fileName.startswith('file:///'):
             fileNameList.append(fileName[len('file:///'):])
     if 1 == len(fileNameList):
         self.setText(fileNameList[0])
         op = Public.Public_ConfigOp(self.configPath)
         op.SaveConfig(self.title, 'path', fileNameList[0])
Esempio n. 12
0
    def __loadConfig(self):
        op = Public.Public_ConfigOp(self.configPath)
        rt = op.ReadConfig('Global', 'ifAutoLoad', Type='bool')
        if True is rt[0]:
            self.ifAutoLoad = rt[1]
        else:
            op.SaveConfig('Global', 'ifAutoLoad', 'True')

        if False is self.ifAutoLoad:
            return
        rt = op.ReadConfig(self.title, 'path')
        if True is rt[0]:
            self.setText(rt[1])
        else:
            logger.warn('读取路径失败:{path}'.format(path=self.title))
Esempio n. 13
0
	def save(self):
		mus = self.session.run(self.mus)
		lvs = self.session.run(self.lvs)
		pb.Pickle_Save([pb.c2i, pb.i2c, mus, lvs], pb.save_path)
		# print(pb.i2c[0], mus[0], lvs[0])
		# print(pb.i2c[1], mus[1], lvs[1])
		# print(pb.i2c[2], mus[2], lvs[2])
		# print(pb.i2c[3], mus[3], lvs[3])

		writer = open(pb.save_path+"_", "w")
		for key in pb.c2i:
			writer.write("{} ".format(key))
			for v in mus[pb.c2i[key]]:
				writer.write("{} ".format(v))
			for v in lvs[pb.c2i[key]]:
				writer.write("{} ".format(v))
			writer.write("\n")
		writer.close()
Esempio n. 14
0
def CashFlow():
    connStr = Public.GetPara('connStr')
    conn = co.connect(connStr)
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    # factor
    configDictList = [{'facName': 'FIN_OCF_Q', 'column': 5, 'qfData': 2},        # 季度经营活动现金流
                      {'facName': 'FIN_OCF_QG', 'column': 5, 'qfData': 5},       # 季度经营活动现金流增长率
                      {'facName': 'FIN_OCF_12M', 'column': 5, 'qfData': 3},      # 12个月经营活动现金流
                      {'facName': 'FIN_OCE_12MG', 'column': 5, 'qfData': 6},     # 12个月经营活动现金流增长率

                      {'facName': 'FIN_ICF_Q', 'column': 8, 'qfData': 2},        # 季度投资活动现金流
                      {'facName': 'FIN_ICF_QG', 'column': 8, 'qfData': 5},       # 季度投资活动现金流增长率
                      {'facName': 'FIN_ICF_12M', 'column': 8, 'qfData': 3},      # 12个月投资活动现金流
                      {'facName': 'FIN_ICE_12MG', 'column': 8, 'qfData': 6},     # 12个月投资活动现金流增长率

                      {'facName': 'FIN_FCF_Q', 'column': 11, 'qfData': 2},       # 季度筹资活动现金流
                      {'facName': 'FIN_FCF_QG', 'column': 11, 'qfData': 5},      # 季度筹资活动现金流增长率
                      {'facName': 'FIN_FCF_12M', 'column': 11, 'qfData': 3},     # 12个月筹资活动现金流
                      {'facName': 'FIN_FCE_12MG', 'column': 11, 'qfData': 6},    # 12个月筹资活动现金流增长率
                     ]
    for configDict in configDictList:
        facName = configDict['facName']
        print('==== ' + facName)
        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        dataList = Public.GetDataList(Public.sqlCash,
                                      lastUpdateDate - dt.timedelta(days=365 * 3),
                                      dt.datetime.now(),
                                      conn)
        qfDataTuple = Public.QuarterFormat(dataList)
        column = configDict['column']
        dataDict = qfDataTuple[configDict['qfData']]
        facDict = {}
        for symbol, data in dataDict.items():
            facDict[symbol] = data[:, [0, 1, 2, column]]
        Public.ToDB(facDict, facName, endDate=None, updateReportDate=False, mongoClient=mc)


    ddd = 0
Esempio n. 15
0
def FinDer(configDictList, endDate):
    if endDate is None:
        dtNow = dt.datetime.now() - dt.timedelta(days=1)
        endDate = dt.datetime(dtNow.year, dtNow.month, dtNow.day)
    else:
        endDate = dt.datetime(endDate.year, endDate.month, endDate.day)
        if endDate.date() >= dt.datetime.now().date():
            endDate = dt.datetime(dt.datetime.now().year, dt.datetime.now().month, dt.datetime.now().day) - \
                      dt.timedelta(days=1)

    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']
    # for each factor
    for configDict in configDictList:
        facName = configDict['facName']
        depFacNameList = configDict['depFacNameList']
        EvalFun = configDict['EvalFun']

        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        tradingDateSet = Public.GetCalendar(lastUpdateDate, endDate)
        currentDate = lastUpdateDate + dt.timedelta(days=1)
        savedDate = lastUpdateDate
        while currentDate <= endDate:
            deficientData = False
            # get all dependent factor
            symbolSet = set()
            depFacListDict = {}
            for d in range(len(depFacNameList)):
                depFacName = depFacNameList[d]
                record = db[depFacName].find_one({'_id': currentDate})
                if record is None:
                    deficientData = True
                    break
                for symbol, value in record.items():
                    if symbol[0] == '_':
                        continue
                    if symbol not in depFacListDict.keys():
                        depFacListDict[symbol] = np.nan * np.zeros(
                            [len(depFacNameList)])
                    depFacListDict[symbol][
                        d] = value if value is not None else np.nan
                symbolSet = symbolSet | record.keys()
            if deficientData:
                break
            # evaluate factor value and save to db
            mongoDoc = {
                '_id': currentDate,
                '_isTrade': (currentDate in tradingDateSet),
                '_updateTime': dt.datetime.now()
            }
            for symbol in symbolSet:
                if symbol[0] == '_':  # system field
                    continue
                facValue = EvalFun(depFacListDict[symbol])
                mongoDoc[symbol] = facValue
            db[facName].save(mongoDoc)
            savedDate = currentDate

            print(facName + ' ' + str(currentDate))
            currentDate += dt.timedelta(days=1)

        db.cfgUpdate.save({'_id': facName, 'lastUpdateDate': savedDate})
Esempio n. 16
0
import redis
import pymongo as pm
import thulac
import os
import Public

dbConfig = Public.GetPara(os.path.join('.', 'config', 'db.txt'))
conn = redis.StrictRedis(host=dbConfig['host'], port=dbConfig['port'], db=int(dbConfig['db']),
                             decode_responses=True)
mc = pm.MongoClient('mongodb://*****:*****@localhost:27017/text')
db = mc['text']
tl = thulac.thulac(user_dict = os.path.join('.', 'dict', 'dict'), filt = False, seg_only=True)

config = conn.hgetall('CONFIG_ES')
config['_id'] = 'CONFIG_ES'
db['CONFIG'].save(config)
keys = conn.keys()
count = 0
for key in keys:
    if len(key) <= 7 or key[0 : 7] != 'http://':
        continue
    try:
        item = conn.hgetall(key)
    except Exception as e:
        ddd = 0
    item['_id'] = key
    if key[len(key) - 2] == ',' or key[len(key) - 3] == ',': # parse
        parse = []
        cut = tl.cut(item['content'])
        for c in cut:
            parse.append(c[0])
Esempio n. 17
0
def StartWeb(**user):
    if not isinstance(user, (dict)):
        raise TypeError('StartAll need a dict(user).')

    name, passwd, time, service, email = user['name'], user['passwd'], str(
        user['time']), user['service'], user['email']
    dn = name + Config.DN_BASE
    PORT, image = Public.Handler(service)
    userhome = os.path.join(Config.SDP_USER_DATA_HOME, name)

    #docker network mode is 'bridge' or 'host'(not allow none and ContainerID)
    if user['network'] != None:
        docker_network_mode = user['network']
    else:
        if Config.DOCKER_NETWORK not in ['bridge', 'host']:
            raise TypeError('Unsupport docker network mode')
        else:
            docker_network_mode = Config.DOCKER_NETWORK

    #define other code type, default is only ftp, disable svn and git, but SVN and git can't exist at the same time!
    if user['enable_svn'] != None:
        enable_svn = True
    else:
        enable_svn = False

    svn_repo = Config.SVN_ADDR + name
    """
    Git是什么?
    Git是目前世界上最先进的分布式版本控制系统(没有之一)。
    Git有什么特点?简单来说就是:高端大气上档次!
    The Git feature that really makes it stand apart from nearly every other SCM out there is its branching model.
    Git allows and encourages you to have multiple local branches that can be entirely independent of each other. The creation, merging, and deletion of those lines of development takes seconds.
    """
    if user['enable_git'] != None:
        enable_git = True
        git_repo = 'git@' + Config.GIT_SVR + ':' + os.path.join(
            Config.GIT_ROOT, name) + '.git'
    else:
        enable_git = False

    #make repo info, make a choice
    if enable_svn == False:
        if enable_git == False:
            repos = "None"
        else:
            repos = "git=> " + git_repo
    if enable_svn == True:
        if enable_git == True:
            #repos = "svn=> " + svn_repo, "git=> "+git_repo
            print "\033[0;31;40mSorry...You have to make a choice between SVN and git, and you don't have to choose all of the options.\033[0m"
            exit()
        else:
            repos = "svn=> " + svn_repo

    userinfo_user = r'''
Dear %s, 以下是您的SdpCloud服务使用信息!
账号: %s
密码: %s
使用期: %d个月
服务类型: %s
验证邮箱: %s
用户域名: %s
版本库信息: %s

更多使用方法请查询官方文档(www.saintic.com),祝您使用愉快。 如果有任何疑惑,欢迎与我们联系:
邮箱: [email protected]
官网: http://www.saintic.com/
问题: https://github.com/saintic/Sdp/issues''' % (name, name, passwd, int(time),
                                                service, email, dn, str(repos))

    userinfo_welcome = r'''<!DOCTYPE html>
<html>
<head>
<title>User information for SdpCloud!</title>
</head>
<body>
<h1><center>Welcome %s:</center></h1>
<p>账号: %s</p>
<p>密码: %s</p>
<p>使用期: %d个月</p>
<p>服务类型: %s</p>
<p>验证邮箱: %s</p>
<p>用户域名: %s</p>
<p>版本库信息: %s</p>

<p>这是一个欢迎页面,请尽快使用FTP、SVN或Git覆盖此页面!</p>
<p><em>Thank you for using SdpCloud.</em></p>
</body>
</html>''' % (name, name, passwd, int(time), service, email, dn, str(repos))

    userinfo_admin = {
        "name": name,
        "passwd": passwd,
        "time": int(time),
        "service": service,
        "email": email,
        "image": image,
        "ip": "127.0.0.1",
        "port": int(PORT),
        "dn": dn,
        "userhome": userhome,
        "repo": str(repos.split()[-1]),
        "expiretime": Public.Time(m=time),
        "network": docker_network_mode
    }

    #define instances for writing redis and sending email.
    rc = Redis.RedisObject()
    ec = Mail.SendMail()
    if rc.ping():
        import Source
        from sh import svn, chmod, chown
        Code = Source.CodeManager(**userinfo_admin)
        Code.ftp()

        if enable_svn == False and enable_git == False:
            os.mkdir(userhome)
            with open(os.path.join(userhome, 'index.html'), 'w') as f:
                f.write(userinfo_welcome)
            chown('-R', Config.FTP_VFTPUSER + ':' + Config.FTP_VFTPUSER,
                  userhome)
            chmod('-R', 'a+t', userhome)

        if enable_svn == True:
            Code.CreateApacheSvn()
            Code.initSvn(userinfo_welcome)

        if enable_git == True:
            Code.Git()
            Code.initGit(userinfo_welcome)

        Code.Proxy()
        Dk = Docker.Docker(
            **{
                "image": image,
                "name": name,
                "port": Config.PORTNAT['web'],
                "bind": ('127.0.0.1', PORT),
                "volume": userhome
            })
        cid = Dk.Create(mode=docker_network_mode)
        Dk.Start(cid)
        userinfo_admin["container"] = cid
        rc.hashset(**userinfo_admin)
        ec.send(name, email, userinfo_user)
    else:
        #raise an error for RedisConnectError(Error.py)
        print "\033[0;31;40mConnect Redis Server Error,Quit.\033[0m"
        sys.exit(7)
Esempio n. 18
0
def Profit():
    connStr = Public.GetPara('connStr')
    conn = co.connect(connStr)
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    # factor
    configDictList = [
        {
            'facName': 'FIN_NP_Q',
            'column': 12,
            'qfData': 2
        },  # 季度净利润
        {
            'facName': 'FIN_NP_QG',
            'column': 12,
            'qfData': 5
        },  # 季度净利润增长率
        {
            'facName': 'FIN_NP_12M',
            'column': 12,
            'qfData': 3
        },  # 12个月净利润
        {
            'facName': 'FIN_NP_12MG',
            'column': 12,
            'qfData': 6
        },  # 12个月净利润增长率
        {
            'facName': 'FIN_NPAPC_Q',
            'column': 13,
            'qfData': 2
        },  # 季度归母净利润
        {
            'facName': 'FIN_NPAPC_QG',
            'column': 13,
            'qfData': 5
        },  # 季度归母净利润增长率
        {
            'facName': 'FIN_NPAPC_12M',
            'column': 13,
            'qfData': 3
        },  # 12个月归母净利润
        {
            'facName': 'FIN_NPAPC_12MG',
            'column': 13,
            'qfData': 6
        },  # 12个月归母净利润增长率
        {
            'facName': 'FIN_OTR_Q',
            'column': 3,
            'qfData': 2
        },  # 季度营业总收入
        {
            'facName': 'FIN_OTR_QG',
            'column': 3,
            'qfData': 5
        },  # 季度营业总收入增长率
        {
            'facName': 'FIN_OTR_12M',
            'column': 3,
            'qfData': 3
        },  # 12个月营业总收入
        {
            'facName': 'FIN_OTR_12MG',
            'column': 3,
            'qfData': 6
        },  # 12个月营业总收入增长率
        {
            'facName': 'FIN_OR_Q',
            'column': 4,
            'qfData': 2
        },  # 季度营业收入
        {
            'facName': 'FIN_OR_QG',
            'column': 4,
            'qfData': 5
        },  # 季度营业收入增长率
        {
            'facName': 'FIN_OR_12M',
            'column': 4,
            'qfData': 3
        },  # 12个月营业收入
        {
            'facName': 'FIN_OR_12MG',
            'column': 4,
            'qfData': 6
        },  # 12个月营业收入增长率
        {
            'facName': 'FIN_OP_Q',
            'column': 9,
            'qfData': 2
        },  # 季度营业利润
        {
            'facName': 'FIN_OP_QG',
            'column': 9,
            'qfData': 5
        },  # 季度营业利润增长率
        {
            'facName': 'FIN_OP_12M',
            'column': 9,
            'qfData': 3
        },  # 12个月营业利润
        {
            'facName': 'FIN_OP_12MG',
            'column': 9,
            'qfData': 6
        },  # 12个月营业利润增长率
        {
            'facName': 'FIN_TP_Q',
            'column': 10,
            'qfData': 2
        },  # 季度利润总额
        {
            'facName': 'FIN_TP_QG',
            'column': 10,
            'qfData': 5
        },  # 季度利润总额增长率
        {
            'facName': 'FIN_TP_12M',
            'column': 10,
            'qfData': 3
        },  # 12个月利润总额
        {
            'facName': 'FIN_TP_12MG',
            'column': 10,
            'qfData': 6
        },  # 12个月利润总额增长率
        {
            'facName': 'FIN_OTC_Q',
            'column': 6,
            'qfData': 2
        },  # 季度营业总成本
        {
            'facName': 'FIN_OTC_12M',
            'column': 6,
            'qfData': 3
        },  # 12个月营业总成本
        {
            'facName': 'FIN_OC_Q',
            'column': 7,
            'qfData': 2
        },  # 季度营业成本
        {
            'facName': 'FIN_OC_12M',
            'column': 7,
            'qfData': 3
        },  # 12个月营业成本
        {
            'facName': 'FIN_ITE_Q',
            'column': 11,
            'qfData': 2
        },  # 季度所得税费用
        {
            'facName': 'FIN_ITE_12M',
            'column': 11,
            'qfData': 3
        }  # 12个月所得税费用
    ]
    for configDict in configDictList:
        facName = configDict['facName']
        print('==== ' + facName)
        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        dataList = Public.GetDataList(
            Public.sqlPrf, lastUpdateDate - dt.timedelta(days=365 * 3),
            dt.datetime.now(), conn)
        qfDataTuple = Public.QuarterFormat(dataList)
        column = configDict['column']
        dataDict = qfDataTuple[configDict['qfData']]
        facDict = {}
        for symbol, data in dataDict.items():
            facDict[symbol] = data[:, [0, 1, 2, column]]
        Public.ToDB(facDict,
                    facName,
                    endDate=None,
                    updateReportDate=False,
                    mongoClient=mc)

    ddd = 0
Esempio n. 19
0
 def setUp(self):
     self.targetApi = Public.domain() + '/shop/company'
Esempio n. 20
0
 def setUp(self):
     self.targetApi = Public.domain() + '/goods/list'
Esempio n. 21
0
 def setUp(self):
     self.targetApi= Public.domain()+'/user/login'
     self.validUsername='******'
     self.invalidUsername='******'
     self.validPwd='123123'
     self.invalidPwd='123456777'
Esempio n. 22
0
 def setUp(self):
     self.targetApi = Public.domain() + '/upload/img'
Esempio n. 23
0
 def setUp(self):
     self.base_url = 'http://192.168.1.241:88'
     self.app = Public.ClusterApi(self.base_url)
Esempio n. 24
0
 def setUp(self):
     self.type = sys.getfilesystemencoding()
     self.postdata=urllib.urlencode({})
     self.targetApi= Public.domain()+'/goods/category'
Esempio n. 25
0
    def create(self, the_type):
        """
        Create and return a code generator that generates a specific portion
        of code for all the visitor producers. Each of the producer visitors
        provides an interface to generate a portion of the code. The following
        portions are supported -- referenced by a string name.

        initFiles
        startSource
        includes1
        includes2
        namespace
        public
        protected
        private
        finishSource
        StartCommand
        CommandHeader

        The visitors correspond to source code files that are generated and
        kept here as a hardwired list of classes. The project parameter can
        be used to hardwire a different set of code generators.
        """

        # Get the list of code producing visitors. The hardwired list is
        # based on the project argument. A different set of visitors can
        # be assembled by project.

        project_visitor_list = self._buildVisitorList()

        # Instance the needed code snippet generator here.

        if the_type == "initFiles":
            code_section_generator = InitFiles.InitFiles()
        elif the_type == "startSource":
            code_section_generator = StartSource.StartSource()
        elif the_type == "includes1":
            code_section_generator = Includes1.Includes1()
        elif the_type == "includes2":
            code_section_generator = Includes2.Includes2()
        elif the_type == "namespace":
            code_section_generator = Namespace.Namespace()
        elif the_type == "public":
            code_section_generator = Public.Public()
        elif the_type == "protected":
            code_section_generator = Protected.Protected()
        elif the_type == "private":
            code_section_generator = Private.Private()
        elif the_type == "finishSource":
            code_section_generator = FinishSource.FinishSource()

        elif the_type == "DictStart":
            code_section_generator = DictStart.DictStart()
        elif the_type == "DictHeader":
            code_section_generator = DictHeader.DictHeader()
        elif the_type == "DictBody":
            code_section_generator = DictBody.DictBody()

        elif the_type == "InstanceDictStart":
            code_section_generator = InstanceDictStart.InstanceDictStart()
        elif the_type == "InstanceDictHeader":
            code_section_generator = InstanceDictHeader.InstanceDictHeader()
        elif the_type == "InstanceDictBody":
            code_section_generator = InstanceDictBody.InstanceDictBody()

        elif the_type == "HtmlStart":
            code_section_generator = HtmlStartPage.HtmlStartPage()
        elif the_type == "HtmlDoc":
            code_section_generator = HtmlDocPage.HtmlDocPage()

        elif the_type == "MdStart":
            code_section_generator = MdStartPage.MdStartPage()
        elif the_type == "MdDoc":
            code_section_generator = MdDocPage.MdDocPage()

        else:
            print "GenFactory: unsupported code section (%s)." % (the_type)
            return None

        self._addVisitor(code_section_generator, project_visitor_list)

        return code_section_generator
Esempio n. 26
0
 def setUp(self):
     self.targetApi= Public.domain()+'/user/check'
     self.token= Public.getUserToken(username='******',pwd='123123')
Esempio n. 27
0
 def setUp(self):
     self.targetApi = Public.domain() + '/user/check'
     self.token = Public.getUserToken(username='******', pwd='123123')
Esempio n. 28
0
 def setUp(self):
     self.base_url = 'http://192.168.1.241:88'
     self.app = Public.InstanceApi(self.base_url)
Esempio n. 29
0
 def setUp(self):
     self.targetApi= Public.domain()+'/goods/list'
Esempio n. 30
0
 def setUp(self):
     self.targetApi= Public.domain()+'/user/publish'
     self.rid=Public.getRequestID('0')
     print self.rid
Esempio n. 31
0
def StartAll(SdpType, **user):
    if not isinstance(SdpType, (str)):
        raise TypeError('StartAll need a type, app or web.')
    if not isinstance(user, (dict)):
        raise TypeError('StartAll need a dict(user).')
    name, passwd, time, service, email = user['name'], user['passwd'], str(
        user['time']), user['service'], user['email']
    dn = name + Config.DN_BASE
    portfile = os.path.join(Config.SDP_DATA_HOME, 'port')

    if not os.path.isdir(Config.SDP_DATA_HOME):
        os.mkdir(Config.SDP_DATA_HOME)
    if not os.path.isdir(Config.SDP_USER_DATA_HOME):
        os.mkdir(Config.SDP_USER_DATA_HOME)
    if not os.path.isdir(Config.SDP_LOGS_DATA_HOME):
        os.mkdir(Config.SDP_LOGS_DATA_HOME)
    if not os.path.isdir(Config.PROXY_DIR):
        os.mkdir(Config.PROXY_DIR)

    #set portfile, read and write(update)
    if os.path.exists(portfile):
        with open(portfile, 'r') as f:
            PORT = f.read()
            PORT = int(PORT) + 1
    else:
        PORT = Config.STARTPORT
    with open(portfile, 'w') as f:
        f.write(str(PORT))
    PORT = int(PORT)

    #define image_name
    if not Config.DOCKER_TAG:
        image = Config.DOCKER_REGISTRY + '/' + service
    else:
        image = Config.DOCKER_REGISTRY + '/' + Config.DOCKER_TAG + '/' + service

    #Web start dockerinfo
    dockerinfo = {"image": image, "name": name}
    if SdpType == "web" or SdpType == "WEB":
        userhome = os.path.join(Config.SDP_USER_DATA_HOME, name)
        os.chdir(Config.SDP_USER_DATA_HOME)
        if not os.path.isdir(name):
            os.mkdir(name)
        dockerinfo["port"] = Config.PORTNAT['web']
        dockerinfo["bind"] = ('127.0.0.1', PORT)
        dockerinfo["volume"] = userhome
        userinfo_admin = {
            "name": name,
            "passwd": passwd,
            "time": int(time),
            "service": service,
            "email": email,
            'image': image,
            'ip': '127.0.0.1',
            'port': int(PORT),
            'dn': dn,
            'userhome': userhome
        }
        conn = dn
    #App start dockerinfo
    elif SdpType == "app" or SdpType == "APP":
        dockerinfo["port"] = Config.PORTNAT[service]
        dockerinfo["bind"] = (Config.SERVER_IP, PORT)
        userinfo_admin = {
            "name": name,
            "passwd": passwd,
            "time": int(time),
            "service": service,
            "email": email,
            'image': image,
            'ip': Config.SERVER_IP,
            'port': int(PORT)
        }
        conn = Config.SERVER_IP + ':' + str(PORT)
    else:
        return 127

    #Run and Start Docker, should build.
    C = Docker.Docker()
    cid = C.Create(**dockerinfo)
    C.Start(cid)
    userinfo_admin['container'] = cid
    userinfo_admin['expiretime'] = Public.Time(m=time)
    userinfo_user = r'''
Dear %s, 以下是您的SdpCloud服务使用信息!
账号: %s;
密码: %s;
使用期: %d;
服务类型: %s;
验证邮箱: %s;
服务连接信息: %s

祝您使用愉快。如果有任何疑惑,欢迎与我们联系:
邮箱: [email protected]
官网: http://www.saintic.com/
微博: http://weibo.com/staugur/
淘宝: https://shop126877887.taobao.com/
''' % (name, name, passwd, int(time), service, email, str(conn))

    userinfo_welcome = r'''<!DOCTYPE html>
<html>
<head>
<title>User information for SdpCloud!</title>
</head>
<body>
<h1><center>Welcome %s:</center></h1>
<p>账号: %s;</p>
<p>密码: %s;</p>
<p>使用期: %d;</p>
<p>服务类型: %s;</p>
<p>验证邮箱: %s;</p>
<p>服务连接信息: %s</p>
<p>这是一个欢迎页面,请尽快使用FTP覆盖此页面!</p>
<p><em>Thank you for using SdpCloud.</em></p>
</body>
</html>
''' % (name, name, passwd, int(time), service, email, str(conn))

    #define connection for redis and mailserver.
    userconn = (name, email, userinfo_user)
    #adminconn = ('Administrator', Config.ADMIN_EMAIL, userinfo_admin)
    rc = RedisObject()
    ec = SendMail()

    #start write data
    if rc.ping():
        rc.hashset(**userinfo_admin)
        ec.send(*userconn)
        #ec.send(*adminconn)
        with open(Config.SDP_UC, 'a+') as f:
            f.write(json.dumps(userinfo_admin))
        if SdpType == "web" or SdpType == "WEB":
            with open(os.path.join(userhome, 'index.html'), 'w') as f:
                f.write(userinfo_welcome)
            import Success
            Code = Success.CodeManager(name)
            Code.ftp()
            Code.Proxy()
    else:
        print "\033[0;31;40mConnect Redis Server Error,Quit.\033[0m"
        sys.exit(7)
Esempio n. 32
0
 def setUp(self):
     self.base_url = 'http://192.168.1.241:88'
     self.app = Public.SettingApi(self.base_url)
Esempio n. 33
0
 def setUp(self):
     self.targetApi = Public.domain() + '/shop/goods'
Esempio n. 34
0
 def setUp(self):
     self.targetApi= Public.domain()+'/user/yzm'
     self.new_tel='13777777777'#用于返回code0发送成功及code6该手机未注册(修改与找回用)
     self.exist_tel='18817763313'#用于返回code5手机号已存在
     self.invalid_tel='1371234564'#用于返回code3手机号无效
Esempio n. 35
0
def Balance():
    connStr = Public.GetPara('connStr')
    conn = co.connect(connStr)
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    # factor
    configDictList = [
        {
            'facName': 'FIN_MC',
            'column': 3,
            'qfData': 1
        },  # 货币资金
        {
            'facName': 'FIN_LA',
            'column': 4,
            'qfData': 1
        },  # 流动资产
        {
            'facName': 'FIN_FA',
            'column': 5,
            'qfData': 1
        },  # 固定资产
        {
            'facName': 'FIN_IA',
            'column': 6,
            'qfData': 1
        },  # 无形资产
        {
            'facName': 'FIN_TNLA',
            'column': 7,
            'qfData': 1
        },  # 非流动资产合计
        {
            'facName': 'FIN_TA',
            'column': 8,
            'qfData': 1
        },  # 资产总计
        {
            'facName': 'FIN_STB',
            'column': 9,
            'qfData': 1
        },  # 短期借款
        {
            'facName': 'FIN_NLL1Y',
            'column': 10,
            'qfData': 1
        },  # 一年内到期的非流动负债
        {
            'facName': 'FIN_TLL',
            'column': 11,
            'qfData': 1
        },  # 流动负债合计
        {
            'facName': 'FIN_LTB',
            'column': 12,
            'qfData': 1
        },  # 长期借款
        {
            'facName': 'FIN_TNLL',
            'column': 13,
            'qfData': 1
        },  # 非流动负债合计
        {
            'facName': 'FIN_TL',
            'column': 14,
            'qfData': 1
        },  # 负债合计
        {
            'facName': 'FIN_PUC',
            'column': 15,
            'qfData': 1
        },  # 实收资本(或股本)
        {
            'facName': 'FIN_UDP',
            'column': 16,
            'qfData': 1
        },  # 未分配利润
        {
            'facName': 'FIN_TOEAPC',
            'column': 17,
            'qfData': 1
        },  # 归母权益合计
        {
            'facName': 'FIN_MSE',
            'column': 18,
            'qfData': 1
        },  # 少数股东权益
        {
            'facName': 'FIN_TOE',
            'column': 19,
            'qfData': 1
        },  # 所有者权益合计
        {
            'facName': 'FIN_TLOE',
            'column': 20,
            'qfData': 1
        },  # 负债和所有者权益合计
        {
            'facName': 'FIN_IVT',
            'column': 21,
            'qfData': 1
        },  # 存货
        {
            'facName': 'FIN_TA_G',
            'column': 8,
            'qfData': 4
        },  # 总资产增长率
        {
            'facName': 'FIN_TL_G',
            'column': 14,
            'qfData': 4
        },  # 总负债增长率
        {
            'facName': 'FIN_TOEAPC_G',
            'column': 17,
            'qfData': 4
        },  # 归母权益增长率
        {
            'facName': 'FIN_TOE_G',
            'column': 19,
            'qfData': 4
        },  # 所有者权益增长率
        {
            'facName': 'FIN_TA_QA',
            'column': 8,
            'qfData': 7
        },  # 季度总资产平均值
        {
            'facName': 'FIN_TOEAPC_QA',
            'column': 17,
            'qfData': 7
        },  # 季度归母权益平均值
        {
            'facName': 'FIN_TOE_QA',
            'column': 19,
            'qfData': 7
        },  # 季度所有者权益平均值
        {
            'facName': 'FIN_IVT_QA',
            'column': 21,
            'qfData': 7
        },  # 季度存货平均值
        {
            'facName': 'FIN_TA_12MA',
            'column': 8,
            'qfData': 8
        },  # 12个月总资产平均值
        {
            'facName': 'FIN_TOEAPC_12MA',
            'column': 17,
            'qfData': 8
        },  # 12个月归母权益平均值
        {
            'facName': 'FIN_TOE_12MA',
            'column': 19,
            'qfData': 8
        },  # 12个月所有者权益平均值
        {
            'facName': 'FIN_IVT_12MA',
            'column': 21,
            'qfData': 8
        }  # 12个月存货平均值
    ]
    for configDict in configDictList:
        facName = configDict['facName']
        print('==== ' + facName)
        lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
        dataList = Public.GetDataList(
            Public.sqlBlc, lastUpdateDate - dt.timedelta(days=365 * 3),
            dt.datetime.now(), conn)
        qfDataTuple = Public.QuarterFormat(dataList)
        column = configDict['column']
        dataDict = qfDataTuple[configDict['qfData']]
        facDict = {}
        for symbol, data in dataDict.items():
            facDict[symbol] = data[:, [0, 1, 2, column]]
        updateReportDate = True if facName == 'FIN_TA' else False
        Public.ToDB(facDict,
                    facName,
                    endDate=None,
                    updateReportDate=updateReportDate,
                    mongoClient=mc)

    ddd = 0
Esempio n. 36
0
def Beta(betaPrefix,
         betaDaysList,
         indexSymbolDict,
         indexSql,
         stockSql,
         endDate=None):
    if endDate is None:
        dtNow = dt.datetime.now() - dt.timedelta(days=1)
        endDate = dt.datetime(dtNow.year, dtNow.month, dtNow.day)
    else:
        endDate = dt.datetime(endDate.year, endDate.month, endDate.day)
        if endDate.date() >= dt.datetime.now().date():
            endDate = dt.datetime(dt.datetime.now().year, dt.datetime.now().month, dt.datetime.now().day) - \
                      dt.timedelta(days=1)

    connStr = Public.GetPara('connStr')
    conn = co.connect(connStr)
    cursor = conn.cursor()
    mongoConn = Public.GetPara('mongoConn')
    mc = pm.MongoClient(mongoConn)
    db = mc['factor']

    for days in betaDaysList:
        for indexCode, indexSymbol in indexSymbolDict.items():
            facName = betaPrefix + '_' + indexSymbol + '_' + str(days)
            lastUpdateDate = Public.GetLastUpdateDate(facName, mc)
            tradingDateSet = Public.GetCalendar(lastUpdateDate, endDate)
            currentDate = lastUpdateDate - dt.timedelta(days=days)
            savedDate = lastUpdateDate
            indexRtnDict = {}
            stockRtnDict = {}
            while currentDate + dt.timedelta(days=1) <= endDate:
                currentDate += dt.timedelta(days=1)
                # if currentDate not in tradingDateSet:
                #     continue

                # get data
                for stockSymbol, stockRtnList in stockRtnDict.items():
                    stockRtnList.append(np.nan)
                for indexSymbol, indexRtnList in indexRtnDict.items():
                    indexRtnList.append(np.nan)

                cursor.execute(
                    stockSql.replace('{TRADE_DATE}',
                                     currentDate.strftime('%Y-%m-%d')))
                stockRtnRecordSet = cursor.fetchall()
                for stockRtnRecord in stockRtnRecordSet:
                    symbol = stockRtnRecord[1]
                    rtn = stockRtnRecord[4]
                    if symbol not in stockRtnDict.keys():
                        stockRtnDict[symbol] = [np.nan]
                    stockRtnDict[symbol][
                        -1] = rtn if rtn is not None else np.nan

                cursor.execute(
                    indexSql.replace('{TRADE_DATE}',
                                     currentDate.strftime('%Y-%m-%d')).replace(
                                         '{INDEX_CODE}', str(indexCode)))
                indexRtnRecordSet = cursor.fetchall()
                for indexRtnRecord in indexRtnRecordSet:
                    symbol = indexRtnRecord[1]
                    if symbol != indexSymbol:
                        raise Exception(
                            'index code is not fit to index symbol!')
                    rtn = indexRtnRecord[4]
                    if symbol not in indexRtnDict.keys():
                        indexRtnDict[symbol] = [np.nan]
                    indexRtnDict[symbol][
                        -1] = rtn if rtn is not None else np.nan

                if currentDate <= lastUpdateDate:
                    continue

                # evaluate beta and save to db
                if indexSymbol not in indexRtnDict.keys() or len(
                        indexRtnDict[indexSymbol]) < days / 2:
                    continue
                mongoDoc = {
                    '_id': currentDate,
                    '_updateTime': dt.datetime.now(),
                    '_isTrade': (currentDate in tradingDateSet)
                }
                indexArr = np.array(indexRtnDict[indexSymbol]
                                    [max(0,
                                         len(indexRtnDict[indexSymbol]) -
                                         days):],
                                    dtype=float)
                for stockSymbol, stockRtnList in stockRtnDict.items():
                    stockArr = np.array(
                        stockRtnList[max(0,
                                         len(stockRtnList) - days):],
                        dtype=float)
                    if len(stockArr) != len(indexArr):
                        continue
                    vld = np.isfinite(stockArr) * np.isfinite((indexArr))
                    if np.sum(vld) < days / 3:  # data is not sufficient
                        continue
                    const = np.ones(len(stockArr))
                    X = np.vstack([indexArr[vld], const[vld]]).T
                    y = stockArr[vld]
                    c, res, rank, s = np.linalg.lstsq(X, y)
                    beta = c[0]
                    mongoDoc[stockSymbol] = beta
                db[facName].save(mongoDoc)

                savedDate = currentDate
                print(facName + ' ' + str(currentDate))

            db.cfgUpdate.save({'_id': facName, 'lastUpdateDate': savedDate})
Esempio n. 37
0
 def setUp(self):
     self.base_url = 'http://192.168.1.241:88'
     self.username = '******'
     self.password = '******'
     self.app = Public.UserApi(self.base_url)
Esempio n. 38
0
 def setUp(self):
     self.targetApi = Public.domain() + "/shop/goods"
Esempio n. 39
0
 def setUp(self):
     self.targetApi = Public.domain() + '/user/login'
     self.validUsername = '******'
     self.invalidUsername = '******'
     self.validPwd = '123123'
     self.invalidPwd = '123456777'
Esempio n. 40
0
 def setUp(self):
     self.targetApi= Public.domain()+'/shop/company'