public class Prophet
{
public string Id { get; set; }
}
public class Prediction
{
public string Id { get; set; }
public string ProphetId { get; set; }
public string Profit { get; set; }
}
public class Team
{
public string Id { get; set; }
public List<string> MemberProphetIds { get; set; }
}
public class Predictions_ByProphet : AbstractMultiMapIndexCreationTask<Predictions_ByProphet.Result>
{
public class Result
{
public string ProphetId { get; set; }
public double Profit { get; set; }
}
public Predictions_ByProphet()
{
AddMap<Prediction>(items => from x in items
select new
{
ProphetId = x.ProphetId,
Profit = x.Profit,
});
Reduce = results => from result in results
group result by result.ProphetId into g
select new
{
ProphetId = g.Key,
Profit = g.Sum(x => x.Profit)
};
}
}
--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
public class Prediction
{
public string Id { get; set; }
public string ProphetId { get; set; }
public double Profit { get; set; }
}
Hibernating Rhinos Ltd
Oren Eini l CEO l Mobile: + 972-52-548-6969
Office: +972-4-622-7811 l Fax: +972-153-4-622-7811
public class Prophet
{
public string Id { get; set; }
public List<string> MemberOfTeams { get; set; }
}
public class Prediction_ByTeam : AbstractMultiMapIndexCreationTask<Prediction_ByTeam.Result>
{
public class Result
{
public string TeamId { get; set; }
public double Profit { get; set; }
}
public Prediction_ByTeam()
{
AddMap<Prediction>(items => from x in
items
let prophet = LoadDocument<Prophet>(x.ProphetId)
from m in prophet.MemberOfTeams
select new
{
Profit = x.Profit,
TeamId = m,
});
Reduce = results => from result in
results
group result by result.TeamId into g
select new
{
TeamId = g.Key,
Profit = g.Sum(x => x.Profit),
};
}
}
class TeamProphetProfit
{ public string TeamId { get; set; }
public string ProphetId { get; set; }
public double? Profit { get; set; }}
var results = new List<TeamProphetProfit>(){ new TeamProphetProfit() { TeamId = "team/1", ProphetId = "prophet/1", Profit = 0 }, new TeamProphetProfit() { TeamId = "team/1", ProphetId = "prophet/2", Profit = 0 }, new TeamProphetProfit() { TeamId = "team/2", ProphetId = "prophet/2", Profit = 0 }, new TeamProphetProfit() { TeamId = "team/3", ProphetId = "prophet/1", Profit = 0 }, new TeamProphetProfit() { TeamId = "-1", ProphetId = "prophet/1", Profit = 1 }, new TeamProphetProfit() { TeamId = "-1", ProphetId = "prophet/1", Profit = 2 }, new TeamProphetProfit() { TeamId = "-1", ProphetId = "prophet/2", Profit = 1 },};
var reduce = from result in results.Take(1)
let prophetsByTeam = results.Where(x => x.TeamId != "-1")
let profitByProphet = results.Where(x => x.TeamId == "-1").GroupBy(y => y.ProphetId).Select(y => new { ProphetId = y.Key, Profit = y.Sum(p => p.Profit) })
let items = prophetsByTeam.Select(t => new
{
Profit = profitByProphet.Where(x => t.ProphetId == x.ProphetId).Sum(u => u.Profit),
TeamId = t.TeamId,
ProphetId = "-1"
})
from item in items
group item by item.TeamId into g
select new
{
Profit = g.Sum(x => x.Profit),
TeamId = g.Key,
ProphetId = "-1"
};
public class Prediction_ByTeam_Test : AbstractMultiMapIndexCreationTask<Prediction_ByTeam_Test.Result>
{
public class Result
{
public string ProphetId { get; set; }
public string TeamId { get; set; }
public double Profit { get; set; }
}
public Prediction_ByTeam_Test()
{
AddMap<Team>(items => from x in items
from t in x.MemberIds
select new
{
ProphetId = t,
TeamId = x.Id,
Profit = 0
});
AddMap<Prediction>(items => from x in items
select new
{
ProphetId = x.ProphetId,
Profit = x.Profit,
TeamId = "-1"
});
Reduce = results => from result in results.Take(1)
let prophetsByTeam = results.Where(x => x.TeamId != "-1")
let profitByProphet = results.Where(x => x.TeamId == "-1").GroupBy(y => y.ProphetId).Select(y => new { ProphetId = y.Key, Profit = y.Sum(p => p.Profit) })
let items = prophetsByTeam.Select(t => new
{
Profit = profitByProphet.Where(x => t.ProphetId == x.ProphetId).Sum(u => u.Profit),
TeamId = t.TeamId,
ProphetId = "-1"
})
from item in items
group item by item.TeamId into g
select new
{
Profit = g.Sum(x => x.Profit),
TeamId = g.Key,
ProphetId = "-1"
};
}
}
from result in Enumerable.Take(results, 1)
select new {
result = result,
prophetsByTeam = results.Where(x => x.TeamId != "-1")
} into this0
select new {
this0 = this0,
profitByProphet = results.Where(x => x.TeamId == "-1").GroupBy(y => y.ProphetId).Select(y => new {
ProphetId = y.Key,
Profit = Enumerable.Sum(y, p => ((double)p.Profit))
})
} into this1
select new {
this1 = this1,
items = this1.this0.prophetsByTeam.Select(t => new {
Profit = Enumerable.Sum(this1.profitByProphet.Where(x => t.ProphetId == x.ProphetId), u => ((double)u.Profit)),
TeamId = t.TeamId,
ProphetId = "-1"
})
} into this2
from item in this2.items
select new {
this2 = this2,
item = item
} into this3
group this3.item by this3.item.TeamId into g
select new {
Profit = Enumerable.Sum(g, x => ((double)x.Profit)),
TeamId = g.Key,
ProphetId = "-1"
}