public void GetGreenhouseDeviceDataForGraphs(string user_id, string token, string greenhouse_id, string device_id, string start_time, string end_time)
        {
            token = token.Trim();
            string role = new BL_User().getUserRoleID(user_id);

            if ((new BL_User().validateTokenByUserID(user_id, token) == 1) && (new BL_Greenhouse().doesGreenhouseIDExist(greenhouse_id, user_id, role)) && (new BL_GreenhouseDevice().doesGreenhouseDeviceExist(greenhouse_id, device_id)))
            {
                DataResponse response = new DataResponse();
                try
                {
                    DataTable Data = new BL_GreenhouseDeviceData().selectDataSet(device_id, start_time, end_time);

                    List <GraphDataPointResponse> dataPointList = new List <GraphDataPointResponse>();

                    foreach (DataRow item in Data.Rows)
                    {
                        dataPointList.Add(new GraphDataPointResponse()
                        {
                            time  = item["collected_time"].ToString(),
                            value = item["data"].ToString()
                        });
                    }
                    HttpContext.Current.Response.Write(new JavaScriptSerializer().Serialize(new GraphDataResponse()
                    {
                        success          = true,
                        errorMessage     = null,
                        listOfDataPoints = dataPointList
                    }));
                    return;
                }
                catch
                {
                    HttpContext.Current.Response.Write(new JavaScriptSerializer().Serialize(new DataListResponse()
                    {
                        success      = false,
                        errorCode    = UniversalProperties.EC_UnhandledError,
                        errorMessage = UniversalProperties.unknownError
                    }));
                }
                HttpContext.Current.Response.Write(new JavaScriptSerializer().Serialize(response));
            }
            else
            {
                HttpContext.Current.Response.Write(new JavaScriptSerializer().Serialize(new DataListResponse()
                {
                    success      = false,
                    errorMessage = UniversalProperties.invalidRequest,
                    errorCode    = UniversalProperties.EC_InvalidRequest,
                }));
            }
        }
        protected void get_visualize_dataset(object sender, EventArgs e)
        {
            RadioButtonList1.Visible = true;
            string location = selectLocation.SelectedValue;
            string device   = selectDevice.SelectedValue;

            string [] time = timePeriod(RadioButtonList1.SelectedIndex);
            string    from = time[0];
            string    to   = time[1];

            DataTable dt_device_names;

            switch (location)
            {
            case "bay_line":
                dt_device_names = new BL_BayLineDeviceData().selectDataSet(device, from, to);
                break;

            case "greenhouse":
                dt_device_names = new BL_GreenhouseDeviceData().selectDataSet(device, from, to);
                break;

            case "level":
                dt_device_names = new BL_BayRackLevelDeviceData().selectDataSet(device, from, to);
                break;

            case "level_line":
                dt_device_names = new BL_BayRackLevelLineDeviceData().selectDataSet(device, from, to);
                break;

            case "rack":
                dt_device_names = new BL_BayRackDeviceData().selectDataSet(device, from, to);
                break;

            case "bay":
                dt_device_names = new BL_BayDeviceData().selectDataSet(device, from, to);
                break;

            default:
                dt_device_names = null;
                break;
            }
            if (dt_device_names.Rows.Count != 0)
            {
                BindChart(dt_device_names);
            }
            else
            {
                ltScripts.Text = "No Data.";
            }
        }
Ejemplo n.º 3
0
        protected void graphRendering(string from, string to)
        {
            string greenhouseID = HttpContext.Current.Request.QueryString["greenhouse_id"];


            StringBuilder strScript = new StringBuilder();

            strScript.Append(@"
            <script>
            window.onload = function () {

                var chart = new CanvasJS.Chart('chart', {
                    animationEnabled: true,
                    axisY2: {
                        title: 'Temperature',
                        lineColor: '#369EAD',
                        tickColor: '#369EAD',
                        labelFontColor: '#369EAD',
                        titleFontColor: '#369EAD',
                        includeZero: false,
                        suffix: '℃'
                    },
                    axisY: [{
                        title: 'Humidity',
                        lineColor: '#369EAD',
                        tickColor: '#369EAD',
                        labelFontColor: '#369EAD',
                        titleFontColor:'#369EAD',
                        includeZero: false,
                        suffix: '%'
                    }, {

                        title: 'co2',
                        lineColor: '#369EAD',
                        tickColor: '#369EAD',
                        labelFontColor: '#369EAD',
                        titleFontColor: '#369EAD',
                        suffix: 'ppm'

                    }],
                    toolTip: {
                        shared: true
                    },
                    legend: {
                        fontSize: 13
                    },
                    data: [");
            DataTable dt_humidity = new BL_GreenhouseDeviceData().selectDeviceDataSetByType(greenhouseID, Constants.HUMIDITY_SENSOR, from, to);

            strScript.Append(@"{
                        type: 'spline',
                        fillOpacity: .3,
                        showInLegend: true,
                        name: 'Humidity',
                        axisYIndex: 0,
                        yValueFormatString: '##.00',
                        xValueFormatString: 'MMM YYYY',
                        dataPoints: [");

            foreach (DataRow data in dt_humidity.Rows)
            {
                strScript.Append("{ x: new Date(Date.parse('" + data["collected_time"] + "'.replace('-', '/', 'g')))" + ", y: " + data["data"] + "},");
            }
            // strScript.Remove(strScript.Length - 1, 1);
            strScript.Append("] },");

            DataTable dt_temperature = new BL_GreenhouseDeviceData().selectDeviceDataSetByType(greenhouseID, Constants.TEMPERATURE_SENSOR, from, to);

            strScript.Append(@"{
                        type: 'spline',
                        showInLegend: true,
                        name: 'Temperature',
                        axisYType: 'secondary',
                        yValueFormatString: '###<sup>o</sup>c',
                        dataPoints: [");

            foreach (DataRow data in dt_temperature.Rows)
            {
                strScript.Append("{ x: new Date(Date.parse('" + data["collected_time"] + "'.replace('-', '/', 'g')))" + ", y: " + data["data"] + "},");
            }
            strScript.Append("] },");

            DataTable dt_co2 = new BL_GreenhouseDeviceData().selectDeviceDataSetByType(greenhouseID, Constants.CO2_SENSOR, from, to);

            strScript.Append(@"{
                        type: 'spline',
                        showInLegend: true,
                        name: 'CO2',
                        axisYIndex: 1,
                        yValueFormatString: '##.00',
                        dataPoints: [");

            foreach (DataRow data in dt_co2.Rows)
            {
                strScript.Append("{ x: new Date(Date.parse('" + data["collected_time"] + "'.replace('-', '/', 'g')))" + ", y: " + data["data"] + "},");
            }
            strScript.Append("] },");


            strScript.Append(@"]
                        });
                    chart.render();

                    }
                </script>");
            ltScripts.Text = strScript.ToString();

            if ((dt_co2.Rows.Count == 0) & (dt_humidity.Rows.Count == 0) & (dt_temperature.Rows.Count == 0))
            {
                RadioButtonList1.Visible = false;
                ltScripts.Text           = "No Data";
            }
        }