Created
July 10, 2024 20:39
-
-
Save meunomeebero/b426bb37232edfe86a8f3c798d49f7a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// => retornar os dados da pagina inicial: homepage | |
| // identificar o usuario que ta entrando -> x | |
| // carregar o historico do usuario => tags -> x | |
| // descobrir as 3 maiores preferencias do user -> x | |
| // procurar no banco de dados videos que tenham semelhanca com as preferencias do user | |
| // retornar 5 videos que tiver maior pontuacao nas preferencias do user | |
| // 3 videos segunda melhor pref do user | |
| // 1 video que seja da terceira melhor pref do user | |
| const historico = [ | |
| 'anao', | |
| 'relampago marquinhos', | |
| 'relampago marquinhos', | |
| 'shrek', | |
| 'anao', | |
| 'anao', | |
| 'anao', | |
| 'shrek', | |
| 'shrek', | |
| 'bolsonaro', | |
| 'lula' | |
| ]; | |
| function pegarUser(req: { ip: string }): string { | |
| const { ip } = req; | |
| return ip; | |
| } | |
| function pegarHistoricoPeloIp(ip: string): Array<string> { | |
| console.log('pegando videos do ip ' + ip) | |
| return historico; | |
| } | |
| function pegarAsPreferenciasDoMeuUsuarioBaseadoNoHistorico(historico: Array<string>): Array<string> { | |
| const map = new Map<string, number>(); | |
| for (const h of historico) { | |
| map.set(h, (map.get(h) || 0) + 1); | |
| } | |
| const sorted = Array.from(map.entries()).sort((a, b) => b[1] - a[1]); | |
| return sorted.slice(0, 3).map(([h]) => h); | |
| } | |
| function pegarVideoBaseadoEmTag(tag: string, qntVideos: number): Array<string> { | |
| return [] | |
| } | |
| function hubHomepage(req: { ip: string }) { | |
| const user = pegarUser(req); | |
| const videos = pegarHistoricoPeloIp(user); | |
| const [p1, p2, p3] = pegarAsPreferenciasDoMeuUsuarioBaseadoNoHistorico(videos); | |
| const videosN1 = pegarVideoBaseadoEmTag(p1, 5); | |
| const videosN2 = pegarVideoBaseadoEmTag(p2, 3); | |
| const videosN3 = pegarVideoBaseadoEmTag(p3, 1); | |
| return [videosN1, videosN2, videosN3]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment