Пример #1
0
 /**
  * @param \SplFileObject $file
  *
  * @return CsvReader
  */
 public function getReader(\SplFileObject $file)
 {
     $reader = new CsvReader($file, $this->delimiter, $this->enclosure, $this->escape);
     if (null !== $this->headerRowNumber) {
         $reader->setHeaderRowNumber($this->headerRowNumber);
     }
     $reader->setStrict($this->strict);
     return $reader;
 }
Пример #2
0
 /**
  * Parses the Data of the uploaded Csv-File
  */
 protected function csvDataParse()
 {
     try {
         $csvReader = new CsvReader($this->_filePath, $this->_delimiter);
         $this->_contentArray = $csvReader->getContents();
         $this->_csvColumns = $csvReader->getKeys();
     } catch (Exception $e) {
         $this->errorDie(_g('Could not parse the Csv-File!'));
     }
 }
Пример #3
0
 public function testParseRow()
 {
     $row = '"AAPL",357.05,357.01,194.06,360.00';
     $parsed = CsvReader::parseRow($row);
     $this->assertEquals(count($parsed), 5);
     $this->assertEquals($parsed[0], "AAPL");
     $this->assertEquals($parsed[1], "357.05");
     $this->assertEquals($parsed[2], "357.01");
     $this->assertEquals($parsed[3], "194.06");
     $this->assertEquals($parsed[4], "360.00");
 }
 /**
  * {@inheritdoc}
  */
 public function read()
 {
     if ($this->executed) {
         return null;
     }
     $this->executed = true;
     $data = array();
     while ($row = parent::read()) {
         $data[] = $row;
     }
     return $data;
 }
 /**
  * CSVの現在行を配列として読み込む
  * @return array|boolean 読み出したCSVの配列、または読み込むデータがない場合はFALSEを返す
  * @access public
  */
 public function read()
 {
     // 行を取得
     if (($arr = parent::read()) === false) {
         return false;
     }
     // フォーマットに合わせて成形
     $csv = array();
     foreach ($this->format as $key => $params) {
         $csv[$key] = $this->filter(rtrim($arr[$this->col]), $params);
         $this->col++;
     }
     $this->col = 0;
     return $csv;
 }
 public function __construct($file, $delimiter = ',', $maxRowLength = 4098, $skipRows = 0)
 {
     parent::__construct($file, $delimiter, $maxRowLength);
     while ($skipRows > 0) {
         parent::next();
         $skipRows--;
     }
     // Extract the header information
     $this->colNames = parent::current();
     foreach ($this->colNames as $index => $name) {
         if (isset($this->colIndexes[$name])) {
             throw new DataFileException("Duplicate column name {$name}!");
         }
         $this->colIndexes[$name] = $index;
     }
     parent::next();
 }
Пример #7
0
 public static function fromCsv($file)
 {
     $reader = \CsvReader::open($file);
     $reader->getHeader();
     while (($row = $reader->readLine()) !== false) {
         $id = isset($row['id']) ? $row['id'] : null;
         $model = self::findOrNew($id);
         foreach ($row as $column => $value) {
             if ($column == 'id') {
                 continue;
             }
             if (!in_array($column, $model->fillable)) {
                 continue;
             }
             $model->{$column} = $value;
         }
         $model->save();
     }
 }
Пример #8
0
 static function getNasdaq($symbol)
 {
     $format = 'n' . 's' . 'b2' . 'b3' . 'j' . 'k' . 'o' . 'p' . 'h' . 'g';
     // Day's low
     $url = 'http://download.finance.yahoo.com/d/quotes.csv' . '?s=' . urlencode($symbol) . '&f=' . $format;
     $http = new HttpClient($url);
     $data = $http->getBody();
     $csv = CsvReader::parse($data);
     if (count($csv) != 1) {
         throw new \Exception('unhandled number of stock results: ' . count($csv));
     }
     $stock = new StockQuoteResult();
     $stock->name = $csv[0][0];
     $stock->symbol = $csv[0][1];
     $stock->ask_realtime = $csv[0][2];
     $stock->bid_realtime = $csv[0][3];
     $stock->low_52w = $csv[0][4];
     $stock->hi_52w = $csv[0][5];
     $stock->open = $csv[0][6];
     $stock->previous_close = $csv[0][7];
     $stock->day_high = $csv[0][8];
     $stock->day_low = $csv[0][9];
     return $stock;
 }
Пример #9
0
<?php

