Beispiel #1
0
        public static List <AWSFieldValue> GetLastAWSInfo(OBTArea area, TimeMode aType, OBTField dataField)
        {
            string wdf = null, wdd = null;

            getQueryField(dataField, out wdf, out wdd);
            string               tableName = AWSItems.getTableName(DateTime.Now, area, aType, dataField);
            DataTable            lastTable = AWSItems.getLastAWStable(tableName);
            List <AWSFieldValue> result = new List <AWSFieldValue>();

            foreach (DataRow row in lastTable.Rows)
            {
                var df = row[wdf];
                if (df != DBNull.Value)
                {
                    var dd = row[wdd];
                    if (dd != DBNull.Value && (double)(decimal)df < 9999)
                    {
                        AWSFieldValue aws = new AWSFieldValue();
                        aws.TM = (DateTime)row["DDATETIME"];
                        aws.ID = row["OBTID"].ToString();
                        aws.V0 = (double)(decimal)df;
                        aws.V1 = (double)(decimal)dd;
                        result.Add(aws);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        public static string getTableName(DateTime date, OBTArea area, TimeMode aType, OBTField?dataField = null)
        {
            string tableName;

            if (aType == TimeMode.MINUTE)
            {
                tableName = "SURF_CHN_MUL_MIN";
            }
            else if (aType == TimeMode.HOUR)
            {
                tableName = "SURF_CHN_MUL_HOR";
            }
            else
            {
                tableName = "SURF_CHN_MUL_DAY";
            }
            return(tableName);
        }
Beispiel #3
0
        /// <summary>
        /// 获取自动站最新数据
        /// </summary>
        List <AWSFieldValue> GetLastAWSInfo(OBTArea area, TimeMode aType, OBTField dataField, int accuracy)
        {
            string               tableName = AWSItems.getTableName(DateTime.Now, area, aType, dataField);
            DataTable            lastTable = AWSItems.getLastAWStable(tableName);
            List <AWSFieldValue> result    = new List <AWSFieldValue>();

            foreach (DataRow row in lastTable.Rows)
            {
                var v0 = row[dataField.ToString()];
                if (v0 != DBNull.Value && (double)(decimal)v0 / accuracy < 9999)
                {
                    AWSFieldValue aws = new AWSFieldValue();
                    aws.TM = (DateTime)row["DDATETIME"];
                    aws.ID = row["OBTID"].ToString();
                    aws.V0 = (double)(decimal)v0 / accuracy;
                    result.Add(aws);
                }
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 自动站属性变值
        /// </summary>
        List <AWSFieldValue> GetOffsetFromDB(DateTime?date, OBTArea area, OBTField fieldName, int accuracy)
        {
            int    offsetHours;
            string field = getFieldName(fieldName, out offsetHours);

            if (offsetHours == 0)
            {
                return(null);
            }
            DateTime checkTime;

            if (date == null)
            {
                checkTime = DateTime.Now.AddMinutes(-5);
                checkTime = checkTime.AddMinutes(-checkTime.Minute % 5);
                checkTime = checkTime.AddSeconds(-checkTime.Second);
            }
            else
            {
                checkTime = date.Value;
            }
            List <AWSFieldValue> result = new List <AWSFieldValue>();
            string        tableName     = AWSItems.getTableName(checkTime, area, TimeMode.MINUTE, fieldName);
            StringBuilder sb            = new StringBuilder();

            sb.AppendFormat(@"SELECT A.obtid, (A.{0}-B.{1})/" + accuracy + " FROM (select obtid,{2} from {3} where ddatetime=:dnow and {4} is not null) A inner join(select obtid, {5} from {6} where ddatetime = :dbefore and {7} is not null) B ON A.obtid = B.obtid",
                            field, field, field, tableName, field, field, tableName, field);
            DataTable data = OracleHelp.ExecuteDataTable(sb.ToString(), T_LOCALOBTMIND.Tunnel.connString, new OracleParameter(":dnow", checkTime), new OracleParameter(":dbefore", checkTime.AddHours(offsetHours)));

            foreach (DataRow row in data.Rows)
            {
                if ((double)(decimal)row[1] < 9999)
                {
                    result.Add(new AWSFieldValue()
                    {
                        TM = checkTime, ID = row[0].ToString(), V0 = (double)(decimal)row[1]
                    });
                }
            }
            return(result);
        }
Beispiel #5
0
        List <AWSFieldValue> GetAWSInfoFromDB(DateTime date, OBTArea area, TimeMode aType, OBTField dataField, int accuracy)
        {
            List <AWSFieldValue> result = new List <AWSFieldValue>();
            string tableName            = AWSItems.getTableName(date, area, aType, dataField);

            if (aType == TimeMode.DAY)
            {
                date = date.Date;
            }
            string    seleceField = dataField.ToString();
            string    sql         = string.Format("select OBTID,{0}/" + accuracy + " from {1} where DDATETIME=:ddate and {2} is not null", seleceField, tableName, seleceField, seleceField);
            DataTable data        = OracleHelp.ExecuteDataTable(sql, T_LOCALOBTMIND.Tunnel.connString, new OracleParameter(":ddate", date));

            foreach (DataRow row in data.Rows)
            {
                result.Add(new AWSFieldValue()
                {
                    ID = row[0].ToString(), V0 = (double)(decimal)row[1]
                });
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 风速
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static List <AWSFieldValue> GetAWSWindFromDB(DateTime date, OBTArea area, TimeMode aType, OBTField dataField)
        {
            string wdf = null, wdd = null;

            getQueryField(dataField, out wdf, out wdd);
            string tableName            = AWSItems.getTableName(date, area, aType);
            List <AWSFieldValue> result = new List <AWSFieldValue>();
            string    selectSQL         = string.Format("select OBTID,{0},{1} from {2} where DDATETIME=:ddate AND {3}>=0 AND {4}>=0 ORDER BY {5} DESC", wdf, wdd, tableName, wdf, wdd, wdf);
            DataTable data              = OracleHelp.ExecuteDataTable(selectSQL, T_LOCALOBTMIND.Tunnel.connString, new OracleParameter(":ddate", aType == TimeMode.DAY ? date.Date : date));

            foreach (DataRow row in data.Rows)
            {
                if ((double)(decimal)row[1] < 9999)
                {
                    result.Add(new AWSFieldValue()
                    {
                        ID = row[0].ToString(), V0 = (double)(decimal)row[1], V1 = (double)(decimal)row[2]
                    });
                }
            }
            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 自动站变温
        /// </summary>
        public static Dictionary <string, decimal> GetOffsetFromDB(DateTime date, OBTArea area, OBTField fieldName)
        {
            int    offsetHours;
            string field = getFieldName(fieldName, out offsetHours);

            if (offsetHours == 0)
            {
                return(null);
            }
            Dictionary <string, decimal> result = new Dictionary <string, decimal>();
            string        tableName             = AWSItems.getTableName(date, area, TimeMode.MINUTE);
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"SELECT A.obtid, A.{0}-B.{1} FROM (select obtid,{2} from {3} where ddatetime=:dnow and {4} is not null) A inner join(select obtid, {5} from {6} where ddatetime = :dbefore and {7} is not null) B ON A.obtid = B.obtid",
                            field, field, field, tableName, field, field, tableName, field);
            DataTable data = OracleHelp.ExecuteDataTable(sb.ToString(), T_LOCALOBTMIND.Tunnel.connString, new OracleParameter(":dnow", date), new OracleParameter(":dbefore", date.AddHours(offsetHours)));

            foreach (DataRow row in data.Rows)
            {
                result.Add(row[0].ToString(), (decimal)row[1]);
            }
            return(result);
        }
Beispiel #8
0
        /// <summary>
        /// 补充滑动雨量
        /// </summary>
        void addOldRain(DateTime date, OBTArea area, TimeMode aType, List <AWSFieldValue> target, OBTField dataField)
        {
            string tableName       = AWSItems.getTableName(date, area, aType, dataField);
            string seleceField     = dataField.ToString();
            int    sliderRainMinut = 0;

            if (dataField == OBTField.R06M)
            {
                sliderRainMinut = 6;
            }
            else if (dataField == OBTField.R12M)
            {
                sliderRainMinut = 12;
            }
            else if (dataField == OBTField.R30M)
            {
                sliderRainMinut = 30;
            }
            else if (dataField == OBTField.R01H)
            {
                sliderRainMinut = 60;
            }
            else if (dataField == OBTField.R02H)
            {
                sliderRainMinut = 120;
            }
            else if (dataField == OBTField.R03H)
            {
                sliderRainMinut = 180;
            }
            else if (dataField == OBTField.R06H)
            {
                sliderRainMinut = 360;
            }
            else if (dataField == OBTField.R12H)
            {
                sliderRainMinut = 60 * 12;
            }
            else if (dataField == OBTField.R24H)
            {
                sliderRainMinut = 60 * 24;
            }
            else if (dataField == OBTField.R48H)
            {
                sliderRainMinut = 60 * 48;
            }
            else if (dataField == OBTField.R72H)
            {
                sliderRainMinut = 60 * 72;
            }
            if (sliderRainMinut > 0)
            {
                StringBuilder sb           = new StringBuilder();
                int           noDataCounts = 0;
                sb.AppendFormat("select DDATETIME,OBTID,{0} from {1} where DDATETIME>:ddate0 and {2}>0 and {2}<99999 and DDATETIME<:ddate1 and OBTID in(", seleceField, tableName, seleceField);
                foreach (var code in AWSCode.OBTCodeList)
                {
                    if (!target.Exists(t => t.ID == code.Key))
                    {
                        if (noDataCounts > 200)
                        {
                            break;
                        }
                        if (noDataCounts++ > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append("'");
                        sb.Append(code.Key);
                        sb.Append("'");
                    }
                }
                sb.Append(") order by DDATETIME desc");
                if (noDataCounts > 0)
                {
                    using (IDataReader reader = OracleHelp.ExecuteReader(sb.ToString(), T_LOCALOBTMIND.Tunnel.connString, new OracleParameter(":ddate0", date.AddMinutes(-sliderRainMinut)), new OracleParameter(":ddate1", date)))
                    {
                        string obtid;
                        int    maxRead = 5000;
                        while (reader.Read())
                        {
                            if (--maxRead == 0)
                            {
                                break;
                            }
                            obtid = reader[1].ToString();
                            if (!target.Exists(t => t.ID == obtid))
                            {
                                double value = (double)(decimal)reader[2];
                                target.Add(new AWSFieldValue()
                                {
                                    ID = obtid, V0 = value, TM = (DateTime)reader[0]
                                });
                                if (--noDataCounts == 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 自动站属性查询
        /// </summary>
        /// <param name="date"></param>
        /// <param name="area"></param>
        /// <param name="aType"></param>
        /// <param name="awsType"></param>
        /// <param name="dataField"></param>
        /// <returns></returns>
        public List <AWSFieldValue> GetFiledValue(AWDType type, DateTime?date, OBTArea area, TimeMode timeMode, OBTField dataField, bool isPlaying, int accuracy, bool orderbyDesc)
        {
            List <AWSFieldValue> gd2mInfo = null;

            if (type == AWDType.WIND)
            {
                if (date == null)
                {
                    gd2mInfo = AWSWind.GetLastAWSInfo(area, timeMode, dataField);
                }
                else
                {
                    gd2mInfo = AWSWind.GetAWSWindFromDB(date.Value, area, timeMode, dataField);
                }
            }
            else
            {
                if (dataField == OBTField.P0)
                {
                    gd2mInfo = GetP0(date);
                }
                else
                {
                    gd2mInfo = GetOffsetFromDB(date, area, dataField, accuracy);
                    if (gd2mInfo == null)
                    {
                        if (date == null)
                        {
                            gd2mInfo = GetLastAWSInfo(area, timeMode, dataField, accuracy);
                        }
                        else
                        {
                            gd2mInfo = GetAWSInfoFromDB(date.Value, area, timeMode, dataField, accuracy);
                        }
                    }
                    if (type == AWDType.RAIN)
                    {
                        if (!isPlaying)
                        {
                            DateTime lastTime;
                            if (date == null)
                            {
                                lastTime = gd2mInfo[0].TM.Value;
                            }
                            else
                            {
                                lastTime = date.Value;
                            }
                            addOldRain(lastTime, area, timeMode, gd2mInfo, dataField);
                        }
                    }
                }
            }
            if (orderbyDesc)
            {
                return(gd2mInfo.OrderByDescending(t => t.V0).ToList());
            }
            else
            {
                return(gd2mInfo.OrderBy(t => t.V0).ToList());
            }
        }
Beispiel #10
0
        /// <summary>
        /// 获取用户地图显示需要的数据
        /// </summary>
        /// <returns></returns>
        public static ClientReport GetAWSDataInfomation(AWDType type, DateTime?date, OBTArea area, TimeMode timeMode, AWSAdmin awsAdmin, string[] citys, OBTField dataField, int accuracy, double minLng, double minLat, double maxLng, double maxLat, int canvasWidth, int canvasHeight, int minSpace, bool isPlaying, bool orderbyDesc)
        {
            List <AWSFieldValue> awsFromDb    = getAwsFieldValueFromDb(type, date, area, timeMode, dataField, accuracy, isPlaying, orderbyDesc);
            List <AWSFieldValue> awsTmpResult = new List <AWSFieldValue>();
            List <AWSFieldValue> statsTarget  = new List <AWSFieldValue>();
            Mercator             myMercator   = new Mercator(minLat, maxLat, canvasHeight, minLng, maxLng, canvasWidth);

            for (int i = 0; i < awsFromDb.Count; i++)
            {
                AWSFieldValue item = awsFromDb[i];
                if (obtCodeList.ContainsKey(item.ID))
                {
                    OBTCODE aws = obtCodeList[item.ID];
                    if (awsAdmin == AWSAdmin.city)
                    {
                        if (AWSCode.ChinaAWS.ContainsKey(item.ID))
                        {
                            continue;
                        }
                    }
                    else if (awsAdmin == AWSAdmin.state)
                    {
                        if (!AWSCode.ChinaAWS.ContainsKey(item.ID))
                        {
                            continue;
                        }
                    }
                    statsTarget.Add(item);
                    if (aws.LONGITUDE > minLng && aws.LATITUDE > minLat && aws.LONGITUDE < maxLng && aws.LATITUDE < maxLat)
                    {
                        //计算CANVAS坐标
                        item.x = myMercator.Longitude2screentX(aws.LONGITUDE);
                        item.y = myMercator.Latitude2screentY(aws.LATITUDE);
                        if (checkSpace(item, awsTmpResult, minSpace))
                        {
                            if (type == AWDType.VIS && aws.AREAID == "45005" && item.V0 < 10)
                            {
                                item.V0 *= 1000;
                                item.V0  = double.Parse(item.V0.ToString("f1"));
                            }
                            awsTmpResult.Add(item);
                        }
                    }
                }
            }
            ClientReport result = new ClientReport()
            {
                aws = awsTmpResult
            };

            result.stats = Stats.getAwsStatis(type, statsTarget, citys);
            if (date == null)
            {
                if (awsTmpResult.Count > 0)
                {
                    result.time = awsTmpResult[0].TM.Value;
                }
            }
            else
            {
                result.time = date.Value;
            }
            return(result);
        }
Beispiel #11
0
        static List <AWSFieldValue> getAwsFieldValueFromDb(AWDType type, DateTime?date, OBTArea area, TimeMode timeMode, OBTField dataField, int accuracy, bool isPlaying, bool orderbyDesc)
        {
            string ckey = null;

            if (date != null)
            {
                ckey = "GetTempratureData" + date.Value.Ticks + area + timeMode + dataField + orderbyDesc;
            }
            else
            {
                ckey = "GetTempratureDataLastDate" + area + timeMode + dataField + orderbyDesc;
            }
            List <AWSFieldValue> result = MyCacheManager.Get(ckey) as List <AWSFieldValue>;

            if (result == null)
            {
                result = myQuery.GetFiledValue(type, date, area, timeMode, dataField, isPlaying, accuracy, orderbyDesc);
                if (result.Count > 0)
                {
                    DateTime expire;
                    if (date != null)
                    {
                        expire = DateTime.Now.AddMinutes(4);
                        if (DateTime.Now - date > TimeSpan.FromMinutes(20))
                        {
                            expire = DateTime.Now.AddHours(8);
                        }
                    }
                    else
                    {
                        expire = DateTime.Now.AddMinutes(1);
                    }
                    MyCacheManager.Insert(ckey, result, expire);
                }
            }
            return(result);
        }
Beispiel #12
0
        /// <summary>
        /// 获取用户时间的自动站全局排序
        /// </summary>
        public static List <AWSFieldValue> GetFullViewSort(AWDType type, DateTime?date, OBTArea area, TimeMode timeMode, AWSAdmin awsAdmin, string[] citys, OBTField dataField, bool orderByDescending, int maxCount, int accuracy, bool orderbyDesc)
        {
            List <AWSFieldValue> result    = new List <AWSFieldValue>();
            List <AWSFieldValue> awsFromDb = getAwsFieldValueFromDb(type, date, area, timeMode, dataField, accuracy, false, orderbyDesc);
            var dataOrderBy = orderByDescending ? awsFromDb.OrderByDescending(t => t.V0).ToArray() : awsFromDb.OrderBy(t => t.V0).ToArray();

            for (int i = 0; i < dataOrderBy.Length; i++)
            {
                var item = dataOrderBy[i];
                if (obtCodeList.ContainsKey(item.ID))
                {
                    OBTCODE aws = obtCodeList[item.ID];
                    if (citys.Length == 0 || citys.Contains(aws.AREAID))
                    {
                        if (awsAdmin == AWSAdmin.city)
                        {
                            if (AWSCode.ChinaAWS.ContainsKey(item.ID))
                            {
                                continue;
                            }
                        }
                        else if (awsAdmin == AWSAdmin.state)
                        {
                            if (!AWSCode.ChinaAWS.ContainsKey(item.ID))
                            {
                                continue;
                            }
                        }
                        result.Add(item);
                        if (--maxCount == 0)
                        {
                            break;
                        }
                    }
                }
            }
            return(result);
        }