Archiv für den Monat: Juni 2014

CouchDB: restore deleted documents

This is a python based approach to restore deleted documents from couchdb if you have not compacted the database already. The following code snipped is based on this solution.

#!/usr/bin/python

import httplib
import json

SERVER_URL = 'localhost:5984' # host address
FILE_NAME = 'deleted.json' # one line in deleted.json: id,rev\n (comma-seperatet id and rev of deleted doc one line each)
DB_NAME = 'db' #database name

conn = httplib.HTTPConnection(SERVER_URL)

def count_lines(filename):
    lines = 0
    for line in open(filename):
        lines += 1
    return lines

with open(FILE_NAME) as file:
	i = 0
	count = count_lines(FILE_NAME)
	for line in file:
		i += 1
		print 'Document [{}/{}]'.format(i,count)
		
		doc = line.split(',')
		id = doc[0]
		rev = doc[1].rstrip()
		
		#empty doc
		uri = '/{}/{}?rev={}'.format(DB_NAME, id, rev)
		body = '{}'
		headers = {"Content-type": "application/json"}
		print uri
		conn.request("PUT", uri, body, headers)
		r = conn.getresponse()
		r.read()
		
		#get old rev
		uri = '/{}/{}?revs_info=true'.format(DB_NAME, id)
		conn.request("GET", uri)
		print uri
		r = conn.getresponse()
		obj = json.loads(r.read())
		oldRev = obj['_revs_info'][2]['rev'].encode("utf-8")
		print oldRev
		currentRev = obj['_revs_info'][0]['rev'].encode("utf-8")
		print currentRev
		
		#get old doc
		uri = '/{}/{}?rev={}'.format(DB_NAME, id, oldRev)
		print uri
		conn.request("GET", uri)
		r = conn.getresponse()
		doc = r.read()
		
		#restore old doc
		uri = '/{}/{}?rev={}'.format(DB_NAME, id, currentRev)
		print uri
		body = doc.replace(oldRev, currentRev)
		headers = {"Content-type": "application/json"}
		conn.request("PUT", uri, body, headers)
		r = conn.getresponse()
		print r.read()

Transfer data via AJAX to NodeJS

Prerequisites

  • NodeJS with Express

Client-Side Code

I’m using a jQuery UI DatePicker as an example. But it can be transferred to any other element for doing an AJAX-Call.

$(document).ready(function() {
	$('#datepicker').datepicker( { 
		onSelect: function(date, pickerInstance){ 
			$.ajax({
				url: '/datepicker',
				data: {'date':date},
				type: 'POST'
			});
		}
	} );
});

Server-Side Code

This code is running on NodeJS.

var app = express()
app.use(express.bodyParser()); // must be before any 'app.use(express.static(__dirname + '/public'))'-statements

...

app.post('/datepicker', function(request, response){
  console.log(request.body)       // your JSON
  response.send(request.body);    // echo the result back
});

It is important to have app.use(express.bodyParser());, which is used for JSON parsing, in the very beginning of the server code. Any routing stuff like app.use(express.static(__dirname + '/public')) must be set afterwards, otherwise the request.body will be undefined.

Einführung in die Informationsfusion

Prüfungsprotokollinhalte

Hier findest du einige Inhalte von Prüfungsprotokollen

Allgemeines

Was ist IF?

  • Definition: Aus verschiedenen Wissensquellen höherwertiges Wissen generieren
  • Arten von höherwertigen Wissen
  • Neues Wissen
  • Besseres Wissen (weniger Unsicherheiten)

Nutzen?

  • Höhere Robustheit/Verlässlichkeit
  • Höhere Auflösung
  • Höhere Abdeckung
  • Kostenreduktion

Probleme von Sensorik?

  • Immer eine Informationsreduktion
  • Fensterung
  • Rauschen
  • Projektion
  • Abtastung

Wann ist Fusion möglich?

  • Gemeinsamer Kontext
  • Unsicherheitsbehaftete Informationen (Wenn sich Informationen widersprechen!)

Einführung in die Informationsfusion weiterlesen