def inspectorWorkTimeSummary(request): """ 进料检验公示汇总 :param request:客户端请求,GET搜索域包含日期的年份和月份 :return:返回报表详细数据的JSON格式文本 """ year = request.GET['year'] month = request.GET['month'] return HttpResponse(json.dumps(Statistic.getInspectorWorkTimeGroupByMaterial(year, month), encoding='GBK'))
def suppliersAnalysis(request): """ 供应商交货情况报表视图 :param request:客户端请求,包括时间范围的开始时间start,时间范围的结束时间end :return:返回报表详细数据的JSON格式文本 """ start = request.GET['start'] end = request.GET['end'] return HttpResponse(json.dumps(Statistic.getSuppliersAssessmentDataByDate(start, end), encoding='GBK'))
def statistic(self): import Statistic Statistic.plotgraph()
def setUpClass(self): #入参 self.userID = '132316' self.AccountIndex = 4 #连接beta环境的MongoDB mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater_data( host=mongoUrl, port=statisticData["mongo_port"]) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID), accountIndex=str( self.AccountIndex)) print(self.mt4Account) '''获取个人展示页的月分析报告数据''' self.profitAndLossAnalysis = Datastatistic.getProfitAndLossAnalysis( webAPIData['hostName'] + datastatisticData['getProfitAndLossAnalysis_url'] + str(self.userID) + "_" + str(self.AccountIndex) + datastatisticData["getProfitAndLossAnalysis_url2"], params="timeType=TimeTypeWeek", printLogs=0) # self.assertEqual(monthAnalysisReport.status_code, webAPIData['status_code_200']) self.weekList = [] self.moneyList = [] self.moneyProfitLongList = [] self.moneyLossLongList = [] self.moneyProfitShortList = [] self.moneyLossShortList = [] self.pipsList = [] self.pipsProfitLongList = [] self.pipsLossLongList = [] self.pipsProfitShortList = [] self.pipsLossShortList = [] self.standardLotsLongList = [] self.standardLotsShortList = [] self.money_close_MongoList = [] for self.item in json.loads( self.profitAndLossAnalysis.text)["data"]["HourAndWeekList"]: #遍历返回数据的所有周 self.weekList.append(self.item["Week"]) #遍历返回数据的所有收益 self.moneyList.append(self.item["Money"]) #遍历返回数据的所有做多盈利收益 self.moneyProfitLongList.append(self.item["MoneyProfitLong"]) #遍历返回数据的所有做多亏损收益 self.moneyLossLongList.append(self.item["MoneyLossLong"]) #遍历返回数据的所有做空盈利收益 self.moneyProfitShortList.append(self.item["MoneyProfitShort"]) #遍历返回数据的所有做空亏损收益 self.moneyLossShortList.append(self.item["MoneyLossShort"]) #遍历返回数据的所有点数 self.pipsList.append(self.item["Pips"]) #遍历返回数据的所有做多盈利点数 self.pipsProfitLongList.append(self.item["PipsProfitLong"]) #遍历返回数据的所有做多亏损点数 self.pipsLossLongList.append(self.item["PipsLossLong"]) #遍历返回数据的所有做空盈利点数 self.pipsProfitShortList.append(self.item["PipsProfitShort"]) #遍历返回数据的所有做空亏损点数 self.pipsLossShortList.append(self.item["PipsLossShort"]) #遍历返回数据的所有做多手数 self.standardLotsLongList.append(self.item["StandardLotsLong"]) #遍历返回数据的所有做空手数 self.standardLotsShortList.append(self.item["StandardLotsShort"]) # #转换时间戳,把时间戳转换为时间 # timeStamp = int(self.item["Month"]) # timeArray = time.localtime(timeStamp) # otherStyleMonth = time.strftime("%Y-%m", timeArray) # print(otherStyleMonth) self.money_close_MongoList = [] self.money_profit_long_close_MongoList = [] self.money_loss_long_close_MongoList = [] self.money_profit_short_close_MongoList = [] self.money_loss_short_close_MongoList = [] self.money_loss_long_close_MongoList = [] self.point_close_MongoList = [] self.point_profit_long_close_MongoList = [] self.point_loss_long_close_MongoList = [] self.point_profit_short_close_MongoList = [] self.point_loss_short_close_MongoList = [] self.standardlots_long_close_MongoList = [] self.standardlots_short_close_MongoList = [] # for i in mongoDB.fm.mg_result_Week.find({"_id":str(self.mt4Account) + "_" + str(self.brokerid) + str(otherStyleMonth) + str(self.item["Week"])}): for i in mongoDB.datastatistic.mg_result_week.find({ "login": str(self.mt4Account), "close_week": self.item["Week"] }): self.mongoList = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList[key] = value #获取MongoDB的平仓收益 self.money_close_MongoList.append( self.mongoList["money_close"]) # print("888888888888") # print(self.mongoList["money_close"]) #获取MongoDB的平仓做多盈利收益 self.money_profit_long_close_MongoList.append( self.mongoList["money_profit_long_close"]) #获取MongoDB的平仓做多亏损收益 self.money_loss_long_close_MongoList.append( self.mongoList["money_loss_long_close"]) #获取MongoDB的平仓做空盈利收益 self.money_profit_short_close_MongoList.append( self.mongoList["money_profit_short_close"]) #获取MongoDB的平仓做空亏损收益 self.money_loss_short_close_MongoList.append( self.mongoList["money_loss_short_close"]) #获取MongoDB的平仓点数 self.point_close_MongoList.append( self.mongoList["point_close"]) #获取MongoDB的平仓做多盈利点数 self.point_profit_long_close_MongoList.append( self.mongoList["point_profit_long_close"]) #获取MongoDB的平仓做多亏损点数 self.point_loss_long_close_MongoList.append( self.mongoList["point_loss_long_close"]) #获取MongoDB的平仓做空盈利点数 self.point_profit_short_close_MongoList.append( self.mongoList["point_profit_short_close"]) #获取MongoDB的平仓做空亏损点数 self.point_loss_short_close_MongoList.append( self.mongoList["point_loss_short_close"]) #获取MongoDB的平仓所有做多手数 self.standardlots_long_close_MongoList.append( self.mongoList["standardlots_long_close"]) #获取MongoDB的平仓所有做空手数 self.standardlots_short_close_MongoList.append( self.mongoList["standardlots_short_close"]) table_1 = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "周", "平仓收益", "平仓做多盈利收益", "平仓做多亏损收益", "平仓做空盈利收益", "平仓做空亏损收益", "做多手数" ]) table_2 = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "周", "平仓点数", "平仓做多盈利点数", "平仓做多亏损点数", "平仓做空盈利点数", "平仓做空亏损点数", "做空手数" ]) try: table_1.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, self.item["Week"], self.mongoList["money_close"], self.mongoList["money_profit_long_close"], self.mongoList["money_loss_long_close"], self.mongoList["money_profit_short_close"], self.mongoList["money_loss_short_close"], self.mongoList["standardlots_long_close"] ]) table_1.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, self.item["Week"], self.item["Money"], self.item["MoneyProfitLong"], self.item["MoneyLossLong"], self.item["MoneyProfitShort"], self.item["MoneyLossShort"], self.item["StandardLotsLong"] ]) table_1.add_row(["", "", "", "", "", "", "", "", "", "", ""]) table_2.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, self.item["Week"], self.mongoList["point_close"], self.mongoList["point_profit_long_close"], self.mongoList["point_loss_long_close"], self.mongoList["point_profit_short_close"], self.mongoList["point_loss_short_close"], self.mongoList["standardlots_short_close"] ]) table_2.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, self.item["Week"], self.item["Pips"], self.item["PipsProfitLong"], self.item["PipsLossLong"], self.item["PipsProfitShort"], self.item["PipsLossShort"], self.item["StandardLotsShort"] ]) table_2.add_row(["", "", "", "", "", "", "", "", "", "", ""]) finally: table_1.reversesort = True table_2.reversesort = True print(table_1) print(table_2)
def test_2_getChoiceTrades_twoWeek(self): '''获取近两周的精选交易员信息''' params = {"category ": "fm", "time": 14} trades = FollowManage.getTraders(webAPIData['hostName'] + followData['getTraders_url'], params=params, printLogs=1) self.assertEqual(trades.status_code, webAPIData['status_code_200']) print("ChoiceTrades_twoWeek:") table = PrettyTable([ "预期/实际", "NickName", "UserID", "AccountIndex", "净值利润因子", "近一周盈亏点数", "交易周期", "平均持仓时间", "粉丝人数", "交易笔数" ]) try: for item in json.loads(trades.text)["data"]["items"]: mt4Account = Statistic.getMt4Account( userID=str(item["UserId"]), accountIndex=str(item["AccountCurrentIndex"])) factorProfitEquity = Statistic.factorProfitEquity( mt4Account=mt4Account, brokerID=item["BrokerId"]) nearWeekPoint = Statistic.nearWeekPoint( mt4Account=mt4Account, brokerID=item["BrokerId"]) tradePeriod = Statistic.tradePeriod(mt4Account=mt4Account, brokerID=item["BrokerId"]) avgTradeTimeMin = Statistic.avgTradeTime( mt4Account=mt4Account, brokerID=item["BrokerId"]) avgTradeTime = str(int(avgTradeTimeMin // 60)) + '小时' + str( int(avgTradeTimeMin % 60)) + '分' fansCount = Statistic.fansCount(mt4Account=mt4Account) historyOrder = Statistic.historyOrder( mt4Account=mt4Account, brokerID=item["BrokerId"]) table.add_row([ "预期结果", item["NickName"], item["UserId"], item["AccountCurrentIndex"], factorProfitEquity, nearWeekPoint, tradePeriod, avgTradeTime, fansCount, historyOrder ]) table.add_row([ "实际结果", item["NickName"], item["UserId"], item["AccountCurrentIndex"], item["ProfitFactor"], item["BizPoint"], item["Weeks"], item["BizAVGTradeTime"], item["FoucsCount"], item["Orders"] ]) table.add_row(["", "", "", "", "", "", "", "", "", ""]) #由于非实时统计数据,实际结果存在误差。净值利润因子预期和实际正负差值小于等于0.2都算断言通过 self.assertAlmostEqual(factorProfitEquity, item["ProfitFactor"], delta=0.9) self.assertAlmostEqual(nearWeekPoint, float(item["BizPoint"]), delta=100000) self.assertAlmostEqual(tradePeriod, item["Weeks"], delta=1) # self.assertEqual(avgTradeTime,item["BizAVGTradeTime"]) self.assertAlmostEqual(fansCount, item["FoucsCount"], delta=100) self.assertAlmostEqual(historyOrder, item["Orders"], delta=10000) finally: table.reversesort = True print(table)
def setUp(self): #入参 self.userID = '163735' self.AccountIndex = 2 mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater_data( host=mongoUrl, port=statisticData["mongo_port"]) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID), accountIndex=str( self.AccountIndex)) print(self.mt4Account) '''获取个人展示页的收益率图表数据''' # accountRoi = Datastatistic.getAccountRoi(webAPIData['hostName'] + followData['getStatisticsOfAccount_url'] + str(self.userID) + "_"+ str(self.AccountIndex) + followData["getStatisticsOfAccount_url1"],printLogs=0) accountRoi = Datastatistic.getAccountRoi( webAPIData['hostName'] + datastatisticData['getAccountRoi_url'] + str(self.userID) + "_" + str(self.AccountIndex) + datastatisticData["getAccountRoi_url2"], printLogs=0) self.assertEqual(accountRoi.status_code, webAPIData['status_code_200']) self.dateList = [] self.roiList = [] for self.items in json.loads(accountRoi.text)["data"]["RoiList"]: self.roiList.append(self.items["Roi"]) self.dateList.append(self.items["Date"]) timeStamp = int(self.items["Date"]) timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d", timeArray) for i in mongoDB.datastatistic_1_16.mg_result_day.find({ "login": str(self.mt4Account), "close_date": otherStyleTime }): self.mongoList_day = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList_day[key] = value table = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "Date", "收益率" ]) try: table.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.mongoList_day["rate_asumasum_profit_balance_close"] ]) table.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.items["Roi"] ]) table.add_row(["", "", "", "", "", ""]) finally: table.reversesort = True print(table) self.monthList = [] self.buyStandardLotsList = [] self.sellStandardLotsList = [] self.pipsList = [] for self.item in json.loads(accountRoi.text)["data"]["MonthDataList"]: self.monthList.append(self.item["Month"]) self.buyStandardLotsList.append(self.item["BuyStandardLots"]) self.sellStandardLotsList.append(self.item["SellStandardLots"]) self.pipsList.append(self.item["Pips"]) monthStamp = int(self.item["Month"]) monthArray = time.localtime(monthStamp) otherStyleMonth = time.strftime("%Y-%m", monthArray) for j in mongoDB.datastatistic_1_16.mg_result_month.find({ "login": str(self.mt4Account), "close_month": otherStyleMonth }): self.mongoList_month = {} for key in statisticData["mongoKeyListAll"]: try: value = j[key] except KeyError: value = statisticData["keyErr"] self.mongoList_month[key] = value table_1 = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "Month", "做多手数", "做空手数", "盈亏点数" ]) try: table_1.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleMonth, self.mongoList_month["standardlots_long_close"], self.mongoList_month["standardlots_short_close"], self.mongoList_month["point_profit_close"] + self.mongoList_month["point_loss_close"] ]) table_1.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleMonth, self.item["BuyStandardLots"], self.item["SellStandardLots"], self.item["Pips"] ]) table_1.add_row(["", "", "", "", "", "", "", ""]) finally: table_1.reversesort = True print(table_1)
def setUpClass(self): #入参 self.userID = '18907' self.AccountIndex = 2 mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater_data( host=mongoUrl, port=statisticData["mongo_port"]) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID), accountIndex=str( self.AccountIndex)) print(self.mt4Account) '''获取个人展示页的净值余额图表数据''' balanceAndEquity = Datastatistic.getDayAccountBalanceAndEquityList( webAPIData['hostName'] + datastatisticData['getDayAccountBalanceAndEquityList_url'] + str(self.userID) + "_" + str(self.AccountIndex) + datastatisticData["getDayAccountBalanceAndEquityList_url2"], printLogs=0) # self.assertEqual(balanceAndEquity.status_code, webAPIData['status_code_200']) self.dateList = [] self.depositList = [] self.withdrawList = [] for self.item in json.loads( balanceAndEquity.text)["data"]["DepositAndWithdrawList"]: self.dateList.append(self.item["Date"]) self.depositList.append(self.item["Deposit"]) self.withdrawList.append(self.item["Withdraw"]) timeStamp = int(self.item["Date"]) timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d", timeArray) print(otherStyleTime) for i in mongoDB.datastatistic.mg_result_day.find({ "login": str(self.mt4Account), "close_date": str(otherStyleTime) }): self.mongoList_day = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList_day[key] = value table = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "Date", "出金", "入金" ]) try: table.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.mongoList_day["deposit"], self.mongoList_day["withdraw"] ]) table.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.item["Deposit"], self.item["Withdraw"] ]) table.add_row(["", "", "", "", "", "", ""]) finally: table.reversesort = True print(table)
def test_1_getAccountsOfUser(self): '''获取用户的交易账号列表''' # userID = "148171" #交易员 userID = "148181" #跟随者 url = webAPIData['hostName'] + personalPageData[ 'getAccountsOfUser_url1'] + userID + personalPageData[ 'getAccountsOfUser_url2'] accountList = PersonalPage.getAccountsOfUser( url, headers=webAPIData['headers'], printLogs=1) #请求成功 返回 200 self.assertEqual(accountList.status_code, webAPIData['status_code_200']) table = PrettyTable([ "预期/实际", "Id", "AccountIndex", "BrokerId", "mt4Account", "AccountType", "净值利润因子/跟随获利点数", "收益率", "跟随周期" ]) try: for item in json.loads(accountList.text)["data"]["accounts"]: mt4Account = Statistic.getMt4Account( userID=str(item["UserId"]), accountIndex=str(item["AccountIndex"])) userType = Statistic.userType(mt4Account=mt4Account) factorProfitEquity = Statistic.factorProfitEquity( mt4Account=mt4Account, brokerID=item["BrokerId"]) pointOfCfClose = Statistic.pointOfCfClose( mt4Account=mt4Account, brokerID=item["BrokerId"]) rateProfit = Statistic.rateProfit(mt4Account=mt4Account, brokerID=item["BrokerId"]) tradePeriod = Statistic.tradePeriod(mt4Account=mt4Account, brokerID=item["BrokerId"]) if userType == 1: table.add_row([ "预期结果", item["Id"], item["AccountIndex"], item["BrokerId"], mt4Account, item["AccountType"], factorProfitEquity, rateProfit, tradePeriod ]) table.add_row([ "实际结果", item["Id"], item["AccountIndex"], item["BrokerId"], mt4Account, item["AccountType"], item["ProfitFactorOrPoint"], item["ROI"] * 100, item["Weeks"] ]) table.add_row(["", "", "", "", "", "", "", "", ""]) #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(factorProfitEquity, float(item["ProfitFactorOrPoint"]), delta=2) self.assertAlmostEqual(rateProfit, float(item["ROI"] * 100), delta=1000000) self.assertAlmostEqual(tradePeriod, float(item["Weeks"]), delta=1000000) elif userType == 2: table.add_row([ "预期结果", item["Id"], item["AccountIndex"], item["BrokerId"], mt4Account, item["AccountType"], pointOfCfClose, rateProfit, tradePeriod ]) table.add_row([ "实际结果", item["Id"], item["AccountIndex"], item["BrokerId"], mt4Account, item["AccountType"], item["ProfitFactorOrPoint"], item["ROI"] * 100, item["Weeks"] ]) table.add_row(["", "", "", "", "", "", "", "", ""]) #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(pointOfCfClose, float(item["ProfitFactorOrPoint"]), delta=200) self.assertAlmostEqual(rateProfit, float(item["ROI"] * 100), delta=10000) self.assertAlmostEqual(tradePeriod, item["Weeks"], delta=10000) finally: table.reversesort = True print(table)
import Statistic import argparse if __name__ == '__main__': parser = argparse.ArgumentParser(description='Starts the client') # parser.add_argument('-room_id', '--room_id', type=int, default=0, parser.add_argument('-room_id', '--room_id', type=str, default='None', help='Sets room ID') # parser.add_argument('-seat_id', '--seat_id', type=int, default=0, parser.add_argument('-seat_id', '--seat_id', type=str, default="None", help='Sets seat ID') args = parser.parse_args() Statistic.check_occupied(args.room_id, args.seat_id)
def setUpClass(self): #入参 self.userID = '140130' self.AccountIndex = 4 # mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoUrl = "mongodb://%s:%s@%s" % (statisticData.mongo_userName, statisticData.mongo_passwd, statisticData.mongo_host) mongoDB = FMCommon.mongoDB_operater_data(host=mongoUrl, port=statisticData.mongo_port) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID), accountIndex=str( self.AccountIndex)) print(self.mt4Account) '''获取个人展示页的收益率图表数据''' accountRoi = Datastatistic.getAccountRoi( webAPIData.hostName + datastatisticData.getAccountRoi_url + str(self.userID) + "_" + str(self.AccountIndex) + datastatisticData.getAccountRoi_url2, printLogs=1) # self.assertEqual(accountRoi.status_code, webAPIData['status_code_200']) '''获取FM的经纪商列表''' self.roiList = [] self.dateList = [] self.selfRoiList = [] self.followRoiList = [] # for self.item in json.loads(accountRoi.text)["data"]["RoiList"]: for self.item in json.loads(accountRoi.text)["data"]["RoiList"]: self.roiList.append(self.item["Roi"]) print(self.roiList[0]) self.dateList.append(self.item["Date"]) self.selfRoiList.append(self.item["SelfRoi"]) self.followRoiList.append(self.item["FollowRoi"]) timeStamp = int(self.item["Date"]) timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d", timeArray) for i in mongoDB.datastatistic_1_16.mg_result_day.find({ "login": str(self.mt4Account), "close_date": str(otherStyleTime) }): self.mongoList = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList[key] = value table = PrettyTable([ "预期/实际", "UserID", "AccountIndex", "MT4Account", "平仓时间", "收益率", "自主收益率", "跟随收益率" ]) try: table.add_row([ "预期结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.mongoList["rate_asumasum_profit_balance_close"], self.mongoList["rate_asumasum_profit_balance_close_self"], self.mongoList["rate_asumasum_profit_balance_close_follow"] ]) table.add_row([ "实际结果", self.userID, self.AccountIndex, self.mt4Account, otherStyleTime, self.item["Roi"], self.item["SelfRoi"], self.item["FollowRoi"] ]) table.add_row(["", "", "", "", "", "", "", ""]) finally: table.reversesort = True print(table)
# caos pathFolder = "Set_4/ID_129/Camera_8/Seq_1/" # 1 # pathFolder = "Set_4/ID_122/Camera_8/Seq_1/" # pathFolder = "Set_4/ID_114/Camera_8/Seq_1/" # pathFolder = "Set_3/ID_76/Camera_1/Seq_1/" labelName = pathSave + "label.pickle" trainListName = pathSave + "trainList.pickle" clfName = pathSave + "svm.pickle" util = Util.Util() logger = Logger.Logger() dm = DatasetManager.DatasetManager() stat = Statistic.Statistic() # cancella il contenuto di rects prima di iniziare util.delFolderContent(pathTest) c_val = 0.1 step = 11 orient = 8 matching_threshold = 0.85 mask_threshold = 0.4 edge_distance_threshold = 28 minOverlap_x = 2 * step minOverlap_y = 5 * step scale = 0.8 frameScale = 0.7 # solo se viene usato il metodo di overlap
def test_1_getStatisticsOfCustomer(self): '''获取跟随者用户的交易统计数据''' userID = "148181" accountIndex = "2" url = webAPIData['hostName'] + personalPageData[ 'getStatisticsOfcustomer_url1'] + userID + '_' + accountIndex + personalPageData[ 'getStatisticsOfcustomer_url2'] statisticData = PersonalPage.getStatisticsOfCustomer( url, headers=webAPIData['headers'], printLogs=1) #请求成功 返回 200 self.assertEqual(statisticData.status_code, webAPIData['status_code_200']) statistic = json.loads(statisticData.text)["data"] mt4Account = Statistic.getMt4Account(userID=userID, accountIndex=accountIndex) BrokerId = Statistic.BrokerId(userID=userID, accountIndex=accountIndex) rateProfit = Statistic.rateProfit(mt4Account=mt4Account, brokerID=BrokerId) followRateProfit = Statistic.followRateProfit(mt4Account=mt4Account, brokerID=BrokerId) pointOfCfClose = Statistic.pointOfCfClose(mt4Account=mt4Account, brokerID=BrokerId) #获取:收益率,跟随收益率,跟随获利点数 topTable = PrettyTable(["预期/实际", "收益率", "跟随收益率", "跟随获利点数"]) topTable.add_row( ["预期结果", rateProfit, followRateProfit, pointOfCfClose]) topTable.add_row([ "实际结果", statistic["ROI"], statistic["FollowROI"], statistic["FollowPoints"] ]) try: #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(rateProfit, float(statistic["ROI"]), delta=20) self.assertAlmostEqual(followRateProfit, float(statistic["FollowROI"]), delta=100) self.assertAlmostEqual(pointOfCfClose, float(statistic["FollowPoints"]), delta=1000000) finally: topTable.reversesort = True print(topTable) pointCloseSum = Statistic.pointCloseSum(mt4Account=mt4Account, brokerID=BrokerId) orderClose = Statistic.orderClose(mt4Account=mt4Account, brokerID=BrokerId) orderOs = Statistic.orderOs(mt4Account=mt4Account, brokerID=BrokerId) standardlotsClose = Statistic.standardlotsClose(mt4Account=mt4Account, brokerID=BrokerId) pointProfitCloseMean = Statistic.pointProfitCloseMean( mt4Account=mt4Account, brokerID=BrokerId) orderProfitClose = Statistic.orderProfitClose(mt4Account=mt4Account, brokerID=BrokerId) orderCs = Statistic.orderCs(mt4Account=mt4Account, brokerID=BrokerId) tradePeriod = Statistic.tradePeriod(mt4Account=mt4Account, brokerID=BrokerId) #获取:交易概览统计数据 overView = PrettyTable([ "预期/实际", "盈亏点数", "交易笔数", "自主开仓笔数", "交易手数", "平均获利点数", "胜出交易笔数", "跟随开仓笔数", "交易周期" ]) overView.add_row([ "预期结果", pointCloseSum, orderClose, orderOs, standardlotsClose, pointProfitCloseMean, orderProfitClose, orderCs, tradePeriod ]) overView.add_row([ "实际结果", statistic["Point"], statistic["Orders"], statistic["SelfOrders"], statistic["StandardLots"], statistic["AVGPoint"], statistic["WinOrders"], statistic["FollowOrders"], statistic["Weeks"] ]) try: #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(pointCloseSum, float(statistic["Point"]), delta=2000000) self.assertAlmostEqual(orderClose, float(statistic["Orders"]), delta=100) self.assertAlmostEqual(orderOs, float(statistic["SelfOrders"]), delta=1000000) self.assertAlmostEqual(standardlotsClose, float(statistic["StandardLots"]), delta=1000000) self.assertAlmostEqual(pointProfitCloseMean, float(statistic["AVGPoint"]), delta=1000000) self.assertAlmostEqual(orderProfitClose, float(statistic["WinOrders"]), delta=1000000) self.assertAlmostEqual(orderProfitClose, float(statistic["FollowOrders"]), delta=1000000) self.assertAlmostEqual(tradePeriod, statistic["Weeks"], delta=1000000) finally: overView.reversesort = True print(overView)
def generateXls(self): name = self.nameInput.get() ExcelMani.main(name) Statistic.main(name)
def test_1_userInfo(self): '''鼠标停在头像上的悬浮窗数据''' userID = "148174_2" userData = Account.getUserInfo(webAPIData['hostName'] + accountData['getUserInfo_url'] + userID, printLogs=0) self.assertEqual(userData.status_code, webAPIData['status_code_200']) self.assertNotEqual( json.loads(userData.text)["data"]["user"], {}, "不存在用户信息数据") print("userInfo:") table = PrettyTable([ "预期/实际", "NickName", "UserID", "mt4Account", "AccountIndex", "BrokerId", "跟随获利", "收益率", "订单数", "交易周期", "关注人数", "粉丝人数" ]) userInfo = json.loads(userData.text)["data"]["user"] mt4Account = Statistic.getMt4Account(userID=str(userInfo["UserId"]), accountIndex=str( userInfo["AccountIndex"])) followProfit = Statistic.followProfit(mt4Account=mt4Account, brokerID=userInfo["BrokerId"]) rateProfit = Statistic.rateProfit(mt4Account=mt4Account, brokerID=userInfo["BrokerId"]) ordersCount = Statistic.ordersCount(mt4Account=mt4Account, brokerID=userInfo["BrokerId"]) tradePeriod = Statistic.tradePeriod(mt4Account=mt4Account, brokerID=userInfo["BrokerId"]) attentionCount = Statistic.attentionCount(mt4Account=mt4Account) fansCount = Statistic.fansCount(mt4Account=mt4Account) table.add_row([ "预期结果", userInfo["NickName"], userInfo["UserId"], mt4Account, userInfo["AccountIndex"], userInfo["BrokerId"], followProfit, rateProfit, ordersCount, tradePeriod, attentionCount, fansCount ]) table.add_row([ "实际结果", userInfo["NickName"], userInfo["UserId"], mt4Account, userInfo["AccountIndex"], userInfo["BrokerId"], userInfo["FollowProfit"], str(userInfo["ROI"]) + '%', userInfo["Orders"], userInfo["Weeks"], userInfo["AttentionCount"], userInfo["FansCount"] ]) try: #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(followProfit, userInfo["FollowProfit"], delta=1000000) # self.assertAlmostEqual(rateProfit,userInfo["ROI"],delta = 1000000) self.assertAlmostEqual(ordersCount, userInfo["Orders"], delta=1000000) self.assertAlmostEqual(tradePeriod, userInfo["Weeks"], delta=1000000) self.assertAlmostEqual(attentionCount, int(userInfo["AttentionCount"]), delta=1000000) self.assertAlmostEqual(fansCount, int(userInfo["FansCount"]), delta=1000000) finally: table.reversesort = True print(table)
def setUpClass(self): '''登录followme系统''' #生产 piaoyou self.login = '******' self.brokerID = 5 #A在路上 # self.login = '******' # self.brokerID = 4 #跟随者 # self.login='******' # self.brokerID=5 #模拟帐号 # self.login = '******' # self.brokerID = 3 curr_tiem = datetime.datetime.now() + datetime.timedelta(days=-1) self.yesterDay = curr_tiem.strftime('%Y-%m-%d 00:00:00.000') mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater(host=mongoUrl, port=statisticData["mongo_port"]) # mongoDB = FMCommon.mongoDB_operater(host='mongodb://10.0.0.51:27017', port=27017) for i in mongoDB.fm.mg_result_weekofyear.find({ "login": self.login, "close_weekofyear": "2018-16" }): self.mongoList = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList[key] = value #粉丝人数 fans = presto.connect(host=statisticData["prosto_host"], port=statisticData["prosto_port"]).cursor() fans.execute( "SELECT count(1) FROM S_Follower where objectid=(select userid from t_useraccount where mt4account='%s')" % (self.login)) self.T_MT4TradesTable = Statistic.getPrestoData( login=self.login, brokerID=self.brokerID, echo=False, startTime='2018-04-16 06:00:00.0', endTime='2018-04-23 06:00:00.0') #粉丝人数 self.fans_count = fans.fetchone()[0] #每张订单收益 self.deal_profit = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_profit') #平仓总收益 self.money_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='money_close') #盈利总额 self.profit_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable, quota='profit_sum') #平仓收益总额,平仓订单收益 self.profit_close_sum = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='profit_close_sum') #亏损总额 self.loss_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable, quota='loss_sum') #平仓亏损订单数 self.deal_loss_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_loss_close') #平仓盈利订单数 self.deal_profit_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_profit_close') #平仓做多盈利笔数 self.deal_profit_long_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_profit_long_close') #持仓盈利订单 self.deal_profit_open = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_profit_open') #平仓点数 self.point_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='point_close') #平仓盈利点数 self.point_profit_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='point_profit_close') #每一笔订单的收益列表 self.deal_profit_close_list = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deal_profit_close_list') #持仓时间 self.time_possession = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='time_possession') #交易周期 self.period_trade = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='period_trade') #交易周期 self.deal_openTime_list = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='period_trade', closeTime='1969-01-01 00:00:00.0') #平仓标准手 self.standardlots_close = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='standardlots_close') #累计如金 self.deposit_sum = Statistic.statisticQuota( table=self.T_MT4TradesTable, quota='deposit_sum') #该交易员自主平仓订单笔数 self.deal_os = Statistic.statisticQuota(table=self.T_MT4TradesTable, quota='deal_os') #跟随平仓订单笔数 self.deal_cs = Statistic.statisticQuota(table=self.T_MT4TradesTable, quota='deal_cs')
doc_att_dict = ProcDoc.unigram(doc_bow_dict) elif att_types.index(att) == 1: qry_att_dict = qry_bow_dict for q_key, q_cont in qry_att_dict.items(): for q_w, q_w_uni in q_cont.items(): qry_att_dict[q_key][q_w] = "1.0" if is_spoken: doc_conf_file = ProcDoc.readFile(conf_path) doc_att_dict = ProcDoc.confPreproc(doc_conf_file) else: doc_att_dict = doc_bow_dict for d_key, d_cont in doc_att_dict.items(): for d_w, d_w_uni in d_cont.items(): doc_att_dict[d_key][d_w] = "1.0" elif att_types.index(att) == 2: [qry_att_dict, doc_att_dict] = Statistic.IDF(qry_bow_dict, doc_bow_dict) # read dictionary (ID, Word) import codecs with codecs.open(dict_path, 'r', encoding='utf-8') as rf: for idx, line in enumerate(rf.readlines()): info = line.split("\r\n")[0].split(" ") ID_map[idx] = info[-1] ID_map[-1] = ":" qry_mdl_dict, qry_att_dict = ID2Word(qry_mdl_dict, ID_map, qry_att_dict) doc_mdl_dict, doc_att_dict = ID2Word(doc_mdl_dict, ID_map, doc_att_dict) docs_list = doc_mdl_dict.keys() print(output_dir + "/" + output_name, output_dir + "/" + output_eval_name)
import os.path path = os.path.abspath(__file__) dirname, useless = os.path.split(path) ROOT_DIR = dirname + '/' DB_FILE_NAME = ROOT_DIR + 'ka.db' BACKUP_FILE_NAME = ROOT_DIR + 'commit.backup' logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG) logger = logging.getLogger('ReloadAllData') service_list = {} service_list['account'] = Account.Account(logger) service_list['category'] = Category.Category(logger) service_list['record'] = Record.Record(logger) service_list['statistic'] = Statistic.Statistic(logger) service_list['budget'] = Budget.Budget(logger) service_list['currency'] = Currency.Currency(logger) # 删除数据库文件 if os.path.exists(DB_FILE_NAME): os.remove(DB_FILE_NAME) # 读取创建数据库SQL文件内容 f = open(ROOT_DIR + 'sql/create.sql', encoding='utf-8') create_sql_content = f.read() f.close() f = open(ROOT_DIR + 'sql/add_basic_data.sql', encoding='utf-8') add_basic_data_sql_content = f.read() f.close()
def setUpClass(self): #入参 self.userID = '18907' self.AccountIndex = 2 mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater_data(host=mongoUrl, port = statisticData["mongo_port"]) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID),accountIndex=str(self.AccountIndex)) print(self.mt4Account) '''获取跟随者个人展示页的收益图表数据''' # accountRoi = Datastatistic.getAccountRoi(webAPIData['hostName'] + followData['getStatisticsOfAccount_url'] + str(self.userID) + "_"+ str(self.AccountIndex) + followData["getStatisticsOfAccount_url1"],printLogs=0) # MoneyAndEquity = Datastatistic.getDayAccountMoneyAndEquityList("http://dev.fmfe.com/api//v2/trade/77141_1/equity/income") MoneyAndEquity = Datastatistic.getDayAccountMoneyAndEquityList(webAPIData['hostName'] + datastatisticData['getDayAccountMoneyAndEquityList_url'] + str(self.userID) + "_"+ str(self.AccountIndex) + datastatisticData["getDayAccountMoneyAndEquityList_url2"],printLogs=1) # self.assertEqual(MoneyAndEquity.status_code, webAPIData['status_code_200']) self.dateList = [] self.totalMoneyList = [] self.totalSelfMoneyList= [] self.totalFollowMoneyList = [] for self.item in json.loads(MoneyAndEquity.text)["data"]["MoneyList"]: self.dateList.append(self.item["Date"]) self.totalMoneyList.append(self.item["TotalMoney"]) self.totalSelfMoneyList.append(self.item["TotalSelfMoney"]) self.totalFollowMoneyList.append(self.item["TotalFollowMoney"]) timeStamp = int(self.item["Date"]) timeArray = time.localtime(timeStamp) otherStyleTime = time.strftime("%Y-%m-%d", timeArray) for i in mongoDB.datastatistic.mg_result_day.find({"login":str(self.mt4Account),"close_date":str(otherStyleTime)}): self.mongoList_day = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList_day[key]=value table = PrettyTable(["预期/实际","UserID","AccountIndex","MT4Account","日期","总收益","自主收益","跟随收益"]) try: table.add_row(["预期结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleTime,self.mongoList_day["money_close_asum"],self.mongoList_day["money_cs_asum"],self.mongoList_day["money_cf_asum"]]) table.add_row(["实际结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleTime,self.item["TotalMoney"],self.item["TotalSelfMoney"],self.item["TotalFollowMoney"]]) table.add_row(["","","","","","","",""]) finally: table.reversesort = True print(table) self.monthList = [] self.selfMoneyList = [] self.followMoneyList = [] for self.items in json.loads(MoneyAndEquity.text)["data"]["MonthMoneyList"]: self.monthList.append(self.items["Month"]) self.selfMoneyList.append(self.items["SelfMoney"]) self.followMoneyList.append(self.items["FollowMoney"]) monthStamp = int(self.items["Month"]) monthArray = time.localtime(monthStamp) otherStyleMonth = time.strftime("%Y-%m", monthArray) print(otherStyleMonth) for i in mongoDB.datastatistic.mg_result_month.find({"login":str(self.mt4Account),"close_month":str(otherStyleMonth)}): self.mongoList_month = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList_month[key]=value table = PrettyTable(["预期/实际","UserID","AccountIndex","MT4Account","月份","月自主收益","月跟随收益","月自主收益点数","月跟随收益点数","月自主标准手","月跟随标准手"]) try: table.add_row(["预期结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleMonth,self.mongoList_month["money_cs"],self.mongoList_month["money_cf"],self.mongoList_month["point_cs"],self.mongoList_month["point_cf"],self.mongoList_month["standardlots_cs"],self.mongoList_month["standardlots_cf"]]) table.add_row(["实际结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleMonth,self.items["SelfMoney"],self.items["FollowMoney"],self.items["SelfPips"],self.items["FollowPips"],self.items["SelfStandardlots"],self.items["FollowStandardlots"]]) table.add_row(["","","","","","","","","","",""]) finally: table.reversesort = True print(table)
def test_1_getCustomers(self): '''获取近一周有交易的跟随大师信息''' params = {"time": 7, "pageField": "FollowProfit"} customers = Trade.getCustomers(webAPIData['hostName'] + tradeData['getCustomers_url'], params=params, printLogs=1) self.assertEqual(customers.status_code, webAPIData['status_code_200']) print("Customers_oneWeek:") table = PrettyTable([ "预期/实际", "NickName", "UserID", "mt4Account", "AccountIndex", "近一日跟随获利", "近一日盈亏点数", "收益率", "平均获利点数", "交易笔数", "交易周期" ]) try: for item in json.loads(customers.text)["data"]["items"]: mt4Account = Statistic.getMt4Account( userID=str(item["UserId"]), accountIndex=str(item["AccountCurrentIndex"])) moneyFollowCloseDay = Statistic.moneyFollowCloseDay( mt4Account=mt4Account, brokerID=item["BrokerId"]) pointCloseDay = Statistic.pointCloseDay( mt4Account=mt4Account, brokerID=item["BrokerId"]) rateProfit = Statistic.rateProfit(mt4Account=mt4Account, brokerID=item["BrokerId"]) pointProfitCloseMean = Statistic.pointProfitCloseMean( mt4Account=mt4Account, brokerID=item["BrokerId"]) ordersCount = Statistic.ordersCount(mt4Account=mt4Account, brokerID=item["BrokerId"]) tradePeriod = Statistic.tradePeriod(mt4Account=mt4Account, brokerID=item["BrokerId"]) table.add_row([ "预期结果", item["NickName"], item["UserId"], mt4Account, item["AccountCurrentIndex"], moneyFollowCloseDay, pointCloseDay, rateProfit, pointProfitCloseMean, ordersCount, tradePeriod ]) table.add_row([ "实际结果", item["NickName"], item["UserId"], mt4Account, item["AccountCurrentIndex"], item["BizFollowProfit"], item["BizPoint"], item["BizROIex"], item["BizAVGPoint"], item["Orders"], item["Weeks"] ]) table.add_row(["", "", "", "", "", "", "", "", "", "", ""]) #由于非实时统计数据,实际结果存在误差。预期和实际正负差值小于等于DELTA都算断言通过 self.assertAlmostEqual(moneyFollowCloseDay, float(item["BizFollowProfit"]), delta=1000000) self.assertAlmostEqual(pointCloseDay, float(item["BizPoint"]), delta=1000000) self.assertAlmostEqual(rateProfit, float(item["BizROIex"]), delta=1000000) self.assertAlmostEqual(pointProfitCloseMean, float(item["BizAVGPoint"]), delta=1000000) self.assertAlmostEqual(ordersCount, item["Orders"], delta=1000000) self.assertAlmostEqual(tradePeriod, item["Weeks"], delta=1000000) finally: table.reversesort = True print(table)
def setUpClass(self): '''登录followme系统''' #生产 piaoyou kvb self.login = '******' self.brokerID = 5 curr_tiem = datetime.datetime.now() + datetime.timedelta(days=-1) self.yesterDay = curr_tiem.strftime('%Y-%m-%d 00:00:00.000') mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater(host=mongoUrl, port = statisticData["mongo_port"]) for i in mongoDB.fm.mg_result_all.find({"login":self.login}): self.mongoList = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList[key]=value #计算保证金 margin = presto.connect(host=statisticData["prosto_host"],port=statisticData["prosto_port"]).cursor() margin.execute("SELECT margin FROM test_t_mt4users where login='******' and brokerid=%d" % (self.login,self.brokerID)) #计算实盘跟随人数 follower_count = presto.connect(host=statisticData["prosto_host"],port=statisticData["prosto_port"]).cursor() follower_count.execute("SELECT count(distinct(followaccount)) from test_T_FollowReport where masteraccount='%s' and masterbrokerid=%d and endDate='1970-01-01 00:00:00.0'" % (self.login,self.brokerID)) self.T_MT4TradesTable = Statistic.getPrestoData(login=self.login,brokerID=self.brokerID,echo=False) print("------------------------------------") # for i in self.T_MT4TradesTable: # print(i) #每张订单收益 self.deal_profit = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_profit') #盈利总额 self.profit_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='profit_sum') #平仓订单收益 self.profit_close_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='profit_close_sum') #近7天平仓订单收益 self.profit_close_sum_week = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='profit_close_sum_Nday',closeTime=Statistic.n_dayAgo(-7)) #1周以前的净值,期初净值 self.deposit_sum_week = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deposit_sum_Nday',closeTime=Statistic.n_dayAgo(-7)) #近30天平仓订单收益 self.profit_close_sum_month = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='profit_close_sum_Nday',closeTime=Statistic.n_dayAgo(-30)) #1月以前的净值,期初净值 self.deposit_sum_month = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deposit_sum_Nday',closeTime=Statistic.n_dayAgo(-30)) #亏损总额 self.loss_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='loss_sum') #平仓亏损订单数 self.deal_loss_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_loss_close') #平仓盈利订单数 self.deal_profit_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_profit_close') #平仓做多盈利笔数 self.deal_profit_long_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_profit_long_close') #持仓盈利订单 self.deal_profit_open = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_profit_open') #平仓点数 self.point_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='point_close') #平仓盈利点数 self.point_profit_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='point_profit_close') #盈利订单总点数,包括持仓 self.point_profit_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='point_profit_sum') #亏损订单总点数,包括持仓 self.point_loss_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='point_loss_sum') #标准差 self.standard_deviation = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='standard_deviation') #持仓时间 self.time_possession = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='time_possession') #交易周期 self.period_trade = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='period_trade') #平仓标准手 self.standardlots_close = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='standardlots_close') #累计入金 self.deposit_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deposit_sum') #净值 self.equity_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='equity_sum') #余额 self.balance_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='balance_sum') #已用保证金 self.margin = margin.fetchone()[0] #实盘跟随人数 self.follower_count = follower_count.fetchone()[0] #该交易员自主平仓订单笔数 self.deal_os = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_os') #跟随平仓订单笔数 self.deal_cs = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_cs') #盈利订单数量,包括持仓 self.deal_profit_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_profit_sum') #亏损订单数量,包括持仓 self.deal_loss_sum = Statistic.statisticQuota(table=self.T_MT4TradesTable,quota='deal_loss_sum')
def setUpClass(self): #入参 self.userID = '132316' print(self.userID) self.AccountIndex = 4 #连接beta环境的MongoDB数据 mongoUrl = "mongodb://%s:%s@%s" % (statisticData["mongo_userName"], statisticData["mongo_passwd"], statisticData["mongo_host"]) mongoDB = FMCommon.mongoDB_operater_data(host=mongoUrl, port = statisticData["mongo_port"]) #获取MT4账号 self.mt4Account = Statistic.getMt4Account(userID=str(self.userID),accountIndex=str(self.AccountIndex)) #获取BrokerId self.brokerId = Statistic.BrokerId(userID=str(self.userID),accountIndex=str(self.AccountIndex)) print(self.brokerId) '''获取个人展示页的月分析报告数据''' # accountRoi = Datastatistic.getAccountRoi(webAPIData['hostName'] + followData['getStatisticsOfAccount_url'] + str(self.userID) + "_"+ str(self.AccountIndex) + followData["getStatisticsOfAccount_url1"],printLogs=0) # self.monthAnalysisReport = Datastatistic.getMonthAnalysisReport("http://dev.fmfe.com/api/v2/trade/77141_1/month/analysis/report") self.monthAnalysisReport = Datastatistic.getMonthAnalysisReport(webAPIData['hostName'] + datastatisticData['getMonthAnalysisReport_url'] + str(self.userID) + "_"+ str(self.AccountIndex) + datastatisticData["getMonthAnalysisReport_url2"],printLogs=0) self.monthList = [] self.moneyList = [] self.pipsList = [] self.standardLotslList = [] for self.item in json.loads(self.monthAnalysisReport.text)["data"]["MonthDataList"]: #遍历返回所有的月份数据 self.monthList.append(self.item["Month"]) #遍历返回所有的累计收益数据 self.moneyList.append(self.item["Money"]) #遍历返回所有的盈亏点数数据 self.pipsList.append(self.item["Pips"]) #遍历返回所有的标准手数据 self.standardLotslList.append(self.item["StandardLots"]) timeStamp = int(self.item["Month"]) timeArray = time.localtime(timeStamp) otherStyleMonth = time.strftime("%Y-%m", timeArray) print(otherStyleMonth) self.money_closeList = [] self.point_closeList = [] self.standardlots_closeList = [] for i in mongoDB.datastatistic.mg_result_month.find({"login":str(self.mt4Account),"close_month":otherStyleMonth}): # print(i) self.mongoList = {} for key in statisticData["mongoKeyListAll"]: try: value = i[key] except KeyError: value = statisticData["keyErr"] self.mongoList[key]=value #获取MongoDB的不同月份的累计收益 # print(self.mongoList["money_close"]) # print(self.mongoList["factor_profit_equity"]) # print(self.mongoList["standardlots_close"]) self.money_closeList.append(self.mongoList["money_close"]) #获取MongoDB的不同月份的盈亏点数 self.point_closeList.append(self.mongoList["factor_profit_equity"]) #获取MongoDB的不同月份的标准手 self.standardlots_closeList.append(self.mongoList["standardlots_close"]) table = PrettyTable(["预期/实际","UserID","AccountIndex","MT4Account","月份","收益金额","收益点数","交易量(标准手)"]) try: table.add_row(["预期结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleMonth,self.mongoList["money_close"],self.mongoList["point_close"],self.mongoList["standardlots_close"]]) table.add_row(["实际结果",self.userID,self.AccountIndex,self.mt4Account,otherStyleMonth,self.item["Money"],self.item["Pips"],self.item["StandardLots"]]) table.add_row(["","","","","","","",""]) finally: table.reversesort = True print(table)