예제 #1
0
파일: Theme.cs 프로젝트: si3792/NGJ_2016
        public Theme()
        {
            m_segments = new List <Segment>();
            weightings = new Weighting();

            this.id             = -1;
            this.restSecondsMax = 0;
            this.restSecondsMin = 0;
            this.priority       = 0;
            this.themeType      = ThemeType.none;
            this.Name           = "";
        }
예제 #2
0
        // Evaluates the most appropriate Segment to follow (or to layer respectively, for Highlights) from the list.	    
	    // This score is calculated by adding three basic scores, each one being a value between 0.0f and 1.0f, and affected by an individual weighting
	    // as authored in the psai Editor.
	    //
	    // 1. compatibility score
	    // 2. intensity score
	    // 3. variety score
	    //
	    // variety itself consists of the Segment's playcount score a random score, each affected by an individual
	    // weighting. 	
	    //
	    // TODO: maxPlaycount, minPlaycount and maxDeltaIntensity should be evaluated within this method. 
	    Segment ChooseBestSegmentFromList(List<Follower> segmentList, Weighting weighting, float intensity, int maxPlaycount, int minPlaycount, float maxDeltaIntensity)
	    {		    
		    #if !(PSAI_NOLOG)
		    {       
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
	                StringBuilder sb = new StringBuilder();
	                sb.Append("ChooseBestSegmentFromList() snippetList.size()=");
	                sb.Append(segmentList.Count);
	                sb.Append(" intensity=");
	                sb.Append(intensity);
	                sb.Append("  maxPlaycount=");
	                sb.Append(maxPlaycount);
	                sb.Append("  minPlaycount=");
	                sb.Append(minPlaycount);
	                sb.Append("  maxDeltaIntensity=");
	                sb.Append(maxDeltaIntensity);
	                sb.Append("  weighting.switchGroups=");
	                sb.Append(weighting.switchGroups);
	                sb.Append("  weighting.intensityVsVariety=");
	                sb.Append( weighting.intensityVsVariety);
	                sb.Append("  weightingLowPlaycountVsRandom=");
	                sb.Append(weighting.lowPlaycountVsRandom);
	                Logger.Instance.Log(sb.ToString(), LogLevel.debug);
                } 
		    }
		    #endif

		    Segment resultSnippet = null;

		    if (segmentList.Count == 0)
		    {
			    #if !(PSAI_NOLOG)
			    {
                    if (LogLevel.debug <= Logger.Instance.LogLevel)
                    {
                    	Logger.Instance.Log("ChooseBestSegmentFromList() empty segment list ! returning null", LogLevel.debug);
                    }
			    }
			    #endif

			    return null;
		    }

		    float playcountNormalizationFactor = 1.0f;
		    float intensityNormalizationFactor = 1.0f;


		    int deltaPlaycount = maxPlaycount - minPlaycount;

		    if (deltaPlaycount > 0)
			    playcountNormalizationFactor = (1.0f / deltaPlaycount);
		    else
			    playcountNormalizationFactor = 0.0f;

		    if (maxDeltaIntensity > 0)
			    intensityNormalizationFactor = ( 1.0f / maxDeltaIntensity );
		    else
			    intensityNormalizationFactor = 0.0f;

		    float bestSegmentScore = 0.0f;


		    int versize = segmentList.Count;
		    for (int i=0; i < versize; i++)
		    {
			    if (segmentList[i] != null)
			    {
                    Segment tmpTeilstueck = m_soundtrack.GetSegmentById(segmentList[i].snippetId);		// TODO: unnecessary waste of CPU cycles ! pass the pointers directly or use a map / dictionary
				
				    //
				    // score calculation new
				    // 
				    float weightingGroupStickyness = 1.0f - weighting.switchGroups;
				    float weightingIntensity = 1.0f - weighting.intensityVsVariety;
				    float weightingVariety = weighting.intensityVsVariety;		// Variety consists of playcount and random
				    float weightingPlaycount = 1.0f - weighting.lowPlaycountVsRandom;
				    float weightingRandom = weighting.lowPlaycountVsRandom;				

				    // switch group 
				    float compatibilityScore = segmentList[i].compatibility * weightingGroupStickyness;		// float value between 0 and 1

				    // intensity
				    float deltaIntensity = intensity - tmpTeilstueck.Intensity;
				    if (deltaIntensity < 0 )
				    {
					    deltaIntensity *= -1.0f;
				    }
				    float intensityScore = ( 1.0f - (deltaIntensity * intensityNormalizationFactor)) * weightingIntensity;
				
		
				    // variety
				    float playCountOfSnippetInPercent = ((tmpTeilstueck.Playcount - minPlaycount) * playcountNormalizationFactor);
				    float playCountScore = (1.0f - playCountOfSnippetInPercent) * weightingPlaycount;		
				
				    float randomPercentValue = GetRandomFloat();		// returns a random percent float (between 0.0f and 0.99f)
				    float randomScore = randomPercentValue * weightingRandom;				
				    float varietyScore = (playCountScore + randomScore) * weightingVariety / 2.0f;

				    float segmentScore = compatibilityScore + intensityScore + varietyScore;

				    // Vergleichen
				    if ( (resultSnippet == null) || (segmentScore > bestSegmentScore))
				    {
					    resultSnippet = tmpTeilstueck;
					    bestSegmentScore = segmentScore;
				    }

				    #if !(PSAI_NOLOG)
				    {
                        /*
                        if (LogLevel.debug <= Logger.Instance.LogLevel)
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.Append("segmentList[");
                            sb.Append(i);
                            sb.Append("]  id=");
                            sb.Append(segmentList[i].snippetId);
                            sb.Append("  segmentScore=");
                            sb.Append(segmentScore);
                            sb.Append("  compatibilityScore=");
                            sb.Append(compatibilityScore);
                            sb.Append("  intensityScore=");
                            sb.Append(intensityScore);
                            sb.Append("  varietyScore=");
                            sb.Append(varietyScore);
                            sb.Append("   [ playCountScore=");
                            sb.Append(playCountScore);
                            sb.Append("  randomScore=");
                            sb.Append(randomScore);
                            sb.Append(" ]");
                            sb.Append("    segmentList[i]->compatibility=");
                            sb.Append(segmentList[i].compatibility);
                            Logger.Instance.Log(sb.ToString(), LogLevel.debug);
                        }
                        */
				    }
                    #endif
                }
		    }

		    #if !(PSAI_NOLOG)
		    {
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(" ...returning Segment id=");
                    sb.Append(resultSnippet.Id);
                    sb.Append("  themeId=");
                    sb.Append(resultSnippet.ThemeId);
                    sb.Append("  playbackCount=");
                    sb.Append(resultSnippet.Playcount);
                    sb.Append("  intensity=");
                    sb.Append(resultSnippet.Intensity);
                    sb.Append("  bestSegmentScore=");
                    sb.Append(bestSegmentScore);
                    Logger.Instance.Log(sb.ToString(), LogLevel.debug);
                }
		    }
		    #endif

		    return resultSnippet;
	    }
예제 #3
0
        public Theme()
        {
            m_segments = new List<Segment>();
            weightings = new Weighting();

            this.id = -1;
            this.restSecondsMax = 0;
            this.restSecondsMin = 0;
            this.priority = 0;
            this.themeType = ThemeType.none;
            this.Name = "";
        }