Ejemplo n.º 1
0
	def _build_schedule(self, data):
		s = Schedule()
		s.id = data['id']
		s.set_next_repetition(data['next_repetition'])
		s.set_phrase_id(data['phrase_id'])
		s.set_speed(data['speed'])
		s.set_pitch(data['pitch'])
		s.set_comment(data['comment'])
		s.set_priority(data['priority'])
		return s
Ejemplo n.º 2
0
	def test_produce_data(self):
		dbh = DatabaseHandler(self.dbfile)
		dbh.init_database()
		dh = DataHandler(self.xmlfile)
		phrases = dh.read_phrases()

		delta = 1
		for phrase in phrases:
			phrase_id = dbh.insert_phrase(phrase)
			schedule = Schedule()
			schedule.set_phrase_id(phrase_id)
			
			repetition_date = datetime.date.today() + datetime.timedelta(days=delta)
			delta += 1
			schedule.set_next_repetition(repetition_date)
			schedule_id = dbh.insert_schedule(schedule)

		schedules = dbh.get_schedules()
		assert len(schedules) > 0 and len(schedules) == len(phrases)
Ejemplo n.º 3
0
 def get_new_schedule(self, phrase, grade, repetition_list=None):
     """
     @param repetition_list: sorted repetition list (earliest rep first)
     @type repetition_list: list of models.Repetition
     @return: new schedule
     @rtype: models.Schedule
     """
     schedule = Schedule()
     schedule.set_phrase_id(phrase.id)
     new_interval = 1
     if repetition_list and len(repetition_list) > 1:
         rep1 = repetition_list[-2]
         rep2 = repetition_list[-1]
         date1 = rep1.get_date()
         date2 = rep2.get_date()
         delta = date2 - date1
         new_interval = self._get_new_interval(delta.days, grade)
     elif repetition_list:
         new_interval = self._get_new_interval(1, grade)
     else:
         new_interval = self._get_new_interval(0, grade)
     schedule.set_next_repetition(datetime.date.today() + datetime.timedelta(days=new_interval))
     return schedule
Ejemplo n.º 4
0
    def bulk_add(self, directory, config, tagline):
        directory = os.path.expanduser(config.MUSIC_DIRECTORY) + directory
        image_files = glob.glob('%s/*.png' % directory)
        sound_files = glob.glob('%s/*.mp3' % directory)

        grouped_files = dict()
        for item in image_files + sound_files:
            item = item.replace(os.path.expanduser(config.MUSIC_DIRECTORY), '')
            key = item[:-4]
            if key not in grouped_files.keys():
                grouped_files[key] = []
            grouped_files[key].append(item)

        inserted_items = []
        item_keys = sorted(grouped_files)
        item_keys.reverse()
        for key in item_keys:
            items = grouped_files[key]
            image = None
            sound = None
            for item in items:
                if item.lower().endswith('.png'):
                    image = item
                elif item.lower().endswith('.mp3'):
                    sound = item

            if image is not None and self.image_present(image):
                print "Image already added: %s. Skipping..." % image
                continue
            if sound is not None and self.sound_present(sound):
                print "Sound already added: %s. Skipping..." % sound
                continue
            if image is None and sound is None:
                print "No image/sound recognized for item: %s" % key
                continue
                
            phrase = Phrase()
            phrase.set_name(key)
            if sound is not None:
                phrase.set_filename(sound)
            if image is not None:
                phrase.set_image(image)
            phrase.set_tagline(tagline)
            phrase.set_from_position(0.0)
            phrase.set_to_position(0.0)
            phrase.set_loop(True)
            phrase.set_speed(100)
            phrase.set_pitch(0)
            phrase.set_comment('')            
            phrase_id = self.insert_phrase(phrase)
            if not phrase_id:
                print "Failed to add phrase to database"
                return
            schedule = Schedule()
            schedule.set_phrase_id(phrase_id)
            schedule.set_next_repetition(datetime.date.today())
            schedule_id = self.insert_schedule(schedule)
            if not schedule_id:
                print "Failed to schedule the new phrase"
                return
            metronome_setup = MetronomeSetup()
            metronome_setup.phrase_id = phrase_id
            metronome_setup.speed = 100
            metronome_setup.meter = 0
            metronome_setup.duration = 300
            metronome_setup.increment = 2
            metronome_setup_id = self.insert_metronome_setup(metronome_setup)
            if not metronome_setup_id:
                print "Failed to insert metronome setup"
                return
            inserted_items.append(key)

        if inserted_items:
            print "Inserted items"
            for item in inserted_items:
                print item
        else:
            print "No items inserted"