Ejemplo n.º 1
0
        public void printCityRegionGroups()
        {
            db = MongoTools.connect("mongodb://localhost", "climaColombia");
            var coll = db.GetCollection <StationGroup>("cityRegionGroups");

            allRegionGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            StreamWriter sw = new StreamWriter("regiongroups.csv");

            foreach (StationGroup sg in allRegionGroups)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(sg.name + ",");
                foreach (int code in sg.stationcodes)
                {
                    sb.Append(code + ",");
                }
                sw.WriteLine(sb.ToString());
            }
            sw.Close();
            cities = MapTools.readCities();


            stations = StationGrouping.getAllStationsFromDB(db);
            JSONout.writeGroup(allRegionGroups, @"C:\Users\Admin\Documents\projects\IAPP\climaColombiaOrg\tools\cityGroups\cityregiongroups.json", stations, cities);
        }
Ejemplo n.º 2
0
        private async Task cityGroupGraphic(StationGroup cityGroup, List <string> weatherCollections, string filename)
        {
            List <City> cities = MapTools.readCities();
            var         c      = cities.Find(x => x.name == cityGroup.name);
            //start end dates

            //set the master pane
            ZedGraphControl zgc    = new ZedGraphControl();
            MasterPane      master = zgc.MasterPane;

            master.Rect = new RectangleF(0, 0, 2000, 666 * weatherCollections.Count);
            master.PaneList.Clear();
            master.Title.Text = "City: " + c.name +
                                " lat: " + Math.Round(c.location[1], 3) + " lon: " + Math.Round(c.location[0], 3) +
                                " alt: " + (int)(c.elevation);// + "\nDate range: " + startDate.Year + "_" + startDate.Month + " >> " + endDate.Year + "_" + endDate.Month;
            master.Title.FontSpec   = new FontSpec("Arial", 7.0f, Color.Black, false, false, false);
            master.Margin.All       = 5;
            master.Legend.IsVisible = false;
            int    stationcode = 0;
            string vname       = "";
            string source      = "";
            int    freq        = 0;

            foreach (string wc in weatherCollections)
            {
                ////create one scatter for each stationvariable
                if (!wc.Contains("Clean"))
                {
                    string[] parts = wc.Split('_');
                    stationcode = Convert.ToInt32(parts[1]);
                    vname       = parts[4];
                    source      = parts[2];
                    freq        = Convert.ToInt32(parts[5]);

                    VariableMeta  meta      = AnnualSummary.getVariableMetaFromDB(vname, source, db);
                    PointPairList pointpair = new PointPairList();
                    pointpair = await GenerateHourlyData(wc, meta);

                    if (pointpair.Count > 0)
                    {
                        AddChartToMaster(master, pointpair, wc, vname, meta, false);
                    }
                }
            }
            //save graphic
            // Refigure the axis ranges for the GraphPanes
            zgc.AxisChange();
            // Layout the GraphPanes using a default Pane Layout
            Bitmap b = new Bitmap(2000, 666 * weatherCollections.Count);

            using (Graphics g = Graphics.FromImage(b))
            {
                master.SetLayout(g, PaneLayout.SingleColumn);
            }
            master.GetImage().Save(@"C:\Users\Admin\Documents\projects\IAPP\piloto\Climate\IDEAM\DailyAnalysis\" + filename + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Ejemplo n.º 3
0
        private void defineCityRegionGroups()
        {
            var coll = db.GetCollection <StationGroup>("regionGroups");

            allRegionGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            cities          = MapTools.readCities();
            regions         = MapTools.readRegions();

            stations = StationGrouping.getAllStationsFromDB(db);
            setCityRegionGroups();
            //insertManyRecord("cityRegionGroups", cityRegionGroup);
        }
        public void getData()
        {
            cities  = MapTools.readCities();
            regions = MapTools.readRegions();
            //get the city's region
            getCityRegionName();
            //gets all the stations for which we have data
            getActiveStations();

            //getStationsFromDB(db);//this is the annula summary
            //gets the full list of meta data for all stations NOAA and IDEAM
            stations = getAllStationsFromDB(db);
        }
        public void printCityMeta()
        {
            var cityGroups = db.GetCollection <StationGroup>("cityGroups");
            List <StationGroup> stationgroups = cityGroups.Find(FilterDefinition <StationGroup> .Empty).ToList();
            List <City>         cities        = MapTools.readCities();
            StreamWriter        sw            = new StreamWriter(@"C: \Users\Admin\Documents\projects\clusterColombia\climacolombia\cities.csv", false, Encoding.UTF8);

            foreach (StationGroup sg in stationgroups)
            {
                var c = cities.Find(x => x.name == sg.name);
                sw.WriteLine(c.name + "," + c.location[1] + "," + c.location[0] + "," + (int)c.elevation);
            }
            sw.Close();
        }
Ejemplo n.º 6
0
        public void readSythYearFromDB()
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            //for the regional fix use:
            //var coll = db.GetCollection<StationGroup>("cityRegionGroups");
            //for the city groups use:
            var coll          = db.GetCollection <StationGroup>("cityGroups");
            var allCityGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();

            this.addLineToLogFile("INFO: preparing to read synthYearsFromDB");
            foreach (StationGroup sg in allCityGroups)
            {
                var city = sg.name;
                //the good from the city groups
                //city == "SANTA FE DE BOGOTÁ" || city == "BARRANQUILLA" || city == "CARTAGENA"||city == "LETICIA"
                if (city == "LETICIA")
                {
                    List <City> cities  = MapTools.readCities();
                    City        current = cities.Find(c => c.name == city);
                    writeEPW(current.name, current.location[1], current.location[0], current.elevation);
                }
            }
        }
        private void groupMonthBarChart(List <StationMonthly> group, string groupname)
        {
            List <Station> stations = StationGrouping.getAllStationsFromDB(db);
            List <City>    cities   = MapTools.readCities();
            var            c        = cities.Find(x => x.name == groupname);
            //find the first month and year of all monthlytotals
            //generate yaxis titles

            int startYear  = 0;
            int startMonth = 0;

            getGroupFirstMonth(group, ref startYear, ref startMonth);
            int endYear  = 0;
            int endMonth = 0;

            getGroupLastMonth(group, ref endYear, ref endMonth);
            DateTime startDate = new DateTime();

            if (startYear != 10000)
            {
                startDate = new DateTime(startYear, startMonth, 1);
            }
            else
            {
                startDate = new DateTime(1985, 1, 1);
            }
            DateTime endDate = new DateTime();

            if (endYear != 0)
            {
                endDate = new DateTime(endYear, endMonth, 1);
            }
            else
            {
                startDate = new DateTime(2018, 8, 1);
            }

            int monthsSpan = (int)Math.Round((endDate - startDate).Days / 30.0, 1);
            //set the master pane
            ZedGraphControl zgc    = new ZedGraphControl();
            MasterPane      master = zgc.MasterPane;

            master.Rect = new RectangleF(0, 0, 2000, 666 * group.Count);
            master.PaneList.Clear();
            master.Title.IsVisible = true;
            master.Title.Text      = "City: " + c.name +
                                     " lat: " + Math.Round(c.location[1], 3) + " lon: " + Math.Round(c.location[0], 3) +
                                     " alt: " + (int)(c.elevation) + "\nDate range: " + startDate.Year + "_" + startDate.Month + " >> " + endDate.Year + "_" + endDate.Month;
            master.Title.FontSpec   = new FontSpec("Arial", 7.0f, Color.Black, false, false, false);
            master.Margin.All       = 5;
            master.Legend.IsVisible = false;
            foreach (StationMonthly sm in group)
            {
                var       s     = stations.Find(x => x.code == sm.code);
                GraphPane pane1 = new GraphPane();
                pane1.BarSettings.Type = BarType.Stack;
                pane1.Border.IsVisible = false;
                pane1.Title.Text       = sm.code.ToString() + " " + s.name +
                                         " lat: " + Math.Round(s.latitude, 3) + " lon: " + Math.Round(s.longitude, 3) +
                                         " alt: " + (int)(s.elevation);
                //only show the first
                pane1.Legend.IsVisible = true;

                //pane1.YAxis.Title.Text = "n records";
                pane1.XAxis.Scale.Max           = monthsSpan;
                pane1.XAxis.Scale.MajorStep     = 12.0;
                pane1.XAxis.Scale.MinorStep     = 1.0;
                pane1.XAxis.MajorTic.Size       = 10;
                pane1.XAxis.MajorGrid.IsVisible = true;
                foreach (VariableMonthly vm in sm.variablesMonthly)
                {
                    List <double> xvalues = new List <double>();
                    for (int m = 0; m <= monthsSpan + 1; m++)
                    {
                        xvalues.Add(0);
                    }
                    Color col;
                    switch (vm.variableName)
                    {
                    case "VV":
                        col = Color.Red;
                        break;

                    case "DV":
                        col = Color.DodgerBlue;
                        break;

                    case "NUB":
                        col = Color.ForestGreen;
                        break;

                    case "RS":
                        col = Color.BlueViolet;
                        break;

                    case "TS":
                        col = Color.YellowGreen;
                        break;

                    case "HR":
                        col = Color.LawnGreen;
                        break;

                    case "PR":
                        col = Color.Orchid;
                        break;

                    default:
                        col = Color.Black;
                        break;
                    }
                    foreach (MonthTotal mt in vm.monthlytotals)
                    {
                        if (mt.month == 0 || mt.year == 0)
                        {
                            continue;
                        }
                        DateTime date = new DateTime(mt.year, mt.month, 1);

                        int datediff = (int)Math.Round((date - startDate).TotalDays / 30.0, 1);
                        if (vm.interval == 10)
                        {
                            xvalues[datediff] = mt.total / 6;
                        }
                        else
                        {
                            xvalues[datediff] = mt.total;
                        }
                    }
                    double[] x = xvalues.ToArray();

                    BarItem myBar = pane1.AddBar(vm.variableName, null, x, col);
                    myBar.Bar.Fill             = new Fill(col, col, col);
                    myBar.Bar.Border.IsVisible = false;
                }
                pane1.AxisChange();
                master.Add(pane1);
            }
            // Refigure the axis ranges for the GraphPanes
            zgc.AxisChange();
            // Layout the GraphPanes using a default Pane Layout
            Bitmap b = new Bitmap(2000, 666 * group.Count);

            using (Graphics g = Graphics.FromImage(b))
            {
                master.SetLayout(g, PaneLayout.SingleColumn);
            }
            master.GetImage().Save(@"C:\Users\Admin\Documents\projects\IAPP\piloto\Climate\groupMonthlyBarCharts\" + groupname + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
        }