original_docstring: 
          Write planning units containing a `pucount`
          Effectively a join of the planning units and the marxan output
          Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
          
docstring: Write planning units containing a `pucount`
  Effectively a join of the planning units and the marxan output
  Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
docstring_tokens: Write planning units containing a ` pucount ` Effectively a join of the planning units and the marxan output Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
code: def thunderstorm_sql(self):
          """
          Write planning units containing a `pucount`
          Effectively a join of the planning units and the marxan output
          Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
          """
          from seak.models import PlanningUnitShapes
  
          stamp = int(self.id)
          sql = "(SELECT geometry, hits, bests FROM seak_planningunitshapes WHERE stamp = %s) as foo" % stamp 
  
          if PlanningUnitShapes.objects.filter(stamp=stamp).count() > 0:
              return sql
  
          pucount = json.loads(self.output_pu_count)
          bests = [int(x) for x in json.loads(self.output_best)['best']]
          pushapes = []
  
          for pu in PlanningUnit.objects.all():
              try:
                  hits = pucount[str(pu.fid)] 
              except KeyError:
                  hits = 0
  
              if pu.fid in bests:
                  best = 1
              else:
                  best = 0
  
              pushapes.append(PlanningUnitShapes(stamp=stamp, fid=pu.fid, pu=pu, name=pu.name,
                  hits=hits, bests=best, geometry=pu.geometry))
  
          PlanningUnitShapes.objects.bulk_create(pushapes)
          return sql
code_tokens: def thunderstorm_sql ( self ) : from seak . models import PlanningUnitShapes stamp = int ( self . id ) sql = "(SELECT geometry, hits, bests FROM seak_planningunitshapes WHERE stamp = %s) as foo" % stamp if PlanningUnitShapes . objects . filter ( stamp = stamp ) . count ( ) > 0 : return sql pucount = json . loads ( self . output_pu_count ) bests = [ int ( x ) for x in json . loads ( self . output_best ) [ 'best' ] ] pushapes = [ ] for pu in PlanningUnit . objects . all ( ) : try : hits = pucount [ str ( pu . fid ) ] except KeyError : hits = 0 if pu . fid in bests : best = 1 else : best = 0 pushapes . append ( PlanningUnitShapes ( stamp = stamp , fid = pu . fid , pu = pu , name = pu . name , hits = hits , bests = best , geometry = pu . geometry ) ) PlanningUnitShapes . objects . bulk_create ( pushapes ) return sql
short_docstring: Write planning units containing a `pucount`
  Effectively a join of the planning units and the marxan output
  Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
short_docstring_tokens: Write planning units containing a ` pucount ` Effectively a join of the planning units and the marxan output Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
comment: """
          Write planning units containing a `pucount`
          Effectively a join of the planning units and the marxan output
          Uses the PlanningUnitShapes mechanism with the scenario id as the stamp
          """