Beispiel #1
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);
 }
 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';
 }