Ejemplo n.º 1
0
        public ActionResult Index(GraphReportForm form)
        {
            GraphReport.Models.DataRequest dataRequest = new GraphReport.Models.DataRequest();
            dataRequest.beginTime = Helpers.ConvertDT2pkTime(form.beginDateTime);
            dataRequest.endTime   = Helpers.ConvertDT2pkTime(form.endDateTime);
            List <GraphReport.Models.Tag> selectedTags = new List <GraphReport.Models.Tag>();

            foreach (string column in form.tags)
            {
                GraphReport.Models.Tag tag = new GraphReport.Models.Tag();
                NameDef nameDef            = GraphController.configSer.NameDef.Find(p => p.column == column);
                tag.column = column;
                if (nameDef.fullNames == null || nameDef.fullNames.Length == 0)
                {
                    tag.label = tag.column;
                }
                else
                {
                    tag.label = nameDef.fullNames[0];
                }
                tag.table = GraphController.configSer.TableDef.Find(p => p.tabName.Contains(nameDef.table)).tabName;
                selectedTags.Add(tag);
            }
            dataRequest.definition  = selectedTags;
            dataRequest.requestType = RequestType.absoulteScale;
            string json = JsonConvert.SerializeObject(dataRequest);

            ViewBag.json = json;
            return(View("data"));
        }
Ejemplo n.º 2
0
        public async Task <DataRequest> proceedSQLquery(DataRequest dataRequest, CIniFile cConfig)
        {
            config = cConfig;
            getDbConfig();
            openDBconnections();

            int    period  = int.MinValue;
            string columns = null;

            string where;
            string[]        conditions1    = { "\"UTC\"", "\"UTC\"" };
            string[]        Operators      = { ">=", "<=" };
            string[]        conditions2    = { "'" + pkTimeToUTC(dataRequest.beginTime) + "'", "'" + pkTimeToUTC(dataRequest.beginTime + dataRequest.timeAxisLength) + "'" };
            List <int>      tagsPos        = new List <int>();
            List <double>   tagMultipliers = new List <double>();
            List <object[]> objects        = new List <object[]>();

            Error.TraceLog("GraphHandler.proceedSQLquery, point0");

            foreach (TableDef tabledef in config.TableDefList)
            {
                Error.TraceLog("GraphHandler.proceedSQLquery, point1");
                foreach (Tag tag in dataRequest.tags)
                {
                    if (tabledef.shortName == tag.table)
                    {
                        columns += " \"" + tag.column + "\",";
                        tagsPos.Add(dataRequest.tags.IndexOf(tag));

                        NameDef nd          = cConfig.NameDefList.Find(p => (p.column == tag.column) & (p.table == tag.table));
                        double  rMultiplier = 1.0;
                        if (nd != null)
                        {
                            rMultiplier = nd.multiplier;
                        }

                        tagMultipliers.Add(rMultiplier);
                        period = tag.period;
                        if (tag.vals == null)
                        {
                            // TK: tady to padalo na deleni nulou 2018-06-20
                            if (period == 0)
                            {
                                period = 20;        // DODELAT
                            }
                            tag.vals = new double[dataRequest.timeAxisLength / period];
                            tag.vals = Extension.Populate(tag.vals, double.MaxValue);
                        }
                    }
                }
                if (columns != null)
                {
                    columns = columns.Substring(0, columns.Length - 1);
                    db opennedDbConn = openDbList.Find(x => x.dbIdx == tabledef.dbIdx);
                    Error.TraceLog("GraphHandler.proceedSQLquery, point2");

                    if (tabledef.usePkTime == true)
                    {
                        long   timeTo   = dataRequest.beginTime + dataRequest.timeAxisLength;
                        long   timeFrom = dataRequest.beginTime;
                        string order    = db.order("pktime", "ASC");
                        try
                        {
                            objects = await opennedDbConn.multipleItemSelectPostgresAsync("pktime," + columns, "\"" + tabledef.tabName + "\"", "(pktime BETWEEN " + timeFrom + " AND " + timeTo + ")", null, order);
                        } catch (Exception e)
                        {
                            string error = "SQL problem: " + e.Message.ToString();
                            dataRequest.errorMessage = error;
                        }
                    }
                    else
                    {
                        where = db.whereMultiple(conditions1, Operators, conditions2);
                        string order = db.order("\"UTC\"", "ASC");
                        try
                        {
                            objects = await opennedDbConn.multipleItemSelectPostgresAsync("\"UTC\"," + columns, "\"" + tabledef.tabName + "\"", where, null, order);
                        }
                        catch (Exception e)
                        {
                            string error = "SQL problem: " + e.Message.ToString();
                            dataRequest.errorMessage = error;
                        }
                    }

                    Error.TraceLog("GraphHandler.proceedSQLquery, point5, " + (tabledef.usePkTime ? "pkTime" : "UTC"));
                    //readResponse(objects, dataRequest, tagsPos, tabledef);
                    //if (objects.Exists(p => p.Any(q => q.GetType() == typeof(DBNull))) == false) {
                    readResponseforTable(objects, tagsPos, tagMultipliers, period, dataRequest, tabledef, tabledef.usePkTime);
                    Error.TraceLog("GraphHandler.proceedSQLquery, point6");
                    //} else
                    //{
                    //   string k = "contains DBNull in the response";
                    //   Error.toFile(k, this.GetType().Name.ToString());
                    //}
                }
                columns = null;
                tagsPos.Clear();
                tagMultipliers.Clear();
            }
            foreach (db connection in openDbList)
            {
                connection.connection.Close();
            }
            return(dataRequest);
        }