Make apsc stats importer nondestructive
Former-commit-id: 1eae8d1c89fabed230ce5d3f02595c29a41b7f5e
--- a/admin/importAPSCEmployees.php
+++ b/admin/importAPSCEmployees.php
@@ -32,23 +32,35 @@
@$sums[$id][$timePeriod] += $data[1];
} else {
echo "<br>ERROR NAME MISSING FROM ID LIST<br><bR>" . PHP_EOL;
-
+
die();
-
}
}
fclose($handle);
}
}
foreach ($sums as $id => $sum) {
- echo $id. "<br>" . PHP_EOL;
+ echo $id . "<br>" . PHP_EOL;
$doc = $db->get($id);
- // print_r($doc);
- if (isset($doc->statistics)) $doc->statistics = Array();
+ echo $doc->name . "<br>" . PHP_EOL;
+ // print_r($doc);
+ $changed = false;
+ if (!isset($doc->statistics)) {
+ $changed = true;
+ $doc->statistics = Array();
+ }
foreach ($sum as $timePeriod => $value) {
- $doc->statistics["employees"][$timePeriod] = Array("value"=>$value, "source"=>"http://apsc.gov.au/stateoftheservice/");
+ if (!isset($doc->statistics->employees->$timePeriod->value)
+ || $doc->statistics->employees->$timePeriod->value != $value) {
+ $changed = true;
+ $doc->statistics["employees"][$timePeriod] = Array("value" => $value, "source" => "http://apsc.gov.au/stateoftheservice/");
+ }
}
- $db->save($doc);
+ if ($changed) {
+ $db->save($doc);
+ } else {
+ echo "not changed" . "<br>" . PHP_EOL;
+ }
}
// employees: timeperiod, source = apsc state of service, value
?>
--- a/include/couchdb.inc.php
+++ b/include/couchdb.inc.php
@@ -5,28 +5,28 @@
require ($basePath . 'couchdb/settee/src/settee.php');
function createDocumentsDesignDoc() {
- /*"views": {
- "web_server": {
- "map": "function(doc) {\n emit(doc.web_server, 1);\n}",
- "reduce": "function (key, values, rereduce) {\n return sum(values);\n}"
- },
- "byAgency": {
- "map": "function(doc) {\n emit(doc.agencyID, 1);\n}",
- "reduce": "function (key, values, rereduce) {\n return sum(values);\n}"
- },
- "byURL": {
- "map": "function(doc) {\n emit(doc.url, doc);\n}"
- },
- "agency": {
- "map": "function(doc) {\n emit(doc.agencyID, doc);\n}"
- },
- "byWebServer": {
- "map": "function(doc) {\n emit(doc.web_server, doc);\n}"
- },
- "getValidationRequired": {
- "map": "function(doc) {\nif (doc.mime_type == \"text/html\" \n&& typeof(doc.validation) == \"undefined\") {\n emit(doc._id, doc._attachments);\n}\n}"
- }
- }*/
+ /* "views": {
+ "web_server": {
+ "map": "function(doc) {\n emit(doc.web_server, 1);\n}",
+ "reduce": "function (key, values, rereduce) {\n return sum(values);\n}"
+ },
+ "byAgency": {
+ "map": "function(doc) {\n emit(doc.agencyID, 1);\n}",
+ "reduce": "function (key, values, rereduce) {\n return sum(values);\n}"
+ },
+ "byURL": {
+ "map": "function(doc) {\n emit(doc.url, doc);\n}"
+ },
+ "agency": {
+ "map": "function(doc) {\n emit(doc.agencyID, doc);\n}"
+ },
+ "byWebServer": {
+ "map": "function(doc) {\n emit(doc.web_server, doc);\n}"
+ },
+ "getValidationRequired": {
+ "map": "function(doc) {\nif (doc.mime_type == \"text/html\" \n&& typeof(doc.validation) == \"undefined\") {\n emit(doc._id, doc._attachments);\n}\n}"
+ }
+ } */
}
function createAgencyDesignDoc() {
@@ -95,7 +95,7 @@
}
}";
// http://stackoverflow.com/questions/646628/javascript-startswith
-$obj->views->score->map = 'if(!String.prototype.startsWith){
+ $obj->views->score->map = 'if(!String.prototype.startsWith){
String.prototype.startsWith = function (str) {
return !this.indexOf(str);
}
@@ -119,7 +119,7 @@
emit(count+doc._id, {id:doc._id, name: doc.name, score:count, orgType: doc.orgType, portfolio:portfolio});
}
}';
- $obj->views->scoreHas->map = 'if(!String.prototype.startsWith){
+ $obj->views->scoreHas->map = 'if(!String.prototype.startsWith){
String.prototype.startsWith = function (str) {
return !this.indexOf(str);
}
@@ -142,7 +142,7 @@
$obj->views->scoreHas->reduce = 'function (key, values, rereduce) {
return sum(values);
}';
- $obj->views->fieldNames->map = '
+ $obj->views->fieldNames->map = '
function(doc) {
for(var propName in doc) {
emit(propName, doc._id);
@@ -157,16 +157,16 @@
}
if (php_uname('n') == "vanille") {
-$serverAddr = 'http://192.168.178.21:5984/';
-
+ $serverAddr = 'http://192.168.178.21:5984/';
} else
if (php_uname('n') == "KYUUBEY") {
- $serverAddr = 'http://192.168.1.148:5984/';
+ $serverAddr = 'http://127.0.0.1:5984/';
} else {
$serverAddr = 'http://127.0.0.1:5984/';
}
- $server = new SetteeServer($serverAddr);
+$server = new SetteeServer($serverAddr);
+
function setteErrorHandler($e) {
echo $e->getMessage() . "<br>" . PHP_EOL;
}
--- a/webserver.php
+++ b/webserver.php
@@ -20,7 +20,15 @@
$website = $docsdb->get(md5($row->value->website));
$serverParts = explode(" ",$website->web_server);
echo "<td>" . $serverParts[0] . "</td>";
- echo "<td>" . $website->mime_type . "</td>";
+ if (!isset($website->validation)) {
+ echo "<td>?</td>";
+ } else {
+ if ($website->validation == "") {
+ echo "<td>No error</td>";
+ } else {
+ echo "<td><pre>" . str_replace("<", "<", $website->validation) . "</pre></td>";
+ }
+ }
} catch (SetteeRestClientException $e) {
// setteErrorHandler($e);
}