Skip to content

Views from SA #18

@codisart

Description

@codisart

main_summaries

      WITH incidents_users AS (
           SELECT a.user_id,
              incidents.id,
              ((incidents.rendered_obsolete_at IS NULL) AND ((incidents.ends_at IS NULL) OR (incidents.ends_at > now()))) AS is_valid,
              (incidents.seen_at IS NULL) AS is_new,
              (incidents.dismissed_at IS NULL) AS is_pending
             FROM (incidents
               JOIN alerts a ON ((a.id = incidents.alert_id)))
          ), total_new_incidents AS (
           SELECT incidents_users.user_id,
              'new_incidents'::text AS label,
              incidents_users.id
             FROM incidents_users
            WHERE (incidents_users.is_new AND incidents_users.is_valid)
          ), total_pending_incidents AS (
           SELECT incidents_users.user_id,
              'pending_incidents'::text AS label,
              incidents_users.id
             FROM incidents_users
            WHERE ((NOT incidents_users.is_new) AND incidents_users.is_pending AND incidents_users.is_valid)
          ), total_non_deleted_alerts AS (
           SELECT alerts.user_id,
              'alerts'::text AS label,
              alerts.id
             FROM alerts
            WHERE ((alerts.deleted_at IS NULL) AND (alerts.archived_at IS NULL))
          ), total_satellites AS (
           SELECT satellites.user_id,
              'satellites'::text AS label,
              satellites.id
             FROM satellites
          ), total_space_objects AS (
           SELECT count(space_objects.id) AS total
             FROM space_objects
          )
   SELECT users.id AS user_id,
      count(users_relations.id) FILTER (WHERE (users_relations.label = 'new_incidents'::text)) AS new_incidents,
      count(users_relations.id) FILTER (WHERE (users_relations.label = 'pending_incidents'::text)) AS pending_incidents,
      count(users_relations.id) FILTER (WHERE (users_relations.label = 'alerts'::text)) AS trackers,
      count(users_relations.id) FILTER (WHERE (users_relations.label = 'satellites'::text)) AS simulated_satellites,
      total_space_objects.total AS ingested_objects
     FROM ((users
       LEFT JOIN ( SELECT total_new_incidents.user_id,
              total_new_incidents.label,
              total_new_incidents.id
             FROM total_new_incidents
          UNION ALL
           SELECT total_pending_incidents.user_id,
              total_pending_incidents.label,
              total_pending_incidents.id
             FROM total_pending_incidents
          UNION ALL
           SELECT total_non_deleted_alerts.user_id,
              total_non_deleted_alerts.label,
              total_non_deleted_alerts.id
             FROM total_non_deleted_alerts
          UNION ALL
           SELECT total_satellites.user_id,
              total_satellites.label,
              total_satellites.id
             FROM total_satellites) users_relations ON ((users_relations.user_id = users.id)))
       CROSS JOIN total_space_objects)
    GROUP BY users.id, total_space_objects.total;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions