예제 #1
0
파일: models.py 프로젝트: xgds/xgds_video
 def getDict(self):
     return {"directoryName": self.directoryName,
             "segNumber": self.segNumber,
             "indexFileName": self.indexFileName,
             "source": self.source.getDict(),
             "startTime": util.pythonDatetimeToJSON(self.startTime), # util.convertUtcToLocal(self.startTime)),
             "endTime": util.pythonDatetimeToJSON(self.endTime), # util.convertUtcToLocal(self.endTime)),
             "timeZone": settings.XGDS_VIDEO_TIME_ZONE['name'],
             "settings": self.settings.getDict(),
             "episode": self.episode.getDict()}
예제 #2
0
파일: models.py 프로젝트: xgds/xgds_video
    def getDict(self):
        episodeStartTime = None
        episodeEndTime = None

        if self.startTime:
            episodeStartTime = util.pythonDatetimeToJSON(self.startTime)

        if self.endTime:  # if endTime is none (when live stream has not ended)
            episodeEndTime = util.pythonDatetimeToJSON(self.endTime)

        return {"shortName": self.shortName,
                "startTime": episodeStartTime,
                "endTime": episodeEndTime}
예제 #3
0
 def getDict(self):
     return {
         "directoryName": self.directoryName,
         "segNumber": self.segNumber,
         "indexFileName": self.indexFileName,
         "source": self.source.getDict(),
         "startTime": util.pythonDatetimeToJSON(
             self.startTime),  # util.convertUtcToLocal(self.startTime)),
         "endTime": util.pythonDatetimeToJSON(
             self.endTime),  # util.convertUtcToLocal(self.endTime)),
         "timeZone": settings.XGDS_VIDEO_TIME_ZONE['name'],
         "settings": self.settings.getDict(),
         "episode": self.episode.getDict()
     }
예제 #4
0
    def getDict(self):
        episodeStartTime = None
        episodeEndTime = None

        if self.startTime:
            episodeStartTime = util.pythonDatetimeToJSON(self.startTime)

        if self.endTime:  # if endTime is none (when live stream has not ended)
            episodeEndTime = util.pythonDatetimeToJSON(self.endTime)

        return {
            "shortName": self.shortName,
            "startTime": episodeStartTime,
            "endTime": episodeEndTime
        }
예제 #5
0
def displayRecordedVideo(request,
                         flightName=None,
                         sourceShortName=None,
                         time=None):
    """ TODO flightName is actually groupName """
    """
    Returns first segment of all sources that are part of a given episode.
    Used for both playing back videos from active episode and also
    for playing videos associated with each note.
    """
    requestedTime = ""
    active = False
    episode = {}
    if time is not None:
        # TODO: this is a duplicate path for playing back video at a certain time, it is legacy from PLRP
        # and was not fully working there; merge these 2 ways of playing back from a time.
        # time is passed as string (yy-mm-dd hh:mm:ss)
        try:
            requestedTime = datetime.datetime.strptime(time,
                                                       "%Y-%m-%d %H:%M:%S")
        except:
            requestedTime = dateparse.parse_datetime(time)
        requestedTime = util.pythonDatetimeToJSON(
            requestedTime)  # util.convertUtcToLocal(requestedTime))

    GET_ACTIVE_EPISODE_METHOD = getClassByName(
        settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    activeepisode = GET_ACTIVE_EPISODE_METHOD()

    # this happens when user clicks on a flight name to view video
    if flightName:
        GET_EPISODE_FROM_NAME_METHOD = getClassByName(
            settings.XGDS_VIDEO_GET_EPISODE_FROM_NAME)
        episode = GET_EPISODE_FROM_NAME_METHOD(flightName)
        if (episode != None and episode == activeepisode):
            active = True

    # this happens when user looks for live recorded
    if not episode:
        episode = activeepisode
        active = True
    if not episode:
        message = 'Video not found'
        if flightName:
            message += ' for ' + flightName
        else:
            message += ': no live video'
        messages.add_message(request, messages.ERROR, message)
        return redirect(reverse('error'))

    if episode:
        if not flightName:
            flightName = episode.shortName

    # get the segments
    segments = episode.videosegment_set.all()
    if not segments:
        msg = 'Video segments not found '
        if flightName:
            msg = msg + flightName
            return recordedVideoError(request, msg)

    sourceShortName = str(sourceShortName)
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(shortName=sourceShortName)
            segments = segments.filter(source=source)
        except:
            pass

    sources = []
    segmentsDict = {}  # dictionary of segments (in JSON) within given episode
    sourceVehicle = {}
    index = 0
    distinctSources = segments.values('source').distinct()
    for sourceDict in distinctSources:
        source = SOURCE_MODEL.get().objects.get(pk=sourceDict['source'])
        sources.append(source)
        sourceVehicle[source.shortName] = source.vehicleName
        sourceSegments = segments.filter(source=source)
        segmentsDict[source.shortName] = [
            seg.getDict() for seg in sourceSegments
        ]
        form = buildNoteForm([episode], source, request, {'index': index})
        source.form = form
        index = index + 1

    if flightName:
        if flightName.find('_') == -1:
            fullFlightName = flightName + "_" + sources[0].shortName
        else:
            fullFlightName = flightName
        GET_TIMEZONE_FROM_NAME_METHOD = getClassByName(
            settings.XGDS_VIDEO_GET_TIMEZONE_FROM_NAME)
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(str(fullFlightName))
    else:
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(None)

    if not segmentsDict:
        return recordedVideoError(request,
                                  "No video segments found " + flightName)
    segmentsJson = json.dumps(segmentsDict,
                              sort_keys=True,
                              indent=4,
                              cls=DatetimeJsonEncoder)
    episodeJson = json.dumps(episode.getDict())

    theTemplate = 'xgds_video/video_recorded_playbacks.html'
    if active:
        theTemplate = 'xgds_video/video_active_playbacks.html'

    ctx = {
        'segmentsJson': segmentsJson,
        'episode': episode,
        'isLive': active,
        'episodeJson': episodeJson,
        'noteTimeStamp':
        requestedTime,  # in string format yy-mm-dd hh:mm:ss (in utc. converted to local time in js)
        'sources': sources,
        'flightName': flightName,
        'flightTZ': flightTimezone,
        'sourceVehicle': json.dumps(sourceVehicle),
        'SSE': settings.XGDS_SSE
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(
            settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    return render_to_response(theTemplate,
                              ctx,
                              context_instance=RequestContext(request))
예제 #6
0
파일: views.py 프로젝트: xgds/xgds_video
def displayRecordedVideo(request, flightName=None, sourceShortName=None, time=None):
    """ TODO flightName is actually groupName """
    """
    Returns first segment of all sources that are part of a given episode.
    Used for both playing back videos from active episode and also
    for playing videos associated with each note.
    """
    requestedTime = ""
    active = False
    episode = {}
    if time is not None:
        # TODO: this is a duplicate path for playing back video at a certain time, it is legacy from PLRP
        # and was not fully working there; merge these 2 ways of playing back from a time.
        # time is passed as string (yy-mm-dd hh:mm:ss)
        try:
            requestedTime = datetime.datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
        except:
            requestedTime = dateparse.parse_datetime(time)
        requestedTime = util.pythonDatetimeToJSON(requestedTime)  # util.convertUtcToLocal(requestedTime))

    GET_ACTIVE_EPISODE_METHOD = getClassByName(settings.XGDS_VIDEO_GET_ACTIVE_EPISODE)
    activeepisode = GET_ACTIVE_EPISODE_METHOD()

    # this happens when user clicks on a flight name to view video
    if flightName:
        GET_EPISODE_FROM_NAME_METHOD = getClassByName(settings.XGDS_VIDEO_GET_EPISODE_FROM_NAME)
        episode = GET_EPISODE_FROM_NAME_METHOD(flightName)
        if (episode != None and episode == activeepisode):
            active = True

    # this happens when user looks for live recorded
    if not episode:
        episode = activeepisode
        active = True
    if not episode:
        message = 'Video not found'
        if flightName:
            message += ' for ' + flightName
        else:
            message += ': no live video'
        messages.add_message(request, messages.ERROR, message)
        return redirect(reverse('error'))

    if episode:
        if not flightName:
            flightName = episode.shortName

    # get the segments
    segments = episode.videosegment_set.all()
    if not segments:
        msg = 'Video segments not found '
        if flightName:
            msg = msg + flightName
            return recordedVideoError(request, msg)

    sourceShortName = str(sourceShortName)
    if sourceShortName == 'None':
        sourceShortName = None
    if sourceShortName:
        try:
            source = SOURCE_MODEL.get().objects.get(shortName=sourceShortName)
            segments = segments.filter(source=source)
        except:
            pass

    sources = []
    segmentsDict = {}  # dictionary of segments (in JSON) within given episode
    sourceVehicle = {}
    index = 0
    distinctSources = segments.values('source').distinct()
    for sourceDict in distinctSources:
        source = SOURCE_MODEL.get().objects.get(pk=sourceDict['source'])
        sources.append(source)
        sourceVehicle[source.shortName] = source.vehicleName
        sourceSegments = segments.filter(source=source)
        segmentsDict[source.shortName] = [seg.getDict() for seg in sourceSegments]
        form = buildNoteForm([episode], source, request, {'index':index})
        source.form = form
        index = index + 1

    if flightName:
        if flightName.find('_') == -1:
            fullFlightName = flightName + "_" + sources[0].shortName
        else:
            fullFlightName = flightName
        GET_TIMEZONE_FROM_NAME_METHOD = getClassByName(settings.XGDS_VIDEO_GET_TIMEZONE_FROM_NAME)
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(str(fullFlightName))
    else:
        flightTimezone = GET_TIMEZONE_FROM_NAME_METHOD(None)

    if not segmentsDict:
        return recordedVideoError(request, "No video segments found " + flightName)
    segmentsJson = json.dumps(segmentsDict, sort_keys=True, indent=4, cls=DatetimeJsonEncoder)
    episodeJson = json.dumps(episode.getDict())

    theTemplate = 'xgds_video/map_recorded_playbacks.html'
    if active:
        theTemplate = 'xgds_video/map_active_playbacks.html'

    noteModelName = str(NOTE_MODEL.get().cls_type())
    noteForm = getClassByName(settings.XGDS_NOTES_BUILD_NOTES_FORM)({'vehicle__name':sourceShortName,
                                                                     'flight__group_name':flightName})
    ctx = {
        'segmentsJson': segmentsJson,
        'episode': episode,
        'isLive': active,
        'episodeJson': episodeJson,
        'noteTimeStamp': requestedTime,  # in string format yy-mm-dd hh:mm:ss (in utc. converted to local time in js)
        'sources': sources,
        'flightName': flightName,
        'flightTZ': flightTimezone,
        'sourceVehicle': json.dumps(sourceVehicle),
        'SSE': settings.XGDS_SSE,
        'modelName': noteModelName,
        'searchModelDict': {noteModelName:settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]},
        'searchForms': {noteModelName: [noteForm,settings.XGDS_MAP_SERVER_JS_MAP[noteModelName]] },
        'app': 'xgds_map_server/js/search/mapViewerSearchApp.js',
        'templates': get_handlebars_templates(list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS), 'XGDS_MAP_SERVER_HANDLEBARS_DIRS'),
    }

    if settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT:
        extraVideoContextFn = getClassByName(settings.XGDS_VIDEO_EXTRA_VIDEO_CONTEXT)
        extraVideoContextFn(ctx)

    return render_to_response(theTemplate,
                              ctx,
                              context_instance=RequestContext(request))