示例#1
0
        public HttpResponseMessage Export(string sessionId, string filename)
        {
            if (!userRepository.CanManageExport(sessionId))
            {
                return(null);
            }

            XSSFWorkbook  wb      = new XSSFWorkbook();
            List <Device> devices = deviceRepository.GetDevices();
            ISheet        sheet;

            sheet = wb.CreateSheet("Average temp of devices");

            var deviceName      = sheet.CreateRow(0);
            var avgTemperatures = sheet.CreateRow(1);

            for (int j = 0; j < devices.Count; j++)
            {
                deviceName.CreateCell(j).SetCellValue(devices[j].Name);
                avgTemperatures.CreateCell(j).SetCellValue(temperatureRepository.GetAverageTemperature(devices[j].Id));
            }


            for (int i = 0; i < devices.Count; i++)
            {
                sheet = wb.CreateSheet(devices[i].Name);
                List <int> temperatures = temperatureRepository.GetTemperatures(devices[i].Id);

                var weekNumber      = sheet.CreateRow(0);
                var weekTemperature = sheet.CreateRow(1);

                for (int j = 0; j < temperatures.Count; j++)
                {
                    weekNumber.CreateCell(j).SetCellValue(j + 1);
                    weekTemperature.CreateCell(j).SetCellValue(temperatures[j]);
                }
            }

            using (var memoryStream = new MemoryStream())
            {
                wb.Write(memoryStream);
                var response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(memoryStream.ToArray())
                };

                response.Content.Headers.ContentType = new MediaTypeHeaderValue
                                                           ("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.Content.Headers.ContentDisposition =
                    new ContentDispositionHeaderValue("attachment")
                {
                    FileName = filename
                };

                return(response);
            }
        }
示例#2
0
        public async Task <List <ListViewDataRow> > GetDesiredDataFromApiForListView(bool isTemperature, bool isHumidity, int amount, string date, string sensorName)
        {
            if (isTemperature && isHumidity)
            {
                isHumidity = false;
            }

            if (isTemperature)
            {
                var rowList      = CreateNewListForTemperature();
                var repo         = new TemperatureRepository();
                var temperatures = await repo.GetTemperatures(amount, date, sensorName);

                foreach (var item in temperatures)
                {
                    rowList.Add(new ListViewDataRow()
                    {
                        RoomName   = item.TemperatureSensor.Room.Name.ToString(),
                        SensorName = item.TemperatureSensor.Name.ToString(),
                        Value      = item.Value.ToString(),
                        Date       = item.Date.ToShortDateString()
                    });
                }
                return(rowList);
            }
            else if (isHumidity)
            {
                var rowList  = CreateNewListForHumidity();
                var repo     = new HumidityRepository();
                var humidity = await repo.GetHumidity(amount, date, sensorName);

                foreach (var item in humidity)
                {
                    rowList.Add(new ListViewDataRow()
                    {
                        RoomName   = item.HumiditySensor.Room.Name.ToString(),
                        SensorName = item.HumiditySensor.Name.ToString(),
                        Value      = item.Value.ToString(),
                        Date       = item.Date.ToShortDateString()
                    });
                }
                return(rowList);
            }
            else
            {
                return(null);
            }
        }
示例#3
0
        public async Task <List <PlotData> > GetTemperatureFromApiForPlot(string dateTime, string sensorName)
        {
            var temperatureList = new List <PlotData>();
            var repo            = new TemperatureRepository();
            var temperatures    = await repo.GetTemperatures(100, dateTime, sensorName);

            foreach (var item in temperatures)
            {
                temperatureList.Add(new PlotData()
                {
                    Value = item.Value,
                    Date  = item.Date
                });
            }
            return(temperatureList);
        }
 public List <Temperature> Get()
 {
     return(_temperatureRepository.GetTemperatures());
 }