예제 #1
0
        public static PredictiveProcessData ParseProcessData(XElement pd, int links, decimal precision)
        {
            PredictiveProcessData res = new PredictiveProcessData(links, precision);
            res.Name = pd.Attribute("Name").Value;
            res.ProcessDataId = pd.Attribute("Id").Value;
            res.UtcFrom = DateTime.Parse(pd.Attribute("UtcFrom").Value);
            res.UtcTo = DateTime.Parse(pd.Attribute("UtcTo").Value);

            foreach (XElement parm in pd.Element("Params").Elements("Param"))
            {
                ProcessDataParam param = new ProcessDataParam();
                String type = parm.Attribute("DataType").Value;
                param.Name = parm.Attribute("Name").Value;
                if (type == "date")
                    param.DateValue = DateTime.Parse(parm.Attribute("Value").Value);
                else if (type == "decimal")
                {
                    string val = parm.Attribute("Value").Value;
                    if (val == "")
                        val = "0.0";
                    param.NumValue = decimal.Parse(val.Replace(".", ","));
                }
                else
                    param.StrValue = parm.Attribute("Value").Value;

                res.Params.Add(param);
            }

            foreach (XElement parm in pd.Element("EnergyData").Elements("Val"))
            {
                res.AddEnergyPoint(DateTime.Parse(parm.Attribute("UtcFrom").Value), Decimal.Parse(parm.Attribute("Value").Value));
            }
            return res;
        }
예제 #2
0
        /// <summary>
        /// returns json object of all available params with all distinct values
        /// </summary>
        /// <returns></returns>
        public static string GetAvailableParams()
        {
            string ret = "{ ";

            var zz = PredictiveProcessData.ParseProcessData(PredictiveProcessData.LoadEnergyProcessDataFromXml(GetCccXmlHttpResponse("GET", String.Format(cccxml_get, JsonConvert.SerializeObject(new int[] { 33000 })))).First(), 5, 0);

            foreach (ProcessDataParam param in zz.Params)
            {
                string val = "";
                if (param.NumValue != null)
                {
                    val = param.NumValue.ToString();
                }
                else if (param.DateValue != null)
                {
                    val = param.DateValue.ToString();
                }
                else
                {
                    val = param.StrValue;
                }
                ret += "\"" + param.Name + "\" : \"" + val + "\", ";
            }
            return(ret.Substring(0, ret.Length - 2) + " }");
        }
예제 #3
0
 /// <summary>
 /// Constructor...
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="paramss"></param>
 public ParamEvaluation(string Name, IEnumerable <ProcessDataParam> paramss)
 {
     ParamName           = Name;
     this.paramss        = paramss.Where(x => x.Name == Name);
     this.distinctValues = this.paramss.Select(x => PredictiveProcessData.getValueAndType(x)).Distinct();
     Ignore = false;
 }
예제 #4
0
        /// <summary>
        /// general GET method for process data
        /// </summary>
        /// <param name="processIds"></param>
        /// <param name="precision"></param>
        /// <param name="links"></param>
        /// <returns></returns>
        public static IEnumerable <PredictiveProcessData> GetProcessFromWS(int[] processIds, decimal precision = 0m, int links = 5)
        {
            List <PredictiveProcessData> ret = new List <PredictiveProcessData>();

            foreach (XElement ent in PredictiveProcessData.LoadEnergyProcessDataFromXml(GetCccXmlHttpResponse("GET", String.Format(cccxml_get, JsonConvert.SerializeObject(processIds)))))
            {
                ret.Add(PredictiveProcessData.ParseProcessData(ent, links, precision));
            }
            return(ret);
        }
예제 #5
0
        /// <summary>
        /// save new process directly from xml
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static bool InsertProcess(FileStream xml)
        {
            string env = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" > " +
                         "<Body xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" > " +
                         "<CCCXML_INSERT xmlns=\"services.wsdl\" > " +
                         "<process_xml xmlns=\"services.wsdl\" type=\"http://www.w3.org/2001/XMLSchema:string\">" +
                         "<![CDATA[<Data>{0}</Data>]]>" +
                         "</process_xml></CCCXML_INSERT></Body></Envelope>";

            foreach (XElement ent in PredictiveProcessData.LoadEnergyProcessDataFromXml(xml))
            {
                string result = GetCccXmlHttpResponse("INSERT", String.Format(env, ent.ToString()));
                if (!result.Contains("Non unique primary key") && !result.Contains("inserted"))
                {
                    xml.Close();
                    return(false);
                }
            }
            xml.Close();
            return(true);
        }