本文整理汇总了Python中skylines.model.Flight类的典型用法代码示例。如果您正苦于以下问题:Python Flight类的具体用法?Python Flight怎么用?Python Flight使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Flight类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_distance_flight
def _get_distance_flight(distance):
return Flight.query() \
.filter(Flight.pilot == g.user) \
.filter(Flight.olc_classic_distance >= distance) \
.order_by(Flight.landing_time) \
.filter(Flight.is_rankable()) \
.first()
示例2: find_meetings
def find_meetings(flight_id):
logger.info("Searching for near flights of flight %d" % flight_id)
flight = Flight.get(flight_id)
# Update FlightPathChunks of current flight
FlightPathChunks.update_flight_path(flight)
other_flights = FlightPathChunks.get_near_flights(flight)
# delete all previous detected points between src and dst
for key in other_flights:
FlightMeetings.query() \
.filter(or_(and_(FlightMeetings.source == flight, FlightMeetings.destination_id == key),
and_(FlightMeetings.destination == flight, FlightMeetings.source_id == key))) \
.delete()
# Insert new meetings into table
for flight_id, meetings in other_flights.iteritems():
other_flight = Flight.get(flight_id)
for meeting in meetings:
FlightMeetings.add_meeting(flight, other_flight, meeting['times'][0], meeting['times'][-1])
db.session.commit()
示例3: run
def run(self, force, date_from, date_to, ids):
current_app.add_celery()
if force:
# invalidate all results
Flight.query().update({'needs_analysis': True})
if ids:
for flight_id in ids:
self.do(flight_id)
elif date_from and date_to:
print date_from
try:
date_from = datetime.strptime(date_from, "%Y-%m-%d")
date_to = datetime.strptime(date_to, "%Y-%m-%d")
except:
print "Cannot parse date."
quit()
q = db.session.query(Flight)
q = q.filter(Flight.takeoff_time >= date_from) \
.filter(Flight.takeoff_time <= date_to)
for flight in q:
self.do(flight.id)
else:
for flight in Flight.query(needs_analysis=True):
self.do(flight.id)
示例4: _distance_flight
def _distance_flight(user, distance, schema):
flight = Flight.query() \
.filter(Flight.pilot == user) \
.filter(Flight.olc_classic_distance >= distance) \
.order_by(Flight.landing_time) \
.filter(Flight.is_rankable()) \
.first()
if flight:
return schema.dump(flight).data
示例5: run
def run(self, force, ids):
current_app.add_celery()
if force:
# invalidate all results
Flight.query().update({'needs_analysis': True})
if ids:
for flight_id in ids:
self.do(flight_id)
else:
for flight in Flight.query(needs_analysis=True):
self.do(flight.id)
示例6: _list
def _list():
query = (
Notification.query(recipient_id=request.user_id)
.join("event")
.options(contains_eager("event"))
.options(subqueryload("event.actor"))
.outerjoin(Event.flight)
.options(contains_eager("event.flight"))
.filter(or_(Event.flight == None, Flight.is_rankable()))
.order_by(Event.time.desc())
)
query = _filter_query(query, request.args)
page = request.args.get("page", type=int, default=1)
per_page = request.args.get("per_page", type=int, default=50)
query = query.limit(per_page)
query = query.offset((page - 1) * per_page)
def get_event(notification):
event = notification.event
event.unread = notification.time_read is None
return event
events = list(convert_event(get_event(notification)) for notification in query)
return jsonify(events=events)
示例7: index
def index():
query = Event.query() \
.options(subqueryload('actor')) \
.options(subqueryload('user')) \
.options(subqueryload('club')) \
.outerjoin(Event.flight) \
.options(contains_eager(Event.flight)) \
.filter(or_(Event.flight == None, Flight.is_rankable())) \
.order_by(Event.time.desc())
query = _filter_query(query, request.args)
page = request.args.get('page', type=int, default=1)
per_page = request.args.get('per_page', type=int, default=50)
events = query.limit(per_page).offset((page - 1) * per_page).all()
events_count = len(events)
if request.args.get('grouped', True, type=str_to_bool):
events = group_events(events)
template_vars = dict(events=events, types=Event.Type)
if page > 1:
template_vars['prev_page'] = page - 1
if events_count == per_page:
template_vars['next_page'] = page + 1
return render_template('timeline/list.jinja', **template_vars)
示例8: check_update_form
def check_update_form(prefix, flight_id, name, status):
if not flight_id:
return None, None, None
# Get flight from database and check if it is writable
flight = Flight.get(flight_id)
if not flight:
abort(404)
if status == UploadStatus.DUPLICATE:
return flight, None, None
else:
if not flight.is_writable(g.current_user):
abort(403)
form = UploadUpdateForm(prefix=str(prefix), obj=flight)
trace = _get_flight_path(flight)
# Force takeoff_time and landing_time to be within the igc file limits
if form.takeoff_time.data < trace['igc_start_time']:
form.takeoff_time.data = trace['igc_start_time']
if form.landing_time.data > trace['igc_end_time']:
form.landing_time.data = trace['igc_end_time']
return flight, trace, form
示例9: update
def update():
flight_id_list = request.values.getlist('flight_id')
model_list = request.values.getlist('model')
registration_list = request.values.getlist('registration')
competition_id_list = request.values.getlist('competition_id')
if (flight_id_list is None
or len(flight_id_list) != len(model_list)
or len(flight_id_list) != len(registration_list)):
flash(_('Sorry, some error happened when updating your flight(s). Please contact a administrator for help.'), 'warning')
return redirect('/flights/latest')
for index, id in enumerate(flight_id_list):
# Parse flight id
try:
id = int(id)
except ValueError:
continue
# Get flight from database and check if it is writable
flight = Flight.get(id)
if not flight or not flight.is_writable(g.current_user):
continue
# Parse model, registration and competition ID
try:
model_id = int(model_list[index])
except ValueError:
model_id = None
if model_id == 0:
model_id = None
registration = registration_list[index]
if registration is not None:
registration = registration.strip()
if not 0 < len(registration) < 32:
registration = None
competition_id = competition_id_list[index]
if competition_id is not None:
competition_id = competition_id.strip()
if not 0 < len(competition_id) < 5:
competition_id = None
# Set new values
flight.model_id = model_id
flight.registration = registration
flight.competition_id = competition_id
flight.time_modified = datetime.utcnow()
db.session.commit()
flash(_('Your flight(s) have been successfully updated.'))
return redirect('/flights/latest')
示例10: _get_takeoff_locations
def _get_takeoff_locations(user):
locations = Location.get_clustered_locations(
Flight.takeoff_location_wkt,
filter=and_(Flight.pilot == user, Flight.is_rankable()),
)
return [loc.to_lonlat() for loc in locations]
示例11: _update_flight
def _update_flight(flight_id, model_id, registration, competition_id,
takeoff_time, scoring_start_time,
scoring_end_time, landing_time):
# Get flight from database and check if it is writable
flight = Flight.get(flight_id)
if not flight or not flight.is_writable(g.current_user):
return False
# Parse model, registration and competition ID
if model_id == 0:
model_id = None
if registration is not None:
registration = registration.strip()
if not 0 < len(registration) <= 32:
registration = None
if competition_id is not None:
competition_id = competition_id.strip()
if not 0 < len(competition_id) <= 5:
competition_id = None
# Set new values
flight.model_id = model_id
flight.registration = registration
flight.competition_id = competition_id
flight.time_modified = datetime.utcnow()
# Update times only if they are reasonable and have been changed...
trigger_analysis = False
if takeoff_time and scoring_start_time and scoring_end_time and landing_time \
and takeoff_time <= scoring_start_time <= scoring_end_time <= landing_time \
and (flight.takeoff_time != takeoff_time
or flight.scoring_start_time != scoring_start_time
or flight.scoring_end_time != scoring_end_time
or flight.landing_time != landing_time):
flight.takeoff_time = takeoff_time
flight.scoring_start_time = scoring_start_time
flight.scoring_end_time = scoring_end_time
flight.landing_time = landing_time
trigger_analysis = True
flight.privacy_level = Flight.PrivacyLevel.PUBLIC
db.session.commit()
if trigger_analysis:
analyse_flight(flight)
try:
tasks.analyse_flight.delay(flight.id)
tasks.find_meetings.delay(flight.id)
except ConnectionError:
current_app.logger.info('Cannot connect to Redis server')
return True
示例12: _update_flight
def _update_flight(flight_id, model_id, registration, competition_id):
# Get flight from database and check if it is writable
flight = Flight.get(flight_id)
if not flight or not flight.is_writable(g.current_user):
return False
# Parse model, registration and competition ID
if model_id == 0:
model_id = None
if registration is not None:
registration = registration.strip()
if not 0 < len(registration) <= 32:
registration = None
if competition_id is not None:
competition_id = competition_id.strip()
if not 0 < len(competition_id) <= 5:
competition_id = None
# Set new values
flight.model_id = model_id
flight.registration = registration
flight.competition_id = competition_id
flight.time_modified = datetime.utcnow()
db.session.commit()
return True
示例13: _largest_flight
def _largest_flight(user, schema):
flight = user.get_largest_flights() \
.filter(Flight.is_rankable()) \
.first()
if flight:
return schema.dump(flight).data
示例14: analyse_flight
def analyse_flight(flight_id, full=2048, triangle=6144, sprint=512):
logger.info("Analysing flight %d" % flight_id)
if analysis.analyse_flight(Flight.get(flight_id), full, triangle, sprint):
db.session.commit()
else:
logger.warn("Analysis of flight %d failed." % flight_id)
示例15: list
def list():
query = Notification.query(recipient_id=request.user_id) \
.join('event') \
.options(contains_eager('event')) \
.options(subqueryload('event.actor')) \
.outerjoin(Event.flight) \
.options(contains_eager('event.flight')) \
.filter(or_(Event.flight == None, Flight.is_rankable())) \
.order_by(Event.time.desc())
query = _filter_query(query, request.args)
page = request.args.get('page', type=int, default=1)
per_page = request.args.get('per_page', type=int, default=50)
query = query.limit(per_page)
query = query.offset((page - 1) * per_page)
def get_event(notification):
event = notification.event
event.unread = (notification.time_read is None)
return event
events = map(get_event, query)
return jsonify(events=(map(convert_event, events)))