Advertisement
Guest User

Untitled

a guest
Aug 29th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. private static PieChart GetPieChart(IEnumerable<AFBaseElement> myElements, string key, List<string> attributeNames, bool flag)
  2. {
  3.  
  4. if (flag)
  5. {
  6. List<string> afList = new List<string>();
  7. foreach (string temp in attributeNames)
  8. {
  9. var attributeValues = GetValuesFromElements(myElements, temp);
  10. var filteredAttributeValues = attributeValues.Where(v => v.IsGood).Select(v => ConvertToDouble(v)).ToList();
  11. var output = filteredAttributeValues.Sum().ToString();
  12. afList.Add(output);
  13. }
  14. PieChart newPieChart = new PieChart(afList, attributeNames, key);
  15. return newPieChart;
  16. }
  17. else
  18. {
  19. List<string> afList = new List<string>();
  20. var attributeNameToValue = new Dictionary<string, double>();
  21. foreach (string temp in attributeNames)
  22. {
  23. var attributeValues = GetValuesFromElements(myElements, temp);
  24. var filteredAttributeValues = attributeValues.Where(v => v.IsGood).Select(v => ConvertToDouble(v)).ToList();
  25. var output = filteredAttributeValues.Sum();
  26. attributeNameToValue.Add(temp, output);
  27. }
  28. var result = attributeNameToValue.OrderByDescending(val => val.Value);
  29. List<string> orderedList = new List<string>();
  30. int count = 0;
  31. foreach(var kvp in result)
  32. {
  33. if(count < 10)
  34. {
  35. afList.Add(kvp.Value.ToString());
  36. orderedList.Add(kvp.Key);
  37. count++;
  38. }
  39. }
  40. PieChart newPieChart = new PieChart(afList, orderedList, key);
  41. return newPieChart;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement