Пример #1
0
 def export_debug(self):
     """
     export all the AIS messages for a single AIS station
     pop open a file browser to allow the user to choose
     a directory to save the
     file and then save csv and jsonl to that location
     """
     dropdowntext = self.stnoptions.get()
     if dropdowntext != '':
         try:
             outpath = tkinter.filedialog.askdirectory()
             if outpath:
                 lookupmmsi = self.stnlookup[dropdowntext]
                 jsonlines, messagecsvlist = \
                     self.tabs.window.messagelog.debug_output(
                         mmsi=lookupmmsi)
                 export.write_json_lines(
                     jsonlines,
                     os.path.join(outpath,
                                  dropdowntext + '-ais-messages.jsonl'))
                 export.write_csv_file(
                     messagecsvlist,
                     os.path.join(outpath,
                                  dropdowntext + '-ais-messages.csv'))
                 tkinter.messagebox.showinfo('Export Files',
                                             'Export Successful')
             else:
                 tkinter.messagebox.showerror('Export Files',
                                              'User cancelled export.')
         except Exception as err:
             AISLOGGER.exception('export error')
             tkinter.messagebox.showerror(type(err).__name__, str(err))
     else:
         tkinter.messagebox.showerror('Export Files', self.nostnerr)
Пример #2
0
    def create_positions_csv(self, outputfile, dialect='excel'):
        """
        create a CSV file of all the position reports for this station

        Args:
            outputfile(str): path to output CSV file to
            dialect(str): excel for CSV, excel-tab for TSV
        """
        positionlines = []
        stndata = [self.mmsi, self.name, self.stnclass,
                   self.stntype, self.flag]
        header = ['Time', 'Latitude', 'Longitude', 'CoG',
                  'True Heading', 'Speed (knots)']
        if self.stnclass == 'A':
            moreheaders = ['Navigation Status', 'Turn Rate',
                           'Special Maneuver', 'Destination', 'ETA']
            header.extend(moreheaders)
        if self.stntype == 'SAR Aircraft':
            header[4] = 'Altitude (m)'
            header[5] = 'Ground Speed (knots)'
        positionlines.append(stndata)
        positionlines.append(header)
        for posrep in self.posrep:
            posrepline = []
            for item in header:
                try:
                    posrepline.append(posrep[item])
                except KeyError:
                    posrepline.append('')
            positionlines.append(posrepline)
        export.write_csv_file(positionlines, outputfile, dialect=dialect)
Пример #3
0
    def export_tsv(self):
        """
        pop open a file browser to allow the user to choose where to save the
        file and then save file to that location

        Raises:
            ExportAborted: if the user clicks cancel
        """
        outputfile = tkinter.filedialog.asksaveasfilename(
            defaultextension=".tsv",
            filetypes=(("tab seperated values", "*.tsv"), ("All Files",
                                                           "*.*")))
        if outputfile:
            tabledata = self.tabs.window.aistracker.create_table_data()
            export.write_csv_file(tabledata, outputfile, dialect='excel-tab')
        else:
            raise ExportAborted('Export cancelled by user.')
Пример #4
0
    def export_debug(self):
        """
        pop open a file browser to allow the user to choose where to save the
        file and then save file to that location

        Raises:
            ExportAborted: if the user clicks cancel
        """
        outpath = tkinter.filedialog.askdirectory()
        if outpath:
            jsonlines, messagecsvlist = \
                self.tabs.window.messagelog.debug_output()
            export.write_json_lines(
                jsonlines, os.path.join(outpath, 'ais-messages.jsonl'))
            export.write_csv_file(messagecsvlist,
                                  os.path.join(outpath, 'ais-messages.csv'))
        else:
            raise ExportAborted('Export cancelled by user.')