예제 #1
0
        /// <summary>
        /// 取得舉手資訊
        /// </summary>
        public IOTProjectViewModel <IOTProjectRecordData> GetInteractiveData()
        {
            var sensors  = mqttDeviceService.GetDeviceSensors(Convert.ToInt64(DeviceEnum.Interactive).ToString(), accessKey).Result;
            var response = new IOTProjectViewModel <IOTProjectRecordData>();

            foreach (var sensor in sensors)
            {
                if (sensor.Id == "vote")
                {
                    var sensorData = sensor.Value.FirstOrDefault();
                    try
                    {
                        if (sensorData != null && sensorData.Count() > 0)
                        {
                            response = JsonConvert.DeserializeObject <IOTProjectViewModel <IOTProjectRecordData> >(sensorData);
                        }
                    }
                    catch (Exception ex)
                    {
                        return(null);
                    }
                }
            }
            ;
            return(response);
        }
예제 #2
0
        /// <summary>
        /// 處理iot取回參數資料
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="iotDatas"></param>
        /// <returns></returns>
        public VoteViewModel ItemProxy(VoteViewModel datas, IOTProjectViewModel <IOTProjectRecordData> iotDatas)
        {
            var participateCount = 0.00;

            //取得在場人數
            datas.PresentCount = Convert.ToInt32(iotDatas.PresentCount);
            var items = ItemCalculateProxy(datas.VoteItems.OrderBy(t => t.Sort), iotDatas, out participateCount);

            datas.VoteItems        = items.ToList();
            datas.ParticipateCount = Convert.ToInt32(participateCount);
            //算參與率
            datas.ParticipateRate = (participateCount != 0.00 && datas.PresentCount != 0) ? Math.Round(participateCount / Convert.ToDouble(datas.PresentCount) * 100, 0) : 0;
            return(datas);
        }
예제 #3
0
        private void MqttClientInteractiveReceived(object sender, MqttMsgPublishEventArgs e)
        {
            var motionResponse = new IOTProjectViewModel <IOTProjectRecordData>();
            var apiResponse    = Encoding.UTF8.GetString(e.Message);
            var sensorStatus   = JsonConvert.DeserializeObject <IOTSensorResponse>(apiResponse);
            var responseValue  = sensorStatus.Value.Length > 0 ? sensorStatus.Value[0] : "0";

            if (responseValue != "0")
            {
                var voteService = new VoteService();
                var rtn         = voteService.GetDetail(voteOuterKey);
                motionResponse = JsonConvert.DeserializeObject <IOTProjectViewModel <IOTProjectRecordData> >(responseValue);
                if (rtn.StartDate.HasValue && (rtn.StartDate.Value <= motionResponse.RecordTime))
                {
                    rtn = voteService.ItemProxy(rtn, motionResponse);
                }
                if (rtn.IsStart)
                {
                    Clients.Group(mqttCircleKey.ToLower()).updateVoteInfo(rtn, "成功");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// 計算投票項目數量+比例
        /// </summary>
        /// <param name="datas"></param>
        /// <param name="iotDatas"></param>
        /// <returns></returns>
        private IOrderedEnumerable <ActVoteItem> ItemCalculateProxy(IOrderedEnumerable <ActVoteItem> datas, IOTProjectViewModel <IOTProjectRecordData> iotDatas, out double participateCount)
        {
            var chooseIndex = 0;

            participateCount = 0.00;
            //塞投票資訊
            foreach (var item in datas)
            {
                item.ChooseCount  = iotDatas.Data[chooseIndex].ChooseCount;
                participateCount += iotDatas.Data[chooseIndex].ChooseCount;
                chooseIndex++;
            }
            //算參與率
            foreach (var item in datas)
            {
                if (participateCount > 0)
                {
                    item.ChooseRate = Math.Round((Convert.ToDouble(item.ChooseCount) / participateCount) * 100, 1);
                }
                else
                {
                    item.ChooseRate = 0;
                }
            }
            return(datas);
        }