Ejemplo n.º 1
0
 def coordinates(self, starttime=None, endtime=None, count=None, *args, **kwargs):
     """
     Web service to return a list of coordinates for graphing on map and timeline
     """
     conn = common.get_sql_conn(self.sql_file)
     c = self._get_images_cursor(conn, starttime, endtime, count)
     out = {'dateTimeFormat': 'iso8601', 'events': []}
     lasttimestamp = None
     delta = timedelta(0,10) # 10 seconds
     savets = True
     for row in c:
         timestamp = row[1]
         if (savets):
             out['timestamp'] = timestamp.strftime(TIMEFT_WEB)
             savets = False
         if ((not(lasttimestamp) or (timestamp - lasttimestamp) >= delta) or row[4]==1):
             out['events'].append({
                 "start": timestamp.strftime(TIMEFT_WEB),
                 "description": "tagged" if row[4] == 1 else "normal",
                 "point": {
                     "lat": row[2], "lon": row[3]}})
             if row[4] == 0:
                 lasttimestamp = timestamp
     c.close()
     conn.close()
     cherrypy.response.headers['Content-Type'] = "text/html"
     return json.dumps(out, indent=4)
Ejemplo n.º 2
0
 def images(self,
            starttime=None,
            endtime=None,
            count=None,
            duration=1,
            jump=0):
     """
     Web service to return images based on a time-range
     """
     conn = common.get_sql_conn(self.sql_file)
     c = self._get_images_cursor(conn, starttime, endtime, count, duration,
                                 jump)
     out = []
     for row in c:
         out.append({
             "timestamp": row[1].strftime(TIMEFT_WEB),
             "point": {
                 "lat": row[2],
                 "lon": row[3]
             },
             "images": row[5:]
         })
     c.close()
     conn.close()
     cherrypy.response.headers['Content-Type'] = "text/html"
     return json.dumps(out, indent=4)
Ejemplo n.º 3
0
def create_db(sql_file, numcams):
    conn = common.get_sql_conn(sql_file)
    c = conn.cursor()
    # make a property for each camera
    camstr = ", ".join(list("cam" + str(i) + " text" for i in range(numcams)))
    c.executescript(
        "drop table if exists images; " +\
        "create table images ( " +\
          "id INTEGER PRIMARY KEY, " +\
          "datetime TIMESTAMP, " +\
          "lat REAL, lon REAL, is_tagged INTEGER DEFAULT 0, " +\
          camstr + ");")
    conn.commit()
    c.close()
    conn.close()
Ejemplo n.º 4
0
def create_db(sql_file, numcams):
    conn = common.get_sql_conn(sql_file)
    c = conn.cursor()
    # make a property for each camera
    camstr = ", ".join(list("cam" + str(i) + " text" for i in range(numcams)))
    c.executescript(
        "drop table if exists images; " +\
        "create table images ( " +\
          "id INTEGER PRIMARY KEY, " +\
          "datetime TIMESTAMP, " +\
          "lat REAL, lon REAL, is_tagged INTEGER DEFAULT 0, " +\
          camstr + ");")
    conn.commit()
    c.close()
    conn.close()
Ejemplo n.º 5
0
 def images(self, starttime=None, endtime=None, count=None, duration=1, jump=0):
     """
     Web service to return images based on a time-range
     """
     conn = common.get_sql_conn(self.sql_file)
     c = self._get_images_cursor(conn, starttime, endtime, count, duration, jump)
     out = []
     for row in c:
         out.append({
             "timestamp": row[1].strftime(TIMEFT_WEB),
             "point": {
                 "lat": row[2], "lon": row[3]},
                 "images": row[5:]})
     c.close()
     conn.close()
     cherrypy.response.headers['Content-Type'] = "text/html"
     return json.dumps(out, indent=4)
Ejemplo n.º 6
0
def load_db(sql_file, ftable, eventhash):
    conn = common.get_sql_conn(sql_file)
    c = conn.cursor()
    n = 0
    for frame in ftable:
        sql = "insert into images values (?,?,?,?,?," + \
          ",".join('?' for i in range(len(frame))) + ")"
        values = [n, frame[0].timestamp()]
        event = eventhash[frame[0].timestamp()] if frame[0].timestamp() in eventhash else None
        if event:
            values += [event.lat(), event.lon(), event.is_tagged()]
        else:
            values += [None,None,None]
        values += list("/".join(f.filename().split("/")[-3:]) for f in frame)
        c.execute(sql,values)
        n += 1
    conn.commit()
    c.close()
    conn.close()
Ejemplo n.º 7
0
def load_db(sql_file, ftable, eventhash):
    conn = common.get_sql_conn(sql_file)
    c = conn.cursor()
    n = 0
    for frame in ftable:
        sql = "insert into images values (?,?,?,?,?," + \
          ",".join('?' for i in range(len(frame))) + ")"
        values = [n, frame[0].timestamp()]
        event = eventhash[frame[0].timestamp()] if frame[0].timestamp(
        ) in eventhash else None
        if event:
            values += [event.lat(), event.lon(), event.is_tagged()]
        else:
            values += [None, None, None]
        values += list("/".join(f.filename().split("/")[-3:]) for f in frame)
        c.execute(sql, values)
        n += 1
    conn.commit()
    c.close()
    conn.close()
Ejemplo n.º 8
0
 def coordinates(self,
                 starttime=None,
                 endtime=None,
                 count=None,
                 *args,
                 **kwargs):
     """
     Web service to return a list of coordinates for graphing on map and timeline
     """
     conn = common.get_sql_conn(self.sql_file)
     c = self._get_images_cursor(conn, starttime, endtime, count)
     out = {'dateTimeFormat': 'iso8601', 'events': []}
     lasttimestamp = None
     delta = timedelta(0, 10)  # 10 seconds
     savets = True
     for row in c:
         timestamp = row[1]
         if (savets):
             out['timestamp'] = timestamp.strftime(TIMEFT_WEB)
             savets = False
         if ((not (lasttimestamp) or (timestamp - lasttimestamp) >= delta)
                 or row[4] == 1):
             out['events'].append({
                 "start":
                 timestamp.strftime(TIMEFT_WEB),
                 "description":
                 "tagged" if row[4] == 1 else "normal",
                 "point": {
                     "lat": row[2],
                     "lon": row[3]
                 }
             })
             if row[4] == 0:
                 lasttimestamp = timestamp
     c.close()
     conn.close()
     cherrypy.response.headers['Content-Type'] = "text/html"
     return json.dumps(out, indent=4)