Changes between Version 9 and Version 10 of AdvancedReports


Ignore:
Timestamp:
02/02/26 20:16:44 (4 days ago)
Author:
231136
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v9 v10  
    55
    66=== 1. Детален извештај за број на лајкови, слушања и просечна оценка за секој албум
     7
     8==== SQL
     9
    710{{{
    811SET search_path TO project;
     
    4649}}}
    4750
     51==== Релациона Алгебра
     52
     53{{{
     54LikeCount <- γ 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
     60ListenCount <-
     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
     71AverageGrade <-
     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
     78Result <-
     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}}}
    4891
    4992=== 2. Детален извештај за број на лајкови, број на слушања, просечна оценка за една песна, како и бројот на плејлисти кои ја содржат
     93
     94==== SQL
    5095{{{
    5196SET search_path TO project;
     
    97142}}}
    98143
     144==== Релациона Алгебра
     145
     146{{{
     147LikeCount <-
     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
     154ListenCount <-
     155γ song_id := l.song_id;
     156  total_listens := COUNT(l.timestamp)
     157(
     158  listens l
     159)
     160
     161AverageGrade <-
     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
     168PlaylistCount <-
     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
     175Result <-
     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}}}
    99198
    100199=== 3. Детален извештај за најпопуларен артист за секој настан рангиран по бројот на следбеници, а потоа по вкупно слушања на сите негови песни
     200
     201==== SQL
    101202{{{
    102203SET search_path TO 'project';
     
    145246}}}
    146247
     248==== Релациона Алгебра
     249{{{
     250FollowersCount <-
     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
     259ListensCount <-
     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
     270BaseResult <-
     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
     285Dominates <-
     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
     299FinalArtists <-
     300BaseResult − π attributes(BaseResult)
     301(
     302  BaseResult ⨝ (BaseResult.artist = Dominates.artist) Dominates
     303)
     304
     305Result <-
     306π e.location,
     307  e.venue,
     308  u.full_name,
     309  fc.followers,
     310  lc.listen_count
     311(
     312  FinalArtists
     313)
     314}}}
    147315
    148316=== 4. Детален извештај за најпопуларниот артист според месечни слушања за изминатата година
     317
     318==== SQL
    149319{{{
    150320SET search_path TO 'project';
     
    205375}}}
    206376
     377==== Релациона Алгебра
     378{{{
     379
     380OneYear <-
     381{ (year_start, year_end) }
     382
     383MonthlyArtistListens <-
     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
     398MaxPerMonth =
     399γ month := mal.month;
     400  max_month_counter := MAX(mal.count)
     401(
     402  MonthlyArtistListens mal
     403)
     404
     405MaxCandidates <-
     406MonthlyArtistListens mal
     407⨝ (mal.month = mpm.month ∧ mal.count = mpm.max_month_counter)
     408MaxPerMonth mpm
     409
     410Dominated <-
     411σ
     412  mal.month = mal1.month ∧
     413  mal.user_id > mal1.user_id
     414(
     415  ρ mal(MaxCandidates)
     416  ×
     417  ρ mal1(MaxCandidates)
     418)
     419
     420MostPopular <-
     421MaxCandidates − π attributes(MaxCandidates)
     422(
     423  MaxCandidates ⨝_{user_id} Dominated
     424)
     425
     426Months(month_num, month_name)
     427
     428FinalResult <-
     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}}}
    207444
    208445=== 5. Детален извештај за процентуалната промена на бројот на слушања на артистите за изминатите 30 дена
    209446
     447==== SQL
    210448{{{
    211449SET search_path TO 'project';
     
    263501
    264502}}}
     503
     504==== Релациона Алгебра
     505
     506{{{
     507
     508OneMonth <-
     509{ (prev_period_start,
     510   prev_period_end,
     511   this_period_start,
     512   this_period_end) }
     513   
     514LastPeriod <-
     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
     532ThisPeriod <-
     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
     547Stats <-
     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
     568Result <-
     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}}}