Ejemplo n.º 1
0
 public static List<Category> Flatten(Category root)
 {
     var flattened = new List<Category> {root};
     foreach (var category in root.Categories)
         flattened.AddRange(Flatten(category));
     return flattened;
 }
Ejemplo n.º 2
0
 public static CategoryViewModel Create(Category root)
 {
     var root_view_model = new CategoryViewModel(root);
     foreach (var c in root.Categories)
     {
         var vm = Create(c);
         root_view_model.Categories.Add(vm);
     }
     return root_view_model;
 }
Ejemplo n.º 3
0
        // Generate data
        public List<KeyValuePair<string, double>> ByYear(Category category)
        {
            var result = new List<KeyValuePair<string, double>>();

            var posts = category.AggregatePosts().Distinct().OrderBy(p => p.Date).ToList();
            var date = posts.First().Date;
            var last_date = posts.Last().Date;
            while (date.Year <= last_date.Year)
            {
                var total = posts.Where(p => p.Date.Year == date.Year).Sum(p => p.Value);
                result.Add(new KeyValuePair<string, double>(date.Year.ToString(), total));
                date = date.AddYears(1);
            }

            return result;
        }
Ejemplo n.º 4
0
        public Category Find(string pattern, Category root)
        {
            //if (root.Name == c)
            //    return root;
            if (Regex.IsMatch(root.Name, pattern))
                return root;

            foreach (var category in root.Categories)
            {
                var result = Find(pattern, category);
                if (result != null)
                    return category;
            }

            return null;
        }
Ejemplo n.º 5
0
 public CategoryViewModel(Category category)
 {
     this.category = category;
     IsMatch = false;
     Categories = new ObservableCollection<CategoryViewModel>();
 }
Ejemplo n.º 6
0
        public static List<Category> FixedCategories(List<Post> posts)
        {
            var result = new List<Category>();

            // Temp category
            Category c;

            var regex_category = new Category("Regex");
            c = new Category("Word1");
            c.Filters.Add(new RegexFilter(new Regex(Wordlist.Instance.Words[0])));
            regex_category.Add(c);
            c = new Category("Word2");
            c.Filters.Add(new RegexFilter(new Regex(Wordlist.Instance.Words[100])));
            regex_category.Add(c);
            c = new Category("Word3");
            c.Filters.Add(new RegexFilter(new Regex(Wordlist.Instance.Words[200])));
            regex_category.Add(c);
            result.Add(regex_category);

            var date_category = new Category("Date");
            c = new Category("Before 1-1-2008");
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2008, 1, 1), Operator = DateOperator.Before });
            date_category.Add(c);
            c = new Category("Equal 1-1-2008");
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2008, 1, 1), Operator = DateOperator.Equal });
            date_category.Add(c);
            c = new Category("After 1-1-2008");
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2008, 1, 1), Operator = DateOperator.After });
            date_category.Add(c);
            c = new Category("Range 1-1-2008 to 1-1-2009");
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2008, 1, 1), Date2 = new DateTime(2009, 1, 1), Operator = DateOperator.Range });
            date_category.Add(c);
            c = new Category("1-1-2008 to 1-1-2009");
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2008, 1, 1), Operator = DateOperator.After });
            c.Filters.Add(new DateFilter { Date1 = new DateTime(2009, 1, 1), Operator = DateOperator.Before });
            date_category.Add(c);
            result.Add(date_category);

            var value_category = new Category("Value");
            c = new Category("Less than 542");
            c.Filters.Add(new ValueFilter { Value1 = 542, Operator = ValueOperator.Less });
            value_category.Add(c);
            c = new Category("Around 542");
            c.Filters.Add(new ValueFilter { Value1 = 542, Epsilon = 5, Operator = ValueOperator.Around });
            value_category.Add(c);
            c = new Category("Greater than 542");
            c.Filters.Add(new ValueFilter { Value1 = 542, Operator = ValueOperator.Greater });
            value_category.Add(c);
            c = new Category("Range 123 - 321");
            c.Filters.Add(new ValueFilter { Value1 = 123, Value2 = 321, Operator = ValueOperator.Range });
            value_category.Add(c);
            result.Add(value_category);

            var hash_category = new Category("Items");
            var f = new HashFilter();
            f.Set.Add(posts[0]);
            f.Set.Add(posts[17]);
            f.Set.Add(posts[23]);
            f.Set.Add(posts[42]);
            hash_category.Filters.Add(f);
            result.Add(hash_category);

            return result;
        }
Ejemplo n.º 7
0
 public Profile()
 {
     Name = string.Empty;
     Accounts = new List<Account>();
     RootCategory = new Category("Root");
 }
Ejemplo n.º 8
0
 public void CategoryByYearGraph(Category category)
 {
     var sw = Stopwatch.StartNew();
     GraphData = new ObservableCollection<KeyValuePair<string, double>>(graph_data_generator.ByYear(category));
     sw.Stop();
     Status = "Elapsed (graph): " + sw.ElapsedMilliseconds + " ms";
 }
Ejemplo n.º 9
0
        public void ByYear(string pattern)
        {
            Category category = CategoryController.Find(pattern);

            ViewModel.CategoryByYearGraph(category);
        }
Ejemplo n.º 10
0
 public void Remove(Category category)
 {
     category.Parent = null;
     Categories.Remove(category);
 }
Ejemplo n.º 11
0
 public void Add(Category category)
 {
     category.Parent = this;
     Categories.Add(category);
 }