c# - Linq calculate average,total and compare the result in query -
i having trouble in following query how add if else in select block want better way write following query
var x = csvparser.parsecsv(@"data.csv"); var unsettledcustomers = x.groupby(g=>g.id). select(gg =>new { id=g.key, total=g.sum(xx=>xx.stake), avg=g.average(ss=>ss.win) });
var unsettledcustomers = x.groupby(g => g.id) .select(g => new { id = g.key, total = g.sum(xx => xx.stake), avg = g.average(ss => ss.win), avgeragebet = g.average(ss => ss.stake), unusualbets = g.where(bet => bet.stake > (10 * g.average(ss => ss.stake))).tolist() }); var allunusualbets = unsettledcustomers.selectmany(y => y.unusualbets);
your posted question:
i want identify bets stake (bet) more 10 times higher customer’s average bet in betting history...
your data id = customer id. note there no instances average bet * 10 higher bet placed there no unusual bets in sample data according have defined in question.
id: 1, averagebet: 400, averagebettimes10: 4000, highest bet: 1000
id: 2, averagebet: 15, averagebettimes10: 150, highest bet: 20
id: 3, averagebet: 110, averagebettimes10: 1100, highest bet: 300
id: 4, averagebet: 237.5, averagebettimes10: 2375, highest bet: 300
id: 5, averagebet: 73.3333333333333, averagebettimes10: 733.333333333333, highest bet: 100
id: 6, averagebet: 162.5, averagebettimes10: 1625, highest bet: 500
Comments
Post a Comment