Permalink
Browse files

Merge branch 'master' of github.com:lizardsystem/lizard-blockbox

Conflicts:
	lizard_blockbox/static/lizard_blockbox/blockbox.coffee
  • Loading branch information...
2 parents 73366ee + 0e66291 commit 74541c41408e463e7f430a252d766e67135da059 @gijs gijs committed Apr 11, 2012
@@ -0,0 +1,38 @@
+from django.core.management.base import BaseCommand
+from django.utils import simplejson as json
+
+from lizard_blockbox import models
+
+
+class Command(BaseCommand):
+ args = '<geojson geojson ...>'
+ help = "Imports the measure geojson file"
+
+ def handle(self, *args, **options):
+ map(self.parse, args)
+
+ def parse(self, json_file):
+ data = json.load(open(json_file, 'rb'))
+ features = data['features']
+ for feature in features:
+ properties = feature['properties']
+ # Parse code key dynamically
+ # Key can be Code_IVM or Code_QS, or something else.
+ short_name_key = [i for i in properties.keys()
+ if i.lower().startswith('code')][0]
+
+ # Parse and save the properties
+ try:
+ measure = models.Measure.objects.get(
+ short_name=properties[short_name_key])
+ except models.Measure.DoesNotExist:
+ print properties[short_name_key]
+ else:
+ measure.name = properties['titel']
+ measure.measure_type = properties['type']
+ measure.traject = properties['traject']
+ #XXX: Be aware that the River Reach must be coupled with
+ # the measure
+ measure.km_from = int(round(properties['km_van']))
+ measure.km_to = int(round(properties['km_tot']))
+ measure.save()
@@ -0,0 +1,100 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Measure.measure_type'
+ db.add_column('lizard_blockbox_measure', 'measure_type', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True), keep_default=False)
+
+ # Adding field 'Measure.km_from'
+ db.add_column('lizard_blockbox_measure', 'km_from', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='measure_km_from', null=True, to=orm['lizard_blockbox.RiverSegment']), keep_default=False)
+
+ # Adding field 'Measure.km_to'
+ db.add_column('lizard_blockbox_measure', 'km_to', self.gf('django.db.models.fields.related.ForeignKey')(blank=True, related_name='measure_km_to', null=True, to=orm['lizard_blockbox.RiverSegment']), keep_default=False)
+
+ # Adding field 'Measure.traject'
+ db.add_column('lizard_blockbox_measure', 'traject', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Measure.measure_type'
+ db.delete_column('lizard_blockbox_measure', 'measure_type')
+
+ # Deleting field 'Measure.km_from'
+ db.delete_column('lizard_blockbox_measure', 'km_from_id')
+
+ # Deleting field 'Measure.km_to'
+ db.delete_column('lizard_blockbox_measure', 'km_to_id')
+
+ # Deleting field 'Measure.traject'
+ db.delete_column('lizard_blockbox_measure', 'traject')
+
+
+ models = {
+ 'lizard_blockbox.floodingchance': {
+ 'Meta': {'object_name': 'FloodingChance'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+ },
+ 'lizard_blockbox.measure': {
+ 'Meta': {'object_name': 'Measure'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'km_from': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'measure_km_from'", 'null': 'True', 'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'km_to': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'measure_km_to'", 'null': 'True', 'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'measure_type': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'short_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'traject': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
+ },
+ 'lizard_blockbox.reach': {
+ 'Meta': {'object_name': 'Reach'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'lizard_blockbox.referencevalue': {
+ 'Meta': {'object_name': 'ReferenceValue'},
+ 'flooding_chance': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.FloodingChance']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'reference': ('django.db.models.fields.FloatField', [], {}),
+ 'riversegment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'scenario': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Scenario']"}),
+ 'target': ('django.db.models.fields.FloatField', [], {}),
+ 'year': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Year']"})
+ },
+ 'lizard_blockbox.riversegment': {
+ 'Meta': {'object_name': 'RiverSegment'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.IntegerField', [], {}),
+ 'the_geom': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True', 'blank': 'True'})
+ },
+ 'lizard_blockbox.scenario': {
+ 'Meta': {'object_name': 'Scenario'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'lizard_blockbox.waterleveldifference': {
+ 'Meta': {'object_name': 'WaterLevelDifference'},
+ 'flooding_chance': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.FloodingChance']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'level_difference': ('django.db.models.fields.FloatField', [], {}),
+ 'measure': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Measure']"}),
+ 'reference_value': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.ReferenceValue']"}),
+ 'riversegment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'scenario': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Scenario']"}),
+ 'year': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Year']"})
+ },
+ 'lizard_blockbox.year': {
+ 'Meta': {'object_name': 'Year'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'year': ('django.db.models.fields.IntegerField', [], {})
+ }
+ }
+
+ complete_apps = ['lizard_blockbox']
@@ -0,0 +1,108 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Renaming column for 'Measure.km_from' to match new field type.
+ db.rename_column('lizard_blockbox_measure', 'km_from_id', 'km_from')
+ # Changing field 'Measure.km_from'
+ db.alter_column('lizard_blockbox_measure', 'km_from', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+ # Removing index on 'Measure', fields ['km_from']
+ db.delete_index('lizard_blockbox_measure', ['km_from_id'])
+
+ # Renaming column for 'Measure.km_to' to match new field type.
+ db.rename_column('lizard_blockbox_measure', 'km_to_id', 'km_to')
+ # Changing field 'Measure.km_to'
+ db.alter_column('lizard_blockbox_measure', 'km_to', self.gf('django.db.models.fields.IntegerField')(null=True))
+
+ # Removing index on 'Measure', fields ['km_to']
+ db.delete_index('lizard_blockbox_measure', ['km_to_id'])
+
+
+ def backwards(self, orm):
+
+ # Adding index on 'Measure', fields ['km_to']
+ db.create_index('lizard_blockbox_measure', ['km_to_id'])
+
+ # Adding index on 'Measure', fields ['km_from']
+ db.create_index('lizard_blockbox_measure', ['km_from_id'])
+
+ # Renaming column for 'Measure.km_from' to match new field type.
+ db.rename_column('lizard_blockbox_measure', 'km_from', 'km_from_id')
+ # Changing field 'Measure.km_from'
+ db.alter_column('lizard_blockbox_measure', 'km_from_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['lizard_blockbox.RiverSegment']))
+
+ # Renaming column for 'Measure.km_to' to match new field type.
+ db.rename_column('lizard_blockbox_measure', 'km_to', 'km_to_id')
+ # Changing field 'Measure.km_to'
+ db.alter_column('lizard_blockbox_measure', 'km_to_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['lizard_blockbox.RiverSegment']))
+
+
+ models = {
+ 'lizard_blockbox.floodingchance': {
+ 'Meta': {'object_name': 'FloodingChance'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '10'})
+ },
+ 'lizard_blockbox.measure': {
+ 'Meta': {'object_name': 'Measure'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'km_from': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'km_to': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
+ 'measure_type': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'short_name': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
+ 'traject': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'})
+ },
+ 'lizard_blockbox.reach': {
+ 'Meta': {'object_name': 'Reach'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'})
+ },
+ 'lizard_blockbox.referencevalue': {
+ 'Meta': {'object_name': 'ReferenceValue'},
+ 'flooding_chance': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.FloodingChance']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'reference': ('django.db.models.fields.FloatField', [], {}),
+ 'riversegment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'scenario': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Scenario']"}),
+ 'target': ('django.db.models.fields.FloatField', [], {}),
+ 'year': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Year']"})
+ },
+ 'lizard_blockbox.riversegment': {
+ 'Meta': {'object_name': 'RiverSegment'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'location': ('django.db.models.fields.IntegerField', [], {}),
+ 'the_geom': ('django.contrib.gis.db.models.fields.PointField', [], {'null': 'True', 'blank': 'True'})
+ },
+ 'lizard_blockbox.scenario': {
+ 'Meta': {'object_name': 'Scenario'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'lizard_blockbox.waterleveldifference': {
+ 'Meta': {'object_name': 'WaterLevelDifference'},
+ 'flooding_chance': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.FloodingChance']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'level_difference': ('django.db.models.fields.FloatField', [], {}),
+ 'measure': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Measure']"}),
+ 'reference_value': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.ReferenceValue']"}),
+ 'riversegment': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.RiverSegment']"}),
+ 'scenario': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Scenario']"}),
+ 'year': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['lizard_blockbox.Year']"})
+ },
+ 'lizard_blockbox.year': {
+ 'Meta': {'object_name': 'Year'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'year': ('django.db.models.fields.IntegerField', [], {})
+ }
+ }
+
+ complete_apps = ['lizard_blockbox']
@@ -75,6 +75,10 @@ class Measure(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
short_name = models.CharField(max_length=100, blank=True, null=True)
+ measure_type = models.CharField(max_length=100, blank=True, null=True)
+ traject = models.CharField(max_length=100, blank=True, null=True)
+ km_from = models.IntegerField(null=True, blank=True)
+ km_to = models.IntegerField(null=True, blank=True)
def __unicode__(self):
name = self.name or self.short_name
@@ -100,10 +104,6 @@ class ReferenceValue(models.Model):
reference = models.FloatField()
target = models.FloatField()
- # class Meta:
- # unique_together = ('riversegment', 'scenario', 'year',
- # 'flooding_chance')
-
def __unicode__(self):
return '%s %s %s Reference: %s' % (
self.riversegment, self.scenario,
@@ -49,15 +49,13 @@ SelectedMeasuresList = Backbone.Collection.extend
# View for single measure table element
MeasureView = Backbone.View.extend
tagName: 'tr'
-
+
events:
click: 'addRow'
-
+
addRow: ->
- console.log "Adding #{@model.get('short_name')} to selection!"
- window.selected_measures_list.add @model
- @
-
+ console.log "Adding #{@model.toJSON().short_name} to selection!"
+
initialize: ->
@model.bind('change', @render, @)
@
@@ -72,10 +70,10 @@ MeasureView = Backbone.View.extend
</a>
</td>
<td>
- (type)
+ #{@model.toJSON().measure_type}
</td>
<td>
- (start km)
+ #{@model.toJSON().km_from}
</td>"""
@
@@ -233,8 +231,7 @@ setPlaceholderTop = (json_data) ->
ed_data = [
data: reference
points:
- show: true
- symbol: "diamond"
+ show: false
lines:
show: true
@@ -477,4 +474,4 @@ $(window).resize ->
$(document).ready ->
window.table_or_map = "map"
setFlotSeries( "/blokkendoos/api/measures/calculated/")
- $(".chzn-select").chosen()
+ $(".chzn-select").chosen()

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -54,9 +54,9 @@ def reference_json(request):
def calculated_measures_json(request):
- """Fetch dummy measure data and JSON it for a preliminary frontpage graph.
+ """Fetch measure data and JSON it for a preliminary frontpage graph.
"""
-
+ #XXX Refactor when needed.
flooding_chance = models.FloodingChance.objects.filter(name="T250")
selected_measures = _selected_measures(request)
measures = models.Measure.objects.filter(short_name__in=selected_measures)
@@ -71,9 +71,9 @@ def calculated_measures_json(request):
location = diff['riversegment__location']
d = water_levels.get(location)
if d is None:
- ref = diff['reference_value__reference']
d = {'reference_value': 0,
- 'reference_target': diff['reference_value__target'] - ref,
+ # -0.10 chosen to have some target..
+ 'reference_target': -0.10,
'difference_level': diff['level_difference']}
else:
d['difference_level'] += diff['level_difference']
@@ -115,7 +115,8 @@ def toggle_measure(request):
def list_measures_json(request):
"""Return a list with all known measures."""
- measures = models.Measure.objects.all().values('name', 'short_name')
+ measures = models.Measure.objects.all().values(
+ 'name', 'short_name', 'measure_type', 'km_from')
selected_measures = _selected_measures(request)
for measure in measures:
selected = measure['short_name'] in selected_measures

0 comments on commit 74541c4

Please sign in to comment.