Ejemplo n.º 1
0
def import_cell_towers(verbose=True):
    towers = sio.loadmat("data/tower_locations.mat")
    towers = towers['towers']
    ac = transaction.get_autocommit()
    transaction.set_autocommit(False)
    for location in towers:
        pt = Point(tuple(location), srid=4326)
        wp = Tower(location=pt, location_dist=pt.transform(900913, clone=True), category="From tower_locations.mat")
        wp.save()
    transaction.commit()
    transaction.set_autocommit(ac)
Ejemplo n.º 2
0
def import_towers(case_id=None, filename=None):
    if case_id:
        if filename:
            case_number = TollsCase.get_case_number(case_id)
            with open(os.path.join(app.config['UPLOAD_FOLDER'], filename),
                      'rb') as f:
                csv_f = csv.reader(f)
                headers = next(csv_f)

                header_options = [
                    '<option value="{i:d}">{header}</option>'.format(
                        i=headers.index(h), header=h) for h in headers
                    if h.strip() != ''
                ]  # ignore columns with blank headers

                if flask.request.method == 'POST':
                    cell_site_id = int(flask.request.form['cellsite'])
                    latitude = int(flask.request.form['latitude'])
                    longitude = int(flask.request.form['longitude'])
                    sector = int(flask.request.form['sector'])
                    azimuth = int(flask.request.form['azimuth'])

                    if cell_site_id < 0 or latitude < 0 or longitude < 0 or sector < 0 or azimuth < 0:
                        return flask.render_template(
                            'towercolumns.html',
                            cid=case_id,
                            fn=filename,
                            casenum=case_number,
                            header_list=header_options,
                            message=
                            'You must select the appropriate column for each '
                            'recognized field.')

                    for row in csv_f:
                        t = Tower(case_id, row[cell_site_id], row[latitude],
                                  row[longitude], row[sector], row[azimuth])
                        t.save()

                    return flask.redirect(
                        flask.url_for('upload_cdrs',
                                      case_id=case_id,
                                      filename=filename))
                else:
                    return flask.render_template('towercolumns.html',
                                                 cid=case_id,
                                                 fn=filename,
                                                 casenum=case_number,
                                                 header_list=header_options)
        else:
            return flask.redirect(
                flask.url_for('upload_towers', case_id=case_id))
    else:
        return flask.redirect(flask.url_for('case_form'))
Ejemplo n.º 3
0
 def satisfiesMinimumDistance(self, latlng):
     """If the tower satisfies the minimum distance from other towers, then it is true"""
     pt = db.GeoPt(latlng['latitude'], latlng['longitude'])
     
     
     # Find if their is a tower distance away from the pt. If there is even one object, this
     # function will return  a value, and make satisfiesMinimumDistance false.
     for level in Tower.getTowerLevelRange():
         filter = Tower.all().filter('Level =', level)
         box = Constants.getBoundingBoxPerLevel(level, pt)
         value = Tower.bounding_box_fetch(filter, box, max_results = 1)
         logging.error(len(value))
         if len(value) != 0:
             return False
     return True
Ejemplo n.º 4
0
 def get(self, swLat, swLon, neLat, neLon):
     """Handles a post request to this page"""
     aEBounds = Bounds.createBoundsFromSimpleData(float(swLat), float(swLon), float(neLat), float(neLon))
     logging.error(aEBounds)
     # Check if one of the objects is on the map
     results = Road.getObjectInBounds(aEBounds)
     if len(results) == 0:
         self.loadRandomDataInBounds(aEBounds)
     
     # Find all of the drawable object within the bounds
     listOfObjects = []
     listOfObjects.extend(Road.getObjectInBounds(aEBounds))
     listOfObjects.extend(Portal.getObjectInBounds(aEBounds))
     listOfObjects.extend(Tower.getObjectInBounds(aEBounds))
     
     # Convert the list of objects into a response
     writeString = '<?xml version="1.0" encoding="UTF-8"?>'
     writeString += "<response>" 
     if listOfObjects is not None:
         for model in listOfObjects:
             if model:
                 writeString += model.toXML()
     writeString += "</response>" 
     
     logging.error(writeString )
     
     # Write the response back to the user
     self.response.out.write(writeString)