public static function show() { parent::show(); $stockInfo = array(); $stockInfo["code"] = $_GET["code"]; $i = Refer::searchCode($stockInfo["code"]); if (!$i) { exit(0); } $stockInfo["name"] = $i['name']; $stockInfo["spell"] = $i['spell']; $stockInfo["period"] = null; /* * $stockInfo["period"] = array('start'=>strtotime("Thu May 28 00:00:00 +0800 2015")*1000, 'end'=>strtotime("Mon Dec 23 00:00:00 +0800 2015")*1000); */ $stockInfo["right"] = "before"; $gd = new GbbqData($stockInfo["code"]); $gbbq = $gd->getGbbqLabel(); $stockInfo['gbbq'] = $gbbq; $dd = new DdeData($stockInfo["code"]); $dde = $dd->getDdeData(); $stockInfo['dde'] = $dde; $tdd = new ThsDoctorData($stockInfo["code"]); $ths = $tdd->getThsDoctorData(); $stockInfo['ths'] = $ths; $ld = new LhbData($stockInfo["code"]); $lhb = $ld->getLhbData(); $stockInfo['lhb'] = $lhb; $rd = new RateData($stockInfo["code"]); $rate = RateData::filterBuy($rd->getRateData()); $stockInfo['rate'] = $rate; $stockInfo['day'] = array(); $typeRight = array("normal", "before", "after"); foreach ($typeRight as $aTypeRight) { $dd = new DayData($stockInfo["code"], $aTypeRight); if ($dd->prepareData()) { $stockInfo['day'][$aTypeRight] = $dd->getStockData(); } else { $stockInfo['day'][$aTypeRight] = null; } } self::setTitle($stockInfo['name'] . '(' . $stockInfo['code'] . ') - Stock -- ForeShadow (Alpha)'); self::$smarty->assign('historyUrl', Url::getBasePhp('History')); self::$smarty->assign('favoriteUrl', Url::getBasePhp('Favorite')); self::$smarty->assign('rawData', json_encode($stockInfo)); self::$smarty->display('Chart.tpl'); }
public static function calcDdeNum($start, $end) { $resultFile = self::$thisTaskDataPath . $start . '_' . $end . '_DdeNum.Table.txt'; $i = 2; $stockList = Refer::getStock(); $stockData = array(); foreach ($stockList as $stkL) { //if (--$i < 0 ) break; $stkT = array('name' => '', 'code' => '', 'DdxNum' => 0, 'DdxPer' => 0, 'DdzNum' => 0, 'DdzPer' => 0, 'TddzNum' => 0, 'TddzPer' => 0, 'TotalNum' => 0, 'TotalPer' => 0, 'DayNum' => 0); $stkT['name'] = '<a target="_blank" href="' . Url::getPhpUri('Chart') . '?code=' . $stkL['code'] . '">' . '<span class="fore-stock-name">' . $stkL['name'] . '</span>' . '<span class="fore-stock-spell displaynone">' . $stkL['spell'] . '</span></a>'; $stkT['code'] = '<span class="fore-stock-code">' . $stkL['code'] . '</span>'; $dd = new DdeData($stkL['code']); if (!$dd->prepareData()) { continue; } $dde = $dd->getDayPeriod($start, $end, 1); //var_dump($dde); if (!$dde) { continue; } foreach ($dde as $d) { //echo $d['ddx']. '('; //echo ($d['ddx'] > 0). ')'; if ($d['ddx'] > 0) { $stkT['DdxNum']++; } if ($d['ddz'] > 0) { $stkT['DdzNum']++; } if ($d['tddz'] > 0) { $stkT['TddzNum']++; } } $stkT['DayNum'] = sizeof($dde); $stkT['DdxPer'] = ceil($stkT['DdxNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['DdzPer'] = ceil($stkT['DdzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TddzPer'] = ceil($stkT['TddzNum'] / $stkT['DayNum'] * 10000) / 10000; $stkT['TotalNum'] = $stkT['DdxNum'] + $stkT['TddzNum'] + $stkT['TddzNum']; $stkT['TotalPer'] = ceil($stkT['TotalNum'] / $stkT['DayNum'] / 3 * 10000) / 10000; //var_dump($stkT); $stockData[] = $stkT; } parent::putTable($resultFile, $stockData); }
public static function updateGpcxwDde() { //日志文件 self::$log = new Log(LOG_PATH, __FILE__); //临时文件 self::$tmp = new Tmp(TMP_PATH); self::$tmp->addTmp('dde.gpcxw.duty.cookie', false); self::$tmp->addTmp('dde.gpcxw.duty.failed', true); self::$tmp->addTmp('dde.gpcxw.duty.process', false); self::$log->debugLog("Begin Update Gpcxw Dde"); $host = 'www.gpcxw.com'; $referer = 'baidu.com'; //首先获取cookie $url = 'http://www.gpcxw.com/ddx/000703.html'; $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); $p = -1; $list = Refer::getStock(); //得到进度 $content = self::$tmp->getTmpContent('dde.gpcxw.duty.process'); $content = explode('===', $content); $lastProcess = $content && $content[0] ? $content[0] : -1; foreach ($list as $item) { $p++; //if ($p >= 3 ) break; if ($p < $lastProcess) { continue; } self::$tmp->putTmpContent('dde.gpcxw.duty.process', $p . '===' . $item['code'] . ' ' . $item['name']); $numCode = substr($item['code'], 2); $data = 0; $dde = new DdeData($item['code']); $last = $dde->getDdeData(); //抓取页面 while (!$data) { if ($data !== 0) { sleep(1); } $data = false; //抓取最新的数据 $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = 'http://www.gpcxw.com/ddx/data2/dde.htm?code=' . $numCode; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran; self::$log->debugLog($item['name'], $item['code'], 'new', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //处理停牌 if (substr($content, 0, 7) == 'tingpai') { $data = false; break; } //读取最新的数据 $cuts = explode('==', $content); if (sizeof($cuts) != 3) { continue; } $k = explode('<=>', $cuts[1]); $k = end($k); $k = explode(' ', $k); $new = $k[0]; $k = explode('<=>', $cuts[2]); $k = end($k); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; //新增的个股 需要抓取历史数据 if (!$last) { //抓取历史的数据 $k = explode('<=>', $cuts[0]); $lastfilemtime = end($k); $ran = mt_rand(); $ran = '0.' . $ran . $ran; $referer = $url; $url = 'http://www.gpcxw.com/ddx/data2/data2.htm?code=' . $numCode . '&m=' . $ran . '&lastfilemtime=' . $lastfilemtime . '&getlsold=1'; self::$log->debugLog($item['name'], $item['code'], 'history', $url); $content = DdeKeeper::curlSinglePage($url, $host, $referer, self::$tmp->getTmpFile('dde.gpcxw.duty.cookie')); if (!$content) { continue; } $content = iconv('GB2312', 'UTF-8//IGNORE', $content); //读取历史数据 $cuts = explode('<=>', $content); if (sizeof($cuts) != 2) { continue; } $k = end($cuts); if (substr($k, strlen($k) - 1) != '|') { $k .= '|'; } $new = $k . $new; } $data = DdeKeeper::parseGpcxwDde($new); } //print_r($data); //处理停牌 if (!$data) { self::$log->noticeLog($item['name'], $item['code'], "TingPai"); continue; } if ($last) { $updata = DdeKeeper::mergeUpdate($last, $data); DdeKeeper::addDde($dde->getDataFile(), $updata); } else { $updata = $data; DdeKeeper::putDde($dde->getDataFile(), $updata); } self::$log->noticeLog($item['name'], $item['code'], "Update Gpcxw Dde Success"); } self::$log->debugLog("Finish Update Gpcxw Dde"); self::$tmp->putTmpContent('dde.gpcxw.duty.process', ''); }
public static function testDdeData() { $dd = new DdeData('sh600010'); if ($dd->prepareData()) { //var_dump($dd->getStockData()); //var_dump($dd->getDaySolo('2015-11-06')['time']); //var_dump($dd->getLastSolo(0)['time']); var_dump($dd->getDayPeriod('2015-10-01', '2015-11-06', 7)); //var_dump($dd->getDayPeriod('2015-11-01', true, 7)); //var_dump($dd->getLastPeriod(true, true)); //var_dump($dd->getLastPeriod(5, true)); //var_dump($dd->getLastPeriod(7, true, 6)); } }