public void GreenTextChangedMethod() { //Arrange Form1 form1 = new Form1(); BusinessRules.employeeList.Clear(); ListView ListView1 = new ListView(); ListView ListView2 = new ListView(); Hourly temp = new Hourly("AA5", "Cheryl", "Kirk", "Cheryl Kirk", 3.98, 4); BusinessRules.AddEmployee(form1, temp); Contract hey = new Contract("L-1337", "John", "Chief", "John Chief", 5); BusinessRules.AddEmployee(form1, hey); Salary sup = new Salary("HAMBURGER", "Phil", "Hartman", "Phil Hartman", 7.896); BusinessRules.AddEmployee(form1, sup); Sales bro = new Sales("EMPLOYEE_ID", "David", "Lynch", "David Lynch", 4, 5.86, 387); BusinessRules.AddEmployee(form1, bro); form1.comboBox2.SelectedItem = "Full Name"; //Act form1.textBox7.Text += "D"; ListView1 = form1.searchEmployees(); ListView2.Items.Add(bro.fullName); //Assert Assert.AreEqual(ListView1.Items[0].ToString(), ListView2.Items[0].ToString()); }
//*************************************************************************************************************** public void NewHourly(string mname, string pname, string hname, bool hourlycurrent) { string path = hourlycurrent ? PathHourly() : PathHourlyList(hname); List <Hourly> hourlys = XmlLoadHourlys(path).ToList(); DateTime lastTime; if (hourlys.Count() > 0) { Hourly last = hourlys.Last(); lastTime = last.Date + new TimeSpan(0, 0, last.Media.Duration); } else { lastTime = DateTime.Now; } Hourly hourly = new Hourly { Date = lastTime, MediaName = mname, ProprietaryName = pname, Guid = Guid.NewGuid().ToString() }; hourlys.Add(hourly); XmlSaveHourlys(hourlys, path); }
public async Task <JObject> makeRequest() { HttpClient client = new HttpClient(); var response = await client.GetAsync($"https://api.openweathermap.org/data/2.5/onecall/timemachine?lat={latitude}&lon={longitude}&dt={startOfDay}&appid={apiKey}"); string stringresult = await response.Content.ReadAsStringAsync(); OpenWeatherMapModel OWMM = new OpenWeatherMapModel(); OWMM = JsonConvert.DeserializeObject <OpenWeatherMapModel>(stringresult); //find 'Hourly' closest to scan time Hourly FoundItem = OWMM.hourly.OrderBy(x => Math.Abs(x.dt - scanDateTimeEpoch)).First(); int result = FoundItem.clouds; string dataQuality = "high"; if (result > 33) { dataQuality = "medium"; if (result > 66) { dataQuality = "low"; } } return(JObject.Parse($"{{'clouds': {result}, 'dataQuality': '{dataQuality}'}}")); }
public void DeleteTestMethod() { BusinessRules.isActive = false; Form1 form1 = new Form1(); BusinessRules.employeeList.Clear(); BusinessRules.isActive = false; ListView ListView1 = new ListView(); ListView ListView2 = new ListView(); Hourly temp = new Hourly("AA5", "Cheryl", "Kirk", "Cheryl Kirk", 3.98, 4); BusinessRules.AddEmployee(form1, temp); Contract hey = new Contract("L-1337", "John", "Chief", "John Chief", 5); BusinessRules.AddEmployee(form1, hey); Salary sup = new Salary("HAMBURGER", "Phil", "Hartman", "Phil Hartman", 7.896); BusinessRules.AddEmployee(form1, sup); Sales bro = new Sales("EMPLOYEE_ID", "David", "Lynch", "David Lynch", 4, 5.86, 387); BusinessRules.AddEmployee(form1, bro); BusinessRules.AddEmployeeDel(form1, bro); form1.populateItem(bro.empId); ListView1 = form1.listView1; ListView2.Items.Add(bro.fullName); Assert.AreEqual(ListView1.Items[0].ToString(), ListView2.Items[0].ToString()); }
public SubscriptionFactory() { hourly = CreateHourly(); daily = CreateDaily(); weekly = CreateWeekly(); familyThreeDiscounts = CreateFamilyThreeDiscounts(); familyFiveDiscounts = CreateFamilyFiveDiscounts(); }
public void Delete(Hourly hourly) { //Hourlys.Remove(hourly); //SaveChanges(); //Hourly h = First; //Reorganize(h.Date,""); }
public Oferts(int id, Areas area, Courses course, Dates date, Weekday weekday, Hourly hourly) { this.Id = id; this.Area = area; this.Course = course; this.Date = date; this.Weekday = weekday; this.Hourly = hourly; }
private void OnTimedEvent(object o) { Hourly current = null; Hourly next = null; lock (WebTVTimer) { current = WebTVTimer.Current; next = WebTVTimer.Next; } if (current != null && HCurrent != current) { if (HCurrent != null) { lock (HCurrent) { HCurrent = current; } } else { HCurrent = current; } if (HCurrent != null) { if (JCurrent != null) { lock (JCurrent) { JCurrent = JsonConvert.SerializeObject(HCurrent.Media, typeof(Media), null); } } else { JCurrent = JsonConvert.SerializeObject(HCurrent.Media, typeof(Media), null); } } } if (next != null && HNext != next) { if (HNext != null) { lock (HNext) { HNext = next; } } else { HNext = next; } if (HNext != null) { if (JNext != null) { lock (JNext) { JNext = JsonConvert.SerializeObject(HNext.Media, typeof(Media), null); } } else { JNext = JsonConvert.SerializeObject(HNext.Media, typeof(Media), null); } } } }
} // A data block containing the weather conditions day-by-day for the next week. public DarkSkyCall() { // Initialize variables latitude = float.NaN; longitude = float.NaN; timezone = null; currently = new Currently(); minutely = new Minutely(); hourly = new Hourly(); daily = new Daily(); }
public async Task <IActionResult> GetAnyHourly(int userId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } Hourly hourly = await _repo.GetAnyHourly(userId); HourlyForReturnDto hourlyForReturn = _mapper.Map <HourlyForReturnDto>(hourly); return(Ok(hourlyForReturn)); }
public void HourlyConstructor() { Hourly hourlyEmp = new Hourly() { EmpType = EType.HOURLY, EmpID = EMP_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, HourlyRate = HOURLY_RATE }; Assert.IsNotNull(hourlyEmp); } // end method HourlyConstructor()
private HourlyForecast[] GenerateHourlyForecast(Hourly hourly) { if (hourly.status == "ok") { List <HourlyForecast> hours = new List <HourlyForecast>(); for (int i = 0; i < hourly.temperature.Length; i++) { hours.Add(new HourlyForecast(hourly.temperature[i], hourly.precipitation[i], hourly.humidity[i], hourly.wind[i])); } return(hours.ToArray()); } return(null); }
public IActionResult CreateHourly([FromQuery] List <int> cityId, [FromBody] Hourly hourlyToCreate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_hourlyRepository.CreateHorlyWeather(cityId, hourlyToCreate)) { ModelState.AddModelError("", $"Something went wrong saving the hourly weather"); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("GetHourly", new { hourlyId = hourlyToCreate.Id }, hourlyToCreate)); }
private IEnumerable <Hourly> XmlLoadHourlys(string path) { List <Hourly> hourlys = new List <Hourly>(); if (!File.Exists(path)) { return(hourlys); } XmlReader reader = XmlReader.Create(path); reader.Read(); if (reader.NodeType == XmlNodeType.XmlDeclaration) { reader.Read(); } if (reader.IsStartElement()) { reader.Read(); } int Count = reader.ReadElementContentAsInt(); for (int i = 0; i < Count; i++) { Hourly hourly = new Hourly(); reader.ReadStartElement(); hourly.Guid = reader.ReadElementContentAsString(); hourly.Year = reader.ReadElementContentAsInt(); hourly.Month = reader.ReadElementContentAsInt(); hourly.Day = reader.ReadElementContentAsInt(); hourly.Hour = reader.ReadElementContentAsInt(); hourly.Minute = reader.ReadElementContentAsInt(); hourly.Second = reader.ReadElementContentAsInt(); hourly.MediaName = reader.ReadElementContentAsString(); hourly.ProprietaryName = reader.ReadElementContentAsString(); hourly.MediaID = reader.ReadElementContentAsInt(); reader.ReadEndElement(); hourly.Media = XmlLoadMedia(hourly.MediaName, hourly.ProprietaryName); if (hourly.Media != NullableMedia) { hourlys.Add(hourly); } } reader.Close(); return(hourlys); }
public void GreenHourlyTestMethod() { //Arrange string empId = ""; string firstName = ""; string lastName = ""; string fullName = "Kevin Urquhart"; double rate = 1; double worked = 1; Hourly emp = new Hourly(empId, firstName, lastName, fullName, rate, worked); //Act string fullN = emp.fullName; //Assert Assert.AreEqual("Kevin Urquhart", fullN); }
public JsonResult FirstMedia() { string channel = (string)Session["Channel"]; Channel Channel = Channels.Find(channel); Hourly current = Channels.HourlyCurrent(channel); Hourly next = Channels.HourlyNext(channel); Media currentmedia = current.Media; Media nextmedia = next.Media; int time = (int)(DateTime.Now - current.Date).TotalSeconds; currentmedia.StartSeconds += time; currentmedia.Duration = currentmedia.Duration - time; string json = JsonConvert.SerializeObject(new { Current = currentmedia, Next = nextmedia }); return(Json(json)); }
public void DeleteHourly(string guid, string name, bool hourlycurrent) { string path = hourlycurrent ? PathHourly() : PathHourlyList(name); List <Hourly> hourlys = XmlLoadHourlys(path).ToList(); //List<Hourly> hourlys = XmlLoadHourlys().ToList<Hourly>(); Hourly hourly = null; foreach (Hourly h in hourlys) { if (h.Guid == guid) { hourly = h; break; } } hourlys.Remove(hourly); XmlSaveHourlys(hourlys, path); }
public void BusinessRulesAdd() { //Create new HOURLY Hourly empTest = new Hourly() { EmpType = EType.HOURLY, EmpID = EMP_ID, FirstName = FIRST_NAME, LastName = LAST_NAME, HourlyRate = HOURLY_RATE }; //Add it to BusinessRules employees dictionary BusinessRules.Instance.Add(uint.Parse(EMP_ID), empTest); //Ensure the employee was added and it matches original Assert.AreEqual(empTest, BusinessRules.Instance[uint.Parse(EMP_ID)]); } // end method BusinessRulesAdd()
public bool CreateHorlyWeather(List <int> citiesId, Hourly hourly) { var cities = _db.Cities .Where(c => citiesId.Contains(c.Id)).ToList(); foreach (var city in cities) { var hourlyCity = new HourlyCity { City = city, Hourly = hourly }; _db.Add(hourlyCity); } _db.Add(hourly); return(Save()); }
public void Reorganize(DateTime firstdate, string name, bool hourlycurrent) { lock (this) { Hourly last = null; foreach (Hourly h in Hourlys.Include(h => h.Media).ToList()) { if (last == null) { h.Date = firstdate; last = h; } else { h.Date = last.Date + new TimeSpan(0, 0, last.Media.Duration); last = h; } } SaveChanges(); } }
public void SearchTest() { //arrange Hourly testEmp2 = new Hourly(6, (double)empType.Hourly, 22.33, 41, "Bill Smithers", "Bill", "Smithers"); BusinessRules.Instance.addEmployee("6", testEmp2); //act ////FAILS //var testResult = BusinessRules.Instance.searchEmployee("TED"); ////FAILS //var testResult1 = BusinessRules.Instance.searchEmployee("0"); //PASSES var testResult2 = BusinessRules.Instance.searchEmployee("Bill"); //Assert //Assert.AreEqual(testEmp2, testResult); //Assert.AreEqual(testEmp2, testResult1); Assert.AreEqual(testEmp2, testResult2); }
static void Main(string[] args) { Employee employee = new Employee(); salcomm sal = new salcomm(); Hourly hourly = new Hourly(); Commissioned commissioned = new Commissioned(); Salaried salaried = new Salaried(); employee.name = "A"; employee.id = 1; employee.basic_sal = 15000; salaried.name = "B"; salaried.id = 2; salaried.basic_sal = 15000; hourly.name = "C"; hourly.id = 3; hourly.hours = 50; hourly.ren_h = 500; commissioned.name = "D"; commissioned.id = 4; commissioned.article_nu = 10; commissioned.unit_price = 500; commissioned.comm_rate = 10; sal.name = "E"; sal.id = 5; sal.article_nu = 10; sal.unit_price = 500; sal.comm_rate = 10; sal.basic_sal = 15000; Console.WriteLine(employee.id + " " + employee.name + " " + employee.calculate_salary()); Console.WriteLine(salaried.id + " " + salaried.name + " " + salaried.calculate_salary()); Console.WriteLine(hourly.id + " " + hourly.name + " " + hourly.calculate_salary()); Console.WriteLine(commissioned.id + " " + commissioned.name + " " + commissioned.calculate_salary()); Console.WriteLine(sal.id + " " + sal.name + " " + sal.calculate_salary()); }
public void Reorganize(DateTime firstdate, string name, bool hourlycurrent) { string path = hourlycurrent ? PathHourly() : PathHourlyList(name); List <Hourly> hourlys = XmlLoadHourlys(path).ToList(); Hourly last = null; foreach (Hourly h in hourlys) { if (last == null) { h.Date = firstdate; last = h; } else { h.Date = last.Date + new TimeSpan(0, 0, last.Media.Duration); last = h; } } XmlSaveHourlys(hourlys, path); }
public bool UpdateHorlyWeather(List <int> citiesId, Hourly hourly) { var cities = _db.Cities .Where(c => citiesId.Contains(c.Id)).ToList(); var hourlyCitiesToDelete = _db.HourlyCities .Where(h => h.HourlyId == hourly.Id); _db.RemoveRange(hourlyCitiesToDelete); foreach (var city in cities) { var hourlyCity = new HourlyCity { City = city, Hourly = hourly }; _db.Add(hourlyCity); } _db.Add(hourly); return(Save()); }
public bool DeletHorlyWeather(Hourly hourly) { _db.Remove(hourly); return(Save()); }
public static void CollectHourlyInformation(Hourly theEmployee) { theEmployee.Wage = InputUtilities.getDoubleInputValue("Hourly Wage"); theEmployee.Hours = InputUtilities.getDoubleInputValue("Hours Worked"); theEmployee.Category = InputUtilities.getStringInputValue(" Category"); }
static void Main(string[] args) { string name = ""; // declare an event of type delegate to fire a chain of events in sequence // Display program information to the user of the application DisplayTittle(); ApplicationUtillies.DisplayDivider("Program Starting"); // prompt user as to what type of employee that will be adding entered bool check = false; string answer = ""; do { while (check == false) { Console.WriteLine(); Console.Write("What type of employee will be created: "); name = Console.ReadLine(); if (name.ToUpper() == "SALARIED") { Console.Clear(); DisplayTittle(); ApplicationUtillies.DisplayDivider("Program Starting"); ApplicationUtillies.DisplayDivider("Collect Salaried Employee Information"); Salaried salaried = new Salaried(); CollectInfo.CollectSalaried(salaried, name.ToUpper()); check = true; } else if (name.ToUpper() == "HOURLY") { Console.Clear(); DisplayTittle(); ApplicationUtillies.DisplayDivider("Collect Hourly Employee Information"); Hourly hourly = new Hourly(); CollectInfo.CollectHourly(hourly, name.ToUpper()); check = true; } else { Console.WriteLine(); Console.Clear(); DisplayTittle(); Console.WriteLine(); CollectInfo.DisplayErrorMessage("Sorry but the emmployee type that you entered does not exist\n"); } } check = false; Console.Write("\nDo you have another employee to enter: "); answer = Console.ReadLine(); } while (answer.ToUpper() == "YES"); // display company employees Console.Clear(); DisplayTittle(); ApplicationUtillies.DisplayDivider("Company Employees"); Console.WriteLine("First Name" + "Last Name".PadLeft(30) + "Job Role".PadLeft(30) + "Pay Scale ".PadLeft(30) + "Annual Salary".PadLeft(30) + "Department".PadLeft(30)); // Display all employees in the company foreach (var emp in CollectInfo.employees) { Console.Write(emp.ToString()); } //Display employee benifit information information foreach (var emp in CollectInfo.employees) { if (emp is Salaried) { emp.DisplayBenefitInfo(); } else if (emp is Hourly) { emp.DisplayBenefitInfo(); } } // pause application ApplicationUtillies.Pause(); }
/// <summary> /// Purpose: helper function to convert form data to an employee and place in an array /// </summary> /// <param name="etype"></param> private void AddEmployee(string etype) { switch (etype) { case "Hourly": userData[_UserIndex] = new Hourly(); userData[_UserIndex]._EmpName = txt_empName.Text; userData[_UserIndex]._EmpType = dbox_empType.Text; userData[_UserIndex]._EmpID = Convert.ToInt32(txt_empID.Text); userData[_UserIndex]._HoursWorked = Convert.ToDouble(txt_info1.Text); userData[_UserIndex]._HourlyRate = Convert.ToDecimal(txt_info2.Text); emp = userData[_UserIndex]; _UserIndex++; MessageBox.Show("An Employee has been added"); break; case "Salary": userData[_UserIndex] = new Salary(); userData[_UserIndex]._EmpName = txt_empName.Text; userData[_UserIndex]._EmpType = dbox_empType.Text; userData[_UserIndex]._EmpID = Convert.ToInt32(txt_empID.Text); userData[_UserIndex]._MonthlySalary = Convert.ToDecimal(txt_info1.Text); emp = userData[_UserIndex]; _UserIndex++; MessageBox.Show("An Employee has been added"); break; case "Contract": userData[_UserIndex] = new Contract(); userData[_UserIndex]._EmpName = txt_empName.Text; userData[_UserIndex]._EmpType = dbox_empType.Text; userData[_UserIndex]._EmpID = Convert.ToInt32(txt_empID.Text); userData[_UserIndex]._ContractSalary = Convert.ToDecimal(txt_info1.Text); emp = userData[_UserIndex]; _UserIndex++; MessageBox.Show("An Employee has been added"); break; case "Sales": userData[_UserIndex] = new Sales(); userData[_UserIndex]._EmpName = txt_empName.Text; userData[_UserIndex]._EmpType = dbox_empType.Text; userData[_UserIndex]._EmpID = Convert.ToInt32(txt_empID.Text); userData[_UserIndex]._MonthlySalary = Convert.ToDecimal(txt_info1.Text); userData[_UserIndex]._ComSales = Convert.ToDecimal(txt_info2.Text); userData[_UserIndex]._GrossSales = Convert.ToDecimal(txt_info3.Text); emp = userData[_UserIndex]; _UserIndex++; MessageBox.Show("An Employee has been added"); break; default: MessageBox.Show(_AddError); break; } }
public IActionResult UpdatHourly(int hourlyId, [FromQuery] List <int> cityId, [FromBody] Hourly hourlyToUpdate) { if (hourlyId != hourlyToUpdate.Id) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_hourlyRepository.UpdateHorlyWeather(cityId, hourlyToUpdate)) { ModelState.AddModelError("", $"Something went wrong updating the hourly weather"); return(StatusCode(500, ModelState)); } return(NoContent()); }
internal void EnterShareSkill() { //Explicit wait GlobalDefinitions.WaitForElement(GlobalDefinitions.driver, By.XPath("//a[contains(.,'Share Skill')]")); //click shareskill ShareSkillButton.Click(); // Populate the excel data GlobalDefinitions.ExcelLib.PopulateInCollection(Base.ExcelPath, "ShareSkill"); //Enter title Title.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Title")); //Enter Description Description.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Description")); // Select on Category Dropdown GlobalDefinitions.wait(10); SelectElement catg = new SelectElement(CategoryDropDown); catg.SelectByText(GlobalDefinitions.ExcelLib.ReadData(2, "Category")); //Select on SubCategory Dropdown GlobalDefinitions.wait(10); SelectElement subcatg = new SelectElement(SubCategoryDropDown); subcatg.SelectByText(GlobalDefinitions.ExcelLib.ReadData(2, "SubCategory")); //Enter Tag names in textbox Tags.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Tags")); Tags.SendKeys(Keys.Return); //Select the Service type if (GlobalDefinitions.ExcelLib.ReadData(2, "ServiceType") == "Hourly basis") { Hourly.Click(); } else if (GlobalDefinitions.ExcelLib.ReadData(2, "ServiceType") == "One-off") { Oneoff.Click(); } //Select the Location type if (GlobalDefinitions.ExcelLib.ReadData(2, "LocationType") == "On-site") { Onsite.Click(); } else if (GlobalDefinitions.ExcelLib.ReadData(2, "LocationType") == "Online") { Online.Click(); } //Click on Start Date dropdown StartDateDropDown.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Startdate")); //Click on End Date dropdown EndDateDropDown.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Enddate")); //Select available days Days.Click(); //Select startTime StartTime.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Starttime")); //select endtime EndTimeDropDown.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Endtime")); if (GlobalDefinitions.ExcelLib.ReadData(2, "SkillTrade") == "Skill-Exchange") { //select SkillTradeOption SkillTradeOption.Click(); //Enter SkillExchange SkillExchange.SendKeys(GlobalDefinitions.ExcelLib.ReadData(2, "Skill-Exchange")); SkillExchange.SendKeys(Keys.Return); } else if (GlobalDefinitions.ExcelLib.ReadData(2, "SkillTrade") == "Credit") { Credit.Click(); Creditvalue.SendKeys(Global.GlobalDefinitions.ExcelLib.ReadData(2, "Credit")); Creditvalue.SendKeys(Keys.Enter); } //Click worksample Worksample.Click(); //Worksample.SendKeys("path"); //upload file using AutoIT AutoItX3 autoit = new AutoItX3(); //Activate so that next action happens on this window autoit.WinActivate("Open"); //autoit.Send(@"D:\Shareskillmars\FileUploadScript.exe"); autoit.Send(@"D:\Shareskillmars\sample.txt"); autoit.Send("{ENTER}"); Thread.Sleep(10000); //Select user option if (GlobalDefinitions.ExcelLib.ReadData(2, "UserStatus") == "Active") { StatusActive.Click(); } else if (GlobalDefinitions.ExcelLib.ReadData(2, "UserStatus") == "Hidden") { StatusHidden.Click(); } //click save or cancel if (Global.GlobalDefinitions.ExcelLib.ReadData(2, "SaveOrCancel") == "Save") { Save.Click(); } else if (Global.GlobalDefinitions.ExcelLib.ReadData(2, "SaveOrCancel") == "Cancel") { Cancel.Click(); } }
public override void Draw(CGRect rect) { base.Draw(rect); _highTemps = null; _lowTemps = null; _hourlyTemps = null; if (Forecasts.Count == 0 || Hourly.Count == 0) { return; } graphRect = new CGRect(rect.X + padding, rect.Y + padding, rect.Width - (padding * 2), rect.Height - (padding * 2)); var days = Hourly.GroupBy(h => h.FCTTIME.mday).Select(g => g.First().FCTTIME.weekday_name_abbrev).ToList(); var dayCount = hourly ? days.Count : Forecasts.Count; var xAxisScale = (graphRect.Width + padding / 2) / dayCount; inset = xAxisScale / 2; var highest = (nfloat)(hourly ? HourlyTemps.Max() : HighTemps.Max()); var lowest = (nfloat)(hourly ? HourlyTemps.Min() : LowTemps.Min()); scaleHigh = NMath.Round(highest, MidpointRounding.AwayFromZero); scaleLow = lowest < 0 ? NMath.Round(lowest, MidpointRounding.AwayFromZero) : NMath.Round(lowest); var rangePadding = Settings.UomTemperature.IsImperial() ? scalePadding : (scalePadding / 2); scaleHigh += rangePadding; scaleLow -= rangePadding; scaleRange = scaleHigh - scaleLow; var scaleIncrement = scaleRange / dividerCount; scaleX = (graphRect.Width - inset) / (hourly ? HourlyTemps.Count : Forecasts.Count); scaleY = graphRect.Height / dividerCount; nfloat x, y; using (CGContext ctx = UIGraphics.GetCurrentContext()) { // Draw x and y axis using (UIColor color = UIColor.White) { color.SetStroke(); ctx.SetLineWidth(1); using (CGPath p = new CGPath()) { p.MoveToPoint(graphRect.GetMinX(), graphRect.GetMaxY()); p.AddLines(new [] { new CGPoint(graphRect.GetMinX(), graphRect.GetMinY()), new CGPoint(graphRect.GetMinX(), graphRect.GetMaxY()), new CGPoint(graphRect.GetMaxX(), graphRect.GetMaxY()) }); ctx.AddPath(p); ctx.DrawPath(CGPathDrawingMode.Stroke); } } // Draw horizontal gridlines using (UIColor color = UIColor.Black.ColorWithAlpha(0.08f)) { for (int i = 1; i < dividerCount; i += 2) { y = (i + 1) * scaleY; color.SetFill(); ctx.FillRect(new CGRect(graphRect.GetMinX(), graphRect.GetMaxY() - y, graphRect.Width, scaleY)); ctx.StrokePath(); } } drawLines(); // Draw y-axis labels nfloat yStep = scaleLow; ctx.SaveState(); ctx.TranslateCTM(0, rect.Height); ctx.ScaleCTM(1, -1); for (int i = 0; i <= dividerCount; i++) { y = padding + (i * scaleY); var step = NMath.Round(yStep).ToString(); drawLabel(ctx, rect, y, padding - 6, UITextAlignment.Right, step, false, true); yStep += scaleIncrement; } // Draw x-axis labels for (int i = 0; i < dayCount; i++) { x = padding + (i * xAxisScale); drawLabel(ctx, rect, padding - 6, x, UITextAlignment.Left, hourly ? days [i] : Forecasts [i]?.date?.weekday_short, false); } ctx.RestoreState(); } }
public override void Draw(Canvas canvas) { base.Draw(canvas); if (!scaled) { density = Resources.DisplayMetrics.Density; padding *= density; lineWidth *= density; fontSize *= density; scaled = true; } _highTemps = null; _lowTemps = null; _hourlyTemps = null; if (Forecasts.Count == 0 || Hourly.Count == 0) { return; } graphRect = new RectF(padding, padding, canvas.Width - padding, canvas.Height - padding); // CGRect (rect.X + padding, rect.Y + padding, rect.Width - (padding * 2), rect.Height - (padding * 2)); System.Diagnostics.Debug.WriteLine($"lineWidth = {lineWidth}"); System.Diagnostics.Debug.WriteLine($"canvas.Width = {canvas.Width}"); System.Diagnostics.Debug.WriteLine($"canvas.Height = {canvas.Height}"); System.Diagnostics.Debug.WriteLine($"graphRect.Width() = {graphRect.Width ()}"); System.Diagnostics.Debug.WriteLine($"graphRect.Height() = {graphRect.Height ()}"); System.Diagnostics.Debug.WriteLine($"graphRect.Left = {graphRect.Left}"); System.Diagnostics.Debug.WriteLine($"graphRect.Top = {graphRect.Top}"); System.Diagnostics.Debug.WriteLine($"graphRect.Right = {graphRect.Right}"); System.Diagnostics.Debug.WriteLine($"graphRect.Bottom = {graphRect.Bottom}"); var days = Hourly.GroupBy(h => h.FCTTIME.mday).Select(g => g.First().FCTTIME.weekday_name_abbrev).ToList(); var dayCount = hourly ? days.Count : Forecasts.Count; var xAxisScale = (graphRect.Width() + padding / 2) / dayCount; inset = xAxisScale / 2; var highest = (float)(hourly ? HourlyTemps.Max() : HighTemps.Max()); var lowest = (float)(hourly ? HourlyTemps.Min() : LowTemps.Min()); scaleHigh = (float)Math.Round(highest, MidpointRounding.AwayFromZero); scaleLow = lowest < 0 ? (float)Math.Round(lowest, MidpointRounding.AwayFromZero) : (float)Math.Round(lowest); var rangePadding = Settings.UomTemperature.IsImperial() ? scalePadding : (scalePadding / 2); scaleHigh += rangePadding; scaleLow -= rangePadding; scaleRange = scaleHigh - scaleLow; var scaleIncrement = scaleRange / dividerCount; scaleX = (graphRect.Width() - inset) / (hourly ? HourlyTemps.Count : Forecasts.Count); scaleY = graphRect.Height() / dividerCount; float x, y; var white = Color.White; // Draw x and y axis var paint = new Paint(); paint.Color = white; paint.StrokeWidth = 1; using (Path path = new Path()) { path.MoveTo(graphRect.Left, graphRect.Top); path.LineTo(graphRect.Left, graphRect.Bottom); path.LineTo(graphRect.Right, graphRect.Bottom); paint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(path, paint); } Color translucentBlack = Color.Argb(20, 0, 0, 0); paint.Color = translucentBlack; paint.SetStyle(Paint.Style.Fill); // Draw horizontal gridlines for (int i = 1; i < dividerCount; i += 2) { y = graphRect.Bottom - ((i + 1) * scaleY); using (RectF grid = new RectF(padding, y, graphRect.Right, y + scaleY)) canvas.DrawRect(grid, paint); } drawLines(canvas, paint); float labelPadding = 6 * density; float yStep = scaleLow; // Draw y-axis labels for (int i = dividerCount; i >= 0; i--) { y = padding + (i * scaleY); var step = Math.Round(yStep).ToString(); drawLabel(canvas, graphRect.Left - labelPadding, y, Paint.Align.Right, step, true); yStep += scaleIncrement; } // Draw x-axis labels for (int i = 0; i < dayCount; i++) { x = padding + (i * xAxisScale); drawLabel(canvas, x, graphRect.Bottom + labelPadding, Paint.Align.Left, hourly ? days [i] : Forecasts [i]?.date?.weekday_short); } }