def remove(self): self.__removed = True @classmethod def unmap(c,s,*args,**kargs): if hasattr(s, "__removed"): return None else: r = super(Layer,c).unmap(s,*args,**kargs) return r jsonwrap.props(Layer, "title", "type", "visible", "layer_id", "subtitle", "opacity", "styles", source={"map":LayerSource}) # The map! class Map(geoiq.GeoIQObj): writeable = True def add_layer(self, source): if self.layers is None: self.layers = [] if not isinstance(source, LayerSource): source = LayerSource(source, self.geoiq) res = Layer({"source":source})
self.__removed = True @classmethod def unmap(c, s, *args, **kargs): if hasattr(s, "__removed"): return None else: r = super(Layer, c).unmap(s, *args, **kargs) return r jsonwrap.props(Layer, "title", "type", "visible", "layer_id", "subtitle", "opacity", "styles", source={"map": LayerSource}) # The map! class Map(geoiq.GeoIQObj): writeable = True def add_layer(self, source): if self.layers is None: self.layers = [] if not isinstance(source, LayerSource): source = LayerSource(source, self.geoiq)
def is_new(self): return self.__new def refresh(self, lose_mods=False): if self.dirty() and not lose_mods: raise RuntimeError("Refreshing a dirty object") self.props = self.svc.get_by_id(self.geoiq_id).props self.isdirty = False return self def save(self): r = self.svc.update(self) if r: self.__new = False self.isdirty = False return r def delete(self): r = self.svc.delete(self) self.props = None self.svc = None return r def compat_endpoint(self, other): return self.svc.endpoint.shares_endpoint(other.svc.endpoint.root) jsonwrap.props(GeoIQObj, geoiq_id={'ro': True, 'mapto': 'id'})
while (self.state != "complete"): dur = time.time() - start #dummy = self.geoiq.datasets.get_by_id(self.geoiq_id) print("Waiting on state: %s (%f,%r)" % (self.state, dur, self.geoiq_id)) if (dur > max_wait): return False wait = (wait * 1.25) # exponential backoff time.sleep(wait) self.refresh() print("FIN", self.state) return True def analyze(self, alg, inps): return self.svc.analyze(self, alg, inps) jsonwrap.props(Dataset, "title", "description", "tags", "published", "data_type", "feature_count", "author", "source", state={"ro": True}, link={"ro": True}, contributor={"ro": True}, published={"ro": True})
def load(self): loader = None if self.is_dataset(): loader = self.geoiq.datasets.get_by_id elif self.is_map(): loader = self.geoiq.maps.get_by_id elif self.is_analysis(): loader = self.geoiq.analysis.get_by_id if (loader is None): raise NotImplementedError("No implementation for: " + tp + "yet.") return loader(self.key) jsonwrap.props(SearchPointer, "detail_link", "description", "type", "tags", "author", "title", "id") def search_pointers(ptrs, *args, **kwargs): return [SearchPointer(p, *args, **kwargs) for p in ptrs] class SearchPage(jsonwrap.JsonWrappedObj): pass jsonwrap.props(SearchPage, "totalResults", "itemsPerPage", "next", entries={
loader = self.geoiq.datasets.get_by_id elif self.is_map(): loader = self.geoiq.maps.get_by_id elif self.is_analysis(): loader = self.geoiq.analysis.get_by_id if (loader is None): raise NotImplementedError("No implementation for: " + tp + "yet.") return loader(self.key) jsonwrap.props(SearchPointer, "detail_link", "description", "type", "tags", "author", "title", "id") def search_pointers(ptrs, *args, **kwargs): return [SearchPointer(p,*args,**kwargs) for p in ptrs] class SearchPage(jsonwrap.JsonWrappedObj): pass jsonwrap.props(SearchPage, "totalResults", "itemsPerPage", "next",
assert(self.__new or self.geoiq_id is not None) def is_new(self): return self.__new def refresh(self, lose_mods=False): if self.dirty() and not lose_mods: raise RuntimeError("Refreshing a dirty object") self.props = self.svc.get_by_id(self.geoiq_id).props self.isdirty = False return self def save(self): r = self.svc.update(self) if r: self.__new = False self.isdirty = False return r def delete(self): r = self.svc.delete(self) self.props = None self.svc = None return r def compat_endpoint(self,other): return self.svc.endpoint.shares_endpoint(other.svc.endpoint.root) jsonwrap.props(GeoIQObj,geoiq_id={'ro':True, 'mapto':'id'})
parsers = [ pp(param) for param in a.parameters ] def res_method(**kargs): args = dict(p(kargs) for p in parsers) return self.analyze(a.algorithm, args) res_method.__doc__ = a.instruction setattr(self, "analyze_" + a.algorithm, res_method) self.algorithms.append((a.algorithm, res_method, a)) def load_all_analyses(self): a = self.geoiq.search("",model=Analysis) for searchres in a: assert(searchres.is_analysis()), ("Searching for analysis returned results of type %s instead." % searchres.tp) # (Permissions?) we sometimes get datasets and maps back. res = searchres.load() if res.built_in and (res.formula is None): self.add_analysis_algorithm(res) geoiq.GeoIQ.regsvc("analysis", AnalysisSvc) class Analysis(geoiq.GeoIQObj): @classmethod def is_ro(cls): return True jsonwrap.props(Analysis, "built_in", "algorithm","formula", "instruction", "parameters")
start = time.time() while (self.state != "complete"): dur = time.time() - start #dummy = self.geoiq.datasets.get_by_id(self.geoiq_id) print("Waiting on state: %s (%f,%r)" % (self.state,dur,self.geoiq_id)) if (dur > max_wait): return False wait = (wait * 1.25) # exponential backoff time.sleep(wait) self.refresh() print("FIN", self.state) return True def analyze(self, alg, inps): return self.svc.analyze(self, alg, inps) jsonwrap.props(Dataset, "title", "description", "tags", "published", "data_type", "feature_count", "author", "source", state={"ro":True}, link={"ro":True}, contributor={"ro":True}, published={"ro":True})