public async Task <IActionResult> GetDataSourceAsync(DataTableBindingModel Args) { var salaryFile = Path.Combine(Directory.GetCurrentDirectory(), _hostingEnvironment.WebRootPath, "sourcefile/salary_data.json"); string JSON = System.IO.File.ReadAllText(salaryFile); return(Json(await _Interface.GetDataSalaryAsync(Args, JSON))); }
public IActionResult GetDataSourceAsync(DataTableBindingModel Args) { var sensorFile = Path.Combine(Directory.GetCurrentDirectory(), _hostingEnvironment.WebRootPath, "sourcefile/sensor_data.json"); string JSON = System.IO.File.ReadAllText(sensorFile); return(Json(_Interface.GetDataSensor(Args, JSON))); }
public async Task <DataTableResultModel> GetDataSalaryAsync(DataTableBindingModel Args, string salary) { List <SalaryConversionModel> Result = new List <SalaryConversionModel>(); int RecordsTotal = 0; try { using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(UserWebApi)) { string apiResponse = await response.Content.ReadAsStringAsync(); double usd = ExchangeRate(CurrencyConverterEnum.IDR, CurrencyConverterEnum.USD); Result = JsonConvert.DeserializeObject <List <SalaryConversionModel> >(apiResponse); RecordsTotal = Result.Count; SalaryConversionModel.Root salaryObj = JsonConvert.DeserializeObject <SalaryConversionModel.Root>(salary); for (int i = 0; i < Result.Count; i++) { int idUser = Result[i].id; for (int ii = 0; ii < salaryObj.array.Count; ii++) { int idSalary = salaryObj.array[ii].id; if (idUser == idSalary) { Result[i].salaryidr = salaryObj.array[ii].salaryInIDR; Result[i].salaryusd = salaryObj.array[ii].salaryInIDR * usd; break; } } } } } } catch (Exception Exception) { throw Exception; } return(new DataTableResultModel() { data = Result, draw = Args.draw, recordsTotal = RecordsTotal, recordsFiltered = RecordsTotal, error = null }); }
public DataTableResultModel GetDataSensor(DataTableBindingModel Args, string sensor) { List <SensorAggregationModel> Result = new List <SensorAggregationModel>(); int RecordsTotal = 0; try { SensorAggregationModel.Root sensorObj = JsonConvert.DeserializeObject <SensorAggregationModel.Root>(sensor); DataTable dt = DataTableBL.ToDataTable(sensorObj.array); DataView view = new DataView(dt); DataTable dtroomArea = view.ToTable(true, "roomarea"); for (int i = 0; i < dtroomArea.Rows.Count; i++) { double mintemp, maxtemp, avgtemp, medtemp; double minhum, maxhum, avghum, medhum; string roomarea = dtroomArea.Rows[i]["roomarea"].ToString(); DataTable dtbak = new DataTable(); dtbak = dt.Clone(); DataRow[] dr = dt.Select("roomarea = '" + roomarea + "'"); foreach (DataRow row in dr) { dtbak.ImportRow(row); } mintemp = Convert.ToDouble(dtbak.AsEnumerable().Min(row => row["temperature"])); maxtemp = Convert.ToDouble(dtbak.AsEnumerable().Max(row => row["temperature"])); avgtemp = Convert.ToDouble(dtbak.AsEnumerable().Average(row => Convert.ToDouble(row["temperature"]))); minhum = Convert.ToDouble(dtbak.AsEnumerable().Min(row => row["humidity"])); maxhum = Convert.ToDouble(dtbak.AsEnumerable().Max(row => row["humidity"])); avghum = Convert.ToDouble(dtbak.AsEnumerable().Average(row => Convert.ToDouble(row["humidity"]))); dtbak.Columns.Remove("id"); dtbak.Columns.Remove("roomarea"); dtbak.AcceptChanges(); double[] tempvalues = Array.ConvertAll <DataRow, double>( dtbak.Select(), delegate(DataRow row) { return((double)row["temperature"]); }); double[] humvalues = Array.ConvertAll <DataRow, double>( dtbak.Select(), delegate(DataRow row) { return((double)row["humidity"]); }); medtemp = GetMedianFromArray(tempvalues); medhum = GetMedianFromArray(humvalues); Result.Add(new SensorAggregationModel { roomarea = roomarea, mintemperature = mintemp, maxtemperature = maxtemp, avgtemperature = avgtemp, medtemperature = medtemp, minhumidity = minhum, maxhumidity = maxhum, avghumidity = avghum, medhumidity = medhum }); } RecordsTotal = Result.Count; } catch (Exception Exception) { throw Exception; } return(new DataTableResultModel() { data = Result, draw = Args.draw, recordsTotal = RecordsTotal, recordsFiltered = RecordsTotal, error = null }); }