Skip to content

Commit acab730

Browse files
committed
modified assignment with greater clarity
1 parent 69dd717 commit acab730

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@ We believe it is important that our assessment of your skills matches the techni
88

99
## Problem 1
1010

11-
Please familiarize yourself with the schema defined in the file `problem1-schema.sql` in this repository. **TODO: Comment SQL Schema**
11+
Please familiarize yourself with the schema defined in the file `problem1-schema.sql` in this repository.
1212

13-
**TODO: Explain what data should be aggregated. Maybe even give schema for final result?**
13+
This schema is an example of a simple event tracking system for desktop live streaming software.
14+
15+
Please write one or more SQL User-Defined Functions to aggregate this table in a way that it can be used to generate the following reports:
16+
- Monthly Active Users based on `stream_start` and `app_start` events
17+
- Daily Active Users based on the same
18+
- Daily count of new users
19+
- User cohort retention based on `stream_start` and `app_start`
20+
21+
Please note, you are to provide the aggregated data necessary to generate these reports. Your output does not necessarily need to generate these reports in their final form.
22+
23+
Your solution should include SQL statements that define your UDF(s).
1424

1525
## Problem 2
1626

17-
Please familiarize yourself with the schema defined in the file `problem2-schema.sql` in this repository. **TODO: Comment SQL Schema**
27+
Please familiarize yourself with the schema defined in the file `problem2-schema.sql` in this repository.
1828

1929
This schema is simple model of the Streamlabs live streaming tools service. Users can use the service to stream to any streaming platform. Users can receive donations from their viewers on the platform. Streamlabs is free to use, but there is a premium subscription service that provides additional features and benefits.
2030

problem1-schema.sql

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
CREATE TABLE `event_tracker` (
22
`id` int(10) unsigned NOT NULL,
33
`user_id` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
4-
`event` varchar(255) CHARACTER SET latin1 NOT NULL,
4+
`event` varchar(255) CHARACTER SET latin1 NOT NULL, -- event includes 'stream_start', 'stream_end', 'app_start', 'app_end'
55
`previous_event` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
6-
`name` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
7-
`stream_length` int(10) unsigned NOT NULL,
8-
`app_length` int(10) unsigned NOT NULL,
6+
`stream_length` int(10) unsigned NOT NULL, -- if event = 'stream_end', this field reflects the length of the stream in seconds, otherwise = NULL
7+
`app_length` int(10) unsigned NOT NULL, -- if event = 'app_end', this field reflects the length of the session in seconds, otherwise = NULL
98
`created_at` timestamp NULL DEFAULT NULL,
109
`updated_at` timestamp NULL DEFAULT NULL,
1110
PRIMARY KEY (`id`),

problem2-schema.sql

+22-26
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
CREATE TABLE `paid_user_subscriptions` (
22
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
3-
`user_id` int(10) unsigned NOT NULL,
4-
`plan_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
5-
`status` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
6-
`expires_at` timestamp NOT NULL,
7-
`deleted_at` timestamp NULL DEFAULT NULL,
3+
`user_id` int(10) unsigned NOT NULL, -- common user identifier across all tables
4+
`plan_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL, -- Posible values: 'monthly' 'annual'
5+
`status` varchar(255) COLLATE utf8_unicode_ci NOT NULL, -- Posible values: 'Active' 'Past Due' 'Cancelled' 'Refunded'
6+
`expires_at` timestamp NOT NULL, -- timestamp when subscription expires
7+
`deleted_at` timestamp NULL DEFAULT NULL, -- timestamp when subscription was deleted for any reason on our end
88
`created_at` timestamp NULL DEFAULT NULL,
99
`updated_at` timestamp NULL DEFAULT NULL,
10-
`cancellation_at` timestamp NULL DEFAULT NULL,
10+
`cancellation_at` timestamp NULL DEFAULT NULL, -- timestamp when user manually cancels subscription
1111
PRIMARY KEY (`id`),
1212
);
13-
1413
CREATE TABLE `stream_logs` (
1514
`id` bigint(20) NOT NULL AUTO_INCREMENT,
16-
`user_id` int(11) DEFAULT NULL,
17-
`event` varchar(100) NOT NULL,
18-
`data` json DEFAULT NULL,
15+
`user_id` int(11) DEFAULT NULL, -- common user identifier across all tables
16+
`event` varchar(100) NOT NULL, -- possible values: 'stream_start' 'stream_end' 'app_start' 'app_end' 'crash'
17+
`data` json DEFAULT NULL, -- json with keys: 'os' 'platform' 'inputResolution' 'game' 'encoder'
1918
`date` date NOT NULL,
2019
`created_at` datetime NOT NULL,
2120
`updated_at` datetime NOT NULL,
2221
PRIMARY KEY (`id`)
2322
);
24-
2523
CREATE TABLE `_donations` (
26-
`donation_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
27-
`user_id` int(11) NOT NULL,
28-
`currency_code` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
29-
`amount` decimal(20,10) DEFAULT NULL,
30-
`donor_id` int(11) DEFAULT NULL,
31-
`name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
32-
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
33-
`message` mediumtext CHARACTER SET utf16,
34-
`verified` int(11) DEFAULT '1',
35-
`fee_id` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
36-
`fee_refunded_at` timestamp NULL DEFAULT NULL,
37-
`source` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
38-
`transaction_id` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL,
39-
`usd_amount` decimal(20,10) DEFAULT NULL,
40-
`data` json DEFAULT NULL,
24+
`donation_id` int(10) unsigned NOT NULL AUTO_INCREMENT, -- identifier for each donation
25+
`user_id` int(11) NOT NULL, -- common user identifier across all tables
26+
`currency_code` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL, -- currency of the donation
27+
`amount` decimal(20,10) DEFAULT NULL, -- donation amount in the indicated currency
28+
`donor_id` int(11) DEFAULT NULL, -- identifier of donor
29+
`email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, -- email of donor
30+
`message` mediumtext CHARACTER SET utf16, -- donation message
31+
`verified` int(11) DEFAULT '1', -- 0: manually created by streamer (read: not a real donation); 1: real donation sent from a payment processor
32+
`source` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL, -- 'paypal' or 'credit_card'
33+
`transaction_id` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL, -- identifier sent from payment processor
34+
`usd_amount` decimal(20,10) DEFAULT NULL, -- donation in USD equivalent
35+
`data` json DEFAULT NULL, -- json details of the donation: donor, media attached, GIF attached
4136
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
4237
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
4338
`deleted_at` timestamp NULL DEFAULT NULL,
4439
PRIMARY KEY (`donation_id`),
4540
);
41+

0 commit comments

Comments
 (0)