# 注册统计

**URL:** https://meta.discourse.org/t/sign-up-stats/311595
**Category:** Data & reporting
**Created:** [2024年六月11日 15:49 UTC](https://meta.discourse.org/t/sign-up-stats/311595 "2024-06-11T15:49:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Isambard](https://avatars.discourse-cdn.com/v4/letter/i/858c86/32.png) [@Isambard](https://meta.discourse.org/u/Isambard)
#### Post date: [2024年六月11日 15:49 UTC](https://meta.discourse.org/t/sign-up-stats/311595/1 "2024-06-11T15:49:21Z")

</div>

继续讨论 [为什么历来注册用户数会减少？](https://meta.discourse.org/t/why-would-the-number-of-all-time-sign-ups-ever-decrease/259962)：

我从一个旧论坛导入了用户，他们在“关于”中的注册统计数据中显示出来。

我将这些用户设置为 TL1 并将其设为不活跃。我的理解是，在 TL1 时，它们不应被自动清理删除。

我想知道停用后，它们是否仍应被计为“注册用户”，如果不是，是否有特定的 rake 命令或 SQL 查询来强制重新计数？

---

<div class="post-metadata">

### Author: ![Isambard](https://avatars.discourse-cdn.com/v4/letter/i/858c86/32.png) [@Isambard](https://meta.discourse.org/u/Isambard)
#### Post date: [2024年六月11日 15:53 UTC](https://meta.discourse.org/t/sign-up-stats/311595/2 "2024-06-11T15:53:25Z")

</div>

我认为我找到了答案：

```plaintext
user_count: User.real.count,
users_last_day: User.real.where('created_at > ?', 1.days.ago).count,
users_7_days: User.real.where('created_at > ?', 7.days.ago).count,
users_30_days: User.real.where('created_at > ?', 30.days.ago).count,

```

```ruby
# 排除虚假用户，如系统用户或匿名用户
scope :real,
      ->(allowed_bot_user_ids: nil) do
  human_users(allowed_bot_user_ids: allowed_bot_user_ids).where(
    "NOT EXISTS(
                     SELECT 1
                     FROM anonymous_users a
                     WHERE a.user_id = users.id
                  )",
  )
end

```

所以停用的用户仍将被计算在内。
