Example #1
0
    def get(self):
        stream_obj = Stream()
        print "mViewNearbyImages:: starts~"

        loc_str = self.request.get("loc_str")
        loc = loc_str.split('_')
        lat = float(loc[0])
        lon = float(loc[1])

        print "mViewNearbyImages:: get location", lat, lon
        images = Image.query().fetch()

        sorted_imgs = sorted(images, key=lambda image: image.date, reverse=True)

        max_idx = len(sorted_imgs)

        print "mViewNearbyImages:: len(sorted_imgs)=", max_idx

        if max_idx >= NUM_IMG_PER_PAGE:
            max_idx = NUM_IMG_PER_PAGE

        img_url_lst = list()
        stream_id_lst = list()
        distance_lst = list()

        R = 6373.0
        r_m_lat = radians(lat)
        r_m_lon = radians(lon)

        for idx in xrange(0, max_idx):
            image = sorted_imgs[idx]
            img_url_lst.append(SERVICE_URL+"/view_photo/"+str(image.blob_key))
            stream_id_lst.append(stream_obj.get_stream_id_by_img_id(image.img_id))

            img_lat = radians(image.location.lat)
            img_lon = radians(image.location.lon)
            dlat = r_m_lat - img_lat
            dlon = r_m_lon - img_lon
            a = (sin(dlat / 2)) ** 2 + cos(r_m_lat) * cos(img_lat) * (sin(dlon / 2)) ** 2
            c = 2 * atan2(sqrt(a), sqrt(1 - a))
            distance = R * c

            distance_lst.append(distance)

        print "mViewNearbyImages:: ldistance_lst=", str(distance_lst)

        self.respond(img_url_lst=img_url_lst, stream_id_lst=stream_id_lst, distance_lst=distance_lst, status="success")
Example #2
0
    def get(self):
        stream_id = self.request.get(IDENTIFIER_STREAM_ID)
        start_idx = self.request.get(VIEW_STREAM_START_INDEX)

        if not start_idx:
            start_idx = 0
        else:
            start_idx = int(start_idx)

        stream_obj = Stream()
        stream = stream_obj.get_stream(stream_id)

        # check if the stream exists
        if not stream:
            return self.respond(error="ViewStreamService >> Requested stream id %s does not exist." % stream_id)

        # now start retrieving images
        img_id_lst = []  # saving img ids
        img_url_lst = []
        stream_img_id_lst = stream.image_id_lst

        nrof_imgs_in_stream = len(stream_img_id_lst)

        last_idx = start_idx + NUM_STREAMS_PER_PAGE

        if last_idx >= nrof_imgs_in_stream:
            last_idx = nrof_imgs_in_stream-1

        idx_lst = xrange(start_idx, last_idx)

        for img_idx in idx_lst:
            img_id = stream_img_id_lst[img_idx]
            img_id_lst.append(img_id)
            image = Image.get_image(img_id)
            img_url_lst.append(SERVICE_URL+"/view_photo/"+str(image.blob_key))

        # increase view count
        stream.increase_view_cnt()

        # generate upload url
        upload_url = blobstore.create_upload_url('/ws/stream/view_imgs')

        self.respond(stream_owner=stream.user_email, stream_name=stream.stream_name, img_id_lst=img_id_lst,
                     img_url_lst=img_url_lst, last_idx=last_idx, nrof_imgs_in_stream=nrof_imgs_in_stream,
                     upload_url=upload_url, status="success")
Example #3
0
    def get(self):

        stream_id = self.request.get(IDENTIFIER_STREAM_ID)

        query_begin_date = self.request.get(QUERY_BEGIN_DATE)
        query_end_date = self.request.get(QUERY_END_DATE)

        begin_date = datetime.strptime(query_begin_date, '%Y-%m-%dT%H:%M:%S.%fZ')
        end_date = datetime.strptime(query_end_date, '%Y-%m-%dT%H:%M:%S.%fZ')

        stream = Stream.get_stream(stream_id)
        response = {}
        markers_lst = list()
        if not stream:
            response['error'] = "Failed to find stream(" + stream_id+")."
            self.respond(**response)
        else:
            for image_id in stream.image_id_lst:
                image = Image.get_image(image_id)
                if begin_date <= image.date <= end_date:
                    content = '<img src="'+get_serving_url(image.blob_key, size=100)+'">'
                    marker = {"latitude": image.location.lat, "longitude": image.location.lon, "content":content}
                    markers_lst.append(marker)
            self.respond(markers=markers_lst, status="success")