function test() { $conn = DBConn(); // select a collection (analogous to a relational database's table) $colnames = ['housesale', 'aptsale', 'flatsale', 'houserent', 'aptrent', 'flatrent', 'officetelrent', 'officetelsale', 'aptlots', 'landsale']; foreach ($colnames as $tname) { mkagg($conn, $tname, 2015, 12); } }
function test() { $conn = new mysqli("p:localhost", "trend", "only!trend!", "trend"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // select a collection (analogous to a relational database's table) $colnames = ['housesale', 'aptsale', 'flatsale', 'houserent', 'aptrent', 'flatrent']; foreach ($colnames as $tname) { mkagg($conn, $tname, 2015, 10); } }
function crawl($tname, $year, $monthArr) { $dealType = $GLOBALS['dealType']; $stateArr = $GLOBALS['stateArr']; if ($monthArr == null) { die("monthArr must be set!"); } $period = intval(($monthArr[0] - 1) / 3) + 1; echo "Working on {$year} ({$period}) " . implode(" ", $monthArr) . "\n"; $db = new mysqli("p:localhost", "trend", "only!trend!", "rtrend"); // Check connection if ($db->connect_error) { die("Connection failed: " . $db->connect_error); } // Set utf8 //$db->set_charset("utf8"); if (!isset($dealType[$tname])) { die("No args for {$tname}\n"); } // get deal type and table name $args = $dealType[$tname]; foreach ($stateArr as $state => $stateCode) { echo "Working on {$year} ({$period}) on {$state} for {$tname}\n"; $cities = getCities($year, $period, $stateCode, $args); $cityArr = json_decode($cities, true); foreach ($cityArr['jsonList'] as $city) { $counties = getCounties($year, $period, $stateCode, $city['CODE'], $args); $countyArr = json_decode($counties, true); foreach ($countyArr['jsonList'] as $county) { $deals = getDeals($year, $period, $stateCode, $city['CODE'], $county['CODE'], $args); $dealArr = json_decode($deals, true); foreach ($monthArr as $month) { // echo("Working on $year/$month ($period) on $state " . $city['NAME'] . " " . $county['NAME'] . "\n"); $infoArr = ['year' => $year, 'month' => $month, 'state' => $state, 'city' => $city['NAME'], 'county' => $county['NAME']]; // update // function update($db, $tname, $metaArr, $json) { update($db, $tname, $infoArr, $deals); } } } } // make aggregation foreach ($monthArr as $month) { echo "Make agg {$tname} on {$year}/{$month}"; mkagg($db, $tname, $year, $month); } $db->close(); }