There wouldn't be a need to execute SQL 10 times to get the result, you could get it in one execution something like:
select sum(dayval) from ( select count(*) / (current_date-day+1) dayval from votes where story_id = 123 and day >= current_date - 9 group by (current_date-day+1) )
(Actual code varies according to DBMS used).
I'm not claiming this would perform well though!
Perhaps a compromise: calculate and store the "start of day" value in a daily batch process, but then add 1 to the stored value for each vote received during the day?
Try this one: everyone has one vote. Your vote sticks to the last thing you voted for. The time thing would come from user behaviour.
there is a logarithmic weighted average that you could do. the advantage of this is that you only ever need to store the "current value" and the weighted average. In your case the "current value" could be number of votes that day, and you could recalculate the weighted average each night.
const float WeightFactor = 0.70; //for example float PreviousAverage = GetPreviousAverage(); float CurrentValue = GetVoteCountToday(); float NewAverage = (WeightFactor * CurrentValue) + ( (1-WeightFactor) * PreviousAverage);
This only really works if you have a new value that occurs at a set frequency. If you want to recalculate your vote at arbritary times then this wouldn't work.
- How to implement a custom rating system (with a declining date relevance)
- How best to implement a login system in VB.NET using LINQ to compare information with an Access table?
- How to select only the records with the highest date in LINQ
- Cannot initialize type '' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
- What does this C# code with an "arrow" mean and how is it called?
- LINQ to SQL: GroupBy() and Max() to get the object with latest date
- how to use entity framework to group by date not date with time
- Linq syntax for OrderBy with custom Comparer<T>
- Entity Framework 6 Code First Custom Functions
- How can you do custom sorting in LINQ with null always on the end?
- Cannot implement type XYZ with a collection initializer because it does not implement 'System.Collections.IEnumerable'
- LINQ; how to get record with max date with join?
- How to implement Unit of Work that works with EF and NHibernate
- How would you implement LINQ methods with SelectMany?
- Intersect with a custom IEqualityComparer using Linq
- How do I use a custom comparer with the Linq Distinct method?
- How to group by custom types with linq
- Entity Framework Group By with Max Date and count
- Getting object with max date time value in one of it's properties
- How to implement SkipWhile with Linq to Sql without first loading the whole list into memory?
- How to: Use async methods with LINQ custom extension method
- Use Linq query to compare date only with DateTime field
- How to get the latest date inserted from the table with Linq to entities
- Use of Distinct with list of custom objects
- LinQ distinct with custom comparer leaves duplicates
- How to use C# LINQ Union to get the Union of Custom list1 with list2
- Why doesn't this code compile in VS2010 with .NET 4.0?
- LINQ TO SQL, Dynamic query with DATE type fields
- Using LINQ to Get Sum/ Average of a List with custom objects
- Is order relevance implied with IEnumerable<T> or should it be explicit?
- How to do a subquery in LINQ?
- Nullable reference type information not exposed from FirstOrDefault
- Search using Linq from the view
- Dynamic LINQ to DataTable: why using hardcode string "it" as DataRow
- How to get the union, intersection and difference of two given Hashtables?
- Multiple LINQ to XML query
- How to convert Linq query for joining 3 tables to Linq method and use Include
- How to custom response in asp.net web api2
- LINQ to Entities: Age calculation in a LINQ query causes "Method cannot be translated into a store expression"
- LINQ: Select <contition> OR <condition>
- Convert List<string> to List<KeyValuePair<string, string>> using Linq
- MVC 4 and LINQ query utilising 2 entities in ViewModel
- Linq search query using ||
- Another System.InvalidOperationException: Sequence contains no elements (using .Any())
- Same data being returned by linq for 2 different executions of a stored procedure?
- How to concatenate two collections by index in LINQ
- Linq PredicateBuilder, grouping and operator precedence
- Linq to SQL nvarchar problem
- LINQ How to Remove Empty Elements at End of Collection
- How to remove particular value from data table in .net