示例#1
0
 def test_localewise_time_ago(self):
   ref = datetime.datetime(2020, 3, 27, 16, 30).timestamp()
   self.assertEqual(time_utils.localewise_time_ago(None, None, ref), 'never')
   ts = datetime.datetime(2020, 3, 27, 16, 30).timestamp()
   self.assertEqual(time_utils.localewise_time_ago(ts, None, ref), 'now')
   ts = datetime.datetime(2020, 3, 27, 16, 25).timestamp()
   self.assertEqual(
     time_utils.localewise_time_ago(ts, None, ref), '5 minute ago')
示例#2
0
    def prepare_data(self, icu, locale) -> list:
        link = {'key': 'ICU (update link)', 'value': icu.name}
        link['link'] = self.link_fn(icu.users[0], icu) if icu.users else None
        result = [link]

        bed_count = icu.bed_counts[-1] if icu.bed_counts else store.BedCount()
        bed_count_dict = bed_count.to_dict(max_depth=0)
        last = bed_count_dict.pop('create_date', None)
        last = None if last is None else last.timestamp()
        display_date = time_utils.localewise_time_ago(last, locale=locale)
        stale = time_utils.is_stale(
            last, days_threshold=self.config.server.num_days_for_stale)
        result.append({
            'key': 'since_update',
            'value': display_date,
            'warning': stale,
            'sort_value': 0 if last is None else last,
            'link': False,
        })
        to_pop = [
            'rowid', 'icu_id', 'message', 'create_date', 'last_modified', 'icu'
        ]
        for key in to_pop:
            bed_count_dict.pop(key, None)
        result.extend(self.format_list_item(bed_count_dict))
        return result
示例#3
0
    def get_icu_data(self) -> List[Dict]:
        """Get bedcounts and augment it with extra information."""
        locale = self.get_user_locale()
        # TODO(olivier): pass the user here!
        bedcounts = self.db.get_visible_bed_counts_for_user(None, force=True)
        data = []
        for count in bedcounts:
            curr = count.to_dict()

            last = count.last_modified
            if last is not None:
                last = last.timestamp()
            curr['since_update'] = time_utils.localewise_time_ago(
                last, locale=locale)
            curr['update_ts'] = last

            free = 0 if count.n_covid_free is None else count.n_covid_free
            occ = 0 if count.n_covid_occ is None else count.n_covid_occ
            curr['n_covid_tot'] = free + occ
            curr['link'] = self.updater.get_url(count.icu.icu_id,
                                                count.icu.name)
            curr['icu_name'] = count.icu.name
            for key in ['last_modified', 'create_date']:
                curr.pop(key, None)

            data.append(curr)
        return data
示例#4
0
 def get_icu_data_by_id(self, icu_id, locale=None, def_val=0):
   """Returns the dictionary of counts for the given icu."""
   bed_count = self.db.get_bed_count_for_icu(icu_id)
   bed_count = bed_count if bed_count is not None else store.BedCount()
   # In case there is a weird corner case, we don't want to crash the form:
   last_update = bed_count.last_modified
   if last_update is not None:
     last_update = last_update.timestamp()
   data = bed_count.to_dict()
   apply_default(data, value=def_val, prefix='n_')
   data['since_update'] = time_utils.localewise_time_ago(last_update, locale)
   data['home_route'] = home.HomeHandler.ROUTE
   data['update_route'] = self.ROUTE
   return data
示例#5
0
    def prepare_data(self, bed_count) -> list:
        icu = bed_count.icu
        result = [{
            'key': 'icu (update link)',
            'value': icu.name,
            'link': self.link_fn(icu.icu_id, icu.name)
        }]

        bed_count_dict = bed_count.to_dict(max_depth=0)
        locale = self.get_user_locale()
        last = bed_count_dict.pop('last_modified').timestamp()
        for key in ['rowid', 'icu_id', 'message', 'create_date']:
            bed_count_dict.pop(key, None)
        bed_count_dict['since_update'] = time_utils.localewise_time_ago(
            last, locale=locale)
        result.extend(self.format_list_item(bed_count_dict))

        return result