Exemplo n.º 1
0
        public async static void run()
        {
            uint cnt;
            uint total;

            if (!EDSClass.Connected)
            {
                EDSClass.Connect();
            }

            /*TimeDuration zone;
             * TimeDuration offset = new TimeDuration();
             * Timestamp s= EDSClass.Client.getServerTime(EDSClass.AuthStr, out zone, out offset);
             *
             * Console.WriteLine(EDSClass.fromTS(zone.seconds));
             * Console.WriteLine(EDSClass.fromTS(offset.seconds));
             * Console.Write(EDSClass.fromTS(s.second));
             * return;*/

            Dictionary <DateTime, int> data = new Dictionary <DateTime, int>();

            DateTime dateStart = DateTime.Parse("01.06.2018 00:00:00");
            DateTime dateEnd   = DateTime.Parse("01.09.2018 00:00:00");
            DateTime date      = dateStart.AddHours(0);
            DateTime dateSet   = DateTime.MinValue;
            bool     prevVal   = false;

            while (date <= dateEnd)
            {
                EDSClass.Connect();
                TabularRequest            req   = new TabularRequest();
                List <TabularRequestItem> items = new List <TabularRequestItem>();
                items.Add(new TabularRequestItem()
                {
                    function = "VALUE",
                    pointId  = new PointId()
                    {
                        iess = "04VT_AM01P-47.MCR@GRARM"
                    }
                });



                req.items = items.ToArray();

                req.period = new TimePeriod()
                {
                    from = new Timestamp()
                    {
                        second = EDSClass.toTS(date)
                    },
                    till = new Timestamp()
                    {
                        second = EDSClass.toTS(date.AddHours(24))
                    }
                };

                req.step = new TimeDuration()
                {
                    seconds = 1
                };

                uint id = EDSClass.Client.requestTabular(EDSClass.AuthStr, req);

                EDSClass.ProcessQuery(id);

                TabularRow[] rows;

                getTabularRequest request = new getTabularRequest()
                {
                    authString = EDSClass.AuthStr,
                    requestId  = id
                };

                getTabularResponse resp = await EDSClass.Client.getTabularAsync(request);

                foreach (TabularRow row in resp.rows)
                {
                    DateTime dt = EDSClass.fromTS(row.ts.second);

                    TabularValue tv = row.values[0];
                    if (tv.quality != Quality.QUALITYGOOD)
                    {
                        continue;
                    }

                    int val = 0;
                    if (tv.value.ipvSpecified)
                    {
                        val = (int)tv.value.ipv.Value;
                    }
                    if (tv.value.pvSpecified)
                    {
                        val = (int)tv.value.pv.Value;
                    }

                    string bin = Convert.ToString(val, 2);
                    bool   on  = false;
                    if (bin.Length >= 3 && bin[bin.Length - 3] == '1')
                    {
                        on = true;
                    }

                    if (!prevVal && on)
                    {
                        dateSet = dt.AddHours(0);
                        data.Add(dt, 0);
                    }
                    if (on)
                    {
                        data[dateSet]++;
                    }
                    prevVal = on;

                    /*string str = string.Format("{0}: {1} {2}", date, bin, on);
                     * Console.WriteLine(str);*/
                }

                date = date.AddHours(24);
                Console.WriteLine(date);
                EDSClass.Disconnect();
            }

            foreach (KeyValuePair <DateTime, int> de in data)
            {
                Console.WriteLine(string.Format("{0}:\t{1}:{2}", de.Key, de.Value / 60, de.Value % 60));
            }
        }
