public static void DelAllData() { var model1 = new ShowAllCatchesViewModel(); var model2 = new LocationViewModel(); var model3 = new ShowAllNoteTacklesViewModel(new Models.Note()); var model4 = new ShowAllTacklesViewModel(new Models.TackleCategory()); var model5 = new ShowAllTrophiesViewModel(); var model6 = new NoteViewModel(); model1.DelAll(); model2.DelAll(); model3.DelAll(); model4.DelAll(); model5.DelAll(); model6.DelAll(); DirectoryInfo notes_di = new DirectoryInfo($"{App.FolderName}\\Assets\\notes"); foreach (var di in notes_di.GetDirectories()) { di.Delete(true); } DirectoryInfo tackles_di = new DirectoryInfo($"{App.FolderName}\\Assets\\tackle"); foreach (var file in tackles_di.GetFiles()) { file.Delete(); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { DateTxt.Text = $"{Note.Date:dd.MM.yyyy}"; TimeTxt.Text = $"{Note.StartTime:HH:mm} - {Note.EndTime:HH:mm}"; #region Location LocationTxt.Text = $"{Note.Location?.Name}"; LatitudeTxt.Text = $"{Note.Location?.Latitude:##.####}"; LongitudeTxt.Text = $"{Note.Location?.Longitude:##.####}"; #endregion #region Trophies var trophies = new ShowAllTrophiesViewModel(Note).Trophies; if (trophies.Count() > 0) { for (int i = 0; i <= 4; i++) { TableColumn column = new TableColumn(); column.Width = new GridLength(100); TrophyTable.Columns.Add(column); } var rowgroup = new TableRowGroup(); TableRow row = new TableRow(); row.Cells.Add(new TableCell(new Paragraph(new Run("Фото")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Вид")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Вес")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Длина")))); rowgroup.Rows.Add(row); foreach (var trophy in trophies) { row = new TableRow(); var img = new Image(); img.Source = new Photo(trophy.Image).Thumbnail; img.Width = 100; img.Height = 100; row.Cells.Add(new TableCell(new BlockUIContainer(img))); row.Cells.Add(new TableCell(new Paragraph(new Run(trophy.Specy.Name)))); row.Cells.Add(new TableCell(new Paragraph(new Run($"{trophy.Weight} гр")))); row.Cells.Add(new TableCell(new Paragraph(new Run($"{trophy.Size} см")))); rowgroup.Rows.Add(row); } TrophyTable.RowGroups.Add(rowgroup); } #endregion #region Catches var catches = new ShowAllCatchesViewModel(Note).Catches; if (catches.Count() > 0) { for (int i = 0; i <= 3; i++) { TableColumn column = new TableColumn(); column.Width = new GridLength(150); CatchTable.Columns.Add(column); } TableRowGroup rowgroup = new TableRowGroup(); TableRow row = new TableRow(); row.Cells.Add(new TableCell(new Paragraph(new Run("Вид")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Количество")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Параметр")))); rowgroup.Rows.Add(row); foreach (var catchy in catches) { row = new TableRow(); row.Cells.Add(new TableCell(new Paragraph(new Run(catchy.Specy.Name)))); row.Cells.Add(new TableCell(new Paragraph(new Run($"{catchy.Count} шт")))); row.Cells.Add(new TableCell(new Paragraph(new Run(catchy.Param)))); rowgroup.Rows.Add(row); } CatchTable.RowGroups.Add(rowgroup); } #endregion #region NoteTackles var notetackles = new ShowAllNoteTacklesViewModel(Note).NoteTackles; if (notetackles.Count() > 0) { for (int i = 0; i <= 4; i++) { TableColumn column = new TableColumn(); column.Width = new GridLength(150); TackleTable.Columns.Add(column); } var rowgroup = new TableRowGroup(); TableRow row = new TableRow(); row.Cells.Add(new TableCell(new Paragraph(new Run("Фото")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Категория")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Название")))); row.Cells.Add(new TableCell(new Paragraph(new Run("Параметр")))); rowgroup.Rows.Add(row); foreach (var notetackle in notetackles) { row = new TableRow(); var img = new Image(); img.Source = new Photo(notetackle.Tackle.Image).Thumbnail; img.Width = 100; img.Height = 100; row.Cells.Add(new TableCell(new BlockUIContainer(img))); row.Cells.Add(new TableCell(new Paragraph(new Run(notetackle.Tackle.TackleCategory.Name)))); row.Cells.Add(new TableCell(new Paragraph(new Run(notetackle.Tackle.Name)))); row.Cells.Add(new TableCell(new Paragraph(new Run(notetackle.Parameter)))); rowgroup.Rows.Add(row); } TackleTable.RowGroups.Add(rowgroup); } #endregion #region Weather Params string temp_min = Note.TempMin < 0 ? $"-{Note.TempMin}" : $"+{Note.TempMin}"; string temp_max = Note.TempMax < 0 ? $"-{Note.TempMax}" : $"+{Note.TempMax}"; TempTxt.Text = $"T = {temp_min} {temp_max} C"; WaterTempTxt.Text = $"T воды = {Note.TempWater}C"; PressureTxt.Text = $"{Note.Pressure} мм"; WindTxt.Text = $"{Note.WindDir}, {Note.WindSpeed} м/с"; if (Note.Rainfall) { CloudTxt.Text = $"{Note.Cloud}, осадки"; } else { CloudTxt.Text = $"{Note.Cloud}"; } MoonTxt.Text = $"{Note.Moon}"; WeatherNoteTxt.Text = $"{Note.WeatherNote}"; #endregion #region Water Params WaterTranspTxt.Text = $"Прозрачность: {Note.WaterTransparency}"; FlowTxt.Text = $"Течение: {Note.Flow}"; DepthTxt.Text = $"Глубина: {Note.Depth:##.#} м"; BottomTxt.Text = $"Дно: {Note.Bottom}"; WaterHeightTxt.Text = $"Уровень воды: {Note.WaterHeight}"; WasteTxt.Text = $"Мусор: {Note.Waste}"; DistanceTxt.Text = $"Дальность: {Note.Distance} м"; WaterNoteTxt.Text = $"{Note.WaterNote}"; #endregion #region Catch Params CatchCountTxt.Text = $"Количество: {Note.CatchCount} штук"; CatchWeightTxt.Text = $"Вес: {Note.CatchWeight:##.#} кг"; NoteTxt.Text = $"{Note.NoteString}"; #endregion }
public void CalculateStat(List <Note> notes, string period) { List <string> dates = new List <string>(); foreach (var note in notes) { dates.Add(note.Date.ToString("dd-MM-yy")); } var ids = from n in notes select n.Id; var catchmodel = new ShowAllCatchesViewModel(ids.ToList()); var trophymodel = new ShowAllTrophiesViewModel(ids.ToList()); var locationmodel = new LocationViewModel(); double totallength = catchmodel.GetTotalLength() + trophymodel.GetTotalLength(); DisplayCommon(period, notes.Count, notes.Sum(p => (p.EndTime - p.StartTime).TotalHours), notes.Sum(p => p.CatchCount), notes.Sum(p => p.CatchWeight), totallength); int row = 10; DrawPointChart("T средняя", row, "дата", "t", dates.ToArray(), notes.Select(p => (p.TempMax + p.TempMin) / 2.0).ToArray()); DrawPointChart("T воды", row = row += 19, "дата", "t", dates.ToArray(), notes.Select(p => (double)p.TempWater).ToArray()); DrawPointChart("Давление", row = row += 19, "дата", "мм", dates.ToArray(), notes.Select(p => (double)p.Pressure).ToArray()); DrawPointChart("Глубина", row = row += 19, "дата", "м", dates.ToArray(), notes.Select(p => p.Depth).ToArray()); DrawPointChart("Дистанция", row = row += 19, "дата", "м", dates.ToArray(), notes.Select(p => (double)p.Distance).ToArray()); DrawPointChart("Улов", row = row += 19, "дата", "кол-во", dates.ToArray(), notes.Select(p => (double)p.CatchCount).ToArray()); //LOCATIONS var locations = locationmodel.Top(notes, 5); DrawBarChart("ТОП 5 мест", row = row + 20, "Места", "Количество", locations); row = row + 25; //TACKLES ShowAllNoteTacklesViewModel notetackleviewmodel; ShowAllTackleCategoriesViewModel tackleCategoryViewModel = new ShowAllTackleCategoriesViewModel(); List <Tackle> tackleslist = new List <Tackle>(); foreach (var note in notes) { notetackleviewmodel = new ShowAllNoteTacklesViewModel(note); notetackleviewmodel.NoteTackles.ToList().ForEach(p => tackleslist.Add(p.Tackle)); } var grouptackles = from t in tackleslist from c in tackleCategoryViewModel.Categories where t.TackleCategory_id == c.Id group t by c.Name into group_by_category orderby group_by_category.Key from x in group_by_category .GroupBy(n => n.Name) .Select(n => new { Name = n.Key, Count = n.Count() }) .OrderByDescending(n => n.Count) .Take(5) group x by group_by_category.Key; foreach (var cat in grouptackles) { var tackles = cat.Select(n => n).ToDictionary(n => n.Name, n => n.Count); DrawBarChart($"{cat.Key} ТОП-5", row, "Снасти", "Количество рыбалок", tackles); row += 22; } //GROUP notes count BY WEATHER var weather_group = (from n in notes group n by n.Cloud into g select new { Name = g.Key, Count = g.Count() }).ToDictionary(t => t.Name, t => t.Count); DrawBarChart("По погоде", row, "Условия", "Количество рыбалок", weather_group); //Group notes count by daytime var daytime_group = (from n in notes group n by new { Flag = n.StartTime.Hour < 12 ? "утро" : "вечер" } into g select new { Name = g.Key, Count = g.Count() }).ToDictionary(t => t.Name.Flag, t => t.Count); DrawBarChart("По времени суток", row += 22, "Условия", "Количество рыбалок", daytime_group); //Group notes count by flow var flow_group = (from n in notes group n by n.Flow into g select new { Name = g.Key, Count = g.Count() }).ToDictionary(t => t.Name, t => t.Count); DrawBarChart("По течению", row += 22, "течение", "Количество рыбалок", flow_group); //Group notes count by bottom var bottom_group = (from n in notes group n by n.Bottom into g orderby g.Count() descending select new { Name = g.Key, Count = g.Count() }).ToDictionary(t => t.Name, t => t.Count); DrawBarChart("По дну", row += 22, "Дно", "Количество рыбалок", bottom_group); //Group catches avg length and catches count by species Dictionary <string, int> catch_counts = new Dictionary <string, int>(); Dictionary <string, int> avg_lenghts = new Dictionary <string, int>(); var specymodel = new ShowAllSpeciesViewModel(); foreach (var specy in specymodel.Species) { totallength = catchmodel.GetTotalLength(c => c.Specy.Name == specy.Name); int totalcount = catchmodel.GetCount(c => c.Specy.Name == specy.Name); var trophies = trophymodel.Trophies.Where(tr => tr.Specy.Name == specy.Name).ToList(); totallength += trophies.Sum(tr => tr.Size); totalcount += trophies.Count(); if (totalcount != 0) { catch_counts.Add(specy.Name, totalcount); avg_lenghts.Add(specy.Name, (int)(totallength / totalcount)); } } DrawBarChart("По рыбам", row += 22, "Вид", "Количество", catch_counts); DrawBarChart("По длине рыб", row += 22, "Вид", "Средняя длина", avg_lenghts); }