Exemplo n.º 1
0
        /// <summary>
        /// 获取测点最新值
        /// </summary>
        /// <param name="points"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public double[] GetPointVal(string[] points, string time)
        {
            double[] val = new double[points.Length];
            double   v   = 0;
            Plink    pk  = new Plink();

            Plink.OpenPi();
            for (int i = 0; i < points.Length; i++)
            {
                pk.GetHisValue(points[i], time, ref v);
                if (kw.Contains(points[i]))
                {
                    v = v / 1000;
                }
                //if (mw.Contains(points[i]))
                //    v = v / 10000;
                if (wkw.Contains(points[i]))
                {
                    v = v * 10;
                }

                if (points[i] == "BERP.1.00CE30001")
                {
                    v = v / 1000;
                }
                v      = getDouble(v, 2);
                val[i] = v;
            }
            //Plink.closePi();
            return(val);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取实时测点数据
        /// </summary>
        /// <param name="real_data">测点</param>
        /// <param name="stime">当前时间</param>
        /// <returns></returns>
        public string GetChartRealData(string[] real_data, string stime)
        {
            this.init();
            int    ret  = 0;
            double drvA = 0;
            string str  = "";

            if (rtDBType == "EDNA")
            {
            }
            else
            {
                Plink.OpenPi();
            }


            for (int i = 0; i < real_data.Length; i++)
            {
                if (rtDBType == "EDNA")
                {
                    ek.GetHisValueByTime(real_data[i].Split(',')[0], stime, ref ret, ref drvA);
                }
                else
                {
                    pk.GetHisValue(real_data[i].Split(',')[0], stime, ref drvA);
                }
                str += DateTimeToUTC(Convert.ToDateTime(stime)) + "," + Math.Round(Convert.ToDouble(drvA.ToString()), 3) + ";";
            }
            return(str.TrimEnd(';'));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取多个数据测点的历史值
        /// </summary>
        /// <param name="points">测点集合</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="eTime">结束时间</param>
        /// <param name="seconds">间隔时间  秒</param>
        /// <returns></returns>
        public IList <Hashtable> GetValToTable(string[] points, string[] pointNames, string sTime, string eTime, int seconds)
        {
            Plink pk  = new Plink();
            int   num = 0;

            int day    = 0;
            int hour   = 0;
            int minute = 0;
            int second = 0;

            day    = Convert.ToDateTime(eTime).Day - Convert.ToDateTime(sTime).Day;
            hour   = Convert.ToDateTime(eTime).Hour - Convert.ToDateTime(sTime).Hour;
            minute = Convert.ToDateTime(eTime).Minute - Convert.ToDateTime(sTime).Minute;
            second = Convert.ToDateTime(eTime).Second - Convert.ToDateTime(sTime).Second;

            second = day * 24 * 3600 + hour * 3600 + minute * 60 * second;

            num = Convert.ToDateTime(eTime).Second - Convert.ToDateTime(sTime).Second;
            num = second / seconds;
            if (second % seconds != 0)
            {
                num += 1;
            }

            DateTime  _sTime = new DateTime(1970, 1, 1);
            Hashtable ht     = new Hashtable();

            for (int k = 0; k < num; k++)
            {
                sTime = Convert.ToDateTime(sTime).AddSeconds(seconds).ToString();
                eTime = sTime;

                ht = new Hashtable();

                for (int i = 0; i < pointNames.Length; i++)
                {
                    if (i == 0)
                    {
                        ht.Add("时间", eTime);
                        pk.GetHisValue(points[i], eTime, ref drv);
                        ht.Add(pointNames[i], drv);
                    }
                    else
                    {
                        pk.GetHisValue(points[i], eTime, ref drv);
                        ht.Add(pointNames[i], drv);
                    }
                }
                list.Add(ht);
            }


            return(list);
        }
Exemplo n.º 4
0
        public IList <Hashtable> GetHistValAndTIme1(string[] points, DateTime st, DateTime et)
        {
            ArrayList         list     = new ArrayList();
            Plink             pk       = new Plink();
            IList <Hashtable> listdata = new List <Hashtable>();

            Hashtable ht = new Hashtable();
            ArrayList ld = new ArrayList();
            ArrayList lt = new ArrayList();

            for (int i = 0; i < points.Length; i++)
            {
                ht = new Hashtable();
                lt = new ArrayList();
                ht.Add("name", points[i].Split('|')[1]);
                //ht.Add("yAxis", i);
                DateTime _sTime  = new DateTime(1970, 1, 1);
                int      seconds = Convert.ToInt32((et - st).TotalSeconds) / 600;
                DateTime dtt     = st;
                Plink.OpenPi();
                while (dtt < et)
                {
                    ld = new ArrayList();
                    pk.GetHisValue(points[i].Split('|')[0], dtt.ToString("yyyy-MM-dd HH:mm:ss"), ref drv);
                    if (drv > 0)
                    {
                        drv = pd.getDouble(drv, 3);
                    }
                    string   timeStamp = DateTimeToUTC(dtt).ToString();
                    DateTime dtStart   = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
                    long     lTime     = long.Parse(timeStamp + "0000000");
                    TimeSpan toNow     = new TimeSpan(lTime);
                    DateTime dtResult  = dtStart.Add(toNow);
                    ld.Add(Convert.ToInt64((dtResult - _sTime).TotalMilliseconds.ToString()));
                    ld.Add(drv);
                    lt.Add(ld);
                    // TimeSpan toNow1 = new TimeSpan(seconds);
                    dtt = dtt.AddSeconds(seconds);
                }
                ht.Add("data", lt);
                listdata.Add(ht);
                //lt = new ArrayList();
                //ht = new Hashtable();
            }

            return(listdata);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取测点历史值
        /// </summary>
        /// <param name="points"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public double[] GetPointVal(string[] points, string time)
        {
            double[] val = new double[points.Length];
            double   v   = 0;
            Plink    pk  = new Plink();

            Plink.OpenPi();
            for (int i = 0; i < points.Length; i++)
            {
                pk.GetHisValue(points[i], time, ref v);

                v      = getDouble(v, 2);
                val[i] = v;
            }
            //Plink.closePi();
            return(val);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取实时测点数据
        /// </summary>
        /// <param name="real_data">测点id</param>
        /// <param name="stime">查询时间</param>
        /// <returns>返回值数组</returns>
        public IList <Hashtable> GetChartData_Real(string[] real_data, string stime)
        {
            this.init();
            int    ret  = 0;
            double drvA = 0;

            if (rtDBType == "EDNA")
            {
            }
            else
            {
                Plink.OpenPi();
            }
            IList <Hashtable> listdata = new List <Hashtable>();
            Hashtable         ht       = new Hashtable();

            for (int i = 0; i < real_data.Length; i++)
            {
                ht = new Hashtable();
                ArrayList ld = new ArrayList();
                ArrayList lt = new ArrayList();
                if (rtDBType == "EDNA")
                {
                    ek.GetHisValueByTime(real_data[i].Split(',')[0], stime, ref ret, ref drvA);
                }
                else
                {
                    pk.GetHisValue(real_data[i].Split(',')[0], stime, ref drvA);
                }
                ld = new ArrayList();
                ld.Add(DateTimeToUTC(Convert.ToDateTime(stime)));
                ld.Add(Math.Round(Convert.ToDouble(drvA.ToString()), 3));
                lt.Add(ld);
                ht.Add("data", lt);
                listdata.Add(ht);
            }
            return(listdata);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取实时测点数据-所有的
        /// </summary>
        /// <param name="real_data">测点id</param>
        /// <param name="stime">查询的起始时间</param>
        /// <param name="etime">结束时间</param>
        /// <returns>返回值数组</returns>
        public IList <Hashtable> GetChartData(string[] real_data, string stime, string etime, out string max_data_total, out string min_data_total)
        {
            this.init();
            int ret = 0, num = 0, num_pin = 1;

            max_data_total = ""; min_data_total = "";
            double drvA = 0;
            double max_data = 0, min_data = 0;

            //dt = new DataTable();
            if (rtDBType == "EDNA")
            {
            }
            else
            {
                Plink.OpenPi();
            }
            IList <Hashtable> listdata = new List <Hashtable>();
            //dt.Columns.Add("序号", typeof(int));
            Hashtable ht = new Hashtable();

            for (int i = 0; i < real_data.Length; i++)
            {
                string[] dv;

                DateTime date;
                if (Convert.ToInt32((DateTime.Parse(etime) - DateTime.Parse(stime)).TotalMinutes) > 20)
                {
                    date = DateTime.Parse(stime);
                    dv   = new string[600]; //值
                }
                else
                {
                    date = DateTime.Parse(stime).AddMinutes(-10);
                    dv   = new string[Convert.ToInt32((DateTime.Parse(etime) - DateTime.Parse(stime).AddMinutes(-10)).TotalSeconds / 1)]; //值
                }

                ht = new Hashtable();
                ArrayList ld = new ArrayList();
                ArrayList lt = new ArrayList();
                ht.Add("name", real_data[i].Split(',')[1]);
                //dt.Columns.Add(real_data[i].Split(',')[1], typeof(double));
                //if (i==real_data.Length-1)
                //{
                //    dt.Columns.Add("时间", typeof(DateTime));
                //}

                while (date < DateTime.Parse(etime))
                {
                    if (rtDBType == "EDNA")
                    {
                        ek.GetHisValueByTime(real_data[i].Split(',')[0], date.ToString(), ref ret, ref drvA);
                    }
                    else
                    {
                        pk.GetHisValue(real_data[i].Split(',')[0], date.ToString(), ref drvA);
                    }
                    ld = new ArrayList();
                    ld.Add(DateTimeToUTC(date));
                    ld.Add(Math.Round(Convert.ToDouble(drvA.ToString()), 3));
                    lt.Add(ld);
                    if (num == 0)
                    {
                        max_data = Convert.ToDouble(drvA.ToString());
                        min_data = Convert.ToDouble(drvA.ToString());
                        num++;
                    }
                    else
                    {
                        if (max_data < Convert.ToDouble(drvA.ToString()))
                        {
                            max_data = Convert.ToDouble(drvA.ToString());
                        }
                        if (min_data > Convert.ToDouble(drvA.ToString()))
                        {
                            min_data = Convert.ToDouble(drvA.ToString());
                        }
                    }
                    if (Convert.ToInt32((DateTime.Parse(etime) - DateTime.Parse(stime)).TotalMinutes) > 20)
                    {
                        date = date.AddSeconds(Convert.ToInt32((DateTime.Parse(etime) - DateTime.Parse(stime)).TotalSeconds) / 600);
                    }
                    else
                    {
                        date = date.AddSeconds(3.0);
                    }
                }

                max_data_total += Math.Round(max_data, 3) + ",";
                min_data_total += Math.Round(min_data, 3) + ",";
                max_data        = 0; min_data = 0;
                ht.Add("data", lt);
                ht.Add("yAxis", i);
                listdata.Add(ht);
            }
            return(listdata);
        }
Exemplo n.º 8
0
        public IList <Hashtable> Get_Required_data(string unit_id, string[] para_id, string[] per, string hanshu, string stime, string etime, out string[] hanshu_gongshi, out string errMsg)
        {
            errMsg         = "";
            hanshu_gongshi = new string[hanshu.Split(',').Length];
            ArrayList         list     = new ArrayList();
            DataSet           DS       = new DataSet();
            IList <Hashtable> listdata = new List <Hashtable>();
            Hashtable         ht       = new Hashtable();

            //循环曲线个数
            for (int i = 0; i < per.Length; i++)
            {
                //获取每条曲线标准负荷
                string sql = "SELECT T_INFO_RL,T_POWERTAG FROM ADMINISTRATOR.T_BASE_POINT_UNIT where T_UNITID=(select distinct u.T_UNITID from T_BASE_CHARTPARAID b inner join  ADMINISTRATOR.T_BASE_UNIT u on b.T_LEVEL1=u.T_UNITDESC where b.T_LEVEL1='" + unit_id + "')";

                DS = dl.RunDataSet(sql, out errMsg);

                if (DS != null)
                {
                    ht = new Hashtable();
                    ArrayList ld  = new ArrayList();
                    ArrayList ldd = new ArrayList();
                    ArrayList lt  = new ArrayList();
                    ArrayList ltt = new ArrayList();

                    double min_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()) * Convert.ToDouble(per[i].Split('|')[0]) / 100;
                    double max_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString()) * Convert.ToDouble(per[i].Split('|')[1]) / 100;

                    int       seconds   = Convert.ToInt32((Convert.ToDateTime(etime) - Convert.ToDateTime(stime)).TotalSeconds) / 300;
                    DateTime  dtt       = Convert.ToDateTime(stime);
                    int       count     = 0;
                    ArrayList _listTime = new ArrayList();
                    while (dtt < Convert.ToDateTime(etime))
                    {
                        double val = new double();
                        Plink.OpenPi();
                        pk.GetHisValue(DS.Tables[0].Rows[0][1].ToString(), dtt.ToString(), ref val);

                        if (val >= min_data && val <= max_data)
                        {
                            count++;
                            _listTime.Add(dtt);
                        }
                        dtt = dtt.AddSeconds(seconds);
                    }
                    if (_listTime.Count > 0)
                    {
                        double[] x = new double[count];
                        double[] y = new double[count];

                        for (int k = 0; k < _listTime.Count; k++)
                        {
                            ld = new ArrayList();
                            double val = new double();
                            Plink.OpenPi();
                            pk.GetHisValue(para_id[0], _listTime[k].ToString(), ref val);
                            if (k == 0)
                            {
                                min_data = val;
                                max_data = val;
                            }
                            else
                            {
                                if (val > max_data)
                                {
                                    max_data = val;
                                }
                                if (val < min_data)
                                {
                                    min_data = val;
                                }
                            }
                            x[k] = val;
                            ld.Add(val);

                            Plink.OpenPi();
                            pk.GetHisValue(para_id[1], _listTime[k].ToString(), ref val);
                            y[k] = val;
                            ld.Add(val);

                            lt.Add(ld);
                        }

                        if (hanshu.Split(',')[0].Trim() == "多项式")
                        {
                            string   gongshi = "";
                            double[] z       = new double[Convert.ToInt32(hanshu.Split(',')[1]) + 1];
                            funPolynomial(x, y, Convert.ToInt32(hanshu.Split(',')[1]), out gongshi, out z);

                            hanshu_gongshi[i] = gongshi;
                            double num = (max_data - min_data) / 20;
                            for (double m = min_data; m < max_data; m = m + num)
                            {
                                ldd = new ArrayList();
                                ldd.Add(m);
                                double y_data = 0;
                                for (int j = z.Length - 1; j >= 0; j--)
                                {
                                    y_data += z[j] * (Math.Pow(m, j));
                                }
                                ldd.Add(y_data);
                                ltt.Add(ldd);
                            }
                        }
                        else if (hanshu.Split(',')[0].Trim() == "线性")
                        {
                            string gongshi = "", a = "", b = "";
                            funXianxing(x, y, out gongshi, out a, out b);
                            hanshu_gongshi[i] = gongshi;
                            double num = (max_data - min_data) / 20;
                            for (double m = min_data; m < max_data; m = m + num)
                            {
                                ldd = new ArrayList();
                                ldd.Add(m);
                                ldd.Add(Convert.ToDouble(a) * m + Convert.ToDouble(b));
                                ltt.Add(ldd);
                            }
                        }
                        else if (hanshu.Split(',')[0].Trim() == "指数")
                        {
                            //y=a*exp(b*x)
                            string gongshi = "", a = "", b = "";
                            funExponent(x, y, out gongshi, out a, out b);
                            hanshu_gongshi[i] = gongshi;
                            double num = (max_data - min_data) / 20;
                            for (double m = min_data; m < max_data; m = m + num)
                            {
                                ldd = new ArrayList();
                                ldd.Add(m);
                                ldd.Add(Convert.ToDouble(a) * (Math.Exp(Convert.ToDouble(b) * m)));
                                ltt.Add(ldd);
                            }
                        }
                        else if (hanshu.Split(',')[0].Trim() == "对数")
                        {
                            //y=a*ln(x)+b
                            string gongshi = "", a = "", b = "";
                            funLogarithm(x, y, out gongshi, out a, out b);
                            hanshu_gongshi[i] = gongshi;
                            double num = (max_data - min_data) / 20;
                            for (double m = min_data; m < max_data; m = m + num)
                            {
                                ldd = new ArrayList();
                                ldd.Add(m);
                                ldd.Add(Convert.ToDouble(a) * Math.Log(m) + Convert.ToDouble(b));
                                ltt.Add(ldd);
                            }
                        }
                        else if (hanshu.Split(',')[0].Trim() == "幂")
                        {
                            //y=a*(x^b)
                            string gongshi = "", a = "", b = "";
                            funPower(x, y, out gongshi, out a, out b);
                            hanshu_gongshi[i] = gongshi;
                            double num = (max_data - min_data) / 20;
                            for (double m = min_data; m < max_data; m = m + num)
                            {
                                ldd = new ArrayList();
                                ldd.Add(m);
                                ldd.Add(Convert.ToDouble(a) * (Math.Pow(m, Convert.ToDouble(b))));
                                ltt.Add(ldd);
                            }
                        }
                        ht.Add("data", lt);
                        ht.Add("type", "scatter");
                        ht.Add("name", "散点图");
                        listdata.Add(ht);
                        ht = new Hashtable();
                        ht.Add("data", ltt);
                        ht.Add("type", "line");
                        ht.Add("name", "拟合公式曲线图");
                        listdata.Add(ht);
                    }
                }
            }
            //for (int i = 0; i < per.Length; i++)
            //{
            //    string sql_Required = "select T_PARAID,T_OUTTABLE from T_BASE_CALCPARA where T_UNITID ='" + unit_id + "' and (T_PARAID ='Pel' or T_PARAID='" + para_id[0] + "' or T_PARAID ='" + para_id[1] + "')";
            //    //string sql = "select T_TYPE from T_BASE_CALCPARA where T_UNITID =" + unit_id + "' and T_PARAID='" + para_id+",";

            //    DS = dl.RunDataSet(sql_Required, out errMsg);

            //    if ((DS.Tables[0].Rows.Count > 0) && (DS.Tables[0].Rows[0]["T_OUTTABLE"].ToString() != "") && (DS.Tables[0].Rows[1]["T_OUTTABLE"].ToString() != "") && (DS.Tables[0].Rows[2]["T_OUTTABLE"].ToString() != ""))
            //    {
            //        ht = new Hashtable();
            //        ArrayList ld = new ArrayList();
            //        ArrayList ldd = new ArrayList();
            //        ArrayList lt = new ArrayList();
            //        ArrayList ltt = new ArrayList();
            //        string str1 = "", str2 = "", str3 = "";

            //        for (int j = 0; j < DS.Tables[0].Rows.Count; j++)
            //        {
            //            if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == "Pel")
            //            {
            //                str1 = "select  ss.D_VALUE as " + para_id[0] + ",sss.D_VALUE as " + para_id[1] + " from (select  s.D_VALUE,s. T_DATETIME from (select D_VALUE,T_DATETIME  from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + ", " +
            //                "(select T_UNITID,\"D_CAPABILITY\" from T_BASE_UNIT where T_UNITID ='" + unit_id + "') as a where  a.T_UNITID = T_INFO_CALCDATA.T_UNITID  and " +
            //                "T_INFO_CALCDATA.T_PARAID = 'Pel' and  T_INFO_CALCDATA.D_VALUE between a.\"D_CAPABILITY\"*" + Convert.ToDouble(per[i].Split('|')[0]) / 100 +
            //                " and a.\"D_CAPABILITY\"*" + Convert.ToDouble(per[i].Split('|')[1]) / 100 + "   ) as s where s.T_DATETIME between '" + stime + "' and '" + etime +
            //                "' group by  s.D_VALUE,s. T_DATETIME order by s.T_DATETIME asc) as q, ";
            //            }
            //            else if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == para_id[0])
            //            {
            //                str2 = "(select D_VALUE,T_DATETIME  from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + " where T_UNITID ='" + unit_id + "' and  T_PARAID='" + para_id[0] + "' ) as ss,";
            //            }
            //            else if (DS.Tables[0].Rows[j]["T_PARAID"].ToString() == para_id[1])
            //            {
            //                str3 = "(select D_VALUE,T_DATETIME  from " + DS.Tables[0].Rows[j]["T_OUTTABLE"].ToString() + " where T_UNITID ='" + unit_id + "' and  T_PARAID='" + para_id[1] + "' ) as sss where  q.T_DATETIME = ss.T_DATETIME and  q.T_DATETIME  =sss.T_DATETIME ";
            //            }
            //        }

            //        string append_sql = str1 + str2 + str3;

            //        DS = dl.RunDataSet(append_sql, out errMsg);

            //        if (DS.Tables[0].Rows.Count > 0)
            //        {

            //            double[] x = new double[DS.Tables[0].Rows.Count];
            //            double[] y = new double[DS.Tables[0].Rows.Count];
            //            double min_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString());
            //            double max_data = Convert.ToDouble(DS.Tables[0].Rows[0][0].ToString());
            //            for (int j = 0; j < DS.Tables[0].Rows.Count; j++)
            //            {
            //                ld = new ArrayList();
            //                ld.Add(Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()));
            //                if (min_data > Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()))
            //                {
            //                    min_data = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString());
            //                }
            //                if (max_data < Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString()))
            //                {
            //                    max_data = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString());
            //                }
            //                x[j] = Convert.ToDouble(DS.Tables[0].Rows[j][0].ToString());
            //                ld.Add(Convert.ToDouble(DS.Tables[0].Rows[j][1].ToString()));

            //                y[j] = Convert.ToDouble(DS.Tables[0].Rows[j][1].ToString());
            //                lt.Add(ld);
            //            }
            //            if (hanshu.Split(',')[0].Trim() == "多项式")
            //            {
            //                string gongshi = "";
            //                double[] z = new double[Convert.ToInt32(hanshu.Split(',')[1]) + 1];
            //                funPolynomial(x, y, Convert.ToInt32(hanshu.Split(',')[1]), out gongshi, out z);

            //                hanshu_gongshi[i] = gongshi;
            //                double num = (max_data - min_data) / 20;
            //                for (double m = min_data; m < max_data; m = m + num)
            //                {
            //                    ldd = new ArrayList();
            //                    ldd.Add(m);
            //                    double y_data = 0;
            //                    for (int j = z.Length - 1; j >= 0; j--)
            //                    {
            //                        y_data += z[j] * (Math.Pow(m, j));
            //                    }
            //                    ldd.Add(y_data);
            //                    ltt.Add(ldd);
            //                }

            //            }
            //            else if (hanshu.Split(',')[0].Trim() == "线性")
            //            {
            //                string gongshi = "", a = "", b = "";
            //                funXianxing(x, y, out gongshi, out  a, out  b);
            //                hanshu_gongshi[i] = gongshi;
            //                double num = (max_data - min_data) / 20;
            //                for (double m = min_data; m < max_data; m = m + num)
            //                {
            //                    ldd = new ArrayList();
            //                    ldd.Add(m);
            //                    ldd.Add(Convert.ToDouble(a) * m + Convert.ToDouble(b));
            //                    ltt.Add(ldd);
            //                }
            //            }
            //            else if (hanshu.Split(',')[0].Trim() == "指数")
            //            {
            //                //y=a*exp(b*x)
            //                string gongshi = "", a = "", b = "";
            //                funExponent(x, y, out gongshi, out a, out b);
            //                hanshu_gongshi[i] = gongshi;
            //                double num = (max_data - min_data) / 20;
            //                for (double m = min_data; m < max_data; m = m + num)
            //                {
            //                    ldd = new ArrayList();
            //                    ldd.Add(m);
            //                    ldd.Add(Convert.ToDouble(a) * (Math.Exp(Convert.ToDouble(b) * m)));
            //                    ltt.Add(ldd);
            //                }
            //            }
            //            else if (hanshu.Split(',')[0].Trim() == "对数")
            //            {
            //                //y=a*ln(x)+b
            //                string gongshi = "", a = "", b = "";
            //                funLogarithm(x, y, out gongshi, out a, out b);
            //                hanshu_gongshi[i] = gongshi;
            //                double num = (max_data - min_data) / 20;
            //                for (double m = min_data; m < max_data; m = m + num)
            //                {
            //                    ldd = new ArrayList();
            //                    ldd.Add(m);
            //                    ldd.Add(Convert.ToDouble(a) * Math.Log(m) + Convert.ToDouble(b));
            //                    ltt.Add(ldd);
            //                }

            //            }
            //            else if (hanshu.Split(',')[0].Trim() == "幂")
            //            {
            //                //y=a*(x^b)
            //                string gongshi = "", a = "", b = "";
            //                funPower(x, y, out gongshi, out a, out b);
            //                hanshu_gongshi[i] = gongshi;
            //                double num = (max_data - min_data) / 20;
            //                for (double m = min_data; m < max_data; m = m + num)
            //                {
            //                    ldd = new ArrayList();
            //                    ldd.Add(m);
            //                    ldd.Add(Convert.ToDouble(a) * (Math.Pow(m, Convert.ToDouble(b))));
            //                    ltt.Add(ldd);
            //                }

            //            }
            //            ht.Add("data", lt);
            //            ht.Add("type", "scatter");
            //            ht.Add("name", "散点图");
            //            listdata.Add(ht);
            //            ht = new Hashtable();
            //            ht.Add("data", ltt);
            //            ht.Add("type", "line");
            //            ht.Add("name", "拟合公式曲线图");
            //            listdata.Add(ht);
            //        }
            //    }
            //}
            return(listdata);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 获取多个数据测点的历史值
        /// </summary>
        /// <param name="points">测点集合</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="eTime">结束时间</param>
        /// <param name="seconds">间隔时间  秒</param>
        /// <returns></returns>
        public IList <Hashtable> GetVal(string[] points, string[] pointNames, string sTime, string eTime, int seconds)
        {
            if (points.Length < 1)
            {
                return(null);
            }

            Plink pk = new Plink();
            //DateTime dt = new DateTime();
            int num = 0;

            int day    = 0;
            int hour   = 0;
            int minute = 0;
            int second = 0;

            day    = Convert.ToDateTime(eTime).Day - Convert.ToDateTime(sTime).Day;
            hour   = Convert.ToDateTime(eTime).Hour - Convert.ToDateTime(sTime).Hour;
            minute = Convert.ToDateTime(eTime).Minute - Convert.ToDateTime(sTime).Minute;
            second = Convert.ToDateTime(eTime).Second - Convert.ToDateTime(sTime).Second;

            second = day * 24 * 3600 + hour * 3600 + minute * 60 * second;

            num = Convert.ToDateTime(eTime).Second - Convert.ToDateTime(sTime).Second;
            num = second / seconds;
            if (second % seconds != 0)
            {
                num += 1;
            }

            DateTime _sTime = new DateTime(1970, 1, 1);

            Plink.OpenPi();
            //循环测点
            for (int i = 0; i < pointNames.Length; i++)
            {
                Hashtable ht = new Hashtable();
                ht.Add("name", pointNames[i]);//添加测点名称
                string _st = sTime;

                ArrayList listD = new ArrayList();
                for (int k = 0; k < num; k++)
                {
                    ArrayList listPoint = new ArrayList();
                    eTime = _st;
                    listPoint.Add(Convert.ToInt64((Convert.ToDateTime(eTime) - _sTime).TotalMilliseconds.ToString()));
                    pk.GetHisValue(points[i], eTime, ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    listPoint.Add(drv);
                    _st = Convert.ToDateTime(eTime).AddSeconds(seconds).ToString();
                    listD.Add(listPoint);
                }
                ht.Add("data", listD);
                list.Add(ht);
            }
            //Plink.closePi();
            return(list);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取实时数据
        /// </summary>
        /// <param name="point">测点名称</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="type">查询类型   年:1 月:2 日:3</param>
        /// <returns></returns>
        public IList <Hashtable> GetValList(string point, string sTime, string type)
        {
            Plink     pk = new Plink();
            DateTime  dt = new DateTime();
            Hashtable h  = new Hashtable();

            val = "";
            Plink.OpenPi();
            if (type == "1")//年比
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-01-01 23:59:59"));
                for (int i = 0; i < 365; i++)
                {
                    h = new Hashtable();
                    h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                    pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("去年", drv);
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("今年", drv);
                    dt = dt.AddDays(1);
                    list.Add(h);
                }
            }
            else if (type == "2")//月比
            {
                int month = Convert.ToDateTime(sTime).Month;
                int year  = Convert.ToDateTime(sTime).Year;

                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-1 11:59:59"));

                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    for (int i = 0; i < 62; i++)
                    {
                        h = new Hashtable();
                        h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                        pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("去年", drv);
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("今年", drv);
                        dt = dt.AddHours(12);
                        list.Add(h);
                    }
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11)
                {
                    for (int i = 0; i < 60; i++)
                    {
                        h = new Hashtable();
                        h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                        pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("去年", drv);
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        h.Add("今年", drv);
                        dt = dt.AddHours(12);
                        list.Add(h);
                    }
                }
                else
                {
                    if (year % 4 == 0)
                    {
                        for (int i = 0; i < 58; i++)
                        {
                            h = new Hashtable();
                            h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                            pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("去年", drv);
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("今年", drv);
                            dt = dt.AddHours(12);
                            list.Add(h);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 55; i++)
                        {
                            h = new Hashtable();
                            h.Add("时间", dt.ToString("MM-dd HH:ss:mm"));
                            pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("去年", drv);
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            h.Add("今年", drv);
                            dt = dt.AddHours(12);
                            list.Add(h);
                        }
                    }
                }
            }
            else if (type == "3")//日比
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-dd 0:14:59"));
                for (int i = 0; i < 96; i++)
                {
                    h = new Hashtable();
                    h.Add("时间", dt.ToString("HH:ss:mm"));
                    pk.GetHisValue(point, dt.AddYears(-1).ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("去年", drv);
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    h.Add("今年", drv);
                    dt = dt.AddMinutes(15);
                    list.Add(h);
                }
            }

            Plink.closePi();
            return(list);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获取实时数据
        /// </summary>
        /// <param name="point">测点名称</param>
        /// <param name="sTime">开始时间</param>
        /// <param name="type">查询类型   日:1 月:2 年:3</param>
        /// <returns></returns>
        public string GetVal(string point, string sTime, string type)
        {
            Plink    pk = new Plink();
            DateTime dt = new DateTime();

            val = "";
            Plink.OpenPi();
            if (type == "1")
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-01-01 23:59:59"));
                for (int i = 0; i < 365; i++)
                {
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    val += drv + ",";
                    dt   = dt.AddDays(1);
                }
            }
            else if (type == "2")
            {
                int month = Convert.ToDateTime(sTime).Month;
                int year  = Convert.ToDateTime(sTime).Year;

                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-1 11:59:59"));

                if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                {
                    for (int i = 0; i < 62; i++)
                    {
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        val += drv + ",";
                        dt   = dt.AddHours(12);
                    }
                }
                else if (month == 4 || month == 6 || month == 9 || month == 11)
                {
                    for (int i = 0; i < 60; i++)
                    {
                        pk.GetHisValue(point, dt.ToString(), ref drv);
                        if (drv > 0)
                        {
                            drv = getDouble(drv, 3);
                        }
                        val += drv + ",";
                        dt   = dt.AddHours(12);
                    }
                }
                else
                {
                    if (year % 4 == 0)
                    {
                        for (int i = 0; i < 58; i++)
                        {
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            val += drv + ",";
                            dt   = dt.AddHours(12);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 55; i++)
                        {
                            pk.GetHisValue(point, dt.ToString(), ref drv);
                            if (drv > 0)
                            {
                                drv = getDouble(drv, 3);
                            }
                            val += drv + ",";
                            dt   = dt.AddHours(12);
                        }
                    }
                }
            }
            else if (type == "3")
            {
                dt = Convert.ToDateTime(Convert.ToDateTime(sTime).ToString("yyyy-MM-dd 0:14:59"));
                for (int i = 0; i < 96; i++)
                {
                    pk.GetHisValue(point, dt.ToString(), ref drv);
                    if (drv > 0)
                    {
                        drv = getDouble(drv, 3);
                    }
                    val += drv + ",";
                    dt   = dt.AddMinutes(15);
                }
            }

            if (val.Length > 0)
            {
                //val = val.Substring(0, val.Length - 1);
                val = val.Remove(val.LastIndexOf(","), 1);
            }
            Plink.closePi();
            return(val);
        }