Jump to content

warrentc3

Recommended Posts

warrentc3

First crack at this... using powershell for now since it's my native language.

Attempting to create a composite movie rating leveraging the standard set of ratings sources, while adding weighting measures to various community ratings.

Definitely some more conditions and logic will be needed for scenarios where subsets of ratings sources are available, but the weighting math should hopefully mitigate a chunk of that.

Feedback welcome!

image.png.01c46ccc4ae2800d5576fe7bca38d4ea.png

$moviename = "Monty Python and the Holy Grail"
$rtaudiencerating = 95
$rtaudiencecount  = 645107
$rtcriticrating   = 98
$rtcriticcount    = 82
$tmdbrating       = 7.8
$tmdbcount        = 5028
$traktrating      = 8.3
$traktcount       = 11089
$metacriticrating = 91
$imdbrating       = 8.2
$imdbcount        = 547137

$ratings = @{}
$null = $ratings.Add('tomatometerallaudience',@{'MaxValue'=100;'rating'=$rtaudiencerating;'weight'=10;'votecount'=$rtaudiencecount } )
$null = $ratings.Add('tomatometerallcritics',@{'MaxValue'=100;'rating'=$rtcriticrating;'weight'=10;'votecount'=$rtcriticcount} )
$null = $ratings.Add('themoviedb',@{'MaxValue'=10;'rating'=$tmdbrating;'weight'=20;'votecount'=$tmdbcount} )
$null = $ratings.Add('trakt',@{'MaxValue'=10;'rating'=$traktrating;'weight'=20;'votecount'=$traktcount} )
$null = $ratings.Add('metacritic',@{'MaxValue'=100;'rating'=$metacriticrating;'weight'=20;'votecount'=0} )
$null = $ratings.Add('imdb',@{'MaxValue'=10;'rating'=$imdbrating;'weight'=20;'votecount'=$imdbcount} )

$community = @{}
$totalcommunityvotes = $ratings['imdb'].votecount + $ratings['trakt'].votecount + $ratings['themoviedb'].votecount + $ratings['tomatometerallaudience'].votecount 
$imdbpercentvotes = [math]::Round( $ratings['imdb'].votecount / $totalcommunityvotes,3)
$traktpercentvotes =  [math]::Round( $ratings['trakt'].votecount / $totalcommunityvotes,3)
$tmdbpercentvotes =  [math]::Round( $ratings['themoviedb'].votecount / $totalcommunityvotes,3)
$rtpercentvotes =  [math]::Round( $ratings['tomatometerallaudience'].votecount / $totalcommunityvotes,3)
$communitysum = $imdbpercentvotes + $traktpercentvotes + $tmdbpercentvotes + $rtpercentvotes
if ( $communitysum -gt 1 ) { $rtpercentvotes = $rtpercentvotes - ($communitysum - 1) }
elseif ( $communitysum -lt 1 ) { $imdbpercentvotes = $imdbpercentvotes + (1 - $communitysum) }

$adjtraktcount = 1; 
if ( $traktpercentvotes -eq 0 -and $ratings['trakt'].votecount -ne 0 ) { $adjtraktcount = 100 }
elseif ( $traktpercentvotes -lt 0.002 ) { $adjtraktcount = 100 }
elseif ( $traktpercentvotes -lt 0.004 ) { $adjtraktcount = 80 }
elseif ( $traktpercentvotes -lt 0.006 ) { $adjtraktcount = 60 }
elseif ( $traktpercentvotes -lt 0.008 ) { $adjtraktcount = 50 }
elseif ( $traktpercentvotes -lt 0.010 ) { $adjtraktcount = 30 }
elseif ( $traktpercentvotes -lt 0.100 ) { $adjtraktcount = 10 }
$adjtmdbcount = 1; 
if ( $tmdbpercentvotes -eq 0 -and $ratings['themoviedb'].votecount -ne 0 ) { $adjtmdbcount = 100 }
elseif ( $tmdbpercentvotes -lt 0.002 ) { $adjtmdbcount = 100 }
elseif ( $tmdbpercentvotes -lt 0.004 ) { $adjtmdbcount = 80 }
elseif ( $tmdbpercentvotes -lt 0.006 ) { $adjtmdbcount = 60 }
elseif ( $tmdbpercentvotes -lt 0.008 ) { $adjtmdbcount = 50 }
elseif ( $tmdbpercentvotes -lt 0.010 ) { $adjtmdbcount = 30 }
elseif ( $tmdbpercentvotes -lt 0.100 ) { $adjtmdbcount = 10 }

$adjtotalcommunityvotes = $ratings['imdb'].votecount + ($ratings['trakt'].votecount*$adjtraktcount) + ($ratings['themoviedb'].votecount*$adjtmdbcount) + $ratings['tomatometerallaudience'].votecount 
$adjimdbpercentvotes = [math]::Round( $ratings['imdb'].votecount / $adjtotalcommunityvotes,3)
$adjtraktpercentvotes =  [math]::Round( ($ratings['trakt'].votecount * $adjtraktcount) / $adjtotalcommunityvotes,3)
$adjtmdbpercentvotes =  [math]::Round( ($ratings['themoviedb'].votecount * $adjtmdbcount) / $adjtotalcommunityvotes,3)
$adjrtpercentvotes =  [math]::Round( $ratings['tomatometerallaudience'].votecount / $adjtotalcommunityvotes,3)
$adjcommunitysum = $adjimdbpercentvotes + $adjtraktpercentvotes + $adjtmdbpercentvotes + $adjrtpercentvotes
if ( $adjcommunitysum -gt 1 ) { $adjrtpercentvotes = $adjrtpercentvotes - ($adjcommunitysum - 1) }
elseif ( $adjcommunitysum -lt 1 ) { $adjimdbpercentvotes = $adjimdbpercentvotes + (1 - $adjcommunitysum) }
$null = $community.Add('imdb',@{'votecount'=$ratings['imdb'].votecount;'percentage'=$imdbpercentvotes;'adjpercent'=$adjimdbpercentvotes } )
$null = $community.Add('trakt',@{'votecount'=$ratings['trakt'].votecount;'percentage'=$traktpercentvotes;'adjpercent'=$adjtraktpercentvotes } )
$null = $community.Add('themoviedb',@{'votecount'=$ratings['themoviedb'].votecount;'percentage'=$tmdbpercentvotes;'adjpercent'=$adjtmdbpercentvotes } )
$null = $community.Add('tomatometerallaudience',@{'votecount'=$ratings['tomatometerallaudience'].votecount;'percentage'=$rtpercentvotes;'adjpercent'=$adjrtpercentvotes } )

$communityweight = 70; 
if ( !$ratings.ContainsKey('metacritic') ) { $communityweight = $communityweight + 20 }
if ( !$ratings.ContainsKey('tomatometerallcritics') ){ $communityweight = $communityweight + 10 }
$scoring = @{}; $scoringtable = New-Object System.Collections.ArrayList
$ratings.GetEnumerator() | ForEach-Object { 
$current = $_;
$source = $current.Name
$sourcetype = $null; if ( $source -in ('tomatometerallcritics','metacritic') ) { $sourcetype = "Critic" } else { $sourcetype = "Community" } 
$sourcerating = $current.Value.rating
$sourcemax = $current.Value.MaxValue
if ( $sourcemax -eq 5 ) { $adjustedmax = $sourcemax*20; $adjustedrating = $sourcerating*20 } elseif ( $sourcemax -eq 10 ) { $adjustedmax = $sourcemax*10; $adjustedrating = $sourcerating*10 } else { $adjustedmax = $sourcemax; $adjustedrating = $sourcerating }
$sourcevotecount = $current.Value.votecount
$communitylookup = $null; $communitylookup = $community[$source]
$communityvotepercent = $communitylookup.percentage
$communityadjvotepercent = $communitylookup.adjpercent
$weighting = 0; if ( $sourcetype -eq "Community" ) { $weighting = $communityadjvotepercent * $communityweight }  else { $weighting = $current.Value.weight } 
$newcompositerating = ($adjustedrating * ($weighting/100 ) )
$null = $scoring.Add($source,@{'SourceType'=$sourcetype;'SourceVoteCount'=$sourcevotecount;'SourceRating'=$sourcerating;'SourceMax'=$sourcemax;'AdjustedRating'=$adjustedrating;'AdjustedMax'=$adjustedmax;'CommunityVotePrc'=$communityvotepercent;'AdjCommunityVotePrc'=$communityadjvotepercent; 'Weight'=$weighting; 'NewRating'= $newcompositerating } )
$null = $scoringtable.Add([pscustomobject]@{'Source' =$source;'SourceType'=$sourcetype;'SourceVoteCount'=$sourcevotecount;'SourceRating'=$sourcerating;'SourceMax'=$sourcemax;'AdjustedRating'=$adjustedrating;'AdjustedMax'=$adjustedmax;'CommunityVotePrc'=$communityvotepercent;'AdjCommunityVotePrc'=$communityadjvotepercent; 'Weight'=$weighting; 'NewRating'= $newcompositerating } )
}
#$highestweight = $scoringtable | Sort-Object Weight -Descending | Select-Object -First 1
if ( ($scoringtable.Weight | Measure-Object -Sum).Sum -gt 100.1 ) { Write-Warning "Weighting calculated over 100.1%"  }
elseif ( ($scoringtable.Weight | Measure-Object -Sum).Sum -lt 99.9 ) { Write-Warning "Weighting calculated under 99.9%"  }

$NewRating = [math]::Round( (($scoringtable.NewRating | Measure-Object -Sum).Sum/10),1) 
Write-Output "",""
Write-Output "Current movie is $($moviename)."
Write-Output "Rotten Tomatoes Critic rating is $($rtcriticrating) out of 100."
Write-Output "Rotten Tomatoes Community rating is $($rtaudiencerating) out of 100."
Write-Output "Metacritic rating is $($metacriticrating) out of 100."
Write-Output "Trakt community rating is $($traktrating) out of 10."
Write-Output "IMDB community rating is $($imdbrating) out of 10."
Write-Output "The MovieDB rating is $($tmdbrating) out of 10."
Write-Output "","New composite rating is $($NewRating) out of 10."

 

Edited by warrentc3
added comment
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...
Riddler84

Nice work. I like such aggregated ratings. Just for your interest, there's already a site, which does something like that. It's also including ratings from Letterboxd and RogerEbert.

Looking at your example, the site calculates a rating of 86 out of 100 for this movie. So it's pretty close.
https://mdblist.com/movie/tt0071853

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...