Changes between Initial Version and Version 1 of model_data


Ignore:
Timestamp:
May 3, 2011, 12:11:19 PM (14 years ago)
Author:
dennisw
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • model_data

    v1 v1  
     1= 2. Model & Data import =
     2== 2.1 Model explained ==
     3[[Image(model1.png, 409px, align=right)]]
     4The image on the right shows the model defined in gheat/models.py
     5
     6As you can see there is a single table ''node'' and a larger table tree.
     7
     8The 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.
     9
     10The 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.
     11
     12NOTE 1: The image is generated by installing [https://github.com/django-extensions/django-extensions django_extentions] and the command: {{{./manage.py graph_models gheat | dot -Tpng -o model.png}}}.
     13
     14NOTE 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.
     15
     16== 2.2 Preparing the database ==
     17The 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.
     18{{{
     19$ ./manage.py syncdb
     20
     21# Some other handy commands are:
     22$ ./manage.py sql gheat  # This prints the sql output from the models file that will be used for creating the tables
     23$ ./manage.py flush  # This flushes the database, leaving the tables intact but empty
     24}}}
     25
     26Remember that when you have edited the models, you have to run the syndb command to make the changes effective in your database.
     27
     28== 2.3 Data import ==
     29There is a data import script for the .csv file format located in gheat/management/commands/import_csv.py:
     30{{{
     31# In theory, only the -f option is needed, but for overview's sake, please use the others aswell.
     32# -f = location of the .csv, e.g. '/home/test.csv'
     33# -m = name of the dataset, e.g. 'Walk in park' or 'Trip with boat'
     34# -g = your name
     35# -e = your email address
     36# -a = antenna
     37# -k = network card
     38
     39$ ./manage.py import_csv -f <file location> -m <dataset name> -g <username> -e <email> -a <antenna> -k <network card>
     40}}}
     41
     42Make sure the variables in this script match the column numbers in your file e.g.;
     43Lat 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]'.
     44Also, take note of the replace() and strip() functions. These should probably be edited aswell.
     45
     46If you would like to add random points to the database, you can run the gheat/management/commands/add_random_points.py:
     47{{{
     48$ ./manage.py add_random_points -c <number of points>
     49}}}