| | 51 | ==== Релациона Алгебра |
| | 52 | |
| | 53 | {{{ |
| | 54 | LikeCount <- γ album_id := a.id; |
| | 55 | total_likes := COUNT(l.listener_id) |
| | 56 | ( |
| | 57 | albums a ⟕ (a.id = l.musical_entity_id) likes l |
| | 58 | ) |
| | 59 | |
| | 60 | ListenCount <- |
| | 61 | γ album_id := s.album_id; |
| | 62 | total_listens := COUNT(l.timestamp) |
| | 63 | ( |
| | 64 | σ s.album_id IS NOT NULL |
| | 65 | ( |
| | 66 | (listens l ⨝ (l.song_id = s.id) songs s) |
| | 67 | ⨝ (s.album_id = a.id) albums a |
| | 68 | ) |
| | 69 | ) |
| | 70 | |
| | 71 | AverageGrade <- |
| | 72 | γ album_id := a.id; |
| | 73 | average_grade := AVG(r.grade) |
| | 74 | ( |
| | 75 | reviews r ⨝ (r.musical_entity_id = a.id) albums a |
| | 76 | ) |
| | 77 | |
| | 78 | Result <- |
| | 79 | π me.title, lk.total_likes, lc.total_listens, ag.average_grade |
| | 80 | ( |
| | 81 | ( |
| | 82 | ( |
| | 83 | musical_entities me ⟕ (lk.album_id = me.id) LikeCount lk |
| | 84 | ) |
| | 85 | ⟕ ListenCount lc |
| | 86 | ) |
| | 87 | ⟕ AverageGrade ag |
| | 88 | ) |
| | 89 | ) |
| | 90 | }}} |
| | 144 | ==== Релациона Алгебра |
| | 145 | |
| | 146 | {{{ |
| | 147 | LikeCount <- |
| | 148 | γ song_id := s.id; |
| | 149 | total_likes := COUNT(l.listener_id) |
| | 150 | ( |
| | 151 | songs s ⨝ (s.id = l.musical_entity_id) likes l |
| | 152 | ) |
| | 153 | |
| | 154 | ListenCount <- |
| | 155 | γ song_id := l.song_id; |
| | 156 | total_listens := COUNT(l.timestamp) |
| | 157 | ( |
| | 158 | listens l |
| | 159 | ) |
| | 160 | |
| | 161 | AverageGrade <- |
| | 162 | γ song_id := r.musical_entity_id; |
| | 163 | average_grade := AVG(r.grade) |
| | 164 | ( |
| | 165 | reviews r ⨝ (r.musical_entity_id = s.id) songs s |
| | 166 | ) |
| | 167 | |
| | 168 | PlaylistCount <- |
| | 169 | γ song_id := ps.song_id; |
| | 170 | count_playlists := COUNT(ps.song_id) |
| | 171 | ( |
| | 172 | songs s ⨝ (s.id = ps.song_id) playlist_songs ps |
| | 173 | ) |
| | 174 | |
| | 175 | Result <- |
| | 176 | π me.title, |
| | 177 | ls.total_listens, |
| | 178 | lc.total_likes, |
| | 179 | ag.average_grade, |
| | 180 | pc.count_playlists |
| | 181 | ( |
| | 182 | ( |
| | 183 | ( |
| | 184 | ( |
| | 185 | ( |
| | 186 | musical_entities me |
| | 187 | ⨝ (me.id = s.id) songs s |
| | 188 | ) |
| | 189 | ⟕ (s.id = lc.song_id) LikeCount lc |
| | 190 | ) |
| | 191 | ⟕ (s.id = ls.song_id) ListenCount ls |
| | 192 | ) |
| | 193 | ⟕ (ls.song_id = pc.song_id) PlaylistCount pc |
| | 194 | ) |
| | 195 | ⟕ (lc.song_id = ag.song_id) AverageGrade ag |
| | 196 | ) |
| | 197 | }}} |
| | 248 | ==== Релациона Алгебра |
| | 249 | {{{ |
| | 250 | FollowersCount <- |
| | 251 | γ artist := a.user_id, |
| | 252 | event_id := pa.event_id; |
| | 253 | followers := COUNT(f.follower) |
| | 254 | ( |
| | 255 | (artists a ⨝ (a.user_id = pa.artist_id) performs_at pa) |
| | 256 | ⟕ (a.user_id = f.followee) follows f |
| | 257 | ) |
| | 258 | |
| | 259 | ListensCount <- |
| | 260 | γ artist := a.user_id; |
| | 261 | listen_count := COUNT(l.timestamp) |
| | 262 | ( |
| | 263 | ( |
| | 264 | (artists a ⨝ (a.user_id = pa.artist_id) performs_at pa) |
| | 265 | ⨝ (pa.artist_id = me.released_by) musical_entities me |
| | 266 | ) |
| | 267 | ⟕ (me.id = l.song_id) listens l |
| | 268 | ) |
| | 269 | |
| | 270 | BaseResult <- |
| | 271 | ( |
| | 272 | ( |
| | 273 | ( |
| | 274 | ( |
| | 275 | events e |
| | 276 | ⨝ (e.event_id = pa.event_id) performs_at pa |
| | 277 | ) |
| | 278 | ⨝ (pa.artist_id = fc.artist) FollowersCount fc |
| | 279 | ) |
| | 280 | ⨝ (fc.artist = lc.artist) ListensCount lc |
| | 281 | ) |
| | 282 | ⨝ (lc.artist = u.user_id) users u |
| | 283 | ) |
| | 284 | |
| | 285 | Dominates <- |
| | 286 | σ |
| | 287 | fc.event_id = fc1.event_id ∧ |
| | 288 | ( |
| | 289 | fc.followers < fc1.followers |
| | 290 | ∨ (fc.followers = fc1.followers ∧ lc.listen_count < lc1.listen_count) |
| | 291 | ∨ (fc.followers = fc1.followers ∧ lc.listen_count = lc1.listen_count ∧ lc.artist < lc1.artist) |
| | 292 | ) |
| | 293 | ( |
| | 294 | (FollowersCount fc ⨝ ListensCount lc) |
| | 295 | × |
| | 296 | (ρ fc1(FollowersCount) ⨝ ρ lc1(ListensCount)) |
| | 297 | ) |
| | 298 | |
| | 299 | FinalArtists <- |
| | 300 | BaseResult − π attributes(BaseResult) |
| | 301 | ( |
| | 302 | BaseResult ⨝ (BaseResult.artist = Dominates.artist) Dominates |
| | 303 | ) |
| | 304 | |
| | 305 | Result <- |
| | 306 | π e.location, |
| | 307 | e.venue, |
| | 308 | u.full_name, |
| | 309 | fc.followers, |
| | 310 | lc.listen_count |
| | 311 | ( |
| | 312 | FinalArtists |
| | 313 | ) |
| | 314 | }}} |
| | 377 | ==== Релациона Алгебра |
| | 378 | {{{ |
| | 379 | |
| | 380 | OneYear <- |
| | 381 | { (year_start, year_end) } |
| | 382 | |
| | 383 | MonthlyArtistListens <- |
| | 384 | γ month := MONTH(l.timestamp), |
| | 385 | user_id := a.user_id; |
| | 386 | count := COUNT(l.timestamp) |
| | 387 | ( |
| | 388 | ( |
| | 389 | ( |
| | 390 | listens l |
| | 391 | ⨝ (l.timestamp ≥ oy.year_start ∧ l.timestamp ≤ oy.year_end) OneYear oy |
| | 392 | ) |
| | 393 | ⨝ (l.song_id = me.id) musical_entities me |
| | 394 | ) |
| | 395 | ⨝ (me.released_by = a.user_id) artists a |
| | 396 | ) |
| | 397 | |
| | 398 | MaxPerMonth = |
| | 399 | γ month := mal.month; |
| | 400 | max_month_counter := MAX(mal.count) |
| | 401 | ( |
| | 402 | MonthlyArtistListens mal |
| | 403 | ) |
| | 404 | |
| | 405 | MaxCandidates <- |
| | 406 | MonthlyArtistListens mal |
| | 407 | ⨝ (mal.month = mpm.month ∧ mal.count = mpm.max_month_counter) |
| | 408 | MaxPerMonth mpm |
| | 409 | |
| | 410 | Dominated <- |
| | 411 | σ |
| | 412 | mal.month = mal1.month ∧ |
| | 413 | mal.user_id > mal1.user_id |
| | 414 | ( |
| | 415 | ρ mal(MaxCandidates) |
| | 416 | × |
| | 417 | ρ mal1(MaxCandidates) |
| | 418 | ) |
| | 419 | |
| | 420 | MostPopular <- |
| | 421 | MaxCandidates − π attributes(MaxCandidates) |
| | 422 | ( |
| | 423 | MaxCandidates ⨝_{user_id} Dominated |
| | 424 | ) |
| | 425 | |
| | 426 | Months(month_num, month_name) |
| | 427 | |
| | 428 | FinalResult <- |
| | 429 | π |
| | 430 | CONCAT(YEAR(oy.year_start), '-', m.month_name), |
| | 431 | u.full_name, |
| | 432 | mp.max_month_counter |
| | 433 | ( |
| | 434 | ( |
| | 435 | ( |
| | 436 | Months m |
| | 437 | ⟕ (m.month_num = mp.month) MostPopular mp |
| | 438 | ) |
| | 439 | ⟕ (mp.user_id = u.user_id) users u |
| | 440 | ) |
| | 441 | × OneYear oy |
| | 442 | ) |
| | 443 | }}} |
| | 503 | |
| | 504 | ==== Релациона Алгебра |
| | 505 | |
| | 506 | {{{ |
| | 507 | |
| | 508 | OneMonth <- |
| | 509 | { (prev_period_start, |
| | 510 | prev_period_end, |
| | 511 | this_period_start, |
| | 512 | this_period_end) } |
| | 513 | |
| | 514 | LastPeriod <- |
| | 515 | σ last_period_count > 0 |
| | 516 | ( |
| | 517 | γ user_id := a.user_id; |
| | 518 | last_period_count := COUNT(l.timestamp) |
| | 519 | ( |
| | 520 | ( |
| | 521 | ( |
| | 522 | listens l ⨝ (l.timestamp ≥ om.prev_period_start ∧ |
| | 523 | l.timestamp ≤ om.prev_period_end) |
| | 524 | OneMonth om |
| | 525 | ) |
| | 526 | ⨝ (l.song_id = me.id) musical_entities me |
| | 527 | ) |
| | 528 | ⟖ (me.released_by = a.user_id) artists a |
| | 529 | ) |
| | 530 | ) |
| | 531 | |
| | 532 | ThisPeriod <- |
| | 533 | γ user_id := a.user_id; |
| | 534 | this_period_count := COUNT(l.timestamp) |
| | 535 | ( |
| | 536 | ( |
| | 537 | ( |
| | 538 | listens l ⨝ (l.timestamp ≥ om.this_period_start ∧ |
| | 539 | l.timestamp ≤ om.this_period_end) |
| | 540 | OneMonth om |
| | 541 | ) |
| | 542 | ⨝ (l.song_id = me.id) musical_entities me |
| | 543 | ) |
| | 544 | ⟖ (me.released_by = a.user_id) artists a |
| | 545 | ) |
| | 546 | |
| | 547 | Stats <- |
| | 548 | π |
| | 549 | u.full_name, |
| | 550 | lp.last_period_count, |
| | 551 | tp.this_period_count, |
| | 552 | om.prev_period_start, |
| | 553 | om.prev_period_end, |
| | 554 | om.this_period_start, |
| | 555 | om.this_period_end, |
| | 556 | pct_change := ((tp.this_period_count − lp.last_period_count) |
| | 557 | / lp.last_period_count) * 100 |
| | 558 | ( |
| | 559 | ( |
| | 560 | ( |
| | 561 | LastPeriod lp ⟕ ThisPeriod tp |
| | 562 | ) |
| | 563 | ⨝ users u |
| | 564 | ) |
| | 565 | × OneMonth om |
| | 566 | ) |
| | 567 | |
| | 568 | Result <- |
| | 569 | τ pct_change DESC |
| | 570 | ( |
| | 571 | π |
| | 572 | full_name, |
| | 573 | previous_period, |
| | 574 | last_period_count, |
| | 575 | this_period, |
| | 576 | this_period_count, |
| | 577 | pct_change |
| | 578 | ( |
| | 579 | Stats s |
| | 580 | ) |
| | 581 | ) |
| | 582 | }}} |