コード例 #1
0
        public void ByDistanceFromLatLong(double[] lonlat, double ele)
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            var siteCoord = new GeoCoordinate(lonlat[1], lonlat[0]);

            double dist = 0;

            double eleDiff = 0;

            StationGroup sg = new StationGroup();

            sg.name = "sumapaz";
            foreach (int actScode in activeStationCodes)
            {
                //get the ref station details

                //find within radius altitude

                if (stations.Exists(x => x.code == actScode))
                {
                    Station s      = stations.Find(x => x.code == actScode);
                    var     sCoord = new GeoCoordinate(s.latitude, s.longitude);
                    dist    = siteCoord.GetDistanceTo(sCoord);
                    eleDiff = ele - s.elevation;
                    if (dist < 20000)//&& Math.Abs(eleDiff) < 100
                    {
                        sg.stationcodes.Add(s.code);
                    }
                }
            }
            CityYearBuilder cyb = new CityYearBuilder();

            cyb.prepOneGroup(sg);
            cyb.makeSynthYear(sg, "medianHour");
        }
コード例 #2
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);
        }
コード例 #3
0
        public async Task syntheticYearDataPrep(string groups)
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            var coll          = db.GetCollection <StationGroup>(groups);
            var allCityGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();

            this.addLineToLogFile("INFO: preparing data");
            foreach (StationGroup sg in allCityGroups)
            {
                var city = sg.name;

                try
                {
                    var cityGroup        = allCityGroups.Find(x => x.name == city);
                    var stationCollNames = getStationsColNames(cityGroup);

                    averageTenMinute(ref stationCollNames);
                    await index60Minutes(stationCollNames);

                    this.addLineToLogFile("INFO: " + city + " data prep completed");
                }
                catch
                {
                    this.addLineToLogFile("WARN: " + city + " data prep failed");
                }
            }
        }
コード例 #4
0
        public async Task syntheticYearBatchFixer(string method)
        {
            CityYearFixer     cyf        = new CityYearFixer();
            List <NeededData> neededData = cyf.readRequiredData();

            stations = StationGrouping.getAllStationsFromDB(db);
            var coll          = db.GetCollection <StationGroup>("cityRegionGroups");
            var allCityGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();

            this.addLineToLogFile("INFO: starting batch of synth years");
            List <Task> tasks = new List <Task>();

            foreach (StationGroup sg in allCityGroups)
            {
                var        city      = sg.name;
                NeededData cityNeeds = neededData.Find(nd => nd.name == city);
                if (cityNeeds != null)
                {
                    if (city != "MITU")
                    {
                        var cityGroup        = allCityGroups.Find(x => x.name == city);
                        var stationCollNames = getStationsColNames(cityGroup);
                        tasks.Add(fixCity(city, method, cityNeeds, stationCollNames));
                    }
                }
            }
            await Task.WhenAll(tasks);
        }
コード例 #5
0
        public void graphCityGroups()
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            var coll = db.GetCollection <StationGroup>("cityGroups");

            stationsByCity = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            graphPerCity();
        }
コード例 #6
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);
        }
コード例 #7
0
        public void temporalCityGroupMonthly()
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            var coll = db.GetCollection <StationGroup>("cityRegionGroups");

            stationsByCity = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();
            foreach (StationGroup cityGroup in stationsByCity)
            {
                weatherCollections = getStationsColNames(cityGroup);

                cityMonthlyGraphs(cityGroup);
            }
        }
コード例 #8
0
        public async Task syntheticYearBatch(string method)
        {
            stations = StationGrouping.getAllStationsFromDB(db);
            var coll          = db.GetCollection <StationGroup>("cityGroups");
            var allCityGroups = coll.Find(FilterDefinition <StationGroup> .Empty).ToList();

            this.addLineToLogFile("INFO: starting batch of synth years");


            foreach (StationGroup sg in allCityGroups)
            {
                await makeSynthYear(sg, method);
            }
        }
コード例 #9
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);
                }
            }
        }
コード例 #10
0
 private void setGroups(object sender, EventArgs e)
 {
     StationGrouping sg = new StationGrouping(false);
 }
コード例 #11
0
        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);
        }
コード例 #12
0
 private void getStationData()
 {
     //list of station meta data
     stations = StationGrouping.getAllStationsFromDB(db);
     var coll = db.GetCollection <StationGroup>("cityGroups");
 }