Request database query results by curve

I have a table of songs and their bits per minute value, and I would like to create playlists that follow the curve as follows:

  ^       . . .
  |     .       .
b |   .           .
p |  .              .
m | .                .
  x-------------------->
    time

I understand that this is probably not possible in a single SQL statement, but I am interested in auditory solutions. At the moment, the best approach that I see is choosing more tracks than necessary and ordering in my application code (python).

+5
source share
3 answers

BPM SQL. , , , . , BPM . BPM.

, , .

+3

, sql- , :

  • sql , (, x - y , z).

  • , , , , .

, - ?

  function makePlaylist(array songList,int playListLength,function curve)
    int x=songList[0].length;
    array playList=new array();//empty array
    int max=getHighestBpmFromList(songList);//getHighestBpmFromList implementation not shown here
    song closestMatch;

    while (playList.length<playListLength)
      currentLength=song.length
      optimalBPM=-(x-songList[0].length)^2+max;//your curve as described above

      closestMatch=findClosestMatch(optimalBPM);//findClosestMatch would find a song
                                                //in the list whose bpm is as close
                                                //as possible to what the bpm 
                                                //should be at x on the curve
                                                //(maybe binary search, since 
                                                //the list is sorted)
      playList.push(closestMatch);
      x++

    return playList;
+1

My idea is to join a table in which there is one field β€œTime” (which contains integers 1..MAX, you can build this table on the fly) using the song table, where the corresponding SongID for each β€œTime” represents a song with bps closest to f (time). f is a function representing a curve. Then you can order the result in time and get a curve.

This method does not concern duplicates, and I do not know whether it is easy to implement it in SQL (I am not an SQL expert).

0
source

All Articles