Ejemplo n.º 1
0
 /**
  * Searches for a track and gives the response
  * 
  * @Route("/searchwidget/{query}", name="searchwidget")
  */
 public function searchWidgetAction($query)
 {
     $lastFmCrawler = new LastFMCrawler();
     $songs = $lastFmCrawler->searchTrack($query, 1, 5);
     $json = array();
     foreach ($songs as $track) {
         $json[] = array('artist' => $track->getArtist()->getName(), 'title' => $track->getTitle(), 'youtube' => $track->getYoutube());
     }
     return new JsonResponse($json);
 }
Ejemplo n.º 2
0
 /**
  * @Route("/events", name="events")
  * @Template("TuneMapsFrontBundle:Contents:events.html.twig")
  */
 public function eventsAction()
 {
     $em = $this->getDoctrine()->getEntityManager();
     $user = $this->get('security.context')->getToken()->getUser();
     $lastFmCrawler = new LastFMCrawler();
     $events = $lastFmCrawler->getEvents($user->getLastLocation());
     $artistrepository = $em->getRepository('TuneMaps\\MusicDataBundle\\Entity\\Artist');
     $artistplayedrepository = $em->getRepository('TuneMaps\\MusicDataBundle\\Entity\\ArtistPlayed');
     /*
      * Event Recommendation Algorithm
      * @author D. Eikelenboom
      * @return list of events
      */
     $user = $this->get('security.context')->getToken()->getUser();
     foreach ($events as $event) {
         //get all attending artists
         $artists = $event->getAttendingArtists();
         $sumPlaycount = 0;
         foreach ($artists as $artist_partial) {
             //get playcount for an artist for this user
             $artist = $artistrepository->findOneBy(array('name' => $artist_partial->getName()));
             $playcount;
             if ($artist == NULL) {
                 //if artist is not in database for this user, then it has not been played yet
                 $playcount = 0;
             } else {
                 //retrieve from crawler if not in own db
                 $artistPlayed = $artistplayedrepository->findOneBy(array('artist' => $artist->getId(), 'user' => $user->getId()));
                 //get playcount
                 if ($artistPlayed != null) {
                     $playcount = $artistPlayed->getTimesPlayed();
                 }
             }
             //and sum the playcounts for the event
             $sumPlaycount = $sumPlaycount + $playcount;
         }
         //total sum of playcounts for this event
         $event->setRank($sumPlaycount);
     }
     //sort events on rank/playcount
     usort($events, function ($a, $b) {
         return $a->getRank() < $b->getRank();
     });
     //limit to a list of 10 events
     $events = array_slice($events, 0, 10);
     return array('events' => $events);
 }
Ejemplo n.º 3
0
 public function getEvents($n, $location)
 {
     $crawler = new LastFMCrawler();
     $events = $crawler->getEvents($location);
     $user = $this->get('security.context')->getToken()->getUser();
     foreach ($events as $event) {
         //get all attending artists
         $artists = $event->getAttendingArtists();
         $playcount = 0;
         foreach ($artists as $artistname) {
             //get playcount for an artist for this user
             $artist = $em->getRepository('TuneMaps\\MusicDataBundle\\Entity\\Artist')->findOneBy(array('name' => $artistname));
             /*$artistPlayed = $em->getRepository('TuneMaps\MusicDataBundle\Entity\ArtistPlayed')->findOneBy(array('artist' => $artist->getId(), 'user' => $user->getId()));
             
             				//get playcount
             				if($artistPlayed != null) {
             					$playcount = $artistPlayed->getTimesPlayed();
             				}*/
         }
     }
     //sort on highest playcount
     return 'test';
 }
Ejemplo n.º 4
0
 /**
  * Gets the song from the last fm API
  * 
  * @param string $artist The artist
  * @param string $title The title
  * @return Song The song
  */
 protected function getSongFromLastFM($artist, $title)
 {
     $lastFmCrawler = new LastFMCrawler();
     $song = $lastFmCrawler->trackInformation($artist, $title);
     return $song;
 }