Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tutorials:advanced:unreal [2019/04/15 15:59] (current)
hawkin created. Moved MongoDB instructions from json-prolog tutorial
Line 1: Line 1:
 +==== Importing new episode data into MongoDB (Additional information) ====
 +If you record data in the Virtual Reality using [[http://​robcog.org/​ | RobCog]], you essentially get the following files:
 +''​RawData_ID.json''​ <- this contains all the recorded events that happened, where everything was, who moved what where when...etc.
 +''​SemanticMap.owl''​ <- contains all information about the environment. Where are the tables spawned before they are manipulated?​ etc. \\
 +   ​EventData
 +     ​|->​ EventData_ID.owl <- contains the times of the events. Which event occurred when, what events are possible...
 +     ​|->​ Timeline_ID.html <- same as the above but as a visualized overview
 +  ​
 +Each episode gets a random ID generated, therefore replace ID here with whatever your data's ID is. In order to be able to access this data in KnowRob, we need to load it into our local MongoDB, since this is where all data is kept for KnowRob to access. Unfortunately,​ at the point in time where this tutorial is being written, MongoDB does not support the import of large files. The recorded episode can become fairly large if one performs multiple pick and place tasks. We can work around it, by splitting it up into multiple parts, which can be loaded into the MongoDB individually. For that, we need a little program called ''​jq''​. If you don't have it, you can install it from [[https://​stedolan.github.io/​jq/​ | here]]. It allows us to manipulate json files from command line. Then you can do the following in the directory where your ''​RawData_ID.json''​ is:
  
 +<code bash>
 +$ mkdir split
 +$ cd split
 +$ cat ../​RawData_ID.json | jq -c -M '​.'​ | split -l 2000
 +</​code>​
 +
 +We create a new directory called ''​split'',​ cd into it, access the file with ''​cat''​ then we use ''​jq''​ to make the file more compact (''​-c''​),​ disable colorful output to the shell (''​-M''​) and format the output in a basic way (''​.''​). Then it's fed to ''​split''​ which creates many files, which are each about 2000 lines long, since that is a size MongoDB is comfortable with. 
 +After this, you should see many files in your split directory, named ''​xaa'',​ ''​xab'',​ ''​xac''​... you get the idea. The amount of files you get depends on the size of your original .json file. 
 +Now we can import the files onto the databse.
 +
 +<code bash>
 +$ mongoimport --db DB-NAME --collection COLLECTION-NAME ​ --file FILE-NAME
 +</​code>​
 +
 +example: ​
 +<code bash>
 +$ mongoimport --db Own-Episodes_set-clean-table --collection RawData_cUCM ​ --file xaa
 +</​code>​
 +
 +I keep everything in one database, and name the collection according to the RawData_ID name, in order to not forget what is what. You can name it however you like. IF you consider importing all the files individually fairly tedious, you can write a script for it. If you do, let us know. Didn't get around to do that yet.
 +Now we can create a ''​mongodump'':​
 +
 +<code bash>
 +$ mongodump --db DB-NAME --collection COLLECTION-NAME
 +</​code>​
 +
 +<code bash>
 +$ mongodump --db Own-Episodes_set-clean-table --collection RawData_cUCM
 +</​code>​
 +Then you get a ''​dump''​ directory, which contains a ''​RawData_ID.bson''​ file and a ''​RawData_ID.metadata.json''​
 +
 +After this, you can just look at how the other episodes and their directories are structured, and create the directories for your data the same way. 
 +
 +Should you ever for some reason need to directly import a ''​*.bson''​ file, you can do so as well, using ''​mongorestore'':​
 +<code bash>
 +$ mongorestore -d DB-NAME -c COLLECTION-NAME FILE-NAME.bson
 +</​code>​
 +<code bash>
 +$ mongorestore -d Own-Episodes_set-clean-table -c RawData_qtzg RawData_qtzg.bson
 +</​code>​