About

The eLog library was initially developed as a research prototype and later published for lifelogging researchers in 2010 to help them easily analyze heterogenous data and complex visualization. It has been kept growing with the progress of mobile computing environments and recently its UI part is released with GPL v3 license for wider usage. The eLog UI library is optimized for mobile environment and can get easily integrated with existing Web services.

Who We Are

The original work was proposed by Pil Ho and later extended the work with collaboration with 28 researchers around the world who contributed their lifelogs, collaborated for lifelog analysis and share research results to build up an open lifelogging platform for the public. Pil Ho has been keeping the development updating the library following up the progress in mobile computing.

Updates

  • Nov. 2014: Change the web page skin using bootstrap.
  • Nov. 2014: Published elog UI library as GPL v3.
  • Oct. 2014: Version up eLog library and documentation.

 

Pics 'n' Trails dataset preparation

This small lab is to post-process Pics 'n' Trails to prepare the data for members. The dataset is composed of binary images and GPS records.

GPS Records Data Schema

GPS records have two types of data: one of CSV text files for 2008 and the other in GDB (Garmin GPS binary format) for 2009 for which GPSBabel is used to decode. Both structures are different as below.

Below is the data structure of CSV text files.

CREATE TABLE `gps_traces` (
  `gps_year` int(11) DEFAULT NULL,
  `gps_month` int(11) DEFAULT NULL,
  `gps_date` int(11) DEFAULT NULL,
  `gps_datestamp` int(11) DEFAULT NULL,
  `gps_seconds` int(11) DEFAULT NULL,
  `gps_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `gps_altitude` double DEFAULT NULL,
  `gps_leglength` double DEFAULT NULL,
  `gps_legtime` int(11) DEFAULT NULL,
  `gps_speed` double DEFAULT NULL,
  `gps_course` double DEFAULT NULL,
  `gps_latitudedirection` char(2) DEFAULT NULL,
  `gps_latitudedegrees` double DEFAULT NULL,
  `gps_latitudefraction` double DEFAULT NULL,
  `gps_longitudedirection` char(2) DEFAULT NULL,
  `gps_longitudedegrees` double DEFAULT NULL,
  `gps_longitudefraction` double DEFAULT NULL,
  `gps_latitudenumeric` double DEFAULT NULL,
  `gps_longitudenumeric` double DEFAULT NULL,
  PRIMARY KEY (`gps_timestamp`),
  KEY `gps_latitudenumeric` (`gps_latitudenumeric`),
  KEY `gps_longitudenumeric` (`gps_longitudenumeric`),
  KEY `gps_altitude` (`gps_altitude`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Use the below command to import local data files

LOAD DATA LOCAL INFILE 'gps20080929tsv.txt' IGNORE INTO TABLE gps_traces;

Below is the data structure of GDB data files.

CREATE TABLE `gps_garmin_gps` (
  `latitude` double DEFAULT NULL,
  `longitude` double DEFAULT NULL,
  `altitude` double DEFAULT NULL,
  `date` char(255) DEFAULT NULL,
  `time` char(255) DEFAULT NULL,
  `gps_timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`gps_timestamp`),
  KEY `longitude` (`longitude`),
  KEY `latitude` (`latitude`),
  KEY `altitude` (`altitude`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Use the below command to import local data files

LOAD DATA LOCAL INFILE '20090108.txt' IGNORE INTO TABLE gps_garmin_gps FIELDS TERMINATED BY ',';

As a statistics, he has collected 514,670 GPS records in 2008 and 29,337 records in 2009.

Image data set Import

 0 ? gps2Num($exifCoord[0]) : 0;
	$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
	$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;

	$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
	return floatval($flip * ($degrees +($minutes/60)+($seconds/3600)));
}

function gps2Num($coordPart) {
	$parts = explode('/', $coordPart);
	if (count($parts) <= 0)
		return 0;

	if (count($parts) == 1)
		return $parts[0];

	return floatval($parts[0]) / floatval($parts[1]);
}

// Set time zone
date_default_timezone_set("UTC");

$path = "";
$set_timeadjust = 0;

$path= "/Users/pilhokim/Documents/Research/eLifeLog/data/pics_n_trails/photos/";
$thumbnail_16_path = '/Users/pilhokim/Documents/Research/eLifeLog/data/pics_n_trails/thumbnail_16/';
$thumbnail_64_path = '/Users/pilhokim/Documents/Research/eLifeLog/data/pics_n_trails/thumbnail_64/';

$bCreateThumbnail = 1;

// Set up the MySQL connection
$mysqli = new mysqli("127.0.0.1", "user_id", "password", "pics_n_trails", 3306);

/* check connection */
if (mysqli_connect_errno()) {
	printf("Connect failed: %s\n", mysqli_connect_error());
  	exit();
}
// Prepare the temporary table 
$query = "TRUNCATE TABLE pics";
if (!($result = $mysqli->query($query))) {
	printf("Table truncation error: %s\n", $mysqli->error);
	exit();
}
$query = "TRUNCATE TABLE pics_exif";
if (!($result = $mysqli->query($query))) {
	printf("Table truncation error: %s\n", $mysqli->error);
	exit();
}
$query = "TRUNCATE TABLE pics_thumbnail_16";
if (!($result = $mysqli->query($query))) {
	printf("Table truncation error: %s\n", $mysqli->error);
	exit();
}
$query = "TRUNCATE TABLE pics_thumbnail_64";
if (!($result = $mysqli->query($query))) {
	printf("Table truncation error: %s\n", $mysqli->error);
	exit();
}

// Recursively read all files in the selected directory 
$ite=new RecursiveDirectoryIterator($path);
$bytestotal=0;
$nbfiles=0;
$imagepath = $path;
$imagesubpath = '';

$ite_image = new RecursiveDirectoryIterator($imagepath);
foreach (new RecursiveIteratorIterator($ite_image) as $imagefilename=>$imagecur) {
	if ($bCreateThumbnail) {
		$newimagepath = $imagecur->getPathname();
		$newimagefile = $imagecur->getFileName();
		$newimagefullpath = substr($newimagepath, 0, strlen($newimagepath) - strlen($newimagefile));
		$newimagesubpath = substr($newimagefullpath, strlen($imagepath) - strlen($newimagefullpath));

		if ($imagesubpath != $newimagesubpath && is_dir($imagepath.$newimagesubpath)) {  
			$imagesubpath = $newimagesubpath;
			echo "Entering the subpath: $imagesubpath\n";
			if (strlen($imagesubpath) > 1) {
				// Create sub directory
				mkdir($thumbnail_16_path.$imagesubpath);
				mkdir($thumbnail_64_path.$imagesubpath);
			}
		}
	}

	if (strstr($imagecur, ".jpg") != "") {
		$filesize=$imagecur->getSize();
		$modified_time = $imagecur->getMTime();
		$bytestotal+=$filesize;
		$nbfiles++;
		echo "$imagefilename => $filesize\n";

		$query = "INSERT IGNORE INTO pics(filepath, image_UTC_timestamp, image_UTC_unix_timestamp)";
		$query = $query."	SELECT ";
		$query = $query."'$imagecur', ";
		$query = $query." CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00'), ";
		$query = $query." UNIX_TIMESTAMP(CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00'))";
		
		if (!($result = $mysqli->query($query))) {
			echo $query."\n";
			printf("Image insertion error: %s\n", $mysqli->error);
			return 0;
		}

		// Create thumbnail
		if ($bCreateThumbnail) {
			list($width, $height) = getimagesize($imagecur->getPathname());

			if ($width >= $height) {
				$thumbnail_16 = imagecreatetruecolor(16, intval($height/$width*16));
				$thumbnail_64 = imagecreatetruecolor(64, intval($height/$width*64));
			}
			else {
				$thumbnail_16 = imagecreatetruecolor(intval($width/$height*16), 16);
				$thumbnail_64 = imagecreatetruecolor(intval($width/$height*64), 64);
			}

			$source = imagecreatefromjpeg($imagecur);

			imagecopyresized($thumbnail_16, $source, 0, 0, 0, 0, imagesx($thumbnail_16), imagesy($thumbnail_16), $width, $height);
			imagejpeg($thumbnail_16, $thumbnail_16_path.$imagesubpath.$imagecur->getFileName(), 100);

			imagecopyresized($thumbnail_64, $source, 0, 0, 0, 0, imagesx($thumbnail_64), imagesy($thumbnail_64), $width, $height);
			imagejpeg($thumbnail_64, $thumbnail_64_path.$imagesubpath.$imagecur->getFileName(), 100);

			/*
			 * After run query
			UPDATE pics
					  SET filepath = REPLACE(filepath, 
					  '/Users/pilhokim/Documents/Research/eLifeLog/data/pics_n_trails',
					  '/var/chroot/home/content/78/7627678/data/users/pics_n_trails'
			);

			UPDATE pics
					  SET 
					  filepath_thumbnail_16 = REPLACE(filepath, 'photos', 'thumbnail_16'),
								 filepath_thumbnail_64 = REPLACE(filepath, 'photos', 'thumbnail_64');
			 */

		}

		// Read EXIF information
		$hasGPS = 0;
		$exif = exif_read_data($imagecur, 0, true);
		if ($exif) {
			$query = "INSERT IGNORE INTO pics_exif(filepath, image_UTC_unix_timestamp, section, section_key, key_value) ";
			$query = $query."	VALUES ";

			$insert_count = 0;
			foreach ($exif as $key => $section) {
				$exif_section = "$key";
				foreach ($section as $name => $val) {
					$exif_key = "$name";

					if ($name == "GPSLatitude") {
						$hasGPS = 1;
					}

					if (is_array($val)) {
						$exif_value = ""; 
						$count = 0;
						foreach ($val as $single_val) {
							if ($count == 0) {
								$exif_value = $exif_value."$single_val"; 
							}
							else {
								$exif_value = $exif_value."\t$single_val"; 
							}
							$count = $count + 1;
						}   
					}   
					else { 
						$exif_value = "$val"; 
					}   

					$exif_value = addslashes($exif_value);

					if ($insert_count == 0) {
						$query = $query." ('$imagefilename', UNIX_TIMESTAMP(CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00')), '$exif_section', '$exif_key', '$exif_value') ";
					}
					else {
						$query = $query.", ('$imagefilename', UNIX_TIMESTAMP(CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00')), '$exif_section', '$exif_key', '$exif_value') ";
					}
					$insert_count = $insert_count + 1;
				}
			}

			// Check GPS info
			if ($hasGPS) {
				$longitude = $exif["GPS"]["GPSLongitude"];
				$longituderef = $exif["GPS"]["GPSLongitudeRef"];
				$latitude = $exif["GPS"]["GPSLatitude"];
				$latituderef = $exif["GPS"]["GPSLatitudeRef"];
			
				$lon = getGps($longitude, $longituderef);
				$lat = getGps($latitude, $latituderef);

				if ($lon) {
						  $query = $query.", ('$imagefilename', UNIX_TIMESTAMP(CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00')), 'GPS', 'Longitude', '$lon') "; }
				if ($lat) {
						  $query = $query.", ('$imagefilename', UNIX_TIMESTAMP(CONVERT_TZ(FROM_UNIXTIME(".$modified_time."), '+9:00', '+0:00')), 'GPS', 'Latitude', '$lat') "; 
				}
			}
		
			if (!($result = $mysqli->query($query))) {
				printf("Image exif insertion error: %s\n", $mysqli->error);
			}
		}
	}
}	

unset($imagefilename, $query);

/* Update the photo timestamp by the location */

$mysqli->close();

$bytestotal=number_format($bytestotal);
echo "Total: $nbfiles files, $bytestotal bytes\n";