Beispiel #1
0
        public static void StatsBySpecies_Table(Document document, Project currentProject)
        {
            try {
                General_queries     prjq  = new General_queries(currentProject);
                List <SpeciesStats> stats = prjq.AllStatsBySpecies;

                document.LastSection.AddParagraph("Statistics by species", "Heading2");

                Table table = document.LastSection.AddTable();
                table.Borders.Visible = true;
                table.TopPadding      = 10;
                table.BottomPadding   = 10;

                Column column = table.AddColumn(Unit.FromCentimeter(5));
                column.Format.Alignment = ParagraphAlignment.Center;


                column = table.AddColumn();
                column.Format.Alignment = ParagraphAlignment.Center;

                column = table.AddColumn();
                column.Format.Alignment = ParagraphAlignment.Center;

                table.Rows.Height = 20;

                Row row = table.AddRow();
                row.Shading.Color = Colors.PaleGoldenrod;

                row.Cells[0].AddParagraph().AddFormattedText("Species", TextFormat.Bold);
                row.Cells[1].AddParagraph().AddFormattedText("Valid pictures", TextFormat.Bold);
                row.Cells[2].AddParagraph().AddFormattedText("Species count", TextFormat.Bold);


                foreach (SpeciesStats spst in stats)
                {
                    row = table.AddRow();
                    if (spst.SpeciesName == "")
                    {
                        row.Cells[0].AddParagraph("Pending images");
                        row.Cells[1].AddParagraph(spst.SpeciesPictures.ToString()).AddFormattedText();
                        row.Cells[2].AddParagraph(spst.SpeciesCount.ToString());
                    }
                    else
                    {
                        row.Cells[0].AddParagraph(spst.SpeciesName);
                        row.Cells[1].AddParagraph(spst.SpeciesPictures.ToString());
                        row.Cells[2].AddParagraph(spst.SpeciesCount.ToString());
                    }
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
        public static void SpeciesPicturesInProject_PieChart(Document document, Project currentProject)
        {
            try {
                General_queries     projq = new General_queries(currentProject);
                List <SpeciesStats> stats = projq.AllStatsBySpecies;

                double[] speciesPictures = new double[stats.Count];
                string[] speciesNames    = new string[stats.Count];

                double speciesSum = 0;

                for (int i = 0; i < stats.Count; i++)
                {
                    speciesSum        += stats[i].SpeciesPictures;
                    speciesPictures[i] = stats[i].SpeciesPictures;
                    speciesNames[i]    = stats[i].SpeciesName;
                }

                document.LastSection.AddParagraph("Pictures in project where the species appears", "Heading2");

                Chart chart = new Chart();
                chart.Type = ChartType.Pie2D;
                chart.Left = 0;

                chart.Width  = Unit.FromCentimeter(10);
                chart.Height = Unit.FromCentimeter(8);

                Series series = chart.SeriesCollection.AddSeries();
                series.Add(speciesPictures);
                XSeries xseries = chart.XValues.AddXSeries();
                xseries.Add(speciesNames);

                chart.RightArea.AddLegend();

                chart.DataLabel.Type     = DataLabelType.Percent;
                chart.DataLabel.Position = DataLabelPosition.OutsideEnd;


                document.LastSection.Add(chart);
            } catch (Exception ex) {
                throw ex;
            }
        }
        public static void SpeciesTimeBehavior_BarChart(Document document, Project currentProject)
        {
            try {
                General_queries projq = new General_queries(currentProject);


                foreach (SpeciesStats spst in projq.AllStatsBySpecies)
                {
                    document.LastSection.AddParagraph(spst.SpeciesName + " Activity Patterns", "Heading2");

                    Chart chart = new Chart();
                    chart.Left = 0;

                    chart.Width  = Unit.FromCentimeter(16);
                    chart.Height = Unit.FromCentimeter(12);
                    Series series = chart.SeriesCollection.AddSeries();
                    series.ChartType = ChartType.Column2D;
                    series.Add(spst.ActivityPatern);
                    series.HasDataLabel = true;

                    XSeries xseries = chart.XValues.AddXSeries();
                    xseries.Add("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23");

                    chart.XAxis.MajorTickMark = TickMarkType.Outside;
                    chart.XAxis.Title.Caption = "Hours of day";

                    chart.YAxis.MajorTickMark     = TickMarkType.Outside;
                    chart.YAxis.HasMajorGridlines = true;
                    chart.YAxis.MajorGridlines.LineFormat.Color = Colors.DarkGray;
                    chart.YAxis.Title.Caption = "Freq";

                    chart.PlotArea.LineFormat.Color = Colors.DarkGray;
                    chart.PlotArea.LineFormat.Width = 1;

                    document.LastSection.Add(chart);
                }
            } catch (Exception ex) {
                throw ex;
            }
        }
        private void WriteGridAbundances(Project currentProject, string shapefileName)
        {
            try {
                List <IPolygon> projectGrids = new List <IPolygon>();
                General_queries projq        = new General_queries(currentProject);

                foreach (Station st in currentProject.StationsList)
                {
                    IPolygon     grid             = st.Grid;
                    StationStats tempStationStats = new StationStats(st.Guid, st.StationID);

                    foreach (StationStats stst in projq.AllStatsByStation)
                    {
                        if (stst.StationGUID == st.Guid)
                        {
                            tempStationStats = stst;
                            grid.UserData    = tempStationStats;
                        }
                    }

                    projectGrids.Add(grid);
                }

                GeometryCollection gc = new GeometryCollection(projectGrids.ToArray());

                //Open Writer
                ShapefileWriter shpWriter = new ShapefileWriter();
                shpWriter.Write(shapefileName, gc);

                //Create Header & Columns for points
                DbaseFileHeader dbfHeader = new DbaseFileHeader();


                dbfHeader.AddColumn("Station_ID", 'C', 20, 0);
                //One column for each species in project
                foreach (SpeciesStats spcst in projq.AllStatsBySpecies)
                {
                    dbfHeader.AddColumn(spcst.SpeciesName, 'N', 20, 0);
                }

                dbfHeader.NumRecords = gc.Count;

                //DBF Writer
                DbaseFileWriter dbfWriter = new DbaseFileWriter(shapefileName + ".dbf");
                dbfWriter.Write(dbfHeader);

                //Loop through Business Object to get Features
                foreach (IPolygon p in gc.Geometries)
                {
                    StationStats data = (StationStats)p.UserData;


                    ArrayList columnValues = new System.Collections.ArrayList();
                    //Add Values

                    columnValues.Add(data.StationID);
                    foreach (SpeciesStats s in data.SpeciesStats)
                    {
                        columnValues.Add(s.SpeciesPictures);
                    }

                    dbfWriter.Write(columnValues);
                }

                //Close File
                dbfWriter.Close();
            } catch (Exception ex) {
                throw ex;
            }
        }