예제 #1
0
    def test_correct_assets_passing_tag_string(self):
        """ Pass tag lists and check for correct assets
        """
        recordings = get_recordings(self.session1.id, str(self.tag1.id))
        self.assertEqual([self.asset1, self.asset3], recordings)

        tag_string = str(self.tag1.id) + "," + str(self.tag2.id)
        recordings = get_recordings(self.session1.id, tag_string)
        self.assertEqual([self.asset3], recordings)
예제 #2
0
    def test_correct_assets_passing_tag_list(self):
        """ Pass tag lists and check for correct assets
        """
        recordings = get_recordings(self.session1.id, [self.tag1.id])
        self.assertEqual([self.asset1, self.asset3], recordings)

        recordings = get_recordings(self.session1.id, [self.tag2.id])
        self.assertEqual([self.asset2, self.asset3], recordings)

        recordings = get_recordings(self.session1.id, [self.tag1.id, self.tag2.id])
        self.assertEqual([self.asset3], recordings)

        recordings = get_recordings(self.session2.id, [self.tag1.id])
        self.assertEqual([self.asset4], recordings)
    def update_request(self, request):
        logging.debug("update_request")
        self.lock.acquire()
        self.all_recordings = db.get_recordings(request)

        #filter recordings
        if "tags" in request:
            tag_ids = request["tags"]
            if not hasattr(tag_ids, "__iter__"):
                tag_ids = tag_ids.split(",")

            tags = Tag.objects.filter(pk__in=tag_ids)
            for tag in tags:
                if tag.filter:
                    logging.debug("Tag with filter found: %s: %s" % (tag, tag.filter))
                    self.all_recordings = getattr(asset_sorters, tag.filter)(assets=self.all_recordings, request=request)

        self.far_recordings = self.all_recordings
        self.nearby_played_recordings = []
        self.nearby_unplayed_recordings = []
        self.update_nearby_recordings(request)
        logging.debug("update_request: all_recordings count: " + str(len(self.all_recordings))
                      + ", far_recordings count: " + str(len(self.far_recordings))
                      + ", nearby_played_recordings count: " + str(len(self.nearby_played_recordings))
                      + ", nearby_unplayed_recordings count: " + str(len(self.nearby_unplayed_recordings)))
        self.lock.release()
 def update_request(self, request, update_nearby = True):
     """
     Updates/Initializes the request stored in the collection by filling
     all_recordings with assets filtered by tags. Optionally leaves
     nearby_unplayed_recordings empty so no assets are triggered until
     modify_stream or move_listener are called.
     """
     logger.debug("update_request")
     self.lock.acquire()
     self.all_recordings = db.get_recordings(request["session_id"],
                                             request.get("tags"))
     self.far_recordings = self.all_recordings
     # Clear the nearby recordings storage.
     self.nearby_played_recordings = []
     self.nearby_unplayed_recordings = []
     # Updating nearby_recording will start stream audio asset playback.
     if (update_nearby):
         self.update_nearby_recordings(request)
     logger.debug("update_request: all_recordings count: " + str(len(self.all_recordings))
                  + ", far_recordings count: " +
                  str(len(self.far_recordings))
                  + ", nearby_played_recordings count: " +
                  str(len(self.nearby_played_recordings))
                  + ", nearby_unplayed_recordings count: " + str(len(self.nearby_unplayed_recordings)))
     self.lock.release()
 def update_request(self, request, update_nearby=True):
     """
     Updates/Initializes the request stored in the collection by filling
     all_recordings with assets filtered by tags. Optionally leaves
     nearby_unplayed_recordings empty so no assets are triggered until
     modify_stream or move_listener are called.
     """
     logger.debug("update_request")
     self.lock.acquire()
     self.all_recordings = db.get_recordings(request["session_id"],
                                             request.get("tags"))
     self.far_recordings = self.all_recordings
     # Clear the nearby recordings storage.
     self.nearby_played_recordings = []
     self.nearby_unplayed_recordings = []
     # Updating nearby_recording will start stream audio asset playback.
     if (update_nearby):
         self.update_nearby_recordings(request)
     logger.debug("update_request: all_recordings count: " +
                  str(len(self.all_recordings)) +
                  ", far_recordings count: " +
                  str(len(self.far_recordings)) +
                  ", nearby_played_recordings count: " +
                  str(len(self.nearby_played_recordings)) +
                  ", nearby_unplayed_recordings count: " +
                  str(len(self.nearby_unplayed_recordings)))
     self.lock.release()
예제 #6
0
	def update_request (self, request):
		logging.debug("update_request")
		self.lock.acquire()
		self.all_recordings = db.get_recordings(request)
		self.far_recordings = self.all_recordings
		self.nearby_played_recordings = []
		self.nearby_unplayed_recordings = []
		self.update_nearby_recordings(request)
		self.lock.release()
    def get_recording(self):
        logger.debug("Getting a recording from the bucket.")
        self.lock.acquire()
        recording = None
        logger.debug("We have %s unplayed recordings.",
                     len(self.nearby_unplayed_recordings))
        if len(self.nearby_unplayed_recordings) > 0:
            index = 0
            recording = self.nearby_unplayed_recordings.pop(index)

            logger.debug("Got %s", recording.filename)
            self.nearby_played_recordings.append(recording)
        elif len(self.nearby_played_recordings) > 0:
            logger.debug("Request: %s", self.request)
            p = models.Project.objects.get(id=int(self.request['project_id']))
            logger.debug("Repeat mode: %s", p.repeat_mode.mode)
            # do this only if project setting calls for it
            if p.is_continuous():
                logger.debug("Continuous mode")
                tags = getattr(self.request, "tags", None)
                self.all_recordings = db.get_recordings(
                    self.request["session_id"], tags)
                self.far_recordings = self.all_recordings
                self.nearby_played_recordings = []
                self.nearby_unplayed_recordings = []
                self.update_nearby_recordings(self.request)
                logger.debug("GET_RECORDING UPDATE: all_recordings count: " +
                             str(len(self.all_recordings)) +
                             ", far_recordings count: " +
                             str(len(self.far_recordings)) +
                             ", nearby_played_recordings count: " +
                             str(len(self.nearby_played_recordings)) +
                             ", nearby_unplayed_recordings count: " +
                             str(len(self.nearby_unplayed_recordings)))
                index = 0
                recording = self.nearby_unplayed_recordings.pop(index)
                logger.debug("Got %s", recording.filename)
                self.nearby_played_recordings.append(recording)
            else:
                logger.debug("Stop mode")

        # If a recording was found and unit tests are not running.
        if recording and not settings.TESTING:
            filepath = os.path.join(settings.MEDIA_ROOT, recording.filename)
            # Check if the file exists on the server.
            if not os.path.isfile(filepath):
                recording = None
                logger.error("File not found: %s", filepath)

        self.lock.release()
        return recording
    def get_recording(self):
        logger.debug("Getting a recording from the bucket.")
        self.lock.acquire()
        recording = None
        logger.debug("We have %s unplayed recordings.",
                     len(self.nearby_unplayed_recordings))
        if len(self.nearby_unplayed_recordings) > 0:
            index = 0
            recording = self.nearby_unplayed_recordings.pop(index)

            logger.debug("Got %s", recording.filename)
            self.nearby_played_recordings.append(recording)
        elif len(self.nearby_played_recordings) > 0:
            logger.debug("Request: %s", self.request)
            p = models.Project.objects.get(id=int(self.request['project_id']))
            logger.debug("Repeat mode: %s", p.repeat_mode.mode)
            # do this only if project setting calls for it
            if p.is_continuous():
                logger.debug("Continuous mode")
                tags = getattr(self.request, "tags", None)
                self.all_recordings = db.get_recordings(self.request["session_id"], tags)
                self.far_recordings = self.all_recordings
                self.nearby_played_recordings = []
                self.nearby_unplayed_recordings = []
                self.update_nearby_recordings(self.request)
                logger.debug("GET_RECORDING UPDATE: all_recordings count: " + str(len(self.all_recordings))
                             + ", far_recordings count: " +
                             str(len(self.far_recordings))
                             + ", nearby_played_recordings count: " +
                             str(len(self.nearby_played_recordings))
                             + ", nearby_unplayed_recordings count: " + str(len(self.nearby_unplayed_recordings)))
                index = 0
                recording = self.nearby_unplayed_recordings.pop(index)
                logger.debug("Got %s", recording.filename)
                self.nearby_played_recordings.append(recording)
            else:
                logger.debug("Stop mode")

        # If a recording was found and unit tests are not running.
        if recording and not settings.TESTING:
            filepath = os.path.join(settings.MEDIA_ROOT, recording.filename)
            # Check if the file exists on the server.
            if not os.path.isfile(filepath):
                recording = None
                logger.error("File not found: %s", filepath)

        self.lock.release()
        return recording
    def get_recording(self):
        logging.debug("Recording Collection: Getting a recording from the bucket.")
        self.lock.acquire()
        recording = None
        logging.debug("Recording Collection: we have " + str(len(self.nearby_unplayed_recordings)) + " unplayed recs.")
        if len(self.nearby_unplayed_recordings) > 0:
#           index = random.randint(0, len(self.nearby_unplayed_recordings) - 1)
            index = 0
            recording = self.nearby_unplayed_recordings.pop(index)
            logging.debug("RecordingCollection: get_recording: Got " + recording.filename)
            self.nearby_played_recordings.append(recording)
        elif len(self.nearby_played_recordings) > 0:
            logging.debug("!!!!!!!!!!!!!!!!!get_recording 1")
            logging.debug("!!!!!!!!!!!!!!!!!get_recording request:  " + str(self.request))
            p = models.Project.objects.get(id=int(self.request['project_id']))
            logging.debug("!!!!!!!!!!!!!!!!!get_recording 2 - repeatmode:" + p.repeat_mode.mode)
            #do this only if project setting calls for it
            if p.repeat_mode.id == 2:
                logging.debug("!!!!!!!!!!!!!!!!!get_recording continuous mode")
                self.all_recordings = db.get_recordings(self.request)
                self.far_recordings = self.all_recordings
                self.nearby_played_recordings = []
                self.nearby_unplayed_recordings = []
                self.update_nearby_recordings(self.request)
                logging.debug("GET_RECORDING UPDATE: all_recordings count: " + str(len(self.all_recordings))
                          + ", far_recordings count: " + str(len(self.far_recordings))
                          + ", nearby_played_recordings count: " + str(len(self.nearby_played_recordings))
                          + ", nearby_unplayed_recordings count: " + str(len(self.nearby_unplayed_recordings)))
                index = 0
                recording = self.nearby_unplayed_recordings.pop(index)
                logging.debug("POST UPDATE RecordingCollection: get_recording: Got " + recording.filename)
                self.nearby_played_recordings.append(recording)
            else:
                logging.debug("!!!!!!!!!!!!!!!!!get_recording stop mode")

        self.lock.release()
        return recording
예제 #10
0
def test12():
	r1 = server.get_questions({'categoryid':'8','subcategoryid':'12','latitude':'20','longitude':'-20'})
	r2 = server.get_questions({'categoryid':'8','subcategoryid':'12','latitude':'20','longitude':'20'})
	r3 = server.get_questions({'categoryid':'8','subcategoryid':'12'})
	r1 = db.get_recordings({'categoryid':'8','subcategoryid':'12','latitude':'20','longitude':'-20','demographicid':'1','usertypeid':'17','genderid':'1','ageid':'17','questionid':'36'})
	return
예제 #11
0
 def test_no_assets_passing_valid_tag_list(self):
     """ Pass valid unused tag and check no assets are returned
     """
     recordings = get_recordings(self.session1.id, [self.tag3.id])
     self.assertEqual([], recordings)
예제 #12
0
 def test_correct_assets_project_default_tags(self):
     """ If we pass no tags, the project defaults are provided
     """
     recordings = get_recordings(self.session1.id)
     self.assertEqual([self.asset1, self.asset3], recordings)