예제 #1
0
def flight_detail(request, slug):
    print 'loading' + slug
    flight=Flight.objects.get(slug=slug)
    timelineEventList=[]
    heartbeats=flight.mavmessage_set.filter(msgType='HEARTBEAT')
    
    #Timeline data construction
    for heartbeat in heartbeats:
        try:
            timelineEventList.append(
                {"start":dt2jsts(heartbeat.timestamp),
                "content":"HB",
                "group":"Heartbeat"})
        except AttributeError:
            pass
    for video in flight.flightvideo_set.all():
        start_time=dt2jsts(flight.start_time()+datetime.timedelta(seconds=video.delayVsLogstart))
        timelineDictForVid={"start":start_time,"group":"Video","editable":True}
        if video.onboard:
            timelineDictForVid['content']='Start of onboard video ' 
        else:
            timelineDictForVid['content']='Start of offboard video ' + video.url
        timelineDictForVid['vidUrl']=video.url
        timelineDictForVid['pk']=video.pk  
        timelineEventList.append(timelineDictForVid)

    #add start and end of log
    if flight.is_tlog:
        log_type='Mavlink telemetry log'
    else:
        log_type='APM dataflash log'
    timelineEventList.append({'start':dt2jsts(flight.start_time()),
                              'end':dt2jsts(flight.end_time()),
                              'group':'Logs',
                              'content':'%s %s' % (log_type, flight.logfile.name)})
    

    for evt in flight.flightevent_set.all():
        print evt
        timelineDictForEvt={"start":dt2jsts(evt.timestamp), "content":evt.get_eventType_display(), "comment":evt.comment}
        timelineDictForEvt['group']='Flight events'
        timelineDictForEvt['pk']=evt.pk
        #timelineDictForEvt['detectionMethod']=evt.detection_method
        
        #Text that explains how the event was created and link to confirm it if it was automatic
        if evt.automatically_detected:
            timelineDictForEvt['className']='autodetected'
            timelineDictForEvt['confirmed']='false'
        else:
            timelineDictForEvt['confirmed']='true'
        timelineEventList.append(timelineDictForEvt)

    return render(request, 'flight_detail.html',{
        'timeline_data':json.dumps(timelineEventList),
        'initial_plot':fltdata.initial_plot(flight),
        'object':flight})
예제 #2
0
def plotDataJSON(request):
    right_axis_msgfield=request.GET.get('right_axis')
    left_axis_msgfield=request.GET.get('left_axis')
    flight=request.GET.get('flight')
    
    rdataQuery=MavDatum.objects.filter(message__flight__slug=flight, msgField=right_axis_msgfield)
    right_axis_data=rdataQuery.values_list('message__timestamp','value')
    
    ldataQuery=MavDatum.objects.filter(message__flight__slug=flight, msgField=left_axis_msgfield)
    left_axis_data=ldataQuery.values_list('message__timestamp','value')
    right_axis_data= '['+','.join([r'[%.1f,%.1f]' % (dt2jsts(timestamp),value) for timestamp, value in right_axis_data])+']'
    left_axis_data= '['+','.join([r'[%.1f,%.1f]' % (dt2jsts(timestamp),value) for timestamp, value in left_axis_data])+']'
    data='[%s,%s]' % (right_axis_data,left_axis_data)
    return HttpResponse(data, content_type='application/json')
예제 #3
0
def sensor_plot_data(flight, msg_field):
    dataQ = logbrowse.models.MavDatum.objects.filter(message__flight=flight,
                                                     msgField=msg_field)
    vals = dataQ.values_list('message__timestamp', 'value')
    return ','.join([
        r'[%.1f,%.1f]' % (dt2jsts(timestamp), value)
        for timestamp, value in vals
    ])
예제 #4
0
def plotDataJSON(request):
    right_axis_msgfield = request.GET.get('right_axis')
    left_axis_msgfield = request.GET.get('left_axis')
    flight = request.GET.get('flight')

    rdataQuery = MavDatum.objects.filter(message__flight__slug=flight,
                                         msgField=right_axis_msgfield)
    right_axis_data = rdataQuery.values_list('message__timestamp', 'value')

    ldataQuery = MavDatum.objects.filter(message__flight__slug=flight,
                                         msgField=left_axis_msgfield)
    left_axis_data = ldataQuery.values_list('message__timestamp', 'value')
    right_axis_data = '[' + ','.join([
        r'[%.1f,%.1f]' % (dt2jsts(timestamp), value)
        for timestamp, value in right_axis_data
    ]) + ']'
    left_axis_data = '[' + ','.join([
        r'[%.1f,%.1f]' % (dt2jsts(timestamp), value)
        for timestamp, value in left_axis_data
    ]) + ']'
    data = '[%s,%s]' % (right_axis_data, left_axis_data)
    return HttpResponse(data, content_type='application/json')
