score:0
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?
score:1
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.
score:2
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.
Source: stackoverflow.com
Related Query
- 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
- What does this C# code with an "arrow" mean and how is it called?
- how to use entity framework to group by date not date with time
- How can you do custom sorting in LINQ with null always on the end?
- 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?
- How do I use a custom comparer with the Linq Distinct method?
- How to group by custom types with linq
- 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
- How to get the latest date inserted from the table with Linq to entities
- How to use C# LINQ Union to get the Union of Custom list1 with list2
- How can I select items with Linq by Date while ignoring Time portion of a DateTime property?
- How to implement method with expression parameter c#
- How do I implement a search feature with Entity Framework?
- How to compare only date part with linq expression?
- C# Code Contracts -- How to ensure that a collection of items contains items with unique properties?
- In Umbraco 7, how can i search for all members with a custom property?
- How to sum a custom object with LinQ?
- I have a custom expression program with a lexer, parser and evaluator. How do I LINQ-ify it?
- How to add Month in date time and Compare with another date time in Linq?
- LINQ VB how to select records with the max date (highest date)
- How to query by where clause with EF code first
- How do I get this Linq query with custom join into a DataSet?
- How do I represent an option calculated column with EF Code First?
- How can I combine IObservable<T>.Throttle() with some other event source using Reactive Extensions?
- C# How to Create a Custom (dynamic) class with Dynamic Linq using XElement in runtime
More Query from same tag
- TreeView selected event is not working to bind treeview selected items in gridview using LINQ
- how to fix the following issue in linq?
- How can I optimise this LinQ query?
- Comparison of two List<T> and fill missing dates and values with the other
- Pagination in C# against DocumentDB without Skip
- How to handle exception raised in linq
- How to sum up an array/list of own classes with an enumerator?
- Efficient way of finding multiple dates per ID
- column filtering using asc/dsc ? complex one . MVC4
- Returning a maximum number of items the LINQ way
- lambda expressions in immediate window for VS2015
- Linq : Group by and sum based on another list
- How do I map similar linq2sql generated results to a single object?
- How does linq Expression<TDelegate> assignment work on a language syntax level
- How to handle heavy query as light and fast version?
- "OR " condition in where clause of linq query is returning null
- LINQ IQueryable Check if Empty without Enumerating
- DataTable remove columns and re-order the columns
- Max in linq to NHibernate for not exist data in database
- How can I make a LINQ Select that includes a child object like a SQL outer join?
- 'Model' does not contain a definition for 'Object"
- How to resolve Lambda Expression
- Linq query using generics & interfaces
- Issue Linq in entity framework?
- GroupBy multiple columns in Linq with Take()
- Why does this anonymous type Linq expression work?
- Remove from list a range based on an objects properties
- Cannot find xml element using linq query in Portable Class Library
- Dynamic linq expression tree with nested properties
- Need to update list item and then put it in textfile