Ejemplo n.º 1
0
        public ActionResult ShowLocationBasedDashboard()
        {
            ShowLocationBasedDashboardModel model = new ShowLocationBasedDashboardModel();

            model.variables       = db.JassVariables.ToList();
            model.variableChoices = new Boolean[model.variables.Count];
            model.variableLevels  = new string[model.variables.Count];
            model.generateFiles   = true;

            ViewBag.LatLonGroupID = Session["LatLonGroupID"];
            int LatLonGroupID = (int)ViewBag.LatLonGroupID;

            var locations = db.JassLatLons.Where(l => l.JassLatLonGroupID == LatLonGroupID);

            model.latlonGroup = db.JassLatLonGroups.Find(ViewBag.LatLonGroupID);
            model.year        = 2013;
            model.month       = 1;
            model.day         = 1;

            ViewBag.JassLatLonID = new SelectList(locations, "JassLatLonID", "Name", 1358);

            return(View("ShowLocationBasedDashboardFirst", model));
        }
Ejemplo n.º 2
0
        public ActionResult ShowLocationBasedDashboard(ShowLocationBasedDashboardModel model)
        {
            ViewBag.LatLonGroupID = Session["LatLonGroupID"];
            int LatLonGroupID = (int)ViewBag.LatLonGroupID;

            model.latlonGroup = db.JassLatLonGroups.Find(ViewBag.LatLonGroupID);

            var locations = db.JassLatLons.Where(l => l.JassLatLonGroupID == LatLonGroupID);

            ViewBag.JassLatLonID = new SelectList(locations, "JassLatLonID", "Name");
            try
            {
                if (model.JassLatLonID != null)
                {
                    model.locations = new List <JassLatLon>();
                    var latlon = db.JassLatLons.Find(model.JassLatLonID);
                    model.locations.Add(latlon);
                }
                else
                {
                    model.locations = model.latlonGroup.JassLatLons;
                }

                DateTime startDate = new DateTime(model.year, model.month, model.day);
                if (model.yearEnd == 0)
                {
                    model.yearEnd = model.year;
                }
                if (model.monthEnd == 0)
                {
                    model.monthEnd = model.month;
                }
                if (model.dayEnd == 0)
                {
                    model.dayEnd = model.day;
                }

                DateTime endDate = new DateTime(model.yearEnd, model.monthEnd, model.dayEnd);
                if (endDate < startDate)
                {
                    endDate = startDate;
                }
                int totalDays = (int)(endDate - startDate).TotalDays + 1;

                ViewBag.LatLonGroupID = Session["LatLonGroupID"];
                model.variables       = db.JassVariables.ToList();
                model.gridValues      = new List <List <List <JassGridValues> > >();
                for (int d = 0; d < totalDays; d++)
                {
                    model.gridValues.Add(new List <List <JassGridValues> >());
                    for (int l = 0; l < model.locations.Count; l++)
                    {
                        model.gridValues[d].Add(new List <JassGridValues>());
                    }
                }


                model.latlonGroup = db.JassLatLonGroups.Find(ViewBag.LatLonGroupID);
                //will hardcode a few variables.. and then generalize

                for (int v = 0; v < model.variables.Count; v++)
                {
                    if (model.variableChoices[v])
                    {
                        string[] levels = new string[1];
                        levels[0] = "0";
                        Boolean hasLevels = false;

                        if (model.variableLevels[v] != null && model.variableLevels[v] != "")
                        {
                            levels    = model.variableLevels[v].Split(',');
                            hasLevels = true;
                        }

                        for (int ll = 0; ll < levels.Length; ll++)
                        {
                            int d = 0;
                            try
                            {
                                int      level = Convert.ToInt16(levels[ll]);
                                DateTime day   = startDate;

                                for (d = 0; d < totalDays; d++)
                                {
                                    for (int l = 0; l < model.locations.Count; l++)
                                    {
                                        string dayString        = apiCaller.fileNameBuilderByDay(model.variables[v].Name, day.Year, day.Month, day.Day) + ".nc";
                                        var    gridResultValues = apiCaller.GetDayValues(dayString, model.locations[l], level);

                                        if (hasLevels)
                                        {
                                            gridResultValues.VariableName += "_" + level;
                                        }
                                        model.gridValues[d][l].Add(gridResultValues);

                                        day = day.AddDays(1);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                apiCaller.createBuilderLog("EXCEPTION", "Error getting values v:" + v + " d: " + d, e.Message, new TimeSpan(), false);
                                ViewBag.JassMessage = "ERROR when getting values";
                            }
                        }
                    }
                }


                if (model.generateFiles)
                {
                    string resultFromFileGeneration = apiCaller.generateOutputTestFile(model.gridValues, model.locations, startDate, endDate);
                    model.Message += resultFromFileGeneration;
                }

                return(View(model));
            }

            catch (Exception e)
            {
                apiCaller.createBuilderLog("EXCEPTION", "LocationStatus", e.Message, new TimeSpan(), false);
                ViewBag.JassMessage = "ERROR when creating LocationStatus";
            }

            return(View(model));
        }