예제 #5
0
def flight_index(request, pilot=None):
    if pilot:
        flights=Flight.objects.filter(pilot__username=pilot)
    else:
        flights=Flight.objects.all()
    timelineEventList=[]
    flightStartLocs=[]
    flightStartLocsJSON = {
        "type": "FeatureCollection", 
        "features": [
        {
            "type": "Feature", 
            "geometry":
                {
                    "type": "MultiPoint", 
                    "coordinates": flightStartLocs
                },
        },]
    };
    for flight in flights:
        #optimize this later-- should be single db transaction
        try:
            timelineEventList.append(
                {"start":flight.start_time().isoformat(),
                "end":flight.start_time().isoformat(),
                "content":"<a href=%s logpk=%s>%s</a>" % (flight.get_absolute_url(), flight.pk, flight.pk),
                "group":"flight",
                "test":"test"
                })
        except AttributeError:
            pass
        # Get the last GPS coordinate for each flight to add to the flight index map.
        # We use the last one because it's more likely to be a better fix that the first.
        try:
            lat, lon = flight.location()
            if lon != 0 and lat != 0: #TODO should actually check the GPS_STATUS messages to throw away points where there is no fix
                if flight.is_tlog:
                    lat=lat/1e7
                    lon=lon/1e7
                flightStartLocsJSON['features'].append(
                    {
                    "type":"Feature",
                    "geometry":{
                            "type":"Point",
                            "coordinates":[lon,lat]
                        },
                     "properties":{"number":unicode(flight.pk),"name":unicode(flight),"slug":flight.slug}
                     })
        #should be except DoesNotExist, find where to import that from
        except:
            pass    

    for video in FlightVideo.objects.all():
        vidDescription="<a href=%s>" % video.url
        #if video.onboard:
            #vidDescription+="Start of onboard video"
        #else:
            #vidDescription+="Start of offboard video"
        vidDescription+="</a>"
        try:
            timelineEventList.append(
                {"start":dt2jsts(video.start_time),
                "content":vidDescription,
                "group":"video"})
        except AttributeError:
            pass
    
    return render(request,
        'flight_list.html',
        {
        'object_list':flights,
        'timeline_data': json.dumps(timelineEventList),
        'flightStartLocs': json.dumps(flightStartLocsJSON)
        })
예제 #6
0
def sensor_plot_data(flight, msg_field):
    dataQ=logbrowse.models.MavDatum.objects.filter(message__flight=flight, msgField=msg_field)
    vals=dataQ.values_list('message__timestamp','value')
    return ','.join([r'[%.1f,%.1f]' % (dt2jsts(timestamp),value) for timestamp, value in vals])
예제 #7
0
def gps_timestamps(flight):
    #unfortunately the timestamps end up with L for 'long' in the JS unless we remove them here.
    #Actually, could probably do the multiplication by 1000 to convert to JS timestamp on the client side.
    #return str(longTstamps).replace('L','')
    return [dt2jsts(timestamp) for timestamp in flight.gps_times()]
예제 #8
0
 def start_time_js(self):
     return dt2jsts(self.start_time())
예제 #9
0
def gps_timestamps(flight):
    #unfortunately the timestamps end up with L for 'long' in the JS unless we remove them here.
    #Actually, could probably do the multiplication by 1000 to convert to JS timestamp on the client side.
    #return str(longTstamps).replace('L','')
    return [dt2jsts(timestamp) for timestamp in flight.gps_times()]
예제 #10
0
 def start_time_js(self):
     return dt2jsts(self.start_time())
예제 #11
0
def flight_index(request, pilot=None):
    if pilot:
        flights = Flight.objects.filter(pilot__username=pilot)
    else:
        flights = Flight.objects.all()
    timelineEventList = []
    flightStartLocs = []
    flightStartLocsJSON = {
        "type":
        "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "geometry": {
                    "type": "MultiPoint",
                    "coordinates": flightStartLocs
                },
            },
        ]
    }
    for flight in flights:
        #optimize this later-- should be single db transaction
        try:
            timelineEventList.append({
                "start":
                flight.start_time().isoformat(),
                "end":
                flight.start_time().isoformat(),
                "content":
                "<a href=%s logpk=%s>%s</a>" %
                (flight.get_absolute_url(), flight.pk, flight.pk),
                "group":
                "flight",
                "test":
                "test"
            })
        except AttributeError:
            pass
        # Get the last GPS coordinate for each flight to add to the flight index map.
        # We use the last one because it's more likely to be a better fix that the first.
        try:
            lat, lon = flight.location()
            if lon != 0 and lat != 0:  #TODO should actually check the GPS_STATUS messages to throw away points where there is no fix
                if flight.is_tlog:
                    lat = lat / 1e7
                    lon = lon / 1e7
                flightStartLocsJSON['features'].append({
                    "type": "Feature",
                    "geometry": {
                        "type": "Point",
                        "coordinates": [lon, lat]
                    },
                    "properties": {
                        "number": unicode(flight.pk),
                        "name": unicode(flight),
                        "slug": flight.slug
                    }
                })
        #should be except DoesNotExist, find where to import that from
        except:
            pass

    for video in FlightVideo.objects.all():
        vidDescription = "<a href=%s>" % video.url
        #if video.onboard:
        #vidDescription+="Start of onboard video"
        #else:
        #vidDescription+="Start of offboard video"
        vidDescription += "</a>"
        try:
            timelineEventList.append({
                "start": dt2jsts(video.start_time),
                "content": vidDescription,
                "group": "video"
            })
        except AttributeError:
            pass

    return render(
        request, 'flight_list.html', {
            'object_list': flights,
            'timeline_data': json.dumps(timelineEventList),
            'flightStartLocs': json.dumps(flightStartLocsJSON)
        })
예제 #12
0
def flight_detail(request, slug):
    print 'loading' + slug
    flight = Flight.objects.get(slug=slug)
    timelineEventList = []
    heartbeats = flight.mavmessage_set.filter(msgType='HEARTBEAT')

    #Timeline data construction
    for heartbeat in heartbeats:
        try:
            timelineEventList.append({
                "start": dt2jsts(heartbeat.timestamp),
                "content": "HB",
                "group": "Heartbeat"
            })
        except AttributeError:
            pass
    for video in flight.flightvideo_set.all():
        start_time = dt2jsts(flight.start_time() +
                             datetime.timedelta(seconds=video.delayVsLogstart))
        timelineDictForVid = {
            "start": start_time,
            "group": "Video",
            "editable": True
        }
        if video.onboard:
            timelineDictForVid['content'] = 'Start of onboard video '
        else:
            timelineDictForVid[
                'content'] = 'Start of offboard video ' + video.url
        timelineDictForVid['vidUrl'] = video.url
        timelineDictForVid['pk'] = video.pk
        timelineEventList.append(timelineDictForVid)

    #add start and end of log
    if flight.is_tlog:
        log_type = 'Mavlink telemetry log'
    else:
        log_type = 'APM dataflash log'
    timelineEventList.append({
        'start':
        dt2jsts(flight.start_time()),
        'end':
        dt2jsts(flight.end_time()),
        'group':
        'Logs',
        'content':
        '%s %s' % (log_type, flight.logfile.name)
    })

    for evt in flight.flightevent_set.all():
        print evt
        timelineDictForEvt = {
            "start": dt2jsts(evt.timestamp),
            "content": evt.get_eventType_display(),
            "comment": evt.comment
        }
        timelineDictForEvt['group'] = 'Flight events'
        timelineDictForEvt['pk'] = evt.pk
        #timelineDictForEvt['detectionMethod']=evt.detection_method

        #Text that explains how the event was created and link to confirm it if it was automatic
        if evt.automatically_detected:
            timelineDictForEvt['className'] = 'autodetected'
            timelineDictForEvt['confirmed'] = 'false'
        else:
            timelineDictForEvt['confirmed'] = 'true'
        timelineEventList.append(timelineDictForEvt)

    return render(
        request, 'flight_detail.html', {
            'timeline_data': json.dumps(timelineEventList),
            'initial_plot': fltdata.initial_plot(flight),
            'object': flight
        })