Esempio n. 1
0
def exportHTML(path, cctv, ecctv, db):
    # Double apparition elimination
    cctv = [Location(n, e, desc=d) for (n, e, d) in \
                set([(loc.north, loc.east, loc.desc) for loc in cctv]) ]
    rawCCTV = []
    toupdate = []
    for loc in cctv:
        if loc.desc == "":
            lookForAddress(loc)
            toupdate+=[loc]
        minloc = path[0]
        mindist = 100000
        for p in path:
            dst = commons.dist(loc, p)
            if dst<mindist:
                minloc = p
                mindist = dst
        loc.time = minloc.time
        rawCCTV.append((loc, mindist))
    stores = []

    db.setAddresses(toupdate)

    ecctv = [Location(n, e, desc=d) for (n, e, d) in \
                 set([(float(loc.north), float(loc.east), str(loc.name)) for loc in ecctv]) ]
    for loc in ecctv:
        minloc = path[0]
        mindist = 100000
        for p in path:
            dst = commons.dist(loc, p)
            if dst<mindist:
                minloc = p
                mindist = dst
        loc.time = minloc.time
        stores.append((loc, mindist))

    # Rendering
    (head1, body1) = makeMapView(path, rawCCTV, stores)
    (head2, body2) = makeReport(path, rawCCTV, stores)

    output = "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n <title>Smile, you're on TV</title>\n "\
        + head1 + "\n\
 <style type=\"text/css\">\n html { height: 100% }\n body { height: 100%; margin: 0; padding: 0 }\n #map-canvas { height: 100%; width: 48%; float:left }\n #report { width:48%; float:right; height: 100%; overflow: auto}\n li{margin-top:10px;}</style>\n\
 </head>\n\n<body>"+body1+"<div id=\"report\">\n"+body2+"\n</div>\n\
 </body>\n</html>"
    return output
Esempio n. 2
0
 def findCCTVs(self, location, tolerance=0.1):
     tolerance /= 10
     c = self.conn.cursor()
     table = "locations"
     locs = c.execute("SELECT * FROM "+table+" WHERE north >= ? AND north <= ? AND east >= ? AND east <= ?",\
                          (location.north-tolerance, location.north+tolerance, location.east-tolerance, location.east+tolerance))
     locations = [Location(row[0], row[1], desc=row[2]) for row in locs]
     locations = [loc for loc in locations if commons.dist(loc, location) <= tolerance*10]
     c.close()
     return locations
Esempio n. 3
0
 def findCCTVsNearPath(self, path):
     # Selects representative points (avoid points too close to each other)
     for i in path:
         for j in path:
             if (i!= j and commons.dist(i,j) < 0.002*self.radius):
                 path.remove(j)
                 extinfo=[]
     for i in path:
         aux = self.findCCTVsNearLoc(i.north, i.east, self.radius)
         extinfo += aux
     return extinfo
Esempio n. 4
0
 def findCCTVsNearLoc(self, locationN, locationE, radius):
     print("Google NEARBY Query")
     loc=location.Location(float(locationN),float(locationE))
     NearbyLoc = []
     conn = HTTPSConnection("maps.googleapis.com")
     parametres = "location="+str(locationN)+","+str(locationE)+"&radius="+str(radius)+"&sensor=false&key="+commons.googleAPIKey
     conn.request("GET", "/maps/api/place/nearbysearch/xml?"+parametres)
     response = conn.getresponse()
     data = response.read()
     root = ET.fromstring(data)
     for result in root.findall('result'):
         loctype = []
         name = result.find('name').text#.encode('utf-8')
         for lc in result.findall('type'):
             loctype.append(lc.text)
         north = result.find('./geometry/location/lat').text
         east = result.find('./geometry/location/lng').text
         aux = Nearby(north, east, loctype, name)
         loc2 = location.Location(float(north),float(east))
         if(commons.dist(loc,loc2) <= 0.001*radius and ('atm' in loctype or 'airport' in loctype or 'bank' in loctype or 'city_hall' in loctype or 'embassy' in loctype or 'gas_station' in loctype or 'hospital' in loctype or 'liquor_store' in loctype or 'local_government_office' in loctype or 'police' in loctype or 'post_office' in loctype or 'subway_station' in loctype or 'train_station' in loctype)):
             NearbyLoc.append(aux)
     return NearbyLoc