Exemplo n.º 2
0
        public async Task <bool> ReadData()
        {
            ResultData = new Dictionary <DateTime, Dictionary <string, double> >();
            DateTime date = DateStart.AddHours(0);

            while (date < DateEnd)
            {
                DateTime de = date.AddHours(0);
                switch (Period)
                {
                case EDSReportPeriod.sec:
                    de = date.AddSeconds(1);
                    break;

                case EDSReportPeriod.minute:
                    de = date.AddMinutes(1);
                    break;

                case EDSReportPeriod.hour:
                    de = date.AddHours(1);
                    break;

                case EDSReportPeriod.day:
                    de = date.AddDays(1);
                    break;

                case EDSReportPeriod.month:
                    de = date.AddMonths(1);
                    break;
                }
                ResultData.Add(date, new Dictionary <string, double>());
                foreach (string id in RequestData.Keys)
                {
                    ResultData[date].Add(id, 0);
                }
                date = de.AddHours(0);
            }


            List <TabularRequestItem> list = new List <TabularRequestItem>();

            foreach (EDSReportRequestRecord rec in RequestData.Values)
            {
                list.Add(new TabularRequestItem()
                {
                    function = EDSClass.getReportFunctionName(rec.Function),
                    pointId  = new PointId()
                    {
                        iess = rec.Point.IESS
                    },
                    shadePriority = rec.Point.IsShade ? ShadePriority.SHADEOVERREGULAR : ShadePriority.REGULAROVERSHADE
                });
            }



            if (!EDSClass.Connected)
            {
                EDSClass.Connect();
            }
            if (EDSClass.Connected)
            {
                if (Period != EDSReportPeriod.month)
                {
                    List <DateTime> dates = ResultData.Keys.ToList();
                    DateTime        ds    = DateStart.AddHours(0);
                    DateTime        de    = DateStart.AddHours(1);
                    while (ds < DateEnd)
                    {
                        if (Period == EDSReportPeriod.minute || Period == EDSReportPeriod.sec)
                        {
                            int i0 = dates.IndexOf(ds);
                            int i1 = i0 + 1000;
                            de = i1 < dates.Count ? dates[i1] : DateEnd;
                        }
                        else
                        {
                            de = de.AddDays(5);
                            try {
                                de = dates.First(d => d >= de);
                            } catch {
                                de = DateEnd;
                            }
                        }

                        EDSClass.Single.GlobalInfo = String.Format("{0}-{1}", ds.ToString("dd.MM.yyyy HH:mm:ss"), de.ToString("dd.MM.yyyy HH:mm:ss"));

                        TabularRequest req = new TabularRequest();
                        req.period = new TimePeriod()
                        {
                            from = new Timestamp()
                            {
                                second = EDSClass.toTS(ds)
                            },
                            till = new Timestamp()
                            {
                                second = EDSClass.toTS(de)
                            }
                        };

                        req.step = new TimeDuration()
                        {
                            seconds = EDSClass.getPeriodSeconds(Period)
                        };
                        req.items = list.ToArray();
                        uint         id = EDSClass.Client.requestTabular(EDSClass.AuthStr, req);
                        TabularRow[] rows;
                        bool         ok = await EDSClass.ProcessQueryAsync(id);

                        if (!ok)
                        {
                            break;
                        }
                        PointId[]     points = EDSClass.Client.getTabular(EDSClass.AuthStr, id, out rows);
                        List <string> keys   = RequestData.Keys.ToList();

                        foreach (TabularRow row in rows)
                        {
                            DateTime dt = EDSClass.fromTS(row.ts.second);
                            for (int i = 0; i < row.values.Count(); i++)
                            {
                                double  val   = EDSClass.getVal(row.values[i].value);
                                PointId point = points[i];
                                string  resId = keys[i];
                                EDSReportRequestRecord request = RequestData[resId];
                                if (request.Function == EDSReportFunction.vyrab && Period == EDSReportPeriod.day)
                                {
                                    val *= 24;
                                }
                                ResultData[dt][resId] = val;
                            }
                        }

                        ds = de.AddHours(0);
                    }
                }
                else
                {
                    DateTime ds = DateStart.AddHours(0);
                    while (ds < DateEnd)
                    {
                        EDSClass.Single.GlobalInfo = String.Format("{0}-{1}", ds.ToString("dd.MM.yyyy"), ds.AddMonths(1).ToString("dd.MM.yyyy"));
                        DateTime       de  = ds.AddMonths(1);
                        TabularRequest req = new TabularRequest();
                        req.period = new TimePeriod()
                        {
                            from = new Timestamp()
                            {
                                second = EDSClass.toTS(ds)
                            },
                            till = new Timestamp()
                            {
                                second = EDSClass.toTS(de)
                            }
                        };


                        int seconds = (int)(EDSClass.toTS(de) - EDSClass.toTS(ds));
                        req.step = new TimeDuration()
                        {
                            seconds = seconds
                        };
                        req.items = list.ToArray();
                        uint         id = EDSClass.Client.requestTabular(EDSClass.AuthStr, req);
                        TabularRow[] rows;
                        bool         ok = await EDSClass.ProcessQueryAsync(id);

                        if (!ok)
                        {
                            break;
                        }
                        PointId[]     points = EDSClass.Client.getTabular(EDSClass.AuthStr, id, out rows);
                        List <string> keys   = RequestData.Keys.ToList();

                        TabularRow row = rows.First();
                        DateTime   dt  = EDSClass.fromTS(row.ts.second);
                        for (int i = 0; i < row.values.Count(); i++)
                        {
                            double  val   = EDSClass.getVal(row.values[i].value);
                            PointId point = points[i];
                            string  resId = keys[i];
                            EDSReportRequestRecord request = RequestData[resId];
                            if (request.Function == EDSReportFunction.vyrab)
                            {
                                val *= seconds / 3600.0;
                            }
                            ResultData[dt][resId] = val;
                        }

                        ds = de.AddHours(0);
                    }
                }
            }

            return(true);
        }