def hello_world(): if request.method == 'POST': segment = request.form['segment'] count = request.form['count'] tag = request.form['tag'] inform = Segment(segment=segment, count=count, tag=tag) # try: db.session.add(inform) db.session.commit() return redirect('/') # except: # return 'Error' else: auth = requests.get(current_app.config['URL_AUTH'], headers=current_app.config['HEADERS_AUTH']) if auth.status_code == 200: tags = requests.get(current_app.config['URL_TAGS'], headers=current_app.config['HEADERS_AUTH']) tags = json.loads(tags.text) segments = requests.get(current_app.config['URL_SEGMENTS'], headers=current_app.config['HEADERS_AUTH']) segments = json.loads(segments.text) return render_template('main.html', tags=tags, segments=segments)
def get_segments(self, file, part, video_id): try: audio_file = "aud.part" + str(part) + "." + file + ".wav" fs, s = aIO.readAudioFile(audio_file) af, _, afn = aF.mtFeatureExtraction(s, fs, int(0.5 * fs), int(0.5 * fs), int(0.1 * fs), int(0.1 * fs)) video_file = "vid.part" + str(part) + "." + file vf, t, vfn = self._video_extractor.extract_features(video_file) except Exception as e: print(e) return None else: segment_features = [] # construct segmentfeature vmean = vf.T.mean(axis=1) for i, val in enumerate(vmean): if isinstance(val, np.ndarray): val = val[0] feature = SegmentFeatures(value=val, seq_no=1, feature_id=self._feature_map[vfn[i]]) segment_features.append(feature) amean = af.mean(axis=1) for i, val in enumerate(amean): feature = SegmentFeatures(value=val, seq_no=1, feature_id=self._feature_map[afn[i]]) segment_features.append(feature) # construct segment with its segmentfeatures segment = Segment(video_id=video_id, start_sec=part, end_sec=self._splitter.get_segment_end(part), features=segment_features) return segment
def _parse_response(self, response_dict): routes = [] for i, route in enumerate(response_dict['routes']): # filter by transfers if self._search_request.no_transfers and len( route['segments']) > 1: continue # create route obj rt = Route( order=i, pl_from=self._search_request.req_from, pl_to=self._search_request.req_to, from_seg=response_dict['places'][route['depPlace']] ['shortName'], transfers=len(route['segments']) - 1, duration=self._parse_duration(route['totalDuration']), duration_raw=route['totalDuration'], ) # filter by total price if not route.get('indicativePrices'): continue else: pr = route['indicativePrices'][-1] if self._search_request.price_lower_limit and \ int(pr['price']) < self._search_request.price_lower_limit: continue if self._search_request.price_upper_limit and \ int(pr['price']) > self._search_request.price_upper_limit: continue # parse total price self._parse_price(route, rt) # parse segments segments = [] types_set = set() for segment in route['segments']: transport_type = response_dict['vehicles'][ segment['vehicle']]['kind'] types_set.add(transport_type) if any(not self._names.get(tr) for tr in types_set): continue for segment in route['segments']: # create segment dict transport_type = response_dict['vehicles'][ segment['vehicle']]['kind'] seg = Segment( to=self._limit_name(response_dict['places'][ segment['arrPlace']]['shortName']), to_full=response_dict['places'][segment['arrPlace']] ['shortName'], transport_type=TransportType( name=self._names[transport_type], icon=self._icons[transport_type], ), ) # parse segment price if segment.get('indicativePrices'): self._parse_price(segment, seg) else: seg.price = '-' seg.price_raw = 0 # parsing specific segment type if segment['segmentKind'] == 'surface': seg.segment_type = 'surface' seg.duration = self._parse_duration( segment['transitDuration'] + segment['transferDuration']) seg.duration_raw = segment['transitDuration'] + segment[ 'transferDuration'] if segment.get('agencies'): seg.frequency = self._parse_frequency( segment['agencies'][0]['frequency']) links = segment['agencies'][0]['links'] for link in links: if link['text'] == 'Book at': seg.book_name = link['displayUrl'] seg.book_url = link['url'] elif link['text'] == 'Schedules at': seg.schedule_name = link['displayUrl'] seg.schedule_url = link['url'] # end else: seg.segment_type = 'air' if segment.get('outbound'): duration = 0 leg = segment['outbound'][0] start_index = leg['hops'][0]['depPlace'] time_start = leg['hops'][0]['depTime'] for hop in leg['hops']: end_index = hop['arrPlace'] duration += hop['duration'] time_end = hop['arrTime'] seg.airport_start_code = response_dict['places'][ start_index]['code'] seg.airport_start_name = response_dict['places'][ start_index]['shortName'] seg.airport_end_code = response_dict['places'][ end_index]['code'] seg.airport_end_name = response_dict['places'][ end_index]['shortName'] seg.time_start = time_start seg.time_end = time_end seg.duration = self._parse_duration(duration) seg.duration_raw = duration seg.operating_days = self._parse_days( leg['operatingDays']) flights = [] for leg in segment['outbound']: flight = Flight(operating_days=self._parse_days( leg['operatingDays'])) if leg.get('indicativePrices'): self._parse_price(leg, flight) duration = 0 hops = [] airlines = [] for hop in leg['hops']: duration += hop['duration'] start_index = hop['depPlace'] end_index = hop['arrPlace'] hp = FlightSegment( airport_start_code=response_dict['places'] [start_index]['code'], airport_start_name=response_dict['places'] [start_index]['shortName'], airport_end_code=response_dict['places'] [end_index]['code'], airport_end_name=response_dict['places'] [end_index]['shortName'], time_start=hop['depTime'], time_end=hop['arrTime'], duration=self._parse_duration( hop['duration']), duration_raw=hop['duration'], airline_name=response_dict['airlines'][ hop['airline']]['name'], ) hops.append(hp) airlines.append(response_dict['airlines'][ hop['airline']]['name']) flight.flight_segments = hops flight.duration_raw = duration flight.duration = self._parse_duration(duration) flight.airlines = ', '.join(a for a in set(airlines)) flights.append(flight) flights_obj = Flights(choices=flights).save() seg.flights = flights_obj # end segments.append(seg) # end # parse transport types transport_types = [ TransportType( name=self._names[tp], icon=self._icons[tp], ) for tp in types_set ] rt.segments = segments rt.transport_types = transport_types routes.append(rt) self._save_best_route(routes) self._search_request.routes = routes self._search_request.save() return self._search_request.result