header("Content-type: text/html; charset=utf-8");
include 'CsvReader.php';
include 'conn.php';
include 'BinarySearch.php';
$prov = array("北京", "天津", "上海", "重庆", "河北", "河南", "云南", "辽宁", "黑龙江", "湖南", "安徽", "山东", "新疆", "江苏", "浙江", "江西", "湖北", "广西", "甘肃", "山西", "内蒙古", "陕西", "吉林", "福建", "贵州", "广东", "青海", "西藏", "四川", "宁夏", "海南", "台湾", "香港", "澳门");
$flow = array();
// $sql = "select * from bxmap.lib";
// $result = mysql_query($sql);
$weblog_file = 'traffic_web.csv';
$weblogreader = new CsvReader($weblog_file);
$line_number = $weblogreader->get_lines();
echo "Number of all records is " . $line_number . "<br>";
$data = $weblogreader->get_data(1000000, 13000000);
$index = 0;
foreach ($data as $each) {
    $ip = ip2long($each[2]);
    $time = strtotime($each[1]);
    $hour = (int) date('H', $time);
    // foreach ($iplist as $eachip) {
    // 	if($eachip[1]>=$ip) {
    // 		$ip_prov=$eachip[5];
    // 		break;
    // 	}
    // }
    // $sql = "select * from bxmap.lib where ipEnd_int >= '$ip'  limit 1";
    // $result = mysql_query($sql);
    // $result_row = mysql_fetch_array($result);
    $ip_prov = BinarySearch($ip);
    if ($ip_prov) {
 /**
  * Creates a new CSV reader reading data from a given TextReader
  * creating Beans for a given class.
  *
  * @param   io.streams.TextReader reader
  * @param   string[] keys
  * @param   text.csv.CsvFormat format
  */
 public function __construct(TextReader $reader, array $keys = array(), CsvFormat $format = NULL)
 {
     parent::__construct($reader, $format);
     $this->keys = $keys;
 }
Пример #11
0
 /**
  * Parse a CSV file, adding the data to the stockData array.
  * 
  * @param $filepath string Path to the .csv file to try and parse.
  */
 private function __parseCsv($filepath)
 {
     $csvReader = new CsvReader();
     if ($csvReader->readFile(makeAbsolutePath($filepath))) {
         $numLines = $csvReader->getNumLines();
         // If the .csv is sane, the first line is the headers
         $headers = $csvReader->getLine(0);
         if ($headers != null) {
             for ($i = 1; $i < $numLines; $i++) {
                 // For every line, convert the indexed array to an associated array
                 // using the headers as keys
                 $line = $csvReader->getLine($i);
                 if ($line != null && count($line) == count($headers)) {
                     $assocLine = array();
                     $numLineParts = count($line);
                     for ($j = 0; $j < $numLineParts; $j++) {
                         $assocLine[$headers[$j]] = $line[$j];
                     }
                     array_push($this->__stockData, $assocLine);
                 }
             }
         }
     }
 }
 /**
  * Creates a new CSV reader reading data from a given TextReader
  * creating Beans for a given class.
  *
  * @param   io.streams.TextReader reader
  * @param   lang.XPClass class
  * @param   text.csv.CsvFormat format
  */
 public function __construct(TextReader $reader, XPClass $class, CsvFormat $format = NULL)
 {
     parent::__construct($reader, $format);
     $this->class = $class;
 }
Пример #13
0
<?php

$lib_file = 'ip_lib.csv';
$libreader = new CsvReader($lib_file);
$ip_line_number = $libreader->get_lines();
$iplist = $libreader->get_data($ip_line_number);
//echo $ip_line_number, chr(10);
//echo "<br>";
function BinarySearch($search_ip)
{
    global $ip_line_number;
    global $iplist;
    $low = 0;
    $high = $ip_line_number - 1;
    while ($low < $high) {
        $current = intval(($low + $high) / 2);
        if ($search_ip >= $iplist[$current][0] && $search_ip <= $iplist[$current][1]) {
            return $iplist[$current][5];
        }
        if ($search_ip > $iplist[$current][1]) {
            $low = $current;
        } else {
            $high = $current;
        }
    }
    // echo $search_ip."<br>";
    return 0;
}
Пример #14
-3
 /**
  * Get the line at index.
  *
  * @param int $index The index of the line to retrieve.
  * @return mixed An array of line data if index is valid, otherwise null.
  */
 public function getLine($index)
 {
     return $this->__csvReader->getLine($index);
 }