The calculations in your comparison code are independent (i.e., the comparison simply depends on ordering the value, which can be calculated without reference to the element you are comparing). Therefore, you must first calculate your positive percentage number and just use the calculated value in your compam.
This must be done in the database, if possible (i.e. if you have access to make changes to the database). Databases are suitable for this kind of calculation, and you could do it on the fly without the need to cache the calculated values, by which I mean a view that determines the percentage for you, rather than predicting and saving the value every time there is a positive or negative voice. This saves you from having to upload all the photos for comparison, as you can simply order a positive percentage. The following is an example sql example that will do the job (note that this is just a sample ... you may want to keep the vote as little or something more efficient). The votes table contains a list of all votes for a particular photo and who voted for it.
declare @votes table( pictureId int, voterId int, vote int) insert into @votes select 1,1,1 insert into @votes select 1,2,-1 insert into @votes select 1,3,1 insert into @votes select 1,4,1 insert into @votes select 2,1,-1 insert into @votes select 2,2,-1 insert into @votes select 2,3,1 insert into @votes select 2,4,1 declare @votesView table( pictureId int, positiveVotes int, NegativeVotes int) insert into @votesView select pictureId, sum(case when vote > 0 then 1 else 0 end) as PositiveVotes, SUM(case when vote < 0 then 1 else 0 end) as NegativeVotes from @votes group by pictureId select pictureId, convert(decimal(6,2),positiveVotes) / convert(decimal(6,2), (positiveVotes + negativeVotes)) as rating from @votesView