Пример #1
0
 def _repr_pretty_(self, p: pretty.PrettyPrinter, cycle: bool) -> None:
   del cycle  # Unused.
   icon = client_textify.online_icon(self._client.data.last_seen_at)
   last_seen = client_textify.last_seen(self._client.data.last_seen_at)
   data = '{icon} {id} @ {host} ({last_seen})'.format(
       icon=icon, id=self.id, last_seen=last_seen, host=self.hostname)
   p.text(data)
Пример #2
0
def _add_last_seen_column(df: pd.DataFrame) -> pd.DataFrame:
    """Adds last seen time ago column to a dataframe of clients.

  Args:
    df: Dataframe of clients.

  Returns:
    Dataframe with a column added.
  """
    if 'last_seen_at' not in df.columns:
        return df

    seen_ago = [client_textify.last_seen(tm) for tm in df['last_seen_at']]
    df.insert(0, 'last_seen_ago', pd.Series(seen_ago))
    return df
Пример #3
0
    def testFuture(self):
        current_time_secs = 1560000000
        last_seen_at = (current_time_secs + 1) * (10**6)

        with mock.patch.object(time, 'time', return_value=current_time_secs):
            self.assertEqual(client.last_seen(last_seen_at), 'in 1 seconds')
Пример #4
0
    def testDays(self):
        current_time_secs = 1560000000
        last_seen_at = (current_time_secs - 4 * 60 * 60 * 24) * (10**6)

        with mock.patch.object(time, 'time', return_value=current_time_secs):
            self.assertEqual(client.last_seen(last_seen_at), '4 days ago')
Пример #5
0
    def testMinutes(self):
        current_time_secs = 1560000000
        last_seen_at = (current_time_secs - 2 * 60) * (10**6)

        with mock.patch.object(time, 'time', return_value=current_time_secs):
            self.assertEqual(client.last_seen(last_seen_at), '2 minutes ago')