markdown 塔斯尔|改进的模型想法/概念

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 塔斯尔|改进的模型想法/概念相关的知识,希望对你有一定的参考价值。

# Tassl Views - V2

A document for gathering all the most ideal views for Tassl data going forward. Learning from our current data structures and their flaws.

**Note** Many views below will be dependent on each-other.

## Goals

- Be as DRY as possible
- Reusability

## Engagement Hosts View
Combines Tassl Departments and Groups into a single view.

I started this view with just a few core columns, additional columns should be added.
```sql
-- Engagement Hosts
WITH engagement_hosts AS (
  SELECT d.id, d.name, d.description, d.integration_id, d.name AS department_name, d.id AS department_id, d.integration_id AS department_integration_id, 'department' AS type,
  s.name AS school_name, d.school_id
  FROM departments d
  LEFT JOIN schools s ON d.school_id = s.id
  UNION
  SELECT g.id, g.name, g.description, g.integration_id, d.name AS deparmtent_name, d.id AS department_id, d.integration_id AS department_integration_id, 'group' AS type,
  s.name AS school_name, g.school_id
  FROM school_groups AS g
  LEFT JOIN departments d ON g.department_id = d.id
  LEFT JOIN schools s ON g.school_id = s.id
)
SELECT * FROM engagement_hosts LIMIT 10;
```

## Event Engagement Hosts View
Very similar to `event_hosts` but with a `engagement_host_id` column - for use with the `engagement_hosts` view above.
```sql
WITH event_engagement_hosts AS (
  SELECT id, event_id, primary_host, COALESCE(department_id, school_group_id) engagement_host_id
  FROM event_hosts
)
SELECT * FROM event_engagement_hosts LIMIT 10;
```

## Event Engagements View

```sql
WITH event_engagements AS (
	SELECT DISTINCT ON (i.id) i.id AS invite_id,
  e.school_id,
	e.id as event_id,
  e.integration_id event_integration_id,
  e.name as event_name,
	i.user_id,
	primary_host.name AS primary_host_name,
	primary_host.integration_id AS primary_host_integration_id,
	primary_host.department_integration_id AS department_integration_id,
	e.integration_id as event_code,
	('='::text ||'"'|| u.integration_id ||'"' ) as user_integration_id,
	i.invited,
	i.rsvp,
	i.checked_in,
	i.modified,
	i.sync_date
	FROM invites i
	LEFT JOIN events e ON i.event_id = e.id
	LEFT JOIN event_engagement_hosts phr ON i.event_id = phr.event_id AND phr.primary_host IS true
	LEFT JOIN engagement_hosts primary_host ON phr.engagement_host_id = primary_host.id
	LEFT JOIN users u ON i.user_id = u.id
)
SELECT * FROM event_engagements
WHERE school_id = 2
AND participant_user_integration_id IS NOT NULL
AND event_intragration_id IS NOT NULL
LIMIT 10;
```


---
---
---

Entire CTE

```sql
-- Improvements/Breaking down our event engagements script (This will help with our Views/DB Meeting, ticket.
WITH
-- Engagement Hosts View (Departments & Groups)
engagement_hosts AS (
	SELECT d.id, d.name, d.description, d.integration_id, d.name AS department_name, d.id AS department_id, d.integration_id AS department_integration_id, 'department' AS type,
	s.name AS school_name, d.school_id
	FROM departments d
	LEFT JOIN schools s ON d.school_id = s.id
	UNION
	SELECT g.id, g.name, g.description, g.integration_id, d.name AS deparmtent_name, d.id AS department_id, d.integration_id AS department_integration_id, 'group' AS type,
	s.name AS school_name, g.school_id
	FROM school_groups AS g
	LEFT JOIN departments d ON g.department_id = d.id
	LEFT JOIN schools s ON g.school_id = s.id
),
-- Event Engagement Hosts View (Event Hosts)
event_engagement_hosts AS (
	SELECT id, event_id, primary_host, COALESCE(department_id, school_group_id) engagement_host_id
	FROM event_hosts
),
-- Event Engagements View (Invites)
event_engagements AS (
	SELECT DISTINCT ON (i.id) i.id AS invite_id,
	e.school_id,
	e.id as event_id,
    e.integration_id event_intragration_id,
    e.name as event_name,
	i.user_id,
	primary_host.name AS primary_host_name,
	primary_host.integration_id AS primary_host_integration_id,
	primary_host.department_integration_id AS department_integration_id,
	e.integration_id as event_code,
	('='::text ||'"'|| u.integration_id ||'"' ) as user_integration_id,
	i.invited,
	i.rsvp,
	i.checked_in,
	i.modified,
	i.sync_date
	FROM invites i
	LEFT JOIN events e ON i.event_id = e.id
	LEFT JOIN event_engagement_hosts phr ON i.event_id = phr.event_id AND phr.primary_host IS true
	LEFT JOIN engagement_hosts primary_host ON phr.engagement_host_id = primary_host.id
	LEFT JOIN users u ON i.user_id = u.id
)
SELECT *
FROM event_engagements
LIMIT 100;
```

以上是关于markdown 塔斯尔|改进的模型想法/概念的主要内容,如果未能解决你的问题,请参考以下文章

GAN的基本介绍和变种

通信算法之九十九:载波同步,符号同步,帧同步,科斯塔斯环载波同步

通信算法之九十九:载波同步,符号同步,帧同步,科斯塔斯环载波同步

从马尔可夫模型到隐马尔可夫模型

虾说区块链-83-blockchain笔记二

markdown 改进子菜单导航的键盘可访问性