Jaewook

Append music_recommend Algorithm

1 +//받은 날씨 데이터를 바탕으로 음악 리스트를 추천해주는 알고리즘.
2 +
3 +//input 값 = 날씨 데이터 ex) Thunderstorm
4 +//output 값 = 리스트 형태의 제목-가수 정보 5쌍 ex) {(여자)아이들-tomboy, 혁오-tomboy, Dua Lipa-don't start now, 폴킴-너를 만나, Bruno Mars-Just the way you are}
5 +//사용 언어 = javascript
6 +
7 +
8 +//코드 전체적인 개요
9 +// if(음악 추천하기 버튼 누름){
10 +// if(날씨 데이터가 일반적){날씨에 맞는 장르 추천, 추천한 장르 보고 맞는 노래 추천, 장르가 2개 이상이어서 노래가 5개를 넘을때는 random_5_Select 함수 사용}
11 +// if(날씨 데이터가 특수함(Snow)){직접 노래 추천}
12 +// 추천받은 노래 5개의 제목과 가수 정보 데이터를 document.write함.
13 +// }
14 +
15 +
16 +function random_5_Select(array){ //사용시 array1 = random_5_Select(array1); 이렇게 해주면 됨
17 + array.sort(() => Math.random() - 0.5);
18 + array.splice(5);
19 + return array;
20 +}
21 +
22 +var rec_Genre = {};
23 +var rec_Song = {};
24 +
25 +if(구현: 음악 추천하기 버튼 누름){
26 + if(WeatherCondition===Thunderstorm){
27 + rec_Song.concat(parsing(url_ballad), parsing(url_RNB_kr, parsing(url_RNB_us)));
28 + rec_song = random_5_Select(rec_song);
29 + }
30 + if(WeatherCondition===Drizzle){
31 + rec_Song.concat(parsing(url_ballad), parsing(url_RNB_kr, parsing(url_RNB_us)));
32 + rec_song = random_5_Select(rec_song);
33 + }
34 + if(WeatherCondition===Rain){
35 + rec_Song.concat(parsing(url_ballad), parsing(url_RNB_kr, parsing(url_RNB_us)));
36 + rec_song = random_5_Select(rec_song);
37 + }
38 + if(WeatherCondition===Clear){
39 + rec_Song.concat(parsing(url_hiphop_kr), parsing(url_hiphop_us), parsing(url_dance), parsing(url_rock_kr), parsing(url_rock_us));
40 + rec_song = random_5_Select(rec_song);
41 + }
42 + if(WeatherCondition===Clouds){
43 + rec_Song.concat(parsing(url_pop), parsing(url_RNB_kr), parsing(url_RNB_us), parsing(url_indie));
44 + rec_song = random_5_Select(rec_song);
45 + }
46 + if(WeatherCondition===Snow){rec_Song.concat(parsing_exception('snow'));}
47 + if(WeatherCondition===Mist){rec_Song.concat(parsing(url_newage));}
48 + if(WeatherCondition===Fog){rec_Song.concat(parsing(url_newage));}
49 +
50 + //밑 4개 종류의 날씨는 거의 나올 확률이 없으므로 그냥 별 의미는 없이 newage장르로 매치함.
51 + if(WeatherCondition===Smoke){rec_Song.concat(parsing(url_newage));}
52 + if(WeatherCondition===Haze){rec_Song.concat(parsing(url_newage));}
53 + if(WeatherCondition===Dust){rec_Song.concat(parsing(url_newage));}
54 + if(WeatherCondition===Sand){rec_Song.concat(parsing(url_newage));}
55 +
56 + document.write(rec_song)
57 +}
58 +