Commit 0ab039a1 authored by Kevin Abel's avatar Kevin Abel
Browse files

Fix BuildingData driver to import new CSV format

parent 512391a6
......@@ -9,6 +9,12 @@ use Zend\Db\Sql\Sql;
class UNL_TourMap_BuildingData
{
const SITE_CITY = 'UNL-CITY';
const SITE_EAST = 'UNL-EAST';
const SITE_LINCOLN = 'UNL-LIN1';
const SITE_LINCOLN_LEASE = 'UNL-LINC';
const SITE_INNOVATION = 'UNL-NIC';
protected $db;
protected $codeAliases;
......@@ -41,9 +47,8 @@ class UNL_TourMap_BuildingData
$table->addColumn(new Column\Varchar('code', 6));
$table->addColumn(new Column\Varchar('name', 255));
$table->addColumn(new Column\Varchar('location', 255));
$table->addColumn(new Column\Boolean('is_official'));
$column = new Column\Varchar('bl_id', 4);
$column = new Column\Varchar('bldg_no', 4);
$column->setNullable(true);
$table->addColumn($column);
......@@ -59,6 +64,7 @@ class UNL_TourMap_BuildingData
$column->setNullable(true);
$table->addColumn($column);
$table->addColumn(new Column\Boolean('is_official'));
$table->addConstraint(new Constraint\PrimaryKey('code'));
$db->query($sql->getSqlStringForSqlObject($table), $db::QUERY_MODE_EXECUTE);
......@@ -73,108 +79,39 @@ class UNL_TourMap_BuildingData
'code' => '?',
'name' => '?',
'location' => '?',
'bldg_no' => '?',
'address' => '?',
'lat' => '?',
'lng' => '?',
'is_official' => '?',
));
$inStmt = $sql->prepareStatementForSqlObject($insert);
foreach (array('all_buildings.csv' => true, 'additional_buildings.csv' => false) as $file => $hasHeaders) {
foreach (array('all_buildings.csv', 'additional_buildings.csv') as $file) {
$csv = new SplFileObject(UNL_TourMap::getDataDir() . '/csv/' . $file);
$csv->setFlags($csv::READ_CSV);
$isOfficial = true;
if ($file == 'additional_buildings.csv') {
$isOfficial = false;
}
foreach ($csv as $i => $line) {
// skip header line
if ($hasHeaders && $i == 0) {
if ($i == 0 || empty($line[1])) {
continue;
}
try {
$inStmt->execute(array(
$line[1],
$line[0],
$line[2],
$isOfficial,
$line[4],
$line[0],
$line[3],
$line[5],
$line[6],
empty($line[0]) ? false : true,
));
} catch (\Exception $e) {
// ignore for now
}
}
}
$update = $sql->update()
->set(array(
'bl_id' => '?',
'address' => '?',
))
->where(array('code' => '?'));
$stmt = $sql->prepareStatementForSqlObject($update);
$csv = new SplFileObject(UNL_TourMap::getDataDir() . '/csv/building_addresses.csv');
$csv->setFlags($csv::READ_CSV);
foreach ($csv as $i => $line) {
if ($i == 0 || count($line) < 6) {
continue;
}
try {
if (!$this->getByCode($line[3])) {
$location = 'Leased Sites in Lincoln, NE';
switch ($line[4]) {
case 'UNL-EAST':
$location = 'East Campus';
break;
case 'UNL-CITY':
$location = 'City Campus';
break;
}
$inStmt->execute(array(
$line[3],
$line[0],
$location,
true,
));
}
$stmt->execute(array(
$line[2],
$line[1],
$line[3],
));
} catch (Exception $e) {
$e; // ignore for now
}
}
$update = $sql->update()
->set(array(
'lat' => '?',
'lng' => '?',
))
->where(array('code' => '?'));
$stmt = $sql->prepareStatementForSqlObject($update);
$csv = new SplFileObject(UNL_TourMap::getDataDir() . '/csv/campus_spatialdata.csv');
$csv->setFlags($csv::READ_CSV);
foreach ($csv as $line) {
if (count($line) < 4) {
continue;
}
try {
$stmt->execute(array(
$line[2],
$line[3],
$line[1],
));
} catch (\Exception $e) {
// ignore for now
}
}
}
protected function executeSelect($where)
......@@ -212,25 +149,30 @@ class UNL_TourMap_BuildingData
public function getAllBuildings()
{
return $this->executeSelect(array('location' => array(
'City Campus',
'East Campus',
'Sites in Lincoln, NE',
'Leased Sites in Lincoln, NE'
self::SITE_CITY,
self::SITE_EAST,
self::SITE_INNOVATION,
self::SITE_LINCOLN,
self::SITE_LINCOLN_LEASE,
)));
}
public function getCityBuildings()
{
return $this->executeSelect(array('location' => 'City Campus'));
return $this->executeSelect(array('location' => self::SITE_CITY));
}
public function getEastBuildings()
{
return $this->executeSelect(array('location' => 'East Campus'));
return $this->executeSelect(array('location' => self::SITE_EAST));
}
public function getLincolnBuildings()
{
return $this->executeSelect(array('location' => array('Sites in Lincoln, NE', 'Leased Sites in Lincoln, NE')));
return $this->executeSelect(array('location' => array(
self::SITE_INNOVATION,
self::SITE_LINCOLN,
self::SITE_LINCOLN_LEASE,
)));
}
}
......@@ -55,13 +55,14 @@ class UNL_TourMap_Marker_Building extends UNL_TourMap_Marker
protected function determineCampus()
{
$data = $this->rawData;
$campus = 'unknown';
if ($data['location'] == 'City Campus') {
$campus = 'lincoln';
if ($data['location'] == UNL_TourMap_BuildingData::SITE_CITY) {
$campus = 'city';
} elseif ($data['location'] == 'East Campus') {
} elseif ($data['location'] == UNL_TourMap_BuildingData::SITE_EAST) {
$campus = 'east';
} elseif (strpos($data['location'], 'Sites in Lincoln') !== false) {
$campus = 'lincoln';
} elseif ($data['location'] == UNL_TourMap_BuildingData::SITE_INNOVATION) {
$campus = 'innovation';
}
$this->campus = $campus;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment