add home directory

This commit is contained in:
kamba4 2024-09-12 19:19:09 +00:00
commit 24718f0da7
13 changed files with 118434 additions and 0 deletions

View file

@ -0,0 +1,67 @@
#!/bin/bash
DIR_OSMUPDATE=$(cd `dirname "$0"`; pwd)
XML_FILE=planet.osm.bz2
XML_RESULT_FILE=surveillance.osm
SQL_FILE=initializeDB.sql
cd $DIR_OSMUPDATE
echo `date "+%d.%m.%Y %H:%M:%S"`" - Starting analysis"
if [ "$1" != "-n" ]
then
echo `date "+%d.%m.%Y %H:%M:%S"`" - Extracting cameras"
bzcat "$XML_FILE" | osmosis --rx file=/dev/stdin --tf accept-nodes man_made=surveillance --tf reject-relations --tf reject-ways --write-xml "$XML_RESULT_FILE"
fi
echo `date "+%d.%m.%Y %H:%M:%S"`" - Generating script"
echo "DELETE FROM position; DELETE FROM tag; COMMIT;" > "$SQL_FILE"
IFS='
'
countPoints=0;
nextCommit=100;
for line in `cat "$XML_RESULT_FILE" | grep -E "<node|</node|<tag" | sed 's/^[ ]*//'`
do
tag=`echo "$line" | cut -c1-5`
if [ "$tag" = "<node" ]
then
nodeId=`echo "$line" | sed 's/.*node id="\([^"]*\)".*/\1/'`
lat=`echo "$line" | sed 's/.*lat="\([^"]*\)".*/\1/'`
lon=`echo "$line" | sed 's/.*lon="\([^"]*\)".*/\1/'`
userid=`echo "$line" | sed -e 's/.*user="\([^"]*\)".*/\1/' -e "s/'/''/g"`
version=`echo "$line" | sed 's/.*version="\([^"]*\)".*/\1/'`
timestamp=`echo "$line" | sed 's/.*timestamp="\([^"]*\)".*/\1/'`
echo "INSERT INTO position (id, latitude, longitude) VALUES ($nodeId, "`echo "$lat" '*' 10000000 | bc | cut -d'.' -f1`","`echo "$lon" '*' 10000000 | bc | cut -d'.' -f1`");" >> "$SQL_FILE"
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, 'lat', '$lat');" >> "$SQL_FILE"
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, 'lon', '$lon');" >> "$SQL_FILE"
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, 'userid', '$userid');" >> "$SQL_FILE"
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, 'version', '$version');" >> "$SQL_FILE"
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, 'timestamp', '$timestamp');" >> "$SQL_FILE"
elif [ "$tag" = "<tag " ]
then
key=`echo "$line" | sed -e 's/.*k="\([^"]*\)".*/\1/' -e "s/'/''/g"`
val=`echo "$line" | sed -e 's/.*v="\([^"]*\)".*/\1/' -e "s/'/''/g"`
echo "INSERT INTO tag (id, k, v) VALUES ($nodeId, '$key', '$val');" >> "$SQL_FILE"
elif [ "$tag" = "</nod" ]
then
countPoints=$(( $countPoints + 1 ))
if [ $countPoints -eq $nextCommit ]
then
echo "COMMIT;" >> "$SQL_FILE"
nextCommit=$(( $nextCommit + 100 ))
fi
fi
done
echo "COMMIT;" >> "$SQL_FILE"
echo `date "+%d.%m.%Y %H:%M:%S"`" - End of update ($countPoints cameras)"

View file

@ -0,0 +1,30 @@
CREATE TABLE statistics (
id BIGINT REFERENCES position ON DELETE CASCADE,
ts VARCHAR(20),
year SMALLINT,
month TINYINT,
day TINYINT,
t TIME,
week TINYINT,
country VARCHAR(2),
area TINYINT,
type TINYINT,
version INT,
PRIMARY KEY (id)
);
-- CREATE INDEX Year ON statistics (year);
-- CREATE INDEX YearMonth ON statistics (year, month);
INSERT INTO statistics (
id,
ts,
version)
SELECT
t1.id,
t1.v,
t2.v
FROM tag AS t1
INNER JOIN tag AS t2
ON t2.id = t1.id
WHERE t2.k = 'version' AND t1.k = 'timestamp';

View file

@ -0,0 +1,20 @@
create database camera;
use camera;
grant all privileges on camera.* to camera@localhost identified by 'xxxxxxxx';
grant select on camera.* to camselect@localhost;
CREATE TABLE position (
id BIGINT PRIMARY KEY,
latitude INT,
longitude INT
);
CREATE TABLE tag (
id BIGINT REFERENCES position ON DELETE CASCADE,
k VARCHAR(100),
v VARCHAR(10000),
PRIMARY KEY (id, k)
);
CREATE INDEX LatLon ON position (latitude, longitude);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,15 @@
<?php
define('REPLICATE_URL', 'https://planet.openstreetmap.org/replication/minute');
define('MYSQL_HOST', 'localhost');
define('MYSQL_DB', 'camera');
define('MYSQL_USER', 'camera');
define('MYSQL_PASSWD', 'xxxxxxxx');
define('USE_STATISTICS', false);
define('WEBSERVICE_COUNTRY_URL', 'http://api.geonames.org/countryCode');
define('WEBSERVICE_USER', 'xxxxxxxx');
define('MAX_WEBREQUESTS_PER_HOUR', 1000);
?>

View file

@ -0,0 +1,2 @@
sequenceNumber=0
timestamp=2012-09-12T07:02:35Z

View file

@ -0,0 +1,2 @@
sequenceNumber=0
timestamp=2012-09-12T07:02:35Z

View file

@ -0,0 +1,287 @@
<?php
include "config.php";
$elementTypes = array();
$count = 0;
$countDelete = 0;
$countModifyDelete = 0;
$countModify = 0;
$countCreate = 0;
$mode = '';
$curNodeAttrs = null;
$curNodeTags = null;
$id = 0;
$latitude = 0;
$longitude = 0;
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB);
if($mysqli->connect_errno) {
echo "Error while connecting to DB : $mysqli->error \n" ;
exit(1);
}
$mysqli->autocommit(FALSE);
if (! ($deleteStmt = $mysqli->prepare("DELETE FROM position WHERE id=?"))) {
echo "Error while preparing delete position statement : " . $mysqli->error ;
exit(1);
}
$deleteStmt->bind_param('d', $id);
if (! ($deleteTagStmt = $mysqli->prepare("DELETE FROM tag WHERE id=?"))) {
echo "Error while preparing delete tag statement : " . $mysqli->error ;
exit(1);
}
$deleteTagStmt->bind_param('d', $id);
if (USE_STATISTICS) {
if (! ($deleteStatsStmt = $mysqli->prepare("DELETE FROM statistics WHERE id=?"))) {
echo "Error while preparing delete statistics statement : " . $mysqli->error ;
exit(1);
}
$deleteStatsStmt->bind_param('d', $id);
}
if (! ($insertStmt = $mysqli->prepare("INSERT INTO position (id, latitude, longitude) VALUES (?, ?, ?)"))) {
echo "Error while preparing insert position statement : " . $mysqli->error ;
exit(1);
}
$insertStmt->bind_param('dii', $id, $latitude, $longitude);
if (! ($insertTagStmt = $mysqli->prepare("INSERT INTO tag (id, k, v) VALUES (?, ?, ?)"))) {
echo "Error while preparing insert tag statement : " . $mysqli->error ;
exit(1);
}
$insertTagStmt->bind_param('dss', $id, $k, $v);
if (USE_STATISTICS) {
if (! ($insertStatsStmt = $mysqli->prepare("INSERT INTO statistics (id, ts, version) VALUES (?, ?, ?)"))) {
echo "Error while preparing insert statistics statement : " . $mysqli->error ;
exit(1);
}
$insertStatsStmt->bind_param('dsi', $id, $ts, $version);
}
function printDebug() {
global $elementTypes, $count, $countDelete, $countModifyDelete, $countModify, $countCreate;
echo "== $count ==============================\n";
foreach($elementTypes as $k => $v) {
echo "$k : $v\n";
}
echo "++++++ Surveillance nodes : ++++++\n";
echo "$countDelete deletions\n";
echo "$countModifyDelete modifications --> deletions\n";
echo "$countModify modifications\n";
echo "$countCreate creations\n";
}
function printDebugCurNode() {
global $curNodeAttrs, $curNodeTags, $mode;
echo "=============\n";
echo "$mode : " . $curNodeAttrs['id'] ." (". $curNodeAttrs['lat'] . " x " . $curNodeAttrs['lon'] . ") : " . $curNodeAttrs['user'] . "\n";
if (! empty($curNodeAttrs)) {
echo " => Attributes :\n";
foreach($curNodeAttrs as $k => $v) {
echo " $k : $v\n";
}
} else {
echo " => No attributes\n";
}
if (! empty($curNodeTags)) {
echo " => Tags :\n";
foreach($curNodeTags as $k => $v) {
echo " $k : $v\n";
}
} else {
echo " => No tags\n";
}
}
function startElement ($parser, $name, $attrs) {
global $elementTypes, $count, $mode, $curNodeAttrs, $curNodeTags;
$count++;
if (array_key_exists($name, $elementTypes)) {
$elementTypes[$name] += 1;
} else {
$elementTypes[$name] = 1;
}
if ($name == 'modify' || $name == 'delete' or $name == 'create') {
$mode = $name;
} else if ($name == 'node') {
$curNodeAttrs = $attrs;
$curNodeTags = array();
} else if ($name == 'tag') {
$curNodeTags[$attrs['k']] = $attrs['v'];
}
}
function endElement ($parser, $name) {
if (USE_STATISTICS) {
global $mode, $deleteStmt, $deleteTagStmt, $deleteStatsStmt, $insertStmt, $insertTagStmt, $insertStatsStmt, $selectStmt, $id, $latitude, $longitude, $k, $v, $ts, $version, $curNodeAttrs, $curNodeTags, $mysqli, $countDelete, $countModifyDelete, $countModify, $countCreate;
} else {
global $mode, $deleteStmt, $deleteTagStmt, $insertStmt, $insertTagStmt, $selectStmt, $id, $latitude, $longitude, $k, $v, $curNodeAttrs, $curNodeTags, $mysqli, $countDelete, $countModifyDelete, $countModify, $countCreate;
}
if ($name == 'modify' || $name == 'delete' or $name == 'create') {
$mode = '';
} else if ($name == 'node') {
if ($mode == 'delete') {
$id = $curNodeAttrs['id'];
if (USE_STATISTICS) {
if (! $deleteStatsStmt->execute()) {
echo "***** Error : Deleting statistics $id : ". $deleteStatsStmt->error . "\n";
}
}
if (! $deleteTagStmt->execute()) {
echo "***** Error : Deleting tags $id : ". $deleteTagStmt->error . "\n";
}
if (! $deleteStmt->execute()) {
echo "***** Error : Deleting $id : ". $deleteStmt->error . "\n";
}
if ($deleteStmt->affected_rows > 0) {
$countDelete++;
$mysqli->commit();
printDebugCurNode();
}
} else if ($mode == 'modify' || $mode == 'create') {
if (! empty($curNodeTags)
&& array_key_exists('man_made', $curNodeTags)
&& $curNodeTags['man_made'] == 'surveillance') {
printDebugCurNode();
$id = $curNodeAttrs['id'];
if ($mode == 'modify') {
$countModify++;
if (USE_STATISTICS) {
if (! $deleteStatsStmt->execute()) {
echo "***** Error : Deleting statistics $id for modification : ". $deleteStatsStmt->error . "\n";
}
}
if (! $deleteTagStmt->execute()) {
echo "***** Error : Deleting tags $id for modification : ". $deleteTagStmt->error . "\n";
}
if (! $deleteStmt->execute()) {
echo "***** Error : Deleting $id for modification : ". $deleteStmt->error . "\n";
}
} else {
$countCreate++;
}
$latitude = (int) ($curNodeAttrs['lat'] * 10000000);
$longitude = (int) ($curNodeAttrs['lon'] * 10000000);
if (! $insertStmt->execute()) {
echo "***** Error : inserting $id ($latitude x $longitude) : ". $insertStmt->error . "\n";
}
$k = 'lat';
$v = $curNodeAttrs['lat'];
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting latitude $v for $id : ". $insertTagStmt->error . "\n";
}
$k = 'lon';
$v = $curNodeAttrs['lon'];
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting longitude $v for $id : ". $insertTagStmt->error . "\n";
}
$k = 'userid';
$v = $curNodeAttrs['user'];
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting user $v for $id : ". $insertTagStmt->error . "\n";
}
$k = 'version';
$v = $curNodeAttrs['version'];
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting version $v for $id : ". $insertTagStmt->error . "\n";
}
$k = 'timestamp';
$v = $curNodeAttrs['timestamp'];
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting timestamp $v for $id : ". $insertTagStmt->error . "\n";
}
foreach($curNodeTags as $k => $v) {
if (! $insertTagStmt->execute()) {
echo "***** Error : inserting tag $k => $v for $id : ". $insertTagStmt->error . "\n";
}
}
if (USE_STATISTICS) {
$ts = $curNodeAttrs['timestamp'];
$version = $curNodeAttrs['version'];
if (! $insertStatsStmt->execute()) {
echo "***** Error : inserting ts $ts, version $version for $id : ". $insertStatsStmt->error . "\n";
}
}
$mysqli->commit();
} else if ($mode == 'modify') {
// delete former surveillance nodes that were modified to non-surveillance nodes
$id = $curNodeAttrs['id'];
if (USE_STATISTICS) {
if (! $deleteStatsStmt->execute()) {
echo "***** Error : Deleting statistics $id for non-surveillance node : ". $deleteStatsStmt->error . "\n";
}
}
if (! $deleteTagStmt->execute()) {
echo "***** Error : Deleting tags $id for non-surveillance node : ". $deleteTagStmt->error . "\n";
}
if (! $deleteStmt->execute()) {
echo "***** Error : Deleting $id for non-surveillance node : ". $deleteStmt->error . "\n";
}
if ($deleteStmt->affected_rows > 0) {
$countModifyDelete++;
$mysqli->commit();
printDebugCurNode();
echo " ==> delete because modified to non-surveillance node\n";
}
}
}
$curNodeAttrs = null;
$curNodeTags = null;
}
}
$file="change_file.osc";
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($xml_parser, "startElement", "endElement");
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
printDebug();
$mysqli->close();
?>

View file

@ -0,0 +1,90 @@
#!/bin/bash
exedir=$(cd `dirname "$0"`; pwd)
REPLICATE_URL=`grep "REPLICATE_URL" "$exedir/config.php" | sed -e 's/.*http/http/' -e 's#...$##' `
if [ -e "/var/lock/update_camera" ]
then
# Maybe an other update is running
otherPid=$(cat "/var/lock/update_camera")
count=$(ps $otherPid | grep -c `basename "$0"`)
if [ $count -gt 0 ]
then
echo "$0 is running yet. Exiting." >&2
exit 1
fi
fi
# OK. We can update the database...
echo $$ > "/var/lock/update_camera"
exeDir=$(cd `dirname "$0"`; pwd);
cd "$exeDir"
if [ -e "state.txt" ]
then
rm "state.txt"
fi
# Read the last update timestamp
lastTimestamp=$(grep "^timestamp=" "lastState.txt" | cut -d'=' -f2-)
lastSeqNum=$(grep "^sequenceNumber=" "lastState.txt" | cut -d'=' -f2-)
wget -nv "$REPLICATE_URL/state.txt"
newTimestamp=$(grep "^timestamp=" "state.txt" | cut -d'=' -f2-)
newSeqNum=$(grep "^sequenceNumber=" "state.txt" | cut -d'=' -f2-)
if [ $newSeqNum -eq $lastSeqNum ]
then
echo "No new file to be processed"
exit 1
fi
curSeqNum=$lastSeqNum
while [ $curSeqNum -lt $newSeqNum ]
do
curSeqNum=$(( $curSeqNum + 1 ))
logFileName="logs/log.$curSeqNum"
if [ -e "change_file.osc" ]
then
rm "change_file.osc"
fi
if [ -e "change_file.osc.gz" ]
then
rm "change_file.osc.gz"
fi
echo `date "+%d/%m/%Y %H:%M"`" - Start processing sequence number $curSeqNum" > "$logFileName"
targetDirName=`echo "000000000$curSeqNum" | sed 's#.*\(...\)\(...\)\(...\)$#\1/\2/\3.osc.gz#'`
targetDirName="$REPLICATE_URL/$targetDirName"
wget -nv "$targetDirName" -O change_file.osc.gz 2>&1 | tee -a $logFileName
if [ $? -gt 0 ]
then
echo "Error during recovery of $targetDirName" | tee -a $logFileName
exit 1
fi
gunzip change_file.osc.gz 2>&1 | tee -a $logFileName
if [ $? -gt 0 ]
then
echo "Error during decompression of $targetDirName" | tee -a $logFileName
exit 1
fi
php update_camera.php 2>&1 | tee -a $logFileName
targetDirName=`echo "$targetDirName" | sed 's/.osc.gz$/.state.txt/'`
wget -nv "$targetDirName" -O lastState.txt 2>&1 | tee -a $logFileName
echo `date "+%d/%m/%Y %H:%M"`" - Finish processing sequence number $curSeqNum" | tee -a "$logFileName"
done
rm "/var/lock/update_camera"

View file

@ -0,0 +1,235 @@
<?php
include "config.php";
if (USE_STATISTICS) {
$mysqli = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB);
if ($mysqli->connect_errno) {
echo "Error while connecting to DB : ".$mysqli->error." \n" ;
exit(1);
}
$mysqli->autocommit(FALSE);
if (!($selectStatsCountryStmt = $mysqli->prepare("SELECT s.id, p.latitude, p.longitude
FROM statistics AS s
INNER JOIN position AS p
ON p.id = s.id
WHERE s.country IS NULL LIMIT ?"))) {
echo "Error while preparing select statistics country statement : ".$mysqli->error."\n";
exit(1);
}
if (!($updateStatsCountryStmt = $mysqli->prepare("UPDATE statistics
SET country = ?
WHERE id = ?"))) {
echo "Error while preparing update statistics country statement : " . $mysqli->error ;
exit(1);
}
if (!($updateStatsDateValuesStmt = $mysqli->prepare("UPDATE statistics
SET year = YEAR(ts),
month = MONTH(ts),
day = DAYOFMONTH(ts),
t = TIME(STR_TO_DATE(ts, '%Y-%m-%dT%H:%i:%sZ')),
week = WEEKOFYEAR(ts)
WHERE id = ?"))) {
echo "Error while preparing update statistics date values statement : " . $mysqli->error ;
exit(1);
}
if (!($updateStatsZeroAreaTypeStmt = $mysqli->prepare("UPDATE statistics
SET area = 0,
type = 0
WHERE id = ?"))) {
echo "Error while preparing update statistics area and type to zero statement : " . $mysqli->error ;
exit(1);
}
if (!($updateStatsAreaStmt = $mysqli->prepare("UPDATE statistics AS s
INNER JOIN tag AS t
ON t.id = s.id
SET s.area = CASE
WHEN t.k = 'surveillance' AND t.v = 'public' THEN 1
WHEN t.k = 'surveillance' AND t.v = 'outdoor' THEN 2
WHEN t.k = 'surveillance' AND t.v = 'indoor' THEN 3
ELSE 0
END
WHERE s.id = ? AND (
t.k = 'surveillance' AND (
t.v = 'public' OR t.v = 'outdoor' OR t.v = 'indoor'))"))) {
echo "Error while preparing update statistics area statement : " . $mysqli->error ;
exit(1);
}
if (!($updateStatsTypeStmt = $mysqli->prepare("UPDATE statistics AS s
INNER JOIN tag AS t
ON t.id = s.id
SET s.type = CASE
WHEN t.k = 'camera:type' AND t.v = 'fixed' THEN 1
WHEN t.k = 'camera:type' AND t.v = 'panning' THEN 2
WHEN t.k = 'camera:type' AND t.v = 'dome' THEN 3
WHEN t.k = 'surveillance:type' AND t.v = 'guard' THEN 4
WHEN (t.k = 'surveillance:type' AND t.v = 'ALPR')
OR (t.k = 'surveillance' AND (
t.v = 'level_crossing' OR
t.v = 'red_light' OR
t.v = 'speed_camera')) THEN 5
ELSE 0
END
WHERE s.id = ? AND (
(t.k = 'camera:type' AND (t.v = 'fixed' OR t.v = 'panning' OR t.v = 'dome')) OR
(t.k = 'surveillance:type' AND (t.v = 'guard' OR t.v = 'ALPR')) OR
(t.k = 'surveillance' AND (
t.v = 'level_crossing' OR
t.v = 'red_light' OR
t.v = 'speed_camera')))"))) {
echo "Error while preparing update statistics type statement : " . $mysqli->error ;
exit(1);
}
function updateStatistics() {
global $selectStatsCountryStmt, $updateStatsCountryStmt, $updateStatsDateValuesStmt, $updateStatsZeroAreaTypeStmt, $updateStatsAreaStmt, $updateStatsTypeStmt;
$statisticsWithoutCountry = getStatisticsWithoutCountry();
foreach($statisticsWithoutCountry as $stats) {
$id = $stats['id'];
$latitude = bcdiv($stats['latitude'], 10000000, 7);
$longitude = bcdiv($stats['longitude'], 10000000, 7);
$countryISO = getCountryISOFromWebservice($id, $latitude, $longitude);
updateStatsCountry($countryISO, $id);
updateStatsDateValues($id);
updateStatsZeroAreaType($id);
updateStatsArea($id);
updateStatsType($id);
}
$selectStatsCountryStmt->close();
$updateStatsCountryStmt->close();
$updateStatsDateValuesStmt->close();
$updateStatsZeroAreaTypeStmt->close();
$updateStatsAreaStmt->close();
$updateStatsTypeStmt->close();
}
function getStatisticsWithoutCountry() {
global $selectStatsCountryStmt;
$selectStatsCountryStmt->bind_param('i', $limit);
$selectStatsCountryStmt->bind_result($id, $latitude, $longitude);
$limit = MAX_WEBREQUESTS_PER_HOUR;
if (! $selectStatsCountryStmt->execute()) {
echo "Error while selecting max ".$limit." statistics where country is empty : ".$selectStatsCountryStmt->error."\n";
}
$result = array();
while ($selectStatsCountryStmt->fetch()) {
$result[] = array(
'id' => $id,
'latitude' => $latitude,
'longitude' => $longitude
);
}
return $result;
}
function getCountryISOFromWebservice($id, $latitude, $longitude) {
echo "Requesting country ISO code for node ".$id." at latitude ".$latitude." and longitude ".$longitude."\n";
$countryURL = WEBSERVICE_COUNTRY_URL."?lat=".$latitude."&lng=".$longitude."&username=".WEBSERVICE_USER;
$webserviceResult = file_get_contents($countryURL);
if (substr($webserviceResult, 0, 3) == "ERR") {
// add radius buffer in km for closest country in coastal areas
$countryURL = WEBSERVICE_COUNTRY_URL."?lat=".$latitude."&lng=".$longitude."&radius=".WEBSERVICE_RADIUS."&username=".WEBSERVICE_USER;
$webserviceResult = file_get_contents($countryURL);
}
if (substr($webserviceResult, 0, 3) == "ERR") {
echo "--- Error from web service : ".$webserviceResult."\n";
$countryISO = "--";
echo "--- Using ".$countryISO." as country code for node ".$id."\n";
} else {
$countryISO = substr($webserviceResult, 0, 2);
echo "--- Result from web service for node ".$id.": ".$countryISO."\n";
}
return $countryISO;
}
function updateStatsCountry($countryISO, $id) {
global $updateStatsCountryStmt;
$updateStatsCountryStmt->bind_param('sd', $countryISO, $id);
echo "--- Updating country ".$countryISO." of node ".$id."\n";
if (! $updateStatsCountryStmt->execute()) {
echo "--- Error while updating country ".$countryISO." of node ".$id." : ".$updateStatsCountryStmt->error."\n";
}
}
function updateStatsDateValues($id) {
global $updateStatsDateValuesStmt;
$updateStatsDateValuesStmt->bind_param('d', $id);
echo "--- Updating date values of node ".$id."\n";
if (! $updateStatsDateValuesStmt->execute()) {
echo "--- Error while updating date values of node ".$id." : ".$updateStatsDateValuesStmt->error."\n";
}
}
function updateStatsZeroAreaType($id) {
global $updateStatsZeroAreaTypeStmt;
$updateStatsZeroAreaTypeStmt->bind_param('d', $id);
echo "--- Updating area and type to zero of node ".$id."\n";
if (! $updateStatsZeroAreaTypeStmt->execute()) {
echo "--- Error while updating area and type to zero of node ".$id." : ".$updateStatsZeroAreaTypeStmt->error."\n";
}
}
function updateStatsArea($id) {
global $updateStatsAreaStmt;
$updateStatsAreaStmt->bind_param('d', $id);
echo "--- Updating area of node ".$id."\n";
if (! $updateStatsAreaStmt->execute()) {
echo "--- Error while updating area of node ".$id." : ".$updateStatsAreaStmt->error."\n";
}
}
function updateStatsType($id) {
global $updateStatsTypeStmt;
$updateStatsTypeStmt->bind_param('d', $id);
echo "--- Updating type of node ".$id."\n";
if (! $updateStatsTypeStmt->execute()) {
echo "--- Error while updating type of node ".$id." : ".$updateStatsTypeStmt->error."\n";
}
}
updateStatistics();
$mysqli->commit();
$mysqli->close();
}
?>

View file

@ -0,0 +1,19 @@
#!/bin/bash
exeDir=$(cd `dirname "$0"`; pwd);
cd "$exeDir"
lastUpdateName="lastStatisticsUpdate.txt"
lastSeqNum=$(grep "^sequenceNumber=" $lastUpdateName | cut -d'=' -f2-)
curSeqNum=$(( $lastSeqNum + 1 ))
curTimestamp=`date +"%Y-%m-%dT%H:%M:%S"`
logFileName="logsStatistics/log.$curSeqNum"
echo `date +"%Y-%m-%d %H:%M"`" - Start processing sequence number $curSeqNum" > $logFileName
php update_statistics.php 2>&1 | tee -a $logFileName
echo `date +"%Y-%m-%d %H:%M"`" - Finish processing sequence number $curSeqNum" | tee -a $logFileName
echo "sequenceNumber=$curSeqNum" > $lastUpdateName
echo "timestamp=$curTimestamp" | tee -a $lastUpdateName