wiki:model_data

Version 4 (modified by dennisw, 13 years ago) ( diff )

--

2. Model & Data import

2.1 Model explained

The image on the right shows the model defined in gheat/models.py

This model 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 : The image is generated by installing django_extentions and the command: ./manage.py graph_models gheat | dot -Tpng -o model.png.

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)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.