Example #1
0
        public async Task <JsonResult> getData()
        {
            string json = null;
            GraphReportResponse response = new GraphReportResponse();
            StreamReader        stream   = new StreamReader(Request.InputStream);

            if (json == null)
            {
                json = stream.ReadToEnd();
            }
            if (json != "")
            {
                //ReportModel RVM = new ReportModel();
                GraphReport.Models.DataRequest dataRequest = JsonConvert.DeserializeObject <GraphReport.Models.DataRequest>(json);
                switch (dataRequest.requestType)
                {
                case RequestType.batches:
                    db conn = new db("InternDelights", 12);

                    break;

                case RequestType.frequency:

                    break;

                case RequestType.differences:

                    break;

                case RequestType.absoulteScale:
                    GraphReportHelper graphReportHelper = new GraphReportHelper();
                    response = await graphReportHelper.GetAbsoulteScale(dataRequest);

                    break;
                }
            }
            else
            {
                return(null);
            }
            return(Json(response, "application/json", JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public async Task <GraphReportResponse> GetAbsoulteScale(DataRequest dataRequest)
        {
            //response precreation
            GraphReportResponse response = new GraphReportResponse();

            response.datasets = new List <DataSet>();
            //response.labels = new List<string>();
            string          tagLabel      = "";
            DateTime        dateTimeLabel = new DateTime();
            List <object[]> objects       = new List <object[]>();
            string          columns       = "";
            db db = new db("InternDelights", 12);

            string[] conditions1 = { "\"UTC\"", "\"UTC\"" };
            string[] Operators   = { ">=", "<=" };
            string[] conditions2 = { "'" + GraphReportHelper.pkTimeToUTC(dataRequest.beginTime) + "'", "'" + GraphReportHelper.pkTimeToUTC(dataRequest.endTime) + "'" };
            string where = db.whereMultiple(conditions1, Operators, conditions2);
            foreach (string table in dataRequest.definition.Select(tag => tag.table).Distinct())
            {
                foreach (GraphReport.Models.Tag tag in dataRequest.definition)
                {
                    columns += " \"" + tag.column + "\",";
                }
                columns = columns.Substring(0, columns.Length - 1);
                objects = await db.multipleItemSelectPostgresAsync("\"UTC\"," + columns, table, where);

                for (int i = 0; i < objects.Count; i++)
                {
                    for (int j = 1; j <= objects[0].Length; j++)
                    {
                        if (i == 0)
                        {
                            DataSet onlyColorDataSet = new DataSet();
                            onlyColorDataSet.backgroundColor = ColorTranslator.ToHtml(Color.DarkOliveGreen);
                            response.datasets.Add(onlyColorDataSet);
                            if (response.datasets[j - 1].data == null)
                            {
                                response.datasets[j - 1].data = new List <double>();
                            }
                        }
                        double doubleValue = (double)objects[i][j];
                        response.datasets[j - 1].data.Add(doubleValue);
                        if (j < dataRequest.definition.Count)
                        {
                            tagLabel = dataRequest.definition[j - 1].label;
                        }
                        response.datasets[j - 1].label = tagLabel;
                    }
                    int lastDay = dateTimeLabel.Day;
                    dateTimeLabel = Helpers.ConvertpkTime2DT(Helpers.utcToPkTime(objects[i][0].ToString()));
                    if (dateTimeLabel.Day != lastDay)
                    {
                        response.labels.Add(dateTimeLabel.ToString());
                    }
                    else
                    {
                        response.labels.Add(dateTimeLabel.ToShortTimeString());
                    }
                }
            }
            return(response);
        }