Beispiel #1
0
        public static void GfsNowCastInsert()
        {
            _log.Info($"Start Insert");
            List <GFS_DB_INSERT_CHECK> gfsDbIndertCheck = new List <GFS_DB_INSERT_CHECK>();

            DateTime UTC;

            double[] LAT;
            double[] LON;
            double[] temp_surfaceValue;
            double[] temp_above_groundValue;
            double[] press_surfaceValue;
            double[] press_mslValue;

            GribEnvironment.Init();
            List <GribMessage> gfs = new List <GribMessage>();

            _log.Info($"Start Insert : {_decodeList[6]}");
            using (GribFile file = new GribFile(_decodeList[6]))
            {
                file.Context.EnableMultipleFieldMessages = true;

                var temp_surface = file.Where(d => d.ParameterName == "Temperature" && d.TypeOfLevel == "surface" && d.Level == 0).Single();

                if (_oceanModel.GFS_DB_INSERT_CHECK.Where(s => s.DATE_OF_FILE == temp_surface.Time).Count() > 0)
                {
                    _log.Info("TRIGGER/*/" + "Gfs DB에 " + temp_surface.Time.ToString() + "데이터가 이미 있습니다.");
                    return;
                }
                var temp_above_ground = file.Where(d => d.ParameterName == "Temperature" && d.TypeOfLevel == "heightAboveGround" && d.Level == 2).Single();
                var press_surface     = file.Where(d => d.ParameterName == "Pressure" && d.TypeOfLevel == "surface" && d.Level == 0).Single();
                var press_msl         = file.Where(d => d.ParameterName == "Pressure reduced to MSL" && d.TypeOfLevel == "meanSea" && d.Level == 0).Single();

                ////////////////////////////////////////////////////////////////////////
                //////////////////DB INSERT
                ////////////////////////////////////////////////////////////////////////

                UTC = temp_surface.Time;
                LAT = temp_surface.GridCoordinateValues.Select(d => d.Latitude).ToArray();
                LON = temp_surface.GridCoordinateValues.Select(d => d.Longitude).ToArray();

                temp_surface.Values(out temp_surfaceValue);
                temp_above_ground.Values(out temp_above_groundValue);
                press_surface.Values(out press_surfaceValue);
                press_msl.Values(out press_mslValue);
            }

            List <GFS> gfsList = new List <GFS>();

            for (int j = 0; j < LAT.Length; j++)
            {
                ////////////////////////////////////////////////////////////////////////
                //////////////////예보 데이터
                ////////////////////////////////////////////////////////////////////////

                gfsList.Add(new GFS
                {
                    UTC               = UTC,
                    LAT               = Convert.ToDecimal(LAT[j]),
                    LON               = Convert.ToDecimal(LON[j]),
                    TEMP_SURFACE      = Convert.ToSingle(temp_surfaceValue[j] - 273.15f),
                    TEMP_ABOVE_GROUND = Convert.ToSingle(temp_above_groundValue[j] - 273.15f),
                    PRESSURE_SURFACE  = Convert.ToSingle(press_surfaceValue[j]),
                    PRESSURE_MSL      = Convert.ToSingle(press_mslValue[j]),
                });
            }
            ////////////////////////////////////////////////////////////////////////
            //////////////////DB INSERT
            ////////////////////////////////////////////////////////////////////////

            int resumeCount     = 0;
            int insertDataCount = 259920;
            var checkDate       = UTC;

            _oceanModel.Database.CommandTimeout = 99999;
            GFS checkDB = _oceanModel.GFS.FirstOrDefault(s => s.UTC == checkDate);

            if (checkDB != null)
            {
                var resumeCount1 = _oceanModel.GFS.Count(s => s.UTC == checkDate);
                resumeCount = resumeCount1;
                if (resumeCount == insertDataCount)
                {
                    gfsDbIndertCheck.Add(new GFS_DB_INSERT_CHECK
                    {
                        FILE_NAME     = _decodeList[4].ToLower(),
                        DATE_OF_FILE  = UTC,
                        DATE_INSERTED = DateTime.UtcNow
                    });
                    gfsDbIndertCheck.ForEach(s => _oceanModel.GFS_DB_INSERT_CHECK.Add(s));
                    _oceanModel.SaveChanges();
                    return;
                }

                _log.Info("TRIGGER/*/" + "Gfs 데이터를 " + resumeCount.ToString() + "개부터 이어 받습니다.");
            }

            var gfsSplit = Split(gfsList, 10000);

            int index = 0;

            foreach (var item in gfsSplit)
            {
                if (index * 10000 >= resumeCount)
                {
                    EFBatchOperation.For(_oceanModel, _oceanModel.GFS).InsertAll(item);
                    Thread.Sleep(500);
                }
                var progress = Math.Round((double)index / 0.26, 2);
                _log.Info($"Gfs Nowcast Db insert :{_decodeList[0]}-{_decodeList[1]}-{_decodeList[2]} {_decodeList[3]}:00 / {progress} %");
                index++;
            }
            gfsSplit = null;
            gfsList  = null;

            gfsDbIndertCheck.Add(new GFS_DB_INSERT_CHECK
            {
                FILE_NAME     = _decodeList[4].ToLower(),
                DATE_OF_FILE  = UTC,
                DATE_INSERTED = DateTime.UtcNow
            });

            gfsDbIndertCheck.ForEach(s => _oceanModel.GFS_DB_INSERT_CHECK.Add(s));
            _oceanModel.SaveChanges();

            _log.Info($"Gfs Db insert Finish");
        }
        public static void GfsForeCastInsertProxy()
        {
            DateTime UTC;

            double[] LAT;
            double[] LON;
            double[] temp_surfaceValue;
            double[] temp_above_groundValue;
            double[] press_surfaceValue;
            double[] press_mslValue;

            GribEnvironment.Init();
            List <GribMessage> gfs = new List <GribMessage>();

            _log.Info($"Start Insert : {_decodeList[6]}");
            using (GribFile file = new GribFile(_decodeList[6]))
            {
                file.Context.EnableMultipleFieldMessages = true;

                var temp_surface      = file.Where(d => d.ParameterName == "Temperature" && d.TypeOfLevel == "surface" && d.Level == 0).SingleOrDefault();
                var temp_above_ground = file.Where(d => d.ParameterName == "Temperature" && d.TypeOfLevel == "heightAboveGround" && d.Level == 2).SingleOrDefault();
                var press_surface     = file.Where(d => d.ParameterName == "Pressure" && d.TypeOfLevel == "surface" && d.Level == 0).SingleOrDefault();
                var press_msl         = file.Where(d => d.ParameterName == "Pressure reduced to MSL" && d.TypeOfLevel == "meanSea" && d.Level == 0).SingleOrDefault();

                UTC = temp_surface.Time;
                LAT = temp_surface.GridCoordinateValues.Select(d => d.Latitude).ToArray();
                LON = temp_surface.GridCoordinateValues.Select(d => d.Longitude).ToArray();

                temp_surface.Values(out temp_surfaceValue);
                temp_above_ground.Values(out temp_above_groundValue);
                press_surface.Values(out press_surfaceValue);
                press_msl.Values(out press_mslValue);
            }
            //ff

            List <GFS_FORECAST_PROXY> gfsList = new List <GFS_FORECAST_PROXY>();

            for (int j = 0; j < LAT.Length; j++)
            {
                gfsList.Add(new GFS_FORECAST_PROXY
                {
                    UTC               = UTC,
                    LAT               = Convert.ToDecimal(LAT[j]),
                    LON               = Convert.ToDecimal(LON[j]),
                    TEMP_SURFACE      = Convert.ToSingle(temp_surfaceValue[j] - 273.15f),
                    TEMP_ABOVE_GROUND = Convert.ToSingle(temp_above_groundValue[j] - 273.15f),
                    PRESSURE_SURFACE  = Convert.ToSingle(press_surfaceValue[j]),
                    PRESSURE_MSL      = Convert.ToSingle(press_mslValue[j]),
                });
            }

            _oceanModel.Database.CommandTimeout = 99999;
            var gfsSplit = Split(gfsList, 10000);
            int index    = 0;

            foreach (var item in gfsSplit)
            {
                EFBatchOperation.For(_oceanModel, _oceanModel.GFS_FORECAST_PROXY).InsertAll(item);
                Thread.Sleep(500);
                var progress = Math.Round((double)index / 0.26, 2);
                _log.Info($"Gfs Forecast Db insert :{_decodeList[0]}-{_decodeList[1]}-{_decodeList[2]} {_decodeList[3]}:00 / {progress} %");
                index++;
            }
            gfsSplit = null;
            gfsList  = null;

            _log.Info($"Gfs Forecast Db insert :{_decodeList[0]}-{_decodeList[1]}-{_decodeList[2]} {_decodeList[3]}:00 / 100 %");

            var conditionWeatherDb = _logModel.CONDITION_OCEAN_WEATHER.First();

            conditionWeatherDb.DATE_LAST_FILE_OF_GFS_FORECAST = _dateNextGfsForecastFileToGet;
            conditionWeatherDb.FILE_NAME_LAST_OF_GFS_FORECAST = _decodeList[4];

            if (_decodeList[4] == "gfs.t00z.pgrb2.0p50.f210")
            {
                conditionWeatherDb.DB_OF_GFS_FORECAST = "PROXY";
                conditionWeatherDb.DATE_LAST_OF_GFS   = UTC;
                //conditionWeatherDb.DATE_LAST_OF_GFS_JSON = UTC;
            }
            _logModel.SaveChanges();
        }