public ActionResult Index(TopTenViewModel vm, bool?showMap) { vm.RiskList = new List <Risk>(); vm.TopTenList = new List <TopTenData>(); vm.MapList = new List <TopTenMap>(); UpdateTopTenParam(vm.Param); CalcTopTenRisk(vm); return(View(vm)); }
public IActionResult Index(DateTime date, string time) { // Time comes in as string ex "09:12" Char delimiter = ':'; String[] substrings = time.Split(delimiter); int hours = Int32.Parse(substrings[0]); int minutes = Int32.Parse(substrings[1]); // Code errored when I tried to AddHours and AddMinutes without creating new variables DateTime dateWithHours = date.AddHours(hours); DateTime dateTimeUser = dateWithHours.AddMinutes(minutes); // Turns user selected time into eqivolent UTC time DateTime dateUTC = dateTimeUser.ToUniversalTime(); List <Hashtag> hashtagsAll = context.Hashtags.ToList(); DateTime dateNowUTC = DateTime.UtcNow; // Compares user selected time to current time // returns 1 if greater, 0 if equal, -1 if less than int result = DateTime.Compare(dateUTC.AddHours(-1), dateNowUTC); // if user selected time is greater than current time return veiw with error message if (result > 0) { List <HashtagCount> hourTopTenError = GetTopTenHour(hashtagsAll, DateTime.UtcNow, context); TopTenViewModel topTenViewModelError = new TopTenViewModel { HourHashtagCounts = hourTopTenError, HashtagsAll = hashtagsAll, DateTimeNow = DateTime.Now, DateTimeUser = DateTime.Now.AddHours(-1), DateTimeError = true }; return(View(topTenViewModelError)); } List <HashtagCount> hourTopTen = GetTopTenHour(hashtagsAll, dateUTC, context); TopTenViewModel topTenViewModel = new TopTenViewModel { HourHashtagCounts = hourTopTen, HashtagsAll = hashtagsAll, DateTimeNow = DateTime.Now, DateTimeUser = dateTimeUser }; return(View(topTenViewModel)); }
public IActionResult Index() { // Database uses UTC time for all DateTime stamps DateTime dateTimeNow = DateTime.UtcNow; List <Hashtag> hashtagsAll = context.Hashtags.ToList(); List <HashtagCount> hourTopTen = GetTopTenHour(hashtagsAll, dateTimeNow, context); TopTenViewModel topTenViewModel = new TopTenViewModel(hourTopTen, hashtagsAll, DateTime.Now.AddHours(-1), DateTime.Now.AddHours(-1)); return(View(topTenViewModel)); }
private async Task GetInfo() { Top10CoinsDetailsRetriever details = new Top10CoinsDetailsRetriever(); Top10RootObject Top10Root = await details.GetTop10Details(); GlobalDetailsRetriever GlobalDetails = new GlobalDetailsRetriever(); GlobalData.GlobalDataRootObject GlobalDataRoot = await GlobalDetails.GetGlobalDataDetails(); Global_Data_viewmodels.Active_Cryptocurrencies = GlobalDataRoot.data.active_cryptocurrencies; Global_Data_viewmodels.Active_Markets = GlobalDataRoot.data.active_markets; Global_Data_viewmodels.Bitcoin_Percentage_Of_Market_Cap = GlobalDataRoot.data.bitcoin_percentage_of_market_cap; Global_Data_viewmodels.Total_Market_Cap = GlobalDataRoot.data.quotes.USD.total_market_cap; Global_Data_viewmodels.Total_Volume_24h = GlobalDataRoot.data.quotes.USD.total_volume_24h; foreach (var v in Top10Root.data) { TopTenViewModel temp = new TopTenViewModel(); temp.Coin_Name = v.Value.name; temp.Coin_Rank = v.Value.rank; temp.Coin_Ticker_Tape = v.Value.symbol; temp.Coin_Price_USD = v.Value.quotes.USD.price; temp.Coin_24_Hour_Change = v.Value.quotes.USD.percent_change_24h; temp.Coin_24_Hour_Volume = v.Value.quotes.USD.volume_24h; temp.Coin_Circulating_Supply = v.Value.total_supply; temp.Coin_Market_Cap = v.Value.quotes.USD.market_cap; temp.Coin_Picture = "ms-appx:///Assets/CryptoSVG/PNG/" + temp.Coin_Ticker_Tape + ".png"; temp.Coin_CMC_String = " $" + String.Format("{0:#,##0.##}", temp.Coin_Market_Cap); temp.Coin_Circ_String = " " + String.Format("{0:#,##0.##}", temp.Coin_Circulating_Supply); temp.Coin_Volume_String = " $" + String.Format("{0:#,##0.##}", temp.Coin_24_Hour_Volume); temp.Coin_24_Hour_Change_String = " " + temp.Coin_24_Hour_Change + "%"; double Coin_Market_Share_Percent = ((double)(temp.Coin_Market_Cap) / (long)(Global_Data_viewmodels.Total_Market_Cap)); int scale = (int)((Coin_Market_Share_Percent / Global_Data_viewmodels.Bitcoin_Percentage_Of_Market_Cap) * 25000000); temp.Coin_Picture_Scale = (int)(Math.Sqrt(scale)); if (temp.Coin_Rank == 1 && temp.Coin_Price_USD > 7000) { //mediaPlayer.Play(); } if (temp.Coin_24_Hour_Change < 0) { temp.Coin_Sign = new SolidColorBrush(Color.FromArgb(230, 201, 19, 19)); } else { temp.Coin_Sign = new SolidColorBrush(Color.FromArgb(230, 19, 201, 31)); } Top_ten_viewmodels.Add(temp); } }
public ActionResult Index(bool?showMap) { TopTenViewModel vm = new TopTenViewModel(); vm.RiskList = new List <Risk>(); vm.TopTenList = new List <TopTenData>(); vm.MapList = new List <TopTenMap>(); vm.Param = new TopTenParam(); vm.Param.PosId = 1; vm.Param.ReportDate = DateTime.Now; vm.Param.ReportDate2 = DateTime.Now; UpdateTopTenParam(vm.Param); CalcTopTenRisk(vm); return(View(vm)); }
// Same as Index.html but used if error occured when searching for hashtag through hashtag controller public IActionResult HashtagNotFound() { List <Hashtag> hashtagsAll = context.Hashtags.ToList(); List <HashtagCount> hourTopTenError = HomeController.GetTopTenHour(hashtagsAll, DateTime.UtcNow, context); TopTenViewModel topTenViewModelError = new TopTenViewModel { HourHashtagCounts = hourTopTenError, HashtagsAll = hashtagsAll, DateTimeNow = DateTime.Now, DateTimeUser = DateTime.Now.AddHours(-1), SearchError = true }; return(View(topTenViewModelError)); }
public void ExportToExcel(int?posId, int?branchId, DateTime reportDate, DateTime reportDate2, bool isApproved, bool showOrg, bool showRiskCode, bool showRiskDate, bool showRiskCat, bool showRiskCause, bool showRiskEffect, bool showRiskOwner, bool showProbLevel, bool showImpactLevel, bool showApprovedMitigations, bool showPlannedMitigations) { TopTenViewModel vm = new TopTenViewModel(); vm.RiskList = new List <Risk>(); vm.TopTenList = new List <TopTenData>(); vm.MapList = new List <TopTenMap>(); vm.Param = new TopTenParam(); vm.Param.PosId = posId; vm.Param.BranchId = branchId; vm.Param.ReportDate = reportDate; vm.Param.ReportDate2 = reportDate2; vm.Param.IsApproved = isApproved; vm.Param.ShowOrg = showOrg; vm.Param.ShowRiskCode = showRiskCode; vm.Param.ShowRiskDate = showRiskDate; vm.Param.ShowRiskCat = showRiskCat; vm.Param.ShowRiskCause = showRiskCause; vm.Param.ShowRiskEffect = showRiskEffect; vm.Param.ShowRiskOwner = showRiskOwner; vm.Param.ShowProbLevel = showProbLevel; vm.Param.ShowImpactLevel = showImpactLevel; vm.Param.ShowApprovedMitigations = showApprovedMitigations; vm.Param.ShowPlannedMitigations = showPlannedMitigations; CalcTopTenRisk(vm); StringWriter sw = new StringWriter(); sw.WriteLine("<table rules='all' border='1' style='border-collapse:collapse;'>"); sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine("<th style='background-color: #eee'>Kode Risiko</th>"); } sw.WriteLine("<th style='background-color: #eee'>Peristiwa Risiko</th>"); if (vm.Param.ShowRiskDate) { sw.WriteLine("<th style='background-color: #eee'>Tanggal</th>"); } if (vm.Param.ShowOrg) { sw.WriteLine("<th style='background-color: #eee'>Unit Kerja</th>"); } if (vm.Param.ShowRiskCat) { sw.WriteLine("<th style='background-color: #eee'>Klasifikasi Risiko</th>"); } if (vm.Param.ShowRiskCause) { sw.WriteLine("<th style='background-color: #eee'>Sebab Risiko</th>"); } if (vm.Param.ShowRiskEffect) { sw.WriteLine("<th style='background-color: #eee'>Akibat Risiko</th>"); } if (vm.Param.ShowRiskOwner) { sw.WriteLine("<th style='background-color: #eee'>RCP</th>"); } if (vm.Param.ShowProbLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Prob</th>"); } if (vm.Param.ShowImpactLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Dampak</th>"); } sw.WriteLine("<th style='background-color: #eee'>Tk. Risiko</th>"); if (vm.Param.ShowApprovedMitigations) { sw.WriteLine("<th style='background-color: #eee'>Mitigasi yg telah Di-approve</th>"); } if (vm.Param.ShowPlannedMitigations) { sw.WriteLine("<th style='background-color: #eee'>Rencana Mitigasi</th>"); } if (vm.Param.ShowRiskOwner) { sw.WriteLine("<th style='background-color: #eee'>tes</th>"); } sw.WriteLine("</tr>"); foreach (var item in vm.TopTenList) { sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine(string.Format("<td>{0}</td>", item.Risk.RiskCode)); } sw.WriteLine(string.Format("<td>{0}</td>", item.Risk.RiskName)); if (vm.Param.ShowRiskDate) { sw.WriteLine(string.Format("<td>{0:dd-MM-yyyy}</td>", item.Risk.RiskDate)); } if (vm.Param.ShowOrg) { sw.WriteLine(string.Format("<td>{0}</td>", Utils.GetRiskOrgName(item.Risk))); } if (vm.Param.ShowRiskCat) { sw.WriteLine("<td>"); if (item.Risk.RiskCat != null) { sw.WriteLine(item.Risk.RiskCat.RiskCatName); } sw.WriteLine("</td>"); } if (vm.Param.ShowRiskCause) { sw.WriteLine("<td>"); if (item.Risk.Caus != null) { sw.WriteLine(item.Risk.Caus.CauseName); } sw.WriteLine("</td>"); } if (vm.Param.ShowRiskEffect) { sw.WriteLine("<td>"); if (item.Risk.Effect != null) { sw.WriteLine(item.Risk.Effect.EffectName); } sw.WriteLine("</td>"); } if (vm.Param.ShowRiskOwner) { sw.WriteLine("<td>{0}</td>", item.Risk.UserInfo.FullName); } if (vm.Param.ShowProbLevel) { sw.WriteLine("<td align='center'>{0}</td>", item.Risk.ProbLevelId); } if (vm.Param.ShowImpactLevel) { sw.WriteLine("<td align='center'>{0}</td>", item.Risk.ImpactLevelId); } sw.WriteLine("<td align='center'>{0}</td>", item.Risk.RiskLevel); if (vm.Param.ShowApprovedMitigations) { sw.WriteLine("<td valign='top' style='padding: 0'>"); if (item.ApprovedMitigations.Count() > 0) { sw.WriteLine("<table rules='all' border='1' style='border-collapse:collapse;'>"); sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine("<th style='background-color: #eee'>Kode Mitigasi</th>"); } sw.WriteLine("<th style='background-color: #eee'>Uraian</th>"); if (vm.Param.ShowRiskDate) { sw.WriteLine("<th style='background-color: #eee'>Tanggal</th>"); } if (vm.Param.ShowProbLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Prob</th>"); } if (vm.Param.ShowImpactLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Dampak</th>"); } sw.WriteLine("<th style='background-color: #eee'>Tk. Risiko</th>"); sw.WriteLine("</tr>"); foreach (var m in item.ApprovedMitigations) { sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine(string.Format("<td>{0}</td>", m.MitigationCode)); } sw.WriteLine(string.Format("<td>{0}</td>", m.MitigationName)); if (vm.Param.ShowRiskDate) { sw.WriteLine(string.Format("<td>{0:dd-MM-yyyy}</td>", m.MitigationDate)); } if (vm.Param.ShowProbLevel) { sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.ProbLevelId)); } if (vm.Param.ShowImpactLevel) { sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.ImpactLevelId)); } sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.RiskLevel)); sw.WriteLine("</tr>"); } sw.WriteLine("</table>"); } sw.WriteLine("</td>"); } if (vm.Param.ShowPlannedMitigations) { sw.WriteLine("<td valign='top' style='padding: 0'>"); if (item.PlannedMitigations.Count() > 0) { sw.WriteLine("<table rules='all' border='1' style='border-collapse:collapse;'>"); sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine("<th style='background-color: #eee'>Kode Mitigasi</th>"); } sw.WriteLine("<th style='background-color: #eee'>Uraian</th>"); if (vm.Param.ShowRiskDate) { sw.WriteLine("<th style='background-color: #eee'>Tanggal</th>"); } if (vm.Param.ShowProbLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Prob</th>"); } if (vm.Param.ShowImpactLevel) { sw.WriteLine("<th style='background-color: #eee'>Tk. Dampak</th>"); } sw.WriteLine("<th style='background-color: #eee'>Tk. Risiko</th>"); sw.WriteLine("</tr>"); foreach (var m in item.PlannedMitigations) { sw.WriteLine("<tr>"); if (vm.Param.ShowRiskCode) { sw.WriteLine(string.Format("<td>{0}</td>", m.MitigationCode)); } sw.WriteLine(string.Format("<td>{0}</td>", m.MitigationName)); if (vm.Param.ShowRiskDate) { sw.WriteLine(string.Format("<td>{0:dd-MM-yyyy}</td>", m.MitigationDate)); } if (vm.Param.ShowProbLevel) { sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.ProbLevelId)); } if (vm.Param.ShowImpactLevel) { sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.ImpactLevelId)); } sw.WriteLine(string.Format("<td align='center'>{0}</td>", m.RiskLevel)); sw.WriteLine("</tr>"); } sw.WriteLine("</table>"); } sw.WriteLine("</td>"); } if (vm.Param.ShowRiskOwner) { sw.WriteLine("<td>{0}</td>", item.Risk.UserInfo.FullName); } sw.WriteLine("</tr>"); } sw.WriteLine("</table>"); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment;filename=top_ten_risks.xls"); Response.ContentType = "application/vnd.ms-excel"; Response.Write(sw.ToString()); Response.End(); }
private void CalcTopTenRisk(TopTenViewModel vm) { /*var risks = db.Risks.Where(p => p.ProbLevelId != null && p.ImpactLevelId != null); * if (vm.Param.PosId == 1) * risks = risks.Where(p => p.DeptId != null); * else if (vm.Param.PosId == 2) * { * risks = risks.Where(p => p.BranchId != null); * if (vm.Param.BranchId != null) * risks = risks.Where(p => p.BranchId == vm.Param.BranchId); * } */ var risks = db.Risks.Where(p => p.ProbLevelId != null && p.ImpactLevelId != null); if (vm.Param.PosId == 1) { risks = risks.Where(p => p.DeptId != null || p.BranchId != null); } else if (vm.Param.PosId == 2) { risks = risks.Where(p => p.DeptId != null && p.SubDivId == vm.Param.BranchId); } else if (vm.Param.PosId == 3) { risks = risks.Where(p => p.BranchId != null); if (vm.Param.BranchId != null) { risks = risks.Where(p => p.BranchId == vm.Param.BranchId); } } else if (vm.Param.PosId == 4) { risks.Where(p => p.Branch.KorwilId == vm.Param.BranchId); } else if (vm.Param.PosId == 5) { risks = risks.Where(p => p.BranchId != null); if (vm.Param.BranchId != null) { risks = risks.Where(p => p.Branch.ClassId == vm.Param.BranchId); } } if (vm.Param.IsApproved) { risks = risks.Where(p => p.CloseDate == null || (p.CloseDate > vm.Param.ReportDate && p.CloseDate < vm.Param.ReportDate2)); risks = risks.Where(p => p.ApprovalDate != null && (p.ApprovalDate >= vm.Param.ReportDate && p.ApprovalDate <= vm.Param.ReportDate2)); } else { risks = risks.Where(p => p.ApprovalDate == null && (p.RiskDate >= vm.Param.ReportDate && p.RiskDate <= vm.Param.ReportDate2)); } foreach (var r in risks) { //if (vm.Param.IsApproved) //{ // var rm = db.RiskMitigations.Where(p => p.RiskId == r.RiskId && p.ApprovalDate != null && p.ApprovalDate <= vm.Param.ReportDate); // if (rm.Count() > 0) // { // var m = rm.OrderByDescending(p => p.ApprovalDate).First(); // AddRiskToList(r, (int)m.ProbLevelId, (int)m.ImpactLevelId, vm.RiskList); // } // else // vm.RiskList.Add(r); //} //else // vm.RiskList.Add(r); vm.RiskList.Add(r); } vm.RiskList = vm.RiskList.OrderByDescending(p => p.RiskLevel).ThenByDescending(p => p.ImpactLevelId).ThenByDescending(p => p.ProbLevelId).Take(10).ToList(); foreach (var r in vm.RiskList) { TopTenData data = new TopTenData(); data.Risk = r; data.ApprovedMitigations = db.RiskMitigations.Where(p => p.RiskId == r.RiskId && p.ApprovalDate != null).ToList(); data.PlannedMitigations = db.RiskMitigations.Where(p => p.RiskId == r.RiskId && p.ApprovalDate == null).ToList(); vm.TopTenList.Add(data); } // map processing here... for (var i = 1; i <= 5; i++) { for (var j = 1; j <= 5; j++) { vm.MapList.Add(new TopTenMap() { ProbLevelId = i, ImpactLevelId = j, Count = 0, RiskLevel = i * j }); } } foreach (var r in vm.RiskList) { foreach (var m in vm.MapList) { if (r.ProbLevelId == m.ProbLevelId && r.ImpactLevelId == m.ImpactLevelId) { m.Count++; break; } } } vm.MaxCount = 0; var maxCount = int.MinValue; foreach (var m in vm.MapList) { if (maxCount < m.Count) { maxCount = m.Count; } } vm.MaxCount = maxCount; }