Ejemplo n.º 1
0
    def test_time_interval(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_time_interval = TimeInterval.from_string(
            '2019-11-11 04:24:06', '2019-11-11 04:24:15',
            self.default_local_time_offset)

        self.assertEqual(expected_time_interval, track.get_time_interval())
Ejemplo n.º 2
0
    def test_lunch_and_network_exists_in_track(self):
        track = Track(datetime.now())
        talk1 = Talk("Fedoka", 3 * 60)
        talk2 = Talk("Tutu de Feijão", 4 * 60)

        track.schedule_talk(talk1)
        track.schedule_talk(talk2)

        timeline_titles = [talk.title for talk in track.get_timeline()]

        assert 'Network' in timeline_titles
        assert 'Lunch' in timeline_titles
Ejemplo n.º 3
0
    def test_talk_is_added_correctly(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta denovo", 60)
        track.schedule_talk(talk)

        scheduled = track.get_timeline()[0]

        assert scheduled.title == talk.title
        assert scheduled.duration == talk.duration
        assert scheduled.date.hour == 9
        assert scheduled.date.minute == 0
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
Ejemplo n.º 4
0
    def track_by_max_overlap(self, tracks, detections):
        current_detections = deepcopy(detections)
        tracks_on_frame = []

        # Check if current_detections can be matched with detections from current tracks
        for track in tracks:
            if track.finished:
                continue
            best_matched = self.match_detections(track.previous_detection,
                                                 current_detections)
            if best_matched:
                track.add_detection_to_tracking(best_matched[0])
                tracks_on_frame.append(track)
                for matching in best_matched:
                    current_detections.remove(matching)
            else:
                track.finished = True

        # For the unkown detection create new detections
        for detection in current_detections:
            new_tracking = Track(self.track_number, detection)
            tracks.append(new_tracking)
            tracks_on_frame.append(new_tracking)
            self.track_number += 1
        return tracks, tracks_on_frame
Ejemplo n.º 5
0
    def get_track(self, track_id):
        """ This method fetches track information from a Spotify track ID.

            This method makes a call to the Spotify Web API and returns the information in
            a Track object containing the information about the track. A songs track ID can be
            found in the Spotify link to the track: https://open.spotify.com/track/{track_id}.

            :param track_id: A String of the track ID
            :return: A Track object
        """
        response = self.__get_data(
            self.url.tracks_url().format(id=str(track_id)))
        name = response['name']
        album = response['album']['name']
        album_id = response['album']['id']
        artists = []
        for album_artists in response['artists']:
            artists.append(album_artists['name'])
        duration_ms = response['duration_ms']
        explicit = response['explicit']
        release_date = response['album']['release_date']
        popularity = response['popularity']
        return Track(name=name,
                     album=album,
                     artists=artists,
                     popularity=popularity,
                     track_id=track_id,
                     album_id=album_id,
                     duration_ms=duration_ms,
                     explicit=explicit,
                     release_date=release_date)
Ejemplo n.º 6
0
    def test_that_i_cant_add_a_talk_when_track_is_full(self):
        track = Track(datetime.now())
        talk = Talk("Really Large Talk", 3 * 60)
        track.schedule_talk(talk)
        talk2 = Talk("Really Large Talk", 4 * 60)
        track.schedule_talk(talk2)

        talk3 = Talk("bostona veia", 30)

        with pytest.raises(NoEnoughtSpace):
            track.schedule_talk(talk3)
Ejemplo n.º 7
0
    def test_talks_is_ordered_by_hour(self):
        date = datetime(2018, 1, 1)
        track = Track(date)
        talk1 = Talk("Fedoka", 3 * 60)
        talk2 = Talk("Tutu de Feijão", 4 * 60)

        track.schedule_talk(talk1)
        track.schedule_talk(talk2)

        timeline = track.get_timeline()

        assert timeline[0].get_title() == 'Fedoka'
        assert timeline[0].get_date() == datetime(2018, 1, 1, 9)
        assert timeline[1].get_title() == 'Lunch'
        assert timeline[1].get_date() == datetime(2018, 1, 1, 12)
        assert timeline[2].get_title() == 'Tutu de Feijão'
        assert timeline[2].get_date() == datetime(2018, 1, 1, 13)
        assert timeline[3].get_title() == 'Network'
        assert timeline[3].get_date() == datetime(2018, 1, 1, 17)
Ejemplo n.º 8
0
    def test_track_is_completed_correctly_when_network_starts_at_16h(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 3 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is True
Ejemplo n.º 9
0
    def test_track_is_completed_correctly(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 4 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is True
Ejemplo n.º 10
0
    def test_track_is_not_valid(self):
        track = Track(datetime.now())
        talk = Talk("first talk", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk 2", 2 * 60)
        track.schedule_talk(talk2)

        assert track.is_full() is False
Ejemplo n.º 11
0
 def generate_tracks_to_talks(self):
     talks_combinations = self.__get_talks_combinations(self.talks)
     self.tracks.append(Track(datetime.now()))
     for combinations in talks_combinations:
         for talk in combinations:
             try:
                 self.__insert_talk_in_track(talk)
             except NoEnoughtSpace:
                 self.__restart_tracks()
         if self.__all_generated_tracks_are_fully():
              return self.tracks_full + self.tracks
     return self.tracks_full + self.tracks
Ejemplo n.º 12
0
    def test_added_a_talk_that_exceed_the_lunch_and_raises_exception(self):
        track = Track(datetime.now())
        talk = Talk("Big KeyNote", 170)
        track.schedule_talk(talk)

        talk2 = Talk("Average Talk", 30)

        with pytest.raises(NoEnoughtSpace):
            track.schedule_talk(talk2)
Ejemplo n.º 13
0
    def create_tracks_from_info(cls, answer, local_time_offset):
        answer_text = cls.__clear_xml_from_namespaces(answer.text)
        answer_xml = ElementTree.fromstring(answer_text)

        match_list = answer_xml.find('matchList')
        match_items = match_list.findall('searchMatchItem')

        tracks = []
        for match_item in match_items:
            media_descriptor = match_item.find('mediaSegmentDescriptor')
            playback_uri = media_descriptor.find('playbackURI')
            new_track = Track(playback_uri.text, local_time_offset)
            tracks.append(new_track)

        return tracks
Ejemplo n.º 14
0
    def test_that_the_talk_date_is_based_on_previous_talk(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta denovo", 30)
        track.schedule_talk(talk)

        talk2 = Talk("bostona veia", 30)
        track.schedule_talk(talk2)
        scheduled = track.get_timeline()[1]

        assert scheduled.title == talk2.title
        assert scheduled.duration == talk2.duration
        assert scheduled.date.hour == 9
        assert scheduled.date.minute == 30
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
Ejemplo n.º 15
0
    def test_that_i_reeschedule_a_talk_when_is_the_lunch_hour(self):
        track = Track(datetime.now())
        talk = Talk("Talk 1", 3 * 60)
        track.schedule_talk(talk)

        talk2 = Talk("Talk on the lunch hour", 30)

        track.schedule_talk(talk2)
        scheduled = track.get_timeline()[2]

        assert scheduled.title == talk2.title
        assert scheduled.duration == talk2.duration
        assert scheduled.date.hour == 13
        assert scheduled.date.minute == 0
        assert scheduled.date.second == 0
        assert scheduled.date.microsecond == 0
Ejemplo n.º 16
0
    def test_when_return_the_conference_complete(self):
        track = Track(datetime.now())
        talks = [
            Talk("Xuxu", 3 * 60),
            Talk("Abacaxi", 4 * 60),
            Talk("Couve", 3 * 60),
            Talk("Frango", 4 * 60)
        ]
        track_management = TrackManagement(talks)
        tracks = track_management.generate_tracks_to_talks()
        conference = Conference(tracks)

        conference = conference.get_formatted_tracks_for_conference()

        assert conference == {
            'Track 1': [
                '09:00AM Xuxu 180', '12:00PM Lunch 60', '01:00PM Abacaxi 240',
                '05:00PM Network 60'
            ],
            'Track 2': [
                '09:00AM Couve 180', '12:00PM Lunch 60', '01:00PM Frango 240',
                '05:00PM Network 60'
            ]
        }
Ejemplo n.º 17
0
    def test_url_to_download(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_url = self.default_track_text

        self.assertEqual(expected_url, track.url_to_download())
Ejemplo n.º 18
0
"""
this file is for the manage of the agents
Author: Zachary
Reserved Rights
"""

from src.track import Track, Car
from mc_agent import MC_Agent
import numpy as np
from tqdm import tqdm

num_action = 9  # the par for how many action the agent can do
epsilon = 0.9  # the discount for the value of the new state
env_track = Track('data/L-track.txt')  # init the env
env_car = Car(env_track)
agent = MC_Agent(epsilon, num_action)  # init the agent

for steps in tqdm(range(100000000)):
    #print('*'*40)
    #print(env_car.pos, "the pos is ")
    action = agent.act_behave(env_car.pos)  # evaluation stage
    reward = env_car.step(action)  # interact with the env
    #print("the reward is", reward)
    if reward == 1:
        print(env_track)
        env_car.reset()

    agent.update()  # update the action-value

print('the value of state is')
print('*' * 40)
Ejemplo n.º 19
0
    def test_file_name(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_name = 'ch01_00000000036000001'

        self.assertEqual(expected_name, track.name())
Ejemplo n.º 20
0
    def test_file_size(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_name = '377108'

        self.assertEqual(expected_name, track.size())
Ejemplo n.º 21
0
 def test_all_text(self):
     track = Track(self.default_track_text, self.default_local_time_offset)
     self.assertEqual(self.default_track_text, track.text())
    def test_url_to_download(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_url = 'rtsp://10.226.39.51/Streaming/tracks/101/?name=ch01_00000000036000001'

        self.assertEqual(expected_url, track.url_to_download())
Ejemplo n.º 23
0
def resolve_tracks_from_detections(detections):
    grouped = group_by_id(detections)
    tracks = {}
    for identifier in grouped.keys():
        tracks[identifier] = Track(identifier, grouped[identifier])
    return tracks
Ejemplo n.º 24
0
    def test_base_url(self):
        track = Track(self.default_track_text, self.default_local_time_offset)
        expected_url = 'rtsp://10.226.39.51/Streaming/tracks/101/'

        self.assertEqual(expected_url, track.base_url())
Ejemplo n.º 25
0
def group_in_tracks(detections, camera):
    grouped = group_by_id(detections)
    tracks = {}
    for id in grouped.keys():
        tracks[id] = Track(id, grouped[id], camera)
    return tracks
Ejemplo n.º 26
0
 def __restart_tracks(self):
     self.tracks.clear()
     self.tracks_full.clear()
     self.tracks.append(Track(datetime.now()))
Ejemplo n.º 27
0
    def test_when_a_talk_is_added_in_an_empty_track(self):
        track = Track(datetime.now())
        talk = Talk("qualquer bosta", 60)
        track.schedule_talk(talk)

        assert len(track.get_timeline()) == 3
Ejemplo n.º 28
0
 def __create_a_new_track_after_stock_a_fully_track(self, current_track):
     self.tracks_full.append(current_track)
     self.tracks.append(Track(datetime.now()))
     self.tracks = self.tracks[1:]
def run_demo(args):

    skip_frames = args.skip_frames
    out_fps = args.out_fps
    sigma_iou = args.sigma_iou
    log = args.log
    in_video_path = args.in_video_path
    device = args.device
    max_miss_frames = 3
    min_frame_th = 3

    video_name = in_video_path.split('/')[-1].split('.')[0]

    # setup experiment directory
    if not os.path.exists('runs'):
        os.makedirs('runs')
    exp_id = len(os.listdir('runs'))
    exp_dir = os.path.join('runs', 'exp_' + str(exp_id))
    os.mkdir(exp_dir)
    violation_dir = os.path.join(exp_dir, 'violations')
    os.mkdir(violation_dir)

    print("Experiment Directory: ", exp_dir)
    print('==== Configuration ====')
    print(args)

    # load models
    model_od = 'models/mobilenet_ssd/FP16/mobilenet-ssd.xml'
    mode_pose = 'models/pose_estimation/FP16/single-human-pose-estimation-0001.xml'
    cls_file = 'models/pose_classifier/classifier.sav'

    ie = IECore()
    detector_person = Detector(ie,
                               path_to_model_xml=model_od,
                               device=device,
                               label_class=15)

    single_human_pose_estimator = HumanPoseEstimator(
        ie, path_to_model_xml=mode_pose, device=device)

    classifier = pickle.load(open(cls_file, 'rb'))

    #read video file
    cap = cv2.VideoCapture(in_video_path)
    ret, frame = cap.read()

    # output video
    out = cv2.VideoWriter(os.path.join(exp_dir, video_name + '.avi'),
                          cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), out_fps,
                          (frame.shape[1], frame.shape[0]))

    #time benchmarks
    total_time = 0
    detector_time = 0
    pose_time = 0
    classification_time = 0
    tracking_time = 0
    operation_count = 0

    tracks_active = []

    t_id = 1
    frame_i = 0
    while (cap.isOpened()):
        # read a frame from video
        ret, frame = cap.read()

        frame_i += 1

        # if valid frame read
        if ret == True:

            # skip frames
            if frame_i % skip_frames == 0:

                operation_count += 1
                start_time = time.time()

                if log:
                    print("====== Frame id : ", str(frame_i))

                # detect person
                s = time.time()
                boxes = detector_person.detect(frame)
                detector_time += time.time() - s

                # extract pose
                s = time.time()
                key_points = [
                    single_human_pose_estimator.estimate(frame, bbox)
                    for bbox in boxes
                ]
                pose_time += time.time() - s

                if log:
                    print("Detections : ", str(len(key_points)))

                # predict state and get detections
                s = time.time()
                detections_frame = []
                for box, k_p in zip(boxes, key_points):
                    features = preprocess(k_p)
                    state = classifier.predict(features)
                    det = Detection(box=box, state=state, frame=frame_i)
                    detections_frame.append(det)
                classification_time += time.time() - s

                dets = detections_frame

                # person tracking
                s = time.time()

                updated_tracks = []
                for track in tracks_active:

                    if len(dets) > 0:

                        best_match = max(
                            dets, key=lambda x: iou(track.position, x.box))
                        if iou(track.position, best_match.box) >= sigma_iou:
                            track.update(best_match.box, best_match.state,
                                         frame_i, frame)
                            updated_tracks.append(track)

                            # remove from best matching detection from detections
                            del dets[dets.index(best_match)]

                    # if track was not updated
                    if len(updated_tracks
                           ) == 0 or track is not updated_tracks[-1]:
                        # finish track when the conditions are met
                        track.miss_track(frame_i)
                        if track.miss_count < max_miss_frames:
                            updated_tracks.append(track)

                # create new tracks
                new_tracks = []

                for det in dets:
                    new_tracks.append(
                        Track(det.box, det.state, det.frame, frame_i, t_id,
                              violation_dir))
                    t_id += 1

                tracks_active = updated_tracks + new_tracks

                tracking_time += time.time() - s

                if log:
                    print("Active Tracks : ", str(len(tracks_active)))

                valid_tracks = [
                    t for t in tracks_active if t.frame_count() > min_frame_th
                ]
                frame = draw_tracks(valid_tracks, frame)

                # save results
                out.write(frame)
                total_time += time.time() - start_time

        else:
            break

    cap.release()

    print("======= FPS Report =======")
    print("Total fps: " + str(float(operation_count) / total_time))
    print("Detector fps: " + str(float(operation_count) / detector_time))
    print("Pose estimation fps: " + str(float(operation_count) / pose_time))
    print("Pose classification fps: " +
          str(float(operation_count) / classification_time))
    print("Person Tracker fps: " + str(float(operation_count) / tracking_time))