Esempio n. 1
0
    def get_departure_arrival_date(self, p_trip='', p_trip_event='') -> int:
        """
        Getter method.
        Returns the s/c's departure or arrival date, for the selected p_trip,
        and for the passed p_trip_event.
        Example:
         - p_trip = 'Earth - Mars'
        - p_trip_event = 'Launching'

        @param p_trip: 'Earth - Mars' or 'Mars - Earth'
        @param p_trip_event: 'Launching' or 'Landing'
        @return: the date
        """
        # Are there selected trajectories for this s/c? There should be.
        if self.get_trajectory_selection_status() != 0:
            # Get the trajectory/ies.
            the_trajectory = []
            if self.get_has_return_trajectory():
                if p_trip == 'Earth - Mars':
                    the_trajectory = list(self._trajectory1)
                elif p_trip == 'Mars - Earth':
                    the_trajectory = list(self._trajectory2)
            else:
                if p_trip == 'Earth - Mars':
                    the_trajectory = list(self._trajectory)

            # Get the departure/arrival date.
            the_date = 0
            if p_trip_event == 'Launching':
                the_date = QDate.toJulianDay(the_trajectory[0])
            elif p_trip_event == 'Landing':
                the_date = QDate.toJulianDay(the_trajectory[1])

            return the_date
    def convert_simple_dats_filter_to_query_format(a_filter):
        """
        Convert a human readable filter to a machine friendly one.

        Example of input filter: ['Departs', 'Earth', 'On', '01-05-2020']
        """
        # TODO: Warning! if-else labyrinth following... Not efficient but not needed at this stage.
        action = a_filter[0]
        planet = a_filter[1]
        # No importa, the calling function knows if the spc is departing/arriving to/from Earth/Mars.
        operator = a_filter[2]
        date = a_filter[3]

        # Convert action to query format (e.g. the table column's name).
        if action == 'Departs':
            action = 'DepDates'
        elif action == 'Arrives':
            action = 'ArrivDates'

        # Convert planet to query format.
        pass

        # Convert operator to query format.
        if operator == 'On':
            operator = '=='
        elif operator == 'Before':
            operator = '<='
        elif operator == 'After':
            operator = '>='

        # Convert date to query format.
        date = QDate.toJulianDay(QDate.fromString(date, 'dd-MM-yyyy'))

        return [action, planet, operator, date]
    def clicked_pcp_viewer(self):
        """
        When user clicks over 'PCP Viewer' btn, the current pcp being displayed should be sent to matlab and a contour
        plot generated.
        The user selects the desired trajectory, and when closing the window, the selected trajectory appears selected
        back in the python app.
        """
        sonet_log(SonetLogType.INFO, 'SonetMainWindow.clicked_pcp_viewer')
        # self.statusbar.showMessage('Not yet implemented :).', SONET_MSG_TIMEOUT)

        # Get the current displayed pcp, as dataframe.
        df = self.sonet_pcp_tabs_qtw.currentWidget().children()[1].model()._data

        # Check.
        if df is None:
            self.statusbar.showMessage('No PCP selected.', SONET_MSG_TIMEOUT)
            return
        elif df.empty:
            self.statusbar.showMessage('No PCP selected.', SONET_MSG_TIMEOUT)
            return

        # Save it to a temporary mat file, which is read by matlab.
        if self.sonet_pcp_tabs_qtw.currentWidget().objectName() == 'sonet_pcp_table_transit_1':
            departure_planet = 'Earth'
            arrival_planet = 'Mars'
        else:
            departure_planet = 'Mars'
            arrival_planet = 'Earth'

        mat_file = SONET_DATA_DIR + 'pcp_viewer_tmp.mat'
        savemat(mat_file, {'departure_planet': departure_planet,
                           'arrival_planet': arrival_planet,
                           'jd0': QDate.toJulianDay(df.iloc[0].DepDates),
                           'cal0': [df.iloc[0].DepDates.year(), df.iloc[0].DepDates.month(), df.iloc[0].DepDates.day()],
                           'departure_dates': df.DepDates.apply(QDate.toJulianDay).tolist(),
                           'arrival_dates': df.ArrivDates.apply(QDate.toJulianDay).tolist(),
                           'm_departure_dates': df.attrs['m_departure_dates'], # This are the original dep dates in the mat file, before filtering trajectories by max dvt.
                           'tofs': df.tof.tolist(),
                           'm_tofs': df.attrs['m_tofs'], # This are the original dep dates in the mat file, before filtering trajectories by max dvt.
                           'dvd': df.dvd.tolist(),
                           'dva': df.dva.tolist(),
                           'dvt': df.dvt.tolist(),
                           'theta': df.theta.tolist()})  # In degrees!

        # Read mat file with matlab, display pcp plot, and return last selected trajectory when closed the app.
        selected_trajectory = matlab_engine.PCP_Viewer(mat_file, nargout=1)
        self.clicked_select_trajectory(p_called_from_pcp_viewer=True, p_pcp_viewer_selected_trajectory=int(selected_trajectory))

        print(df.iloc[int(selected_trajectory)])