Beispiel #1
0
def test_parseDate(value, expected, pd_timestamp):
    if expected is None:
        with pytest.raises(ValueError):
            parseDate(value, pd_timestamp=pd_timestamp)
    else:
        expected = date(expected['year'], expected['month'], expected['day'])
        if pd_timestamp:
            expected = pd.Timestamp(expected)
        assert parseDate(value, pd_timestamp=pd_timestamp) == expected
Beispiel #2
0
    def removeRows(self, **kwargs):
        """ Remove row(s) from the DataFrame by date or index. 
        
            Pass either 'dates' or 'index' kwarg.
        
            Note that this assumes dates are unique in the object.
        """
        dates = kwargs.get("dates", None)
        if dates is not None:
            if isinstance(dates, str):
                dates = [dates]
            if not isinstance(dates, list):
                raise TypeError("CycleData.removeRows takes list of dates")

            idx = []
            for date in dates:
                idx += list(self.df[self.df['Date'] == parseDate(
                    date, pd_timestamp=True)].index)

            self.df.drop(idx, inplace=True)
            self.dataChanged.emit(None)

        index = kwargs.get("index", None)
        if index is not None:
            self.df.drop(index, inplace=True)
            self.dataChanged.emit(None)
    def test_tied_data(self, setup, qtbot, monkeypatch):
        new = {
            'Date': [parseDate("7 May 2021", pd_timestamp=True)],
            'Time': [parseDuration("00:42:11")],
            'Distance (km)': [25.08],
            'Calories': [375.1],
            'Gear': [6]
        }

        # don't need dialog to pop up
        monkeypatch.setattr(NewPBDialog, "exec_",
                            lambda *args: QDialog.Accepted)
        with qtbot.waitSignal(self.parent.data.dataChanged):
            self.parent.data.append(new)

        rowNums = [
            self.pb.bestSessions.verticalHeaderItem(i).text()
            for i in range(self.pb.bestSessions.rowCount())
        ]
        assert rowNums == ["1=", "1=", "3", "4", "5"]

        date0 = self.pb.bestSessions.item(0, 0).text()
        assert date0 == "07 May 2021"

        date1 = self.pb.bestSessions.item(1, 0).text()
        assert date1 == "04 May 2021"
Beispiel #4
0
 def __lt__(self, other):
     item0 = self.text()
     item1 = other.text()
     item0, item1 = [
         parseDate(item).strftime("%d %b %Y") for item in [item0, item1]
     ]
     value0 = dayMonthYearToFloat(item0)
     value1 = dayMonthYearToFloat(item1)
     return value0 < value1
def getNewData(key):
    newDataParams = {
        'best month and best session':
        ({
            'Date': [parseDate("6 May 2021", pd_timestamp=True)],
            'Time': [parseDuration("00:42:15")],
            'Distance (km)': [25.1],
            'Calories': [375.4],
            'Gear': [6]
        },
         "<center><span>New #2 avg. speed - </span><span style='color: #f7f13b'>35.64km/h</span>!<br>and<br><span>New best month - </span><span style='color: #f7f13b'>May 2021</span>!<br><span>Congratulations!</span></center>",
         "<b>May 2021</b>: <b>150.72</b> km, <b>04:16:35</b> hours, <b>2254.2</b> calories"
         ),
        'best month':
        ({
            'Date': [parseDate("6 May 2021", pd_timestamp=True)],
            'Time': [parseDuration("00:45:15")],
            'Distance (km)': [25.1],
            'Calories': [375.4],
            'Gear': [6]
        },
         "<center><span>New best month - </span><span style='color: #f7f13b'>May 2021</span>!<br><span>Congratulations!</span></center>",
         "<b>May 2021</b>: <b>150.72</b> km, <b>04:19:35</b> hours, <b>2254.2</b> calories"
         ),
        'best session':
        ({
            'Date': [parseDate("6 April 2021", pd_timestamp=True)],
            'Time': [parseDuration("00:42:15")],
            'Distance (km)': [25.1],
            'Calories': [375.4],
            'Gear': [6]
        },
         "<center><span>New #2 avg. speed - </span><span style='color: #f7f13b'>35.64km/h</span>!<br><span>Congratulations!</span></center>",
         "<b>April 2021</b>: <b>155.93</b> km, <b>04:27:03</b> hours, <b>2332.1</b> calories"
         )
    }
    return newDataParams[key]
    def test_new_data_different_column(self, setup, qtbot, monkeypatch,
                                       variables):
        # test dialog message when table is sorted by Time
        new = {
            'Date': [parseDate("7 April 2021", pd_timestamp=True)],
            'Time': [parseDuration("01:05:03")],
            'Distance (km)': [25.08],
            'Calories': [375.1],
            'Gear': [6]
        }

        self.pb.bestSessions.horizontalHeader().sectionClicked.emit(1)
        qtbot.wait(variables.shortWait)

        # don't need dialog to pop up
        monkeypatch.setattr(NewPBDialog, "exec_",
                            lambda *args: QDialog.Accepted)
        with qtbot.waitSignal(self.parent.data.dataChanged):
            self.parent.data.append(new)

        expected = "<center><span>New #1 time - </span><span style='color: #f7f13b'>01:05:03</span>!<br><span>Congratulations!</span></center>"
        assert self.pb.newPBdialog.label.text() == expected
Beispiel #7
0
    def combineRows(self, date):
        """ Combine all rows in the dataframe with the given data. """
        i0, *idx = self.df[self.df['Date'] == parseDate(
            date, pd_timestamp=True)].index

        combinable = ['Time', 'Distance (km)', 'Calories', 'Avg. speed (km/h)']

        for i in idx:
            for name in combinable:
                if name == 'Time':
                    t0 = hourMinSecToFloat(
                        parseDuration(self.df.iloc[i0][name]))
                    t1 = hourMinSecToFloat(parseDuration(
                        self.df.iloc[i][name]))
                    newValue = floatToHourMinSec(t0 + t1)
                    self.df.at[i0, name] = newValue
                elif name == 'Avg. speed (km/h)':
                    self.df.at[i0, name] = self.df['Distance (km)'][
                        i0] / hourMinSecToFloat(self.df['Time'][i0])
                else:
                    self.df.at[i0, name] += self.df.iloc[i][name]

        self.df.drop(idx, inplace=True)
        self.dataChanged.emit(i0)
Beispiel #8
0
def test_parseDate_value_error():
    with pytest.raises(ValueError):
        parseDate("25 Jn 2021")
Beispiel #9
0
def test_parseDate_type_error():
    with pytest.raises(TypeError):
        parseDate(25)