Example #1
0
    def get(self, request, flightID):

        try:
            flight = Flight.objects.get(id=flightID)
        except Flight.DoesNotExist:
            return Response({}, status=status.HTTP_404_NOT_FOUND)

        mongo_db_handle, mongo_connection = get_mongo_connection_handle()

        # Do we have a collection for the flight in the MongoDB instance?
        # If not, this means the flight has been created, but no data yet exists for it.
        if not str(flight.id) in mongo_db_handle.list_collection_names():
            return Response({}, status=status.HTTP_204_NO_CONTENT)

        # If we get here, then there is a collection -- and we can get the data for it.
        mongo_collection_handle = get_mongo_collection_handle(
            mongo_db_handle, str(flight.id))

        # Get all of the data.
        # This also omits the _id field that is added by MongoDB -- we don't need it.
        log_entries = mongo_collection_handle.find({}, {'_id': False})
        stream = io.StringIO()

        stream.write(f'[{os.linesep}{os.linesep}')

        # Get the count and if it matches the length...
        log_entries_list = list(log_entries)
        entries = {}

        df = pd.json_normalize(log_entries_list)
        if ('eventDetails.name' in df.keys()):

            unique = df['eventDetails.name'].unique()
            for name in (unique):
                event = df[df['eventDetails.name'] == name]
                sortedEvent = event.sort_values(
                    by="timestamps.sinceSessionStartMillis")
                sortedTime = sortedEvent[
                    "timestamps.sinceSessionStartMillis"].to_numpy()
                sortedIDs = sortedEvent["sessionID"].to_numpy()
                entries[name] = {}
                entries[name]["timestamps"] = [int(x) for x in sortedTime]
                entries[name]["sessionIDs"] = sortedIDs.tolist()

            stream.write(f'{json.dumps(entries)}{os.linesep}{os.linesep}')

            stream.write(f']')
            stream.seek(0)

            response = StreamingHttpResponse(stream,
                                             content_type='application/json')
            response[
                'Content-Disposition'] = f'attachment; filename=logui-{str(flight.id)}.log'

            mongo_connection.close()
            return response
Example #2
0
    def get(self, request, flightID, sessionID):

        try:
            flight = Flight.objects.get(id=flightID)
        except Flight.DoesNotExist:
            return Response({}, status=status.HTTP_404_NOT_FOUND)

        mongo_db_handle, mongo_connection = get_mongo_connection_handle()

        # Do we have a collection for the flight in the MongoDB instance?
        # If not, this means the flight has been created, but no data yet exists for it.
        if not str(flight.id) in mongo_db_handle.list_collection_names():
            return Response({}, status=status.HTTP_204_NO_CONTENT)

        # If we get here, then there is a collection -- and we can get the data for it.
        mongo_collection_handle = get_mongo_collection_handle(
            mongo_db_handle, str(flight.id))

        # Get all of the data.
        # This also omits the _id field that is added by MongoDB -- we don't need it.
        log_entries = mongo_collection_handle.find(
            {'sessionID': str(sessionID)}, {'_id': False})
        stream = io.StringIO()

        stream.write(f'[{os.linesep}{os.linesep}')

        # Get the count and if it matches the length...
        no_entries = log_entries.count()
        counter = 0

        for entry in log_entries:
            if counter == (no_entries - 1):
                stream.write(f'{json.dumps(entry)}{os.linesep}{os.linesep}')
                continue

            stream.write(f'{json.dumps(entry)},{os.linesep}{os.linesep}')
            counter += 1

        stream.write(f']')
        stream.seek(0)

        response = StreamingHttpResponse(stream,
                                         content_type='application/json')
        response[
            'Content-Disposition'] = f'attachment; filename=logui-{str(flight.id)}.log'

        mongo_connection.close()
        return response
Example #3
0
    def handle_log_events(self, request_dict):
        if not self._session:
            self.close(code=4006)
            return

        for item in request_dict['payload']['items']:
            print(item)
            if item['eventType'] == 'statusEvent' and item['eventDetails'][
                    'type'] == 'stopped':
                self._session.client_end_timestamp = date_parser.parse(
                    item['timestamps']['eventTimestamp'])
                self._session.server_end_timestamp = datetime.now()
                self._session.save()

            item['applicationID'] = str(self._application.id)
            item['flightID'] = str(self._flight.id)

            if not self._mongo_collection:
                self._mongo_collection = get_mongo_collection_handle(
                    self._mongo_db_handle, str(self._flight.id))
            # print(item)
            self._mongo_collection.insert(item)
Example #4
0
    def get(self, request, flightID):

        try:
            flight = Flight.objects.get(id=flightID)
        except Flight.DoesNotExist:
            return Response({}, status=status.HTTP_404_NOT_FOUND)

        mongo_db_handle, mongo_connection = get_mongo_connection_handle()

        # Do we have a collection for the flight in the MongoDB instance?
        # If not, this means the flight has been created, but no data yet exists for it.
        if not str(flight.id) in mongo_db_handle.list_collection_names():
            return Response({}, status=status.HTTP_204_NO_CONTENT)

        # If we get here, then there is a collection -- and we can get the data for it.
        mongo_collection_handle = get_mongo_collection_handle(
            mongo_db_handle, str(flight.id))

        # Get all of the data.
        # This also omits the _id field that is added by MongoDB -- we don't need it.
        log_entries = mongo_collection_handle.find({}, {'_id': False})
        stream = io.StringIO()

        stream.write(f'[{os.linesep}{os.linesep}')

        # Get the count and if it matches the length...
        # no_entries = log_entries.count()
        log_entries_list = list(log_entries)
        entries = {}

        # log_entries_json = json.loads(log_entries_list)
        df = pd.json_normalize(log_entries_list)
        unique = df['sessionID'].unique()
        all_values = []
        for i, id in enumerate(unique):
            if id is None:
                continue
            session = df[df['sessionID'] == id]
            entries[id] = {}
            for func in statisticMethods:
                entry = func(session)
                if isinstance(entry, dict) and "average" in entry.keys(
                ) and "total" in entry.keys(
                ):  #To do: make adaptive for all keys in dict
                    entries[id][func.__name__ + "_total"] = entry["total"]
                    entries[id][func.__name__ + "_average"] = entry["average"]
                    if func.__name__ + "_total" not in all_values:
                        all_values.append(func.__name__ + "_total")
                        all_values.append(func.__name__ + "_average")
                else:
                    entries[id][func.__name__] = entry
                    if func.__name__ not in all_values:
                        all_values.append(func.__name__)
        stream.write(f'{json.dumps(entries)},{os.linesep}{os.linesep}')
        stream.write(f'{json.dumps(all_values)}{os.linesep}{os.linesep}')

        stream.write(f']')
        stream.seek(0)

        response = StreamingHttpResponse(stream,
                                         content_type='application/json')
        response[
            'Content-Disposition'] = f'attachment; filename=logui-{str(flight.id)}.log'

        mongo_connection.close()
        return response
Example #5
0
    def get(self, request, flightID):

        try:
            flight = Flight.objects.get(id=flightID)
        except Flight.DoesNotExist:
            return Response({}, status=status.HTTP_404_NOT_FOUND)

        mongo_db_handle, mongo_connection = get_mongo_connection_handle()

        # Do we have a collection for the flight in the MongoDB instance?
        # If not, this means the flight has been created, but no data yet exists for it.
        if not str(flight.id) in mongo_db_handle.list_collection_names():
            return Response({}, status=status.HTTP_204_NO_CONTENT)

        # If we get here, then there is a collection -- and we can get the data for it.
        mongo_collection_handle = get_mongo_collection_handle(
            mongo_db_handle, str(flight.id))

        # Get all of the data.
        # This also omits the _id field that is added by MongoDB -- we don't need it.
        log_entries = mongo_collection_handle.find({}, {'_id': False})
        stream = io.StringIO()

        stream.write(f'[{os.linesep}{os.linesep}')

        # Get the count and if it matches the length...
        # no_entries = log_entries.count()
        log_entries_list = list(log_entries)
        entries = {}

        df = pd.json_normalize(log_entries_list)
        unique = df['sessionID'].unique()
        all_values = []
        for i, id in enumerate(unique):
            if id is None:
                continue
            session = df[df['sessionID'] == id]
            if ('eventDetails.name' in session.keys()):
                unique_vals = session['eventDetails.name'].unique()
                value_counts = session['eventDetails.name'].value_counts()
                entries[id] = {}
                for val in unique_vals:
                    if (not (isinstance(val, float) and math.isnan(val))):
                        if val not in all_values:
                            all_values.append(val)
                        count = value_counts.get(val)
                        entries[id][val] = int(count)

        stream.write(f'{json.dumps(entries)},{os.linesep}{os.linesep}')
        stream.write(f'{json.dumps(all_values)}{os.linesep}{os.linesep}')

        stream.write(f']')
        stream.seek(0)

        response = StreamingHttpResponse(stream,
                                         content_type='application/json')
        response[
            'Content-Disposition'] = f'attachment; filename=logui-{str(flight.id)}.log'

        mongo_connection.close()
        return response