Version 3 (modified by 14 years ago) ( diff ) | ,
---|
2. Model & Data import
2.1 Model explained
The image on the right shows the model defined in gheat/models.py
As you can see there is a single table Node and a larger table tree.
The Node table will be used for the Wireless Leiden node locations. This makes it possible to, for example, create an extra layer with a node's maximum range.
The bigger table tree is used for saving all the collected data. There is a table Meting which contains the lats & lons, signal strength, and 2 foreign keys which refer to Accespoint, where all the accespoint data is saved, and Meetrondje, a table defining datasets. Meetrondje has again 2 foreign keys, one to Gebruiker where the name and email address is saved of the person who owns the dataset, and one to Apparatuur where device information will be stored.
NOTE 1: The image is generated by installing django_extentions and the command: ./manage.py graph_models gheat | dot -Tpng -o model.png
.
NOTE 2: On this moment only the gheat_meting(lat, lng, signaal) are used for generating heatmaps, so make sure you at least put some data in those columns.
2.2 Preparing the database
The model may exist in the gheat/ folder, but it doesn't exist in your database yet. You can use the following command to sync the database.
$ ./manage.py syncdb # Some other handy commands are: $ ./manage.py sql gheat # This prints the sql output from the models file that will be used for creating the tables $ ./manage.py flush # This flushes the database, leaving the tables intact but empty
Remember that when you have edited the models, you have to run the syndb command to make the changes effective in your database.
2.3 Data import
There is a data import script for the .csv file format located in gheat/management/commands/import_csv.py:
# In theory, only the -f option is needed, but for overview's sake, please use the others aswell. # -f = location of the .csv, e.g. '/home/test.csv' # -m = name of the dataset, e.g. 'Walk in park' or 'Trip with boat' # -g = your name # -e = your email address # -a = antenna # -k = network card $ ./manage.py import_csv -f <file location> -m <dataset name> -g <username> -e <email> -a <antenna> -k <network card>
Make sure the variables in this script match the column numbers in your file e.g.; Lat is read from the first column [0], if the lat in your file is in the 4th column, change 'lat = row[0]' to 'lat = row[3]'. Also, take note of the replace() and strip() functions. These should probably be edited aswell.
If you would like to add random points to the database, you can run the gheat/management/commands/add_random_points.py:
$ ./manage.py add_random_points -c <number of points>
Time to get the application running; Running the application
Attachments (2)
-
model1.png
(25.1 KB
) - added by 14 years ago.
models image
- model2.png (27.4 KB ) - added by 13 years ago.
Download all attachments as: .zip