I've a lot of data whit prices of a product from different firms by week. I've a class named WeekPrice
witch contains a list of firms
. Here you've my class structure.
Here you've a little part of the data in JSON format:
[
{
"ID": 1,
"NumberOfWeek": 1,
"Year": 2016,
"Date": "01/04/2016",
"Firms": [
{
"ID": 1,
"Name": "Firm ABC",
"Price": 0.73
},
{
"ID": 2,
"Name": "DEF Solutions",
"Price": 0.97
}
]
},
{
"ID": 2,
"NumberOfWeek": 2,
"Year": 2016,
"Date": "08/04/2016",
"Firms": [
{
"ID": 3,
"Name": "Firm ABC",
"Price": 0.83
},
{
"ID": 4,
"Name": "DEF Solutions",
"Price": 0.94
}
]
}
]
I'll to make a graph that shows the evolution of the price for one firm by week. to this I need to get the price and the week in a object. In the C# code below DoublePoint
is used for do this. The property Data
is the week number and Value
is the price.
List<DoublePoint> list = (from week in MyListWitData
where week.Year == DateTime.Now.Year
group week by week.NumberOfWeek into grp
select new DoublePoint()
{
Data = grp.Key,
Value = (double)(from price in grp.ToList()
where price.Year == DateTime.Now.Year
select (from firm in prijs.Bedrijf
where firm.Name == "Firm ABC"
select firm.Price
).FirstOrDefault<decimal>()
).FirstOrDefault()
}).ToList<DoublePoint>();
It works perfectly but the only problem is that the code is a little bit messy. Can you refactor my code so it's better in performance and easier to read it?
Thanks in advance
Frim ABC
as a name instead ofFirm ABC
? \$\endgroup\$ – Denis Apr 6 '16 at 13:18