private async Task <string> Depart(IVessel vessel, string vesselName, DateTime ts) { var wait = await vessel.GetTicksToWait(); if (wait == 0) { var r = new Random(); int routeIndex = r.Next(0, routes.Count - 1); await vessel.SetRoute(routes[routeIndex]); AssignAllocationAsync(vessel, ts); var obj = new IntakeEventModel(); obj.VesselCode = vesselName; obj.DepartureDate = ts; obj.Intake = await vessel.GetCapacity(); await new KafkaProducer().SendToKafka(JsonConvert.SerializeObject(obj), "intake"); await vessel.Depart(ts); await vessel.ResetDistanceOnRoute(); return(vesselName); } else { //_logger.LogInformation(vesselName+" Waiting"); var i = wait - 1; await vessel.SetTicksToWait(i); } return(""); }
public async Task AssignAllocationAsync(IVessel v, DateTime ts) { int capacity = await v.GetCapacity(); var r = new Random(); var range = r.Next(80, 120); var percentage = range / 100f; var percentagePerCompany = percentage / 3f; var companies = Configuration.Constants.Companies.OrderBy(x => r.Next()).Take(3); foreach (var c in companies) { var a = (int)Math.Round(capacity * percentagePerCompany); await v.AddAllocationToVessel(a, c, ts); } }