Copy below:
Gone through the problem an got the relevant answer also made blog on it so visit the blog post
Some of the important aspects covered are described breifly as follows.
This field stores the number of users who have rated the item its value should be incremented.
A field which stores the user ratings in CSV string format should add the new users rating like.
int NewNumberOfRatings = OldNumberOfRatings + 1;
float NewAverage = OldAverage + ( ( NewRating - OldAverage ) / NewNumberOfRatings);
float NewAverage = ( ( OldAverage * OldNumberOfRatings ) + NewRating ) / NewNumberOfRatings;
FieldUserValue[] ratedUsers = item["RatedBy"] as FieldUserValue[];
//where ratedUsers becomes an array of users who have already rated.
List<FieldUserValue> newUsersRated = new List<FieldUserValue>();
foreach (FieldUserValue ratedUser in ratedUsers)
Change the user rating in this CSV string by use of userIndex.
FieldUserValue[] ratedUsers = item["RatedBy"] as FieldUserValue[];
for (int i = 0; i < ratedUsers.Length; i++)
if (ratedUsers[i].LookupValue == user.Title)
string[] userRatings = item["Ratings"].split(',');
int OldRating = int.Parse(userRatings[userIndex]);
int NewRating = 3; //any desired number from 1 to 5.
userRatings[userIndex] = NewRating.ToString();
change the average value using formula
float OldAverage = item["AverageRating"];
int NumberOfRatings = item["RatingCount"];
float NewAverage = OldAverage + ( ( NewRating - OldRating ) / NumberOfRatings );