Example #1
0
        /// <summary>
        /// 将监测数据读入到数据集合
        /// </summary>
        /// <param name="sqlStr"> sql语句 </param>
        /// <param name="data"> 数据集合 </param>
        /// <param name="config">配置</param>
        private void GetValueFromDB(string sqlStr, IList <MonitorData> data, FactorConfig config)
        {
            MonitorData temp;
            DataTable   dt = SqlHelper.ExecuteDataSetText(sqlStr, null).Tables[0];

            foreach (DataRow row in dt.Rows)
            {
                temp                 = new MonitorData();
                temp.SensorId        = Convert.ToInt32(row[0]);
                temp.AcquisitionTime = Convert.ToDateTime(row[1]);
                temp.Location        = Convert.ToString(row[2]);

                temp.Values = new decimal?[row.ItemArray.Length - 3];
                for (int i = 3; i < row.ItemArray.Length; i++)
                {
                    if (row[i] != DBNull.Value)
                    {
                        temp.Values[i - 3] =
                            Convert.ToDecimal(Convert.ToDecimal(row[i]).ToString("f" + config.DecimalPlaces[i - 3]));
                    }
                }

                temp.Columns = config.Display;
                temp.Unit    = config.Unit;
                data.Add(temp);
            }
        }
        public object GetDailyDataByGroupAndDate(int groupId, DateTime startDate, DateTime endDate)
        {
            string       unit         = "mm";
            int          decimalPlace = 2;
            FactorConfig config       =
                Config.GetConfigByFactors(
                    new[] { int.Parse(ConfigurationManager.AppSettings["SettleFactorId"]) }, 0)///修改
                .FirstOrDefault();

            if (config != default(FactorConfig) && config.Unit.Length > 0)
            {
                unit = config.Unit[0];
            }

            if (config != default(FactorConfig) && config.DecimalPlaces.Length > 0)
            {
                decimalPlace = config.DecimalPlaces[0];
            }

            using (SecureCloud_Entities entity = new SecureCloud_Entities())
            {
                var query = from data in entity.T_THEMES_DEFORMATION_SETTLEMENT
                            from sensor in entity.T_DIM_SENSOR
                            from sensorGrp in entity.T_DIM_SENSOR_GROUP_CHENJIANG
                            where data.SENSOR_ID == sensor.SENSOR_ID &&
                            sensor.SENSOR_ID == sensorGrp.SENSOR_ID &&
                            sensorGrp.GROUP_ID == groupId &&
                            !sensor.IsDeleted &&
                            sensor.Identification != 1 &&
                            data.ACQUISITION_DATETIME >= startDate &&
                            data.ACQUISITION_DATETIME <= endDate
                            select new
                {
                    Acquistiontime = data.ACQUISITION_DATETIME,
                    SensorId       = data.SENSOR_ID,
                    Location       = sensor.SENSOR_LOCATION_DESCRIPTION,
                    Len            = sensorGrp.LENGTH,
                    Value          = data.SETTLEMENT_VALUE
                };
                var unitList = Config.GetUnitBySensorID(Convert.ToInt32(query.Select(m => m.SensorId).FirstOrDefault()));
                unit = unitList[0] ?? "mm";

                return(new JObject(
                           new JProperty("unit", unit),
                           new JProperty("data",
                                         new JArray(query.ToList().GroupBy(g => new
                {
                    Year = g.Acquistiontime.GetValueOrDefault().Year,
                    Month = g.Acquistiontime.GetValueOrDefault().Month,
                    Day = g.Acquistiontime.GetValueOrDefault().Day
                }).Select(d =>
                          new JObject(
                              new JProperty("acquistiontime", new DateTime(d.Key.Year, d.Key.Month, d.Key.Day)),
                              new JProperty("values",
                                            new JArray(
                                                d.GroupBy(g => new { g.SensorId, g.Len, g.Location })
                                                .OrderBy(g => g.Key.Len)
                                                .Select(v =>
                                                        new JObject(
                                                            new JProperty("sensorId", v.Key.SensorId),
                                                            new JProperty("location", v.Key.Location),
                                                            new JProperty("len", v.Key.Len),
                                                            new JProperty("value", Math.Round(v.Select(value =>
                                                                                                       value.Value.GetValueOrDefault())
                                                                                              .Average(), decimalPlace))))))))))));
            }
        }