1 from django.contrib.gis.db import models
2 from django.conf import settings
3 from madrona.features.models import Feature, FeatureForm
4 from madrona.common.utils import get_class
5 from madrona.features import register
6 from django.contrib.gis.geos import GEOSGeometry
7 from madrona.common.utils import asKml
8 import os
11 """
12 Abstract Feature model representing the inputs and outputs
13 of an analysis or modeling run
14 """
15
16 @property
24
25 @property
27 """
28 Translate the model outputs to KML Placemark or Folder
29 """
30 return """
31 <Placemark id="%s">
32 <visibility>0</visibility>
33 <name>%s</name>
34 </Placemark>
35 """ % (self.uid, self.name)
36
37 @property
39 """
40 Translate the model outputs to KML Placemark or Folder
41 """
42 return """
43 <Placemark id="%s">
44 <visibility>0</visibility>
45 <name>%s (Working...)</name>
46 </Placemark>
47 """ % (self.uid, self.name)
48
49 @property
52
53 @classmethod
56
57 @classmethod
60
61 @property
70
71 @classmethod
73 return [f for f in klass._meta.fields if f.attname.startswith('output_')]
74
75 @property
77 """
78 Returns a dict of all output parameters
79 If processing is incomplete, values will be None
80 """
81 odict = {}
82 for f in self.output_fields():
83 odict[f.verbose_name] = self._get_FIELD_display(f)
84 return odict
85
86 @property
88 if self.done:
89 return "<p>All done</p>"
90 else:
91 return "<p>Not done yet; output fields are still blank"
92
93 @property
95 """
96 How many sub-tasks completed out of a total
97 e.g. (3,6) means 3 out of 6 pieces are complete so progress bar can show 50%
98 """
99 return (1,1)
100
101 @property
103 """
104 If it's asynchronously processed, this is the definitive
105 property to determine if processing is completed.
106 """
107
108 for of in self.outputs.keys():
109 if self.outputs[of] is None:
110 return False
111 return True
112
114 """
115 Method to execute the model.
116 Passes all input parameters to the analysis backend,
117 takes the results and stores in the model output fields.
118 """
119 pass
120
122 """
123 Reset button; Sets all output fields to None
124 """
125 for f in self.output_fields():
126 self.__dict__[f.attname] = None
127
128 '''
129 Note on keyword args rerun and form: these are extracted from kwargs so that they will not cause an unexpected
130 keyword argument error during call to super.save
131 Note on rerun: When set to false no output fields will be cleared and the run method will not be called
132 Note on form: This is passed from feature.views update and create methods. In the case of m2m fields this needs to
133 be called after super.save. Since it also needs to be called before self.run, it will be passed from here (in kwargs)
134 to the superclass (Feature) save method.
135 (rather than its previous location in feature views update and create (after save has completed))
136 '''
137 - def save(self, rerun=True, *args, **kwargs):
145
148