def execute(self): """ Executing all tiles sequentially """ for i, tile in enumerate(self.tiles, 1): LOG.progress('Running tile %d of %d, %s sites', i, self.num_tiles, len(tile)) self.run_tile(i, tile)
def export(output_id, target, export_type='xml,geojson,csv'): """ Export the given calculation `output_id` from the database to the specified `target` directory in the specified `export_type`. """ output = models.Output.objects.get(id=output_id) if isinstance(target, basestring): # create target directory makedirs(target) for exptype in export_type.split(','): key = (output.output_type, exptype) if key in export_output: return export_output(key, output, target) LOG.warn('No "%(fmt)s" exporter is available for "%(output_type)s"' ' outputs' % dict(fmt=export_type, output_type=output.output_type))
def export(output_id, target, export_type='xml,geojson,csv'): """ Export the given calculation `output_id` from the database to the specified `target` directory in the specified `export_type`. """ output = models.Output.objects.get(id=output_id) if isinstance(target, basestring): # create target directory makedirs(target) for exptype in export_type.split(','): key = (output.output_type, exptype) if key in export_output: return export_output(key, output, target) LOG.warn( 'No "%(fmt)s" exporter is available for "%(output_type)s"' ' outputs' % dict(fmt=export_type, output_type=output.output_type))
def insert_datum(self, asset_data): """ Insert a single asset entry. :param asset_data: an instance of :class:`openquake.commonlib.risk_parsers.AssetData` """ for cost_type in self.cost_types: if not any(cost_type == cost.cost_type for cost in asset_data.costs): if cost_type in self.ignore_missing_costs: LOG.warn('asset %s, %s cost is missing', asset_data.asset_ref, cost_type) else: raise ValueError("Invalid Exposure. " "Missing cost %s for asset %s" % ( cost_type, asset_data.asset_ref)) asset = models.ExposureData.objects.create( exposure_model=self.model, asset_ref=asset_data.asset_ref, taxonomy=asset_data.taxonomy, area=asset_data.area, number_of_units=asset_data.number, site="POINT(%s %s)" % (asset_data.site.longitude, asset_data.site.latitude)) model = asset_data.exposure_metadata deductible_is_absolute = model.conversions.deductible_is_absolute insurance_limit_is_absolute = ( model.conversions.insurance_limit_is_absolute) for cost in asset_data.costs: cost_type = self.cost_types.get(cost.cost_type, None) if cost_type is None: raise ValueError("Invalid Exposure. Missing conversion " "for cost type %s" % cost.cost_type) if cost.retrofitted is not None: retrofitted = models.ExposureData.per_asset_value( cost.retrofitted, cost_type.retrofitted_conversion, asset_data.area, model.conversions.area_type, asset_data.number, model.asset_category) else: retrofitted = None converted_cost = models.ExposureData.per_asset_value( cost.value, cost_type.conversion, asset_data.area, model.conversions.area_type, asset_data.number, model.asset_category) models.Cost.objects.create( exposure_data=asset, cost_type=cost_type, converted_cost=converted_cost, converted_retrofitted_cost=retrofitted, deductible_absolute=models.make_absolute( cost.deductible, converted_cost, deductible_is_absolute), insurance_limit_absolute=models.make_absolute( cost.limit, converted_cost, insurance_limit_is_absolute)) for odata in asset_data.occupancy: models.Occupancy.objects.create(exposure_data=asset, occupants=odata.occupants, period=odata.period)