Пример #1
0
def getAllData():
    a = getAllIdFromSina.sinaIdManage()
    #a.initFromSinaHy()
    a.initLocalData()

    sinaobj = CollectSinaData(6)
    sids = []
    for id,v in a.allstockmap.items():
        sids.append(id)

    res = sinaobj.startLoop(sids)
Пример #2
0
def createAllTable():
    a = getAllIdFromSina.sinaIdManage()
    #a.initFromSinaHy()
    a.initLocalData()
    newdb = stockDB()
    newAdds = []
    for id,v in a.allstockmap.items():

        if newdb.createTable(id):
            count = newdb.getLineCount(id)
            newAdds.append(id)
    print "createTable success:", newAdds
Пример #3
0
 def get_context_data(self, **kwargs):
     try:
         context = super(TurnoverRatioView, self).get_context_data(**kwargs)
         
         idManager = getAllIdFromSina.sinaIdManage()
         a = CalcTurnOverRatio.CalcTurnOverRate()
         idManager = getAllIdFromSina.sinaIdManage()
         idManager.initLocalData()
         datas = a.getHighRate(idManager, 100)
         slist = []
         for line in datas:
             stockId = line[CalcTurnOverRatio.RATE_COL_ID]
             detailinfo = idManager.allstockmap[stockId]
             
             KLurl = '/stockKL?s='+stockId
             sinaUrl = "http://vip.stock.finance.sina.com.cn/moneyflow/#!ssfx!"+stockIDforSina(stockId)
             onedata = [stockId,KLurl,detailinfo[getAllIdFromSina.SCOL_NAME],sinaUrl]
             onedata.append("%.2f"%(line[CalcTurnOverRatio.RATE_COL_LONGRATE]-line[CalcTurnOverRatio.RATE_COL_MIDRATE]))
             onedata.append("%.2f"%((line[CalcTurnOverRatio.RATE_COL_1PRI]-line[CalcTurnOverRatio.RATE_COL_0PRI])/line[CalcTurnOverRatio.RATE_COL_0PRI]))
             onedata.append("%.2f"%(line[CalcTurnOverRatio.RATE_COL_MIDRATE]-line[CalcTurnOverRatio.RATE_COL_SHORTRATE]))
             onedata.append("%.2f"%((line[CalcTurnOverRatio.RATE_COL_2PRI]-line[CalcTurnOverRatio.RATE_COL_1PRI])/line[CalcTurnOverRatio.RATE_COL_1PRI]))
             onedata.append("%.2f"%(line[CalcTurnOverRatio.RATE_COL_SHORTRATE]))
             onedata.append("%.2f"%((line[CalcTurnOverRatio.RATE_COL_3PRI]-line[CalcTurnOverRatio.RATE_COL_2PRI])/line[CalcTurnOverRatio.RATE_COL_2PRI]))
             onedata.append(detailinfo[getAllIdFromSina.SCOL_PB])
             onedata.append("%.2f"%(float(detailinfo[getAllIdFromSina.SCOL_MKTCAP])/10000))
             onedata.append("%.2f"%(float(detailinfo[getAllIdFromSina.SCOL_NMC])/10000))
             onedata.append(detailinfo[getAllIdFromSina.SCOL_PER])
             onedata.append(detailinfo[getAllIdFromSina.SCOL_TURNOVERRATIO])
             
             slist.append(onedata)
             
         context['listStocks'] = slist
     except Exception as e:
         logger.exception(u'加载基本信息出错[%s]!', e)
         
     return context
Пример #4
0
    def getAvgStockCount(self, tr):
        count = -1
        tds = re.findall(r'<td colspan="4">[^\d<]*(\d+)', tr)
        if len(tds) > 0:
            count = int(tds[0])
        else:
            log.warn("getAvgStockCount Failed!"+tr)
        return count
        
    def getBigHolder(self, tr, i):
        regexStr = r'<td><div align="center">%d</div></td>\s*<td><div align="center">(<a[^>]*>|)([^<]*)(</a>|)</div></td>\s*<td><div align="center">(<a[^>]*>|)([^<]*)(</a>|)[^<]*</div></td>\s*<td><div align="center">(<a[^>]*>|)([^<]*)(</a>|)[^<]*</div></td>\s*<td><div align="center">([^<]*)</div></td>'%i
        tds = re.findall(regexStr, tr)
        if len(tds) > 0:
            return (tds[0][1],tds[0][4],tds[0][7],tds[0][9])
        else:
            log.warn("getBigHolder Failed!"+tr+" regex="+regexStr+" tds=%d"%len(tds))
            return None
        
if __name__ == '__main__':

    idManager = getAllIdFromSina.sinaIdManage()
    a = SinaStockDetail()
    #a.createTable()
    idManager.initLocalData()
    for k,v in idManager.allstockmap.items():
        a.getStockHolder(k)
        #break
    
    

Пример #5
0
    def get_context_data(self, **kwargs):
        context = super(StockDetailView, self).get_context_data(**kwargs)

        showday = kwargs.get("day",None)

        if showday == None or not self.sid:
            return context
        
        context['KLurl'] = 'http://taohui.org.cn/stockKL/?s='+self.sid
        sdb = dbAPI.stockDB()
        
        filename = 'pankou_%s_%s.jpg'%(self.sid, showday)
        imgUrl = '/stockimage/'+filename
        imgLoc = "/mnt/myblog/stock/"+filename
        context['pankouVolUrl'] = imgUrl
        xAxisTitle = 'showday %s'%(showday)
        yAxisTitle = 'VOL'

        rows = sdb.getDayData(self.sid, datetime.datetime.strptime(showday, '%Y%m%d').date())
        if len(rows) == 0:
            print len(rows),sid,showday[0:4],showday[4,2],showday[6,2]
            return context

        pankouDatas = []
        times = []
        lastVol = rows[0][dbAPI.DBCOL_EXCH_VOL]
        for row in rows:
            times.append(str(row[1]))
            
            pline = [row[dbAPI.DBCOL_CUR_PRI],row[dbAPI.DBCOL_EXCH_VOL]-lastVol,\
                     row[dbAPI.DBCOL_EXCH_AMOUNT],row[dbAPI.DBCOL_TIME],\
                     row[dbAPI.DBCOL_COMP_BUY_PRI],row[dbAPI.DBCOL_COMP_SELL_PRI] ]
            for i in range(20):
                pline.append(row[10+i])
            pankouDatas.append(pline)
            lastVol = row[dbAPI.DBCOL_EXCH_VOL]
            
        idManager = getAllIdFromSina.sinaIdManage()
        idManager.initLocalData()
        print idManager.allstockmap[self.sid]
                
        context['pankouDatas'] = pankouDatas
        context['dataLen'] = len(pankouDatas)
        context['highest'] = rows[-1][dbAPI.DBCOL_HIGH_PRI]
        context['lowest'] = rows[-1][dbAPI.DBCOL_LOW_PRI]
        context['open'] = rows[-1][dbAPI.DBCOL_OPEN_PRI]
        context['price'] = rows[-1][dbAPI.DBCOL_CUR_PRI]
        context['day'] = rows[-1][dbAPI.DBCOL_DATE].strftime('%Y%m')
        context['volume'] = rows[-1][dbAPI.DBCOL_EXCH_VOL]
        context['amount'] = rows[-1][dbAPI.DBCOL_EXCH_AMOUNT]
        
        if os.path.exists(imgLoc):
            print imgLoc,'picfile exist!'
            return context
            
        linenames = []
        for i in range(5):
            linenames.append("buy%d"%(i+1))
        for i in range(5):
            linenames.append("sell%d"%(1+i))
            
        voldatas = []

        for i in range(5):
            line1 = []
            line2 = []
            for row in rows:
                line1.append(int(row[29-2*i-1]))
                line2.append("%.2f"%(row[29-2*i]))
            voldatas.append(line1)

        curprices = []
        vols = []
        for row in rows:
            vols.append(int(row[8]))

        line = []
        for row in rows:
            line.append("%.2f"%row[3])
        curprices.append(line)
        
        for i in range(5):
            line1 = []
            line2 = []
            for row in rows:
                line1.append(int(row[10+2*i]))
                line2.append("%.2f"%(row[10+2*i+1])) 
            voldatas.append(line1)
        
        colors=['0x00CED1','0x00C5CD','0x008B8B','0x00688B','0x0000CD',\
                '0xEEA2AD','0xEE82EE','0xEE7942','0xEE6A50','0xEE3B3B']

        
        chart = CreateDiagram.SelfDefStockChart()
        
        chart.addXYChart("pankouVol", voldatas, times, linenames, \
                                      colors, xAxisTitle,yAxisTitle)
        c = chart.addXYChart("pankouVol", curprices, times, ['curpri'], \
                                      ['0xff9999'], xAxisTitle,yAxisTitle)
        #chart.addBar(c, vols, times)
        chart.makeChart(imgLoc)

        return context
Пример #6
0
    def get_context_data(self, **kwargs):
        try:
            context = super(EarningsOverView, self).get_context_data(**kwargs)

            kdataproc = ReadLocalData()
            shDapanRows = kdataproc.getLocalData(DPshzhongzhi)
            shDapanDict = {}
            print 'shDapanRows=',len(shDapanRows)
            for row in shDapanRows:
                shDapanDict[row[DATE_COL_DATE]]=row
        
            allOperRows = Operations.objects.all()
            ownerDict = {}
            
            sinaIds = []
            for row in allOperRows:
                if ownerDict.has_key(row.owner):
                    if ownerDict[row.owner].has_key(row.stockId):
                        ownerDict[row.owner][row.stockId].append(row)
                    else:
                        ownerDict[row.owner][row.stockId] = [row]
                        sinaIds.append(stockIDforSina(row.stockId))
                else:
                    ownerDict[row.owner] = {row.stockId:[row]}
                    sinaIds.append(stockIDforSina(row.stockId))
            
            sinadata = getCurDataFromSina.sinaStockAPI()
            resultmap = sinadata.getCurPriFromSina(sinaIds)
            realSinaData = {}

            for i in range(len(sinaIds)):
                realSinaData[sinaIds[i]] = resultmap[i]
            
            allOwnerInfo = []
            idManager = getAllIdFromSina.sinaIdManage()
            idManager.initLocalData()

            for owner, stockrows in ownerDict.items():
                curCostTotal, curEarningTotal, historyEarningTotal = 0,0,0

                i = 0
                listTableDatas = []
                alreadyHolderDatas = []
                for sid, onestock in stockrows.items():
                    if not sid in idManager.allstockmap:
                        continue
                    detailinfo = idManager.allstockmap[sid]
                    sortdata = sorted(onestock,key = lambda x:x.time,reverse = False) 
                    #print onestock,'--',sortdata
                    curCost, curEarning, historyEarning = self.analysisTrade(sortdata, realSinaData[stockIDforSina(sid)], listTableDatas, alreadyHolderDatas, detailinfo, shDapanDict)
                    curCostTotal += curCost
                    curEarningTotal += curEarning
                    historyEarningTotal += historyEarning
                print owner,curCostTotal, curEarningTotal, historyEarningTotal
      
                allOwnerInfo.append([owner, listTableDatas,alreadyHolderDatas,curCostTotal, curEarningTotal, historyEarningTotal])
                    
            context['allOwnerInfo'] = allOwnerInfo
        except Exception as e:
            logger.exception(u'加载基本信息出错[%s]!', e)
            
        return context