예제 #1
0
 def serialize_attributes(self):
     from general.utils import format
     attributes = []
     if self.input_parameter_wind_speed:
         wind_speed = '%s m/s' %format(self.input_avg_wind_speed, 1)
         attributes.append({'title': 'Minimum Average Wind Speed', 'data': wind_speed})
     if self.input_parameter_distance_to_shore:
         distance_to_shore = '%s - %s miles' %(format(self.input_min_distance_to_shore, 0), format(self.input_max_distance_to_shore, 0))
         attributes.append({'title': 'Distance to Shore', 'data': distance_to_shore})
     if self.input_parameter_depth:
         depth_range = '%s - %s meters' %(format(self.input_min_depth, 0), format(self.input_max_depth, 0))
         attributes.append({'title': 'Depth Range', 'data': depth_range})
     if self.input_parameter_distance_to_awc:
         distance_to_awc = '%s miles' %format(self.input_distance_to_awc, 0)
         attributes.append({'title': 'Max Distance to Proposed AWC Hub', 'data': distance_to_awc})
     if self.input_parameter_distance_to_substation:
         distance_to_substation = '%s miles' %format(self.input_distance_to_substation, 0)
         attributes.append({'title': 'Max Distance to Coastal Substation', 'data': distance_to_substation})
     if self.input_filter_distance_to_shipping:
         miles_to_shipping = format(self.input_distance_to_shipping, 0)
         if miles_to_shipping == 1:
             distance_to_shipping = '%s mile' %miles_to_shipping
         else:
             distance_to_shipping = '%s miles' %miles_to_shipping
         attributes.append({'title': 'Minimum Distance to Shipping Lanes', 'data': distance_to_shipping})
     if self.input_filter_ais_density:
         attributes.append({'title': 'Excluding Areas with High Ship Traffic', 'data': ''})
     if self.input_filter_uxo:
         attributes.append({'title': 'Excluding Areas with Unexploded Ordnances', 'data': ''})
     attributes.append({'title': 'Number of Leaseblocks', 'data': self.lease_blocks.count(',')+1})
     return { 'event': 'click', 'attributes': attributes }
예제 #2
0
 def serialize_attributes(self):
     from general.utils import format
     attributes = []
     attributes.append({
         'area':
         'Area',
         'data':
         '%s sq miles' % format(self.area_in_sq_miles, 1)
     })
     return {'event': 'click', 'attributes': attributes}
예제 #3
0
 def depth_range_output(self):
     if self.min_depth == self.max_depth:
         return "%s feet" %format(meters_to_feet(-self.min_depth),0)
     else:
         return "%s - %s feet" %( format(meters_to_feet(-self.min_depth),0), format(meters_to_feet(-self.max_depth),0) )     
예제 #4
0
 def wind_speed_output(self):
     if self.min_wind_speed == self.max_wind_speed:
         return "%s mph" %format(mps_to_mph(self.min_wind_speed),1)
     else:
         return "%s - %s mph" %( format(mps_to_mph(self.min_wind_speed),1), format(mps_to_mph(self.max_wind_speed),1) )
예제 #5
0
    def kml(self):  
        #from general.utils import format 
        import time

        #the following list appendation strategy was a good 10% faster than string concatenation
        #(biggest improvement however came by adding/populating a geometry_client column in leaseblock table)
        combined_kml_list = []
        if len(self.lease_blocks) == 0:  #empty result
            leaseblock_ids = []
            combined_kml_list.append('<Folder id="%s"><name>%s -- 0 Leaseblocks</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
        else:
            leaseblock_ids = [int(id) for id in self.lease_blocks.split(',')]
            combined_kml_list.append('<Folder id="%s"><name>%s</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
        combined_kml_list.append('<LookAt><longitude>-73.5</longitude><latitude>39</latitude><heading>0</heading><range>600000</range></LookAt>')
        combined_kml_list.append('<styleUrl>#%s-default</styleUrl>' % (self.model_uid()))
        combined_kml_list.append('%s' % self.leaseblock_style())
        print 'Generating KML for %s Lease Blocks' % len(leaseblock_ids)
        start_time = time.time()
        leaseblocks = LeaseBlock.objects.filter(pk__in=leaseblock_ids)
        for leaseblock in leaseblocks:
            try:
                kml =   """
                    <Placemark>
                        <visibility>1</visibility>
                        <styleUrl>#%s-leaseblock</styleUrl>
                        <ExtendedData>
                            <Data name="header"><value>%s</value></Data>
                            <Data name="prot_number"><value>%s</value></Data>
                            <Data name="depth_range_output"><value>%s</value></Data>
                            <Data name="substrate"><value>%s</value></Data>
                            <Data name="sediment"><value>%s</value></Data>
                            <Data name="wea_label"><value>%s</value></Data>
                            <Data name="wea_state_name"><value>%s</value></Data>
                            <Data name="distance_to_shore"><value>%s</value></Data>
                            <Data name="distance_to_awc"><value>%s</value></Data>
                            <Data name="wind_speed_output"><value>%s</value></Data>
                            <Data name="ais_density"><value>%s</value></Data>
                            <Data name="user"><value>%s</value></Data>
                            <Data name="modified"><value>%s</value></Data>
                        </ExtendedData>
                        %s
                    </Placemark>
                    """ % ( self.model_uid(), self.name, leaseblock.prot_numb,                             
                            leaseblock.depth_range_output, 
                            leaseblock.majority_substrate, #LeaseBlock Update: might change back to leaseblock.substrate
                            leaseblock.majority_sediment, #TODO: might change sediment to a more user friendly output
                            leaseblock.wea_label,
                            leaseblock.wea_state_name,
                            format(leaseblock.avg_distance,0), format(leaseblock.awc_min_distance,0),
                            #LeaseBlock Update: added the following two entries (min and max) to replace avg wind speed for now
                            leaseblock.wind_speed_output,
                            leaseblock.ais_density,
                            self.user, self.date_modified.replace(microsecond=0), 
                            #asKml(leaseblock.geometry.transform( settings.GEOMETRY_CLIENT_SRID, clone=True ))
                            asKml(leaseblock.geometry_client)
                          ) 
            except: 
                #this is in place to handle (at least one - "NJ18-05_6420") instance in which null value was used in float field max_distance
                print "The following leaseblock threw an error while generating KML:  %s" %leaseblock.prot_numb
                continue
            combined_kml_list.append(kml )
        combined_kml_list.append("</Folder>")
        combined_kml = ''.join(combined_kml_list)
        elapsed_time = time.time() - start_time
        print 'Finished generating KML (with a list) for %s Lease Blocks in %s seconds' % (len(leaseblock_ids), elapsed_time)
        
        return combined_kml
예제 #6
0
 def serialize_attributes(self):
     from general.utils import format
     attributes = []
     attributes.append({'area': 'Area', 'data': '%s sq miles' %format(self.area_in_sq_miles, 1)})
     return { 'event': 'click', 'attributes': attributes }
예제 #7
0
 def serialize_attributes(self):
     from general.utils import format
     attributes = []
     report_values = {}
     leaseblocks = LeaseBlock.objects.filter(prot_numb__in=self.leaseblock_ids.split(','))
     if (len(leaseblocks) > 0): 
         #get wind speed range
         try:
             min_wind_speed = format(self.get_min_wind_speed(leaseblocks),3)
             max_wind_speed = format(self.get_max_wind_speed(leaseblocks),3)
             wind_speed_range = '%s to %s m/s' %(min_wind_speed, max_wind_speed)
         except:
             min_wind_speed = 'Unknown'
             max_wind_speed = 'Unknown'
             wind_speed_range = 'Unknown'
         attributes.append({'title': 'Average Wind Speed Range', 'data': wind_speed_range})
         try:
             avg_wind_speed = format(self.get_avg_wind_speed(leaseblocks),3)
             avg_wind_speed_output = '%s m/s' %avg_wind_speed
         except:
             avg_wind_speed = 'Unknown'
             avg_wind_speed_output = 'Unknown'
         attributes.append({'title': 'Average Wind Speed', 'data': avg_wind_speed_output})
         report_values['wind-speed'] = {'min': min_wind_speed, 'max': max_wind_speed, 'avg': avg_wind_speed, 'selection_id': self.uid}
         
         #get distance to coastal substation
         min_distance_to_substation = format(self.get_min_distance_to_substation(leaseblocks), 0)
         max_distance_to_substation = format(self.get_max_distance_to_substation(leaseblocks), 0)
         distance_to_substation_range = '%s to %s miles' %(min_distance_to_substation, max_distance_to_substation)
         attributes.append({'title': 'Distance to Coastal Substation', 'data': distance_to_substation_range})
         avg_distance_to_substation = format(self.get_avg_distance_to_substation(leaseblocks), 1)
         avg_distance_to_substation_output = '%s miles' %avg_distance_to_substation
         attributes.append({'title': 'Average Distance to Coastal Substation', 'data': avg_distance_to_substation_output})
         report_values['distance-to-substation'] = {'min': min_distance_to_substation, 'max': max_distance_to_substation, 'avg': avg_distance_to_substation, 'selection_id': self.uid}
                     
         #get distance to awc range
         min_distance_to_awc = format(self.get_min_distance_to_awc(leaseblocks), 0)
         max_distance_to_awc = format(self.get_max_distance_to_awc(leaseblocks), 0)
         distance_to_awc_range = '%s to %s miles' %(min_distance_to_awc, max_distance_to_awc)
         attributes.append({'title': 'Distance to Proposed AWC Hub', 'data': distance_to_awc_range})
         avg_distance_to_awc = format(self.get_avg_distance_to_awc(leaseblocks), 1)
         avg_distance_to_awc_output = '%s miles' %avg_distance_to_awc
         attributes.append({'title': 'Average Distance to Proposed AWC Hub', 'data': avg_distance_to_awc_output})
         report_values['distance-to-awc'] = {'min': min_distance_to_awc, 'max': max_distance_to_awc, 'avg': avg_distance_to_awc, 'selection_id': self.uid}
         
         #get distance to shipping lanes
         min_distance_to_shipping = format(self.get_min_distance_to_shipping(leaseblocks), 0)
         max_distance_to_shipping = format(self.get_max_distance_to_shipping(leaseblocks), 0)
         miles_to_shipping = '%s to %s miles' %(min_distance_to_shipping, max_distance_to_shipping)
         attributes.append({'title': 'Distance to Shipping Lanes', 'data': miles_to_shipping})
         avg_distance_to_shipping = format(self.get_avg_distance_to_shipping(leaseblocks),1)
         avg_distance_to_shipping_output = '%s miles' %avg_distance_to_shipping
         attributes.append({'title': 'Average Distance to Shipping Lanes', 'data': avg_distance_to_shipping_output})
         report_values['distance-to-shipping'] = {'min': min_distance_to_shipping, 'max': max_distance_to_shipping, 'avg': avg_distance_to_shipping, 'selection_id': self.uid}
         
         #get distance to shore range
         min_distance = format(self.get_min_distance(leaseblocks), 0)
         max_distance = format(self.get_max_distance(leaseblocks), 0)
         distance_to_shore = '%s to %s miles' %(min_distance, max_distance)
         attributes.append({'title': 'Distance to Shore', 'data': distance_to_shore})
         avg_distance = format(self.get_avg_distance(leaseblocks),1)
         avg_distance_output = '%s miles' %avg_distance
         attributes.append({'title': 'Average Distance to Shore', 'data': avg_distance_output})
         report_values['distance-to-shore'] = {'min': min_distance, 'max': max_distance, 'avg': avg_distance, 'selection_id': self.uid}
         
         #get depth range
         min_depth = format(self.get_min_depth(leaseblocks), 0)
         max_depth = format(self.get_max_depth(leaseblocks), 0)
         depth_range = '%s to %s meters' %(min_depth, max_depth)
         if min_depth == 0 or max_depth == 0:
             depth_range = 'Unknown'
         attributes.append({'title': 'Depth', 'data': depth_range})
         avg_depth = format(self.get_avg_depth(leaseblocks), 0)
         avg_depth_output = '%s meters' %avg_depth
         if avg_depth == 0:
             avg_depth_output = 'Unknown'
         attributes.append({'title': 'Average Depth', 'data': avg_depth_output})
         report_values['depth'] = {'min': min_depth, 'max': max_depth, 'avg': avg_depth, 'selection_id': self.uid}
         '''
         if self.input_filter_ais_density:
             attributes.append({'title': 'Excluding Areas with High Ship Traffic', 'data': ''})
         '''    
             
         attributes.append({'title': 'Number of Leaseblocks', 'data': self.leaseblock_ids.count(',')+1})
     else:
         attributes.append({'title': 'Number of Leaseblocks', 'data': 0})
     return { 'event': 'click', 'attributes': attributes, 'report_values': report_values }
예제 #8
0
 def depth_range_output(self):
     if self.min_depth == self.max_depth:
         return "%s meters" %format(-self.min_depth,0)
     else:
         return "%s - %s meters" %( format(-self.min_depth,0), format(-self.max_depth,0) )     
예제 #9
0
 def wind_speed_output(self):
     if self.min_wind_speed == self.max_wind_speed:
         return "%s mph" %format(mps_to_mph(self.min_wind_speed),1)
     else:
         return "%s - %s mph" %( format(mps_to_mph(self.min_wind_speed),1), format(mps_to_mph(self.max_wind_speed),1) )
예제 #10
0
    def kml(self):  
        #from general.utils import format 
        import time

        #the following list appendation strategy was a good 10% faster than string concatenation
        #(biggest improvement however came by adding/populating a geometry_client column in leaseblock table)
        combined_kml_list = []
        if len(self.lease_blocks) == 0:  #empty result
            leaseblock_ids = []
            combined_kml_list.append('<Folder id="%s"><name>%s -- 0 Leaseblocks</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
        else:
            leaseblock_ids = [int(id) for id in self.lease_blocks.split(',')]
            combined_kml_list.append('<Folder id="%s"><name>%s</name><visibility>0</visibility><open>0</open>' %(self.uid, self.name))
        combined_kml_list.append('<LookAt><longitude>-73.5</longitude><latitude>39</latitude><heading>0</heading><range>600000</range></LookAt>')
        combined_kml_list.append('<styleUrl>#%s-default</styleUrl>' % (self.model_uid()))
        combined_kml_list.append('%s' % self.leaseblock_style())
        print 'Generating KML for %s Lease Blocks' % len(leaseblock_ids)
        start_time = time.time()
        leaseblocks = LeaseBlock.objects.filter(pk__in=leaseblock_ids)
        for leaseblock in leaseblocks:
            try:
                kml =   """
                    <Placemark>
                        <visibility>1</visibility>
                        <styleUrl>#%s-leaseblock</styleUrl>
                        <ExtendedData>
                            <Data name="header"><value>%s</value></Data>
                            <Data name="prot_number"><value>%s</value></Data>
                            <Data name="depth_range_output"><value>%s</value></Data>
                            <Data name="substrate"><value>%s</value></Data>
                            <Data name="sediment"><value>%s</value></Data>
                            <Data name="wea_label"><value>%s</value></Data>
                            <Data name="wea_state_name"><value>%s</value></Data>
                            <Data name="distance_to_shore"><value>%s</value></Data>
                            <Data name="distance_to_awc"><value>%s</value></Data>
                            <Data name="wind_speed_output"><value>%s</value></Data>
                            <Data name="ais_density"><value>%s</value></Data>
                            <Data name="user"><value>%s</value></Data>
                            <Data name="modified"><value>%s</value></Data>
                        </ExtendedData>
                        %s
                    </Placemark>
                    """ % ( self.model_uid(), self.name, leaseblock.prot_numb,                             
                            leaseblock.depth_range_output, 
                            leaseblock.majority_seabed, #LeaseBlock Update: might change back to leaseblock.substrate
                            leaseblock.majority_sediment, #TODO: might change sediment to a more user friendly output
                            leaseblock.wea_label,
                            leaseblock.wea_state_name,
                            format(leaseblock.avg_distance,0), format(leaseblock.awc_min_distance,0),
                            #LeaseBlock Update: added the following two entries (min and max) to replace avg wind speed for now
                            leaseblock.wind_speed_output,
                            leaseblock.ais_density,
                            self.user, self.date_modified.replace(microsecond=0), 
                            #asKml(leaseblock.geometry.transform( settings.GEOMETRY_CLIENT_SRID, clone=True ))
                            asKml(leaseblock.geometry_client)
                          ) 
            except: 
                #this is in place to handle (at least one - "NJ18-05_6420") instance in which null value was used in float field max_distance
                print "The following leaseblock threw an error while generating KML:  %s" %leaseblock.prot_numb
                continue
            combined_kml_list.append(kml )
        combined_kml_list.append("</Folder>")
        combined_kml = ''.join(combined_kml_list)
        elapsed_time = time.time() - start_time
        print 'Finished generating KML (with a list) for %s Lease Blocks in %s seconds' % (len(leaseblock_ids), elapsed_time)
        
        return combined_kml