public async Task <IHttpActionResult> PutJourneys(int id, Journeys journeys)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != journeys.Id)
            {
                return(BadRequest());
            }

            db.Entry(journeys).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JourneysExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        private async void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var menu = new PopupMenu(this, lv.GetChildAt(e.Position - lv.FirstVisiblePosition));

            menu.Inflate(Resource.Layout.SearchJourneyMenu);
            Journeys j = userJourneys[e.Position];

            menu.MenuItemClick += async(s, a) =>
            {
                switch (a.Item.ItemId)
                {
                case Resource.Id.pop_buttonSearchApply:
                    // Add user to applicants for journey

                    j.Applicants += pref.GetString("UserID", "") + ",";
                    DBHelper.UpdateJourney(j);
                    UserProfiles up = await DBHelper.GetUsersProfile(j.DriverID);

                    DBHelper.SendApplicationNoticeEmail(up.Email, j);
                    StartActivity(typeof(MainProfileActivity));

                    break;

                case Resource.Id.pop_buttonSearchView:
                    edit.PutString("SelectedJourneyID", j.ID);
                    edit.Commit();
                    StartActivity(typeof(ShowJourney));
                    break;
                }
            };
            menu.Show();
        }
Ejemplo n.º 3
0
        private void ListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            var menu = new PopupMenu(this, lv.GetChildAt(e.Position - lv.FirstVisiblePosition)); //lv.GetChildAt(e.Position)

            menu.Inflate(Resource.Layout.JourneyMenu);
            menu.MenuItemClick += (s, a) =>
            {
                switch (a.Item.ItemId)
                {
                case Resource.Id.pop_button1:
                    Journeys j = userJourneys[e.Position];
                    edit.PutString("SelectedJourneyID", j.ID);
                    edit.Commit();
                    StartActivity(typeof(ShowJourney));
                    // goto details for selected journey
                    break;

                case Resource.Id.pop_button2:
                    // cancel/delete this journey, if it has no passengers.
                    break;
                }
            };
            try
            {
                menu.Show();
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 4
0
        private async void CreateJourney()
        {
            Journeys j = new Journeys();

            j.CreatedBy         = UserID;
            j.DepartureDate     = initialDepDate.ToShortDateString();
            j.DepartureDateTime = initialDepTime.ToShortTimeString();
            j.DriverID          = UserID;
            j.From       = LocationHelper.ReverseGeoLoc(fromMarker.Position.Latitude, fromMarker.Position.Longitude);
            j.FromLat    = fromMarker.Position.Latitude;
            j.FromLon    = fromMarker.Position.Longitude;
            j.To         = LocationHelper.ReverseGeoLoc(toMarker.Position.Latitude, toMarker.Position.Longitude);
            j.ToLat      = toMarker.Position.Latitude;
            j.ToLon      = toMarker.Position.Longitude;
            j.Passengers = "";
            ProgressDialog progress;

            progress = new ProgressDialog(this);
            progress.Indeterminate = true;
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetMessage("Creating... Please wait...");
            progress.SetCancelable(false);
            progress.Show();
            CurrentPlatform.Init();
            DBHelper.InsertJourney(j);
            progress.Hide();
            Toast.MakeText(ApplicationContext, "Journey created!", ToastLength.Short).Show();
        }
Ejemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     Journey = Player.GetComponent <Journeys>();
     if (Journey != null)
     {
         StepsDoneCount = Journey.StepsDone.Count;
     }
 }
Ejemplo n.º 6
0
 public string Serialize(Journeys journeys)
 {
     return(JsonConvert.SerializeObject(journeys,
                                        Formatting.Indented, new JsonSerializerSettings
     {
         ContractResolver = new CamelCasePropertyNamesContractResolver()
     }));
 }
Ejemplo n.º 7
0
        public void Price(string inputPath, string outputPath)
        {
            IEnumerable <Tap> tapsList = _tapDeserializer.Serialize(inputPath);
            Journeys          compute  = _travel.Compute(tapsList.ToList());
            string            customerSummariesSerialized = _journeySerializer.Serialize(compute);

            _printer.Print(customerSummariesSerialized, outputPath);
        }
        public decimal GetTotalPrice()
        {
            if (!Journeys.Any())
            {
                return(default(decimal));
            }

            return(Journeys.Sum(x => x.Price));
        }
Ejemplo n.º 9
0
        public void Add(DateTime fromDateTime, DateTime toDateTime)
        {
            Journey          journey          = new Journey(fromDateTime.Date.AddHours(12).ToUniversalTime(), toDateTime.Date.AddHours(12).ToUniversalTime());
            JourneyViewModel journeyViewModel = new JourneyViewModel(journey);

            Journeys.Insert(0, journeyViewModel);
            journey.Save();
            UpdateApplicationBadge();
            SelectedJourney = journeyViewModel;
        }
Ejemplo n.º 10
0
 public void Delete()
 {
     if (SelectedJourney != null)
     {
         var journeyToDelete = SelectedJourney;
         SelectedJourney = null;
         Journeys.Remove(journeyToDelete);
         journeyToDelete.Journey.Delete();
     }
 }
Ejemplo n.º 11
0
        public async Task <IHttpActionResult> GetJourneys(int id)
        {
            Journeys journeys = await db.Journeys.FindAsync(id);

            if (journeys == null)
            {
                return(NotFound());
            }

            return(Ok(journeys));
        }
Ejemplo n.º 12
0
        public async Task <IHttpActionResult> PostJourneys(Journeys journeys)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Journeys.Add(journeys);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = journeys.Id }, journeys));
        }
        public string GetRoute()
        {
            if (Journeys == null || Journeys.Count == 0)
            {
                return(string.Empty);
            }

            var firstJourney = Journeys.OrderBy(x => x.DepartureDate).First();
            var lastJourney  = Journeys.OrderBy(x => x.DepartureDate).Last();

            return(string.Format("{0}{1}", firstJourney.Departure, lastJourney.Arrival));
        }
        public void AddJourney(Journey journey)
        {
            ValidateNewJourney(journey);

            if (Journeys == null)
            {
                Journeys = new HashSet <Journey>();
            }

            Journeys.Add(journey);

            UpdateModifiedDate();
        }
Ejemplo n.º 15
0
        public async Task <IHttpActionResult> DeleteJourneys(int id)
        {
            Journeys journeys = await db.Journeys.FindAsync(id);

            if (journeys == null)
            {
                return(NotFound());
            }

            db.Journeys.Remove(journeys);
            await db.SaveChangesAsync();

            return(Ok(journeys));
        }
Ejemplo n.º 16
0
        private async void CreateJourney()
        {
            Journeys j = new Journeys();

            j.CreatedBy         = UserID;
            j.DepartureDate     = initialDepDate.ToShortDateString();
            j.DepartureDateTime = initialDepTime.ToShortTimeString();
            j.DriverID          = UserID;
            j.From           = LocationHelper.ReverseGeoLoc(fromMarker.Position.Latitude, fromMarker.Position.Longitude);
            j.FromLat        = fromMarker.Position.Latitude;
            j.FromLon        = fromMarker.Position.Longitude;
            j.To             = LocationHelper.ReverseGeoLoc(toMarker.Position.Latitude, toMarker.Position.Longitude);
            j.ToLat          = toMarker.Position.Latitude;
            j.ToLon          = toMarker.Position.Longitude;
            j.NoOfPassengers = Convert.ToInt32(numPassengers.SelectedItem.ToString());
            if (DateTime.Now > initialDepDate)
            {
                j.Completed = true;
            }
            else
            {
                j.Completed = false;
            }
            j.Filled     = false;
            j.Passengers = "";
            j.Applicants = "";
            ProgressDialog progress;

            progress = new ProgressDialog(this);
            progress.Indeterminate = true;
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetMessage("Creating... Please wait...");
            progress.SetCancelable(false);
            progress.Show();
            CurrentPlatform.Init();
            DBHelper.InsertJourney(j);
            if (additionalDatesList != null)
            {
                foreach (DateTime d in additionalDatesList)
                {
                    j.DepartureDate = d.ToShortDateString();
                    DBHelper.InsertJourney(j);
                }
            }
            progress.Hide();
            Toast.MakeText(ApplicationContext, "Journey created!", ToastLength.Short).Show();
        }
Ejemplo n.º 17
0
        public AddIdPWizard()
        {
            IsApplied = false;
            var journeys = new List <JourneyRef>();

            foreach (var j in App.PolicySet.Base.Root.Element(Constants.dflt + "UserJourneys").Elements(Constants.dflt + "UserJourney")
                     .Where(jr => jr.Element(Constants.dflt + "OrchestrationSteps").Elements(Constants.dflt + "OrchestrationStep").First().Element(Constants.dflt + "ClaimsProviderSelections") != null))
            {
                journeys.Add(new JourneyRef()
                {
                    Name       = j.Attribute("Id").Value,
                    IsSelected = true,
                    Source     = j,
                });
            }
            Journeys = journeys;
            Apply    = new DelegateCommand(() =>
            {
                // TODO: add a wizard step to first configure the IdP (if it is AAD)
                try
                {
                    CreatedIdP = CreateIdP();
                    App.PolicySet.Base.Root.Element(Constants.dflt + "ClaimsProviders").Add(CreatedIdP);
                    foreach (var j in Journeys.Where(jr => jr.IsSelected))
                    {
                        j.Source.AddIdPToJourney(CreatedIdP);
                    }
                    ;
                    IsApplied = true;
                    if (Closing != null)
                    {
                        Closing();
                    }
                } catch (Exception ex)
                {
                    MainWindow.Trace.Add(new TraceItem {
                        Msg = ex.Message
                    });
                }
            })
            {
                Enabled = false
            };
            SelectedIdPType = IdPTypes.First();
        }
Ejemplo n.º 18
0
        private void Parse()
        {
            while ((line = file.ReadLine()) != null)
            {
                lineCh         = line.ToCharArray();
                recordIdentity = line.Substring(0, 2);
                switch (recordIdentity)
                {
                case "QS":
                    Journeys.Add(new JourneyRecord(lineCh));
                    break;

                case "QO":
                    Journeys[Journeys.Count - 1].setOrigin(lineCh);
                    break;

                case "QI":
                    Journeys[Journeys.Count - 1].addIntermediateRecord(lineCh);
                    break;

                case "QT":
                    Journeys[Journeys.Count - 1].setDestination(lineCh);
                    break;

                case "QD":
                    addRoute();
                    break;

                case "QL":
                    addLocation();
                    break;

                case "QB":
                    setLocationGridRef();
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 19
0
        private bool Equal(Journeys cs, Journeys cs2)
        {
            IOrderedEnumerable <CustomerSummary> customerSummaries  = cs.CustomerSummaries.OrderBy(i => i.CustomerId);
            IOrderedEnumerable <CustomerSummary> customerSummaries2 = cs2.CustomerSummaries.OrderBy(i => i.CustomerId);
            IEnumerable <(CustomerSummary First, CustomerSummary Second)> valueTuples = customerSummaries.Zip(customerSummaries2);

            foreach (var summaries in valueTuples)
            {
                bool b             = summaries.First.CustomerId == summaries.Second.CustomerId;
                bool b1            = summaries.First.TotalCostInCents == summaries.Second.TotalCostInCents;
                bool sequenceEqual = summaries.First.Trips.OrderBy(trip => trip.StartedJourneyAt)
                                     .SequenceEqual(summaries.Second.Trips.OrderBy(t => t.StartedJourneyAt));

                bool equal = b || b1 || sequenceEqual;
                if (equal is false)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 20
0
        private Journeys CustomerSummaries()
        {
            Journeys journeys = new Journeys
            {
                CustomerSummaries = new[]
                {
                    new CustomerSummary
                    {
                        CustomerId       = 1,
                        TotalCostInCents = 480,
                        Trips            = new[]
                        {
                            new Trip
                            {
                                StationStart     = "A",
                                StationEnd       = "D",
                                StartedJourneyAt = 1572242400,
                                CostInCents      = 240,
                                ZoneFrom         = 1,
                                ZoneTo           = 2
                            },
                            new Trip
                            {
                                StationStart     = "D",
                                StationEnd       = "A",
                                StartedJourneyAt = 1572282000,
                                CostInCents      = 240,
                                ZoneFrom         = 1,
                                ZoneTo           = 2
                            }
                        }
                    }
                }
            };

            return(journeys);
        }
Ejemplo n.º 21
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ShowJourney);
            string jID = pref.GetString("SelectedJourneyID", "");

            thisJourney = await DBHelper.GetJourneys(pref.GetString("SelectedJourneyID", ""));

            SetTextViewMessages();

            fromLocation = new MarkerOptions();
            fromLocation.SetTitle("From Here");
            fromLocation.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
            fromLocation.SetPosition(new LatLng(thisJourney.FromLat, thisJourney.FromLon));

            toLocation = new MarkerOptions();
            toLocation.SetTitle("To Here");
            toLocation.SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
            toLocation.SetPosition(new LatLng(thisJourney.ToLat, thisJourney.ToLon));

            InitMapFragment();
            // Create your application here
        }
Ejemplo n.º 22
0
        public MockObjects()
        {
            Vehicles1 = new Vehicles();
            Vehicles2 = new Vehicles();
            Vehicles3 = new Vehicles();

            Journeys1 = new Journeys();

            Services1 = new Services();

            FuelPurchases1 = new FuelPurchases();

            Vehicles2.Add("BMW", "X5", 2006, "1BGZ784", 93);
            Vehicles2.Add("Tesla", "Roadster", 2008, "8HDZ576", 0);

            Vehicles3.Add("BMW", "X5", 2006, "1BGZ784", 93);
            Vehicles3.Add("Tesla", "Roadster", 2008, "8HDZ576", 0);

            Journeys1.Add(Vehicles2.List[0], new DateTime(2019, 1, 15, 15, 45, 00), 10);
            Journeys1.Add(Vehicles2.List[0], new DateTime(2019, 3, 16, 21, 10, 00), 20);

            FuelPurchases1.Add(Vehicles2.List[0], 357.11m, 39.23, new DateTime(2019, 11, 18, 22, 15, 00));
            FuelPurchases1.Add(Vehicles2.List[0], 161.80m, 49.57, new DateTime(2019, 11, 21, 12, 15, 00));

            Services1.Add(Vehicles2.List[0], 10, 473.02m, new DateTime(2018, 12, 20));
            Services1.Add(Vehicles2.List[0], 15, 537.20m, new DateTime(2019, 3, 16));

            Vehicle1 = new Vehicle(17)
            {
                Manufacturer       = "Chevrolet",
                Model              = "Cadillac",
                MakeYear           = 1959,
                RegistrationNumber = "C4D1LL4C",
                TankCapacity       = 79
            };
        }
Ejemplo n.º 23
0
 public bool IsAnythingToSave()
 {
     return(Journeys.Any(x => x.Journey.HasBeenChanged));
 }
Ejemplo n.º 24
0
        public void UpdateApplicationBadge()
        {
            int numberOfUnsavedJourneys = Journeys.Count(x => x.Journey.HasBeenChanged);

            Application.Instance.BadgeLabel = (numberOfUnsavedJourneys > 0) ? numberOfUnsavedJourneys.ToString() : string.Empty;
        }
 //Journey Class Method: Distance travelled
 public void AddJourney(double distanceTravelled)
 {
     Journeys.Add(new Journey(distanceTravelled));
 }
Ejemplo n.º 26
0
        private void CreateJourneyFromPairedBts(List <BusinessTrip> bts)
        {
            BusinessTrip firstBt = bts.OrderBy(bt => bt.StartDate).FirstOrDefault();
            BusinessTrip lastBt  = bts.OrderByDescending(bt => bt.EndDate).FirstOrDefault();

            DaysBetweenStartDateAndOrderStartDate = (firstBt.StartDate - firstBt.OrderStartDate.Value).Days;
            DaysBetweenOrderEndDateAndEndDate     = (lastBt.OrderEndDate.Value - lastBt.EndDate.Date).Days;

            DateTime?StartDateForJourneyForStartDifference = firstBt.OrderStartDate;
            DateTime?StartDateForJourneyForEndDifference   = lastBt.EndDate.AddDays(1);

            CalendarItem item       = new CalendarItem();
            Employee     empFirstBt = (from e in context.Employees where e.EmployeeID == firstBt.EmployeeID select e).FirstOrDefault();
            Employee     empLastBt  = (from e in context.Employees where e.EmployeeID == lastBt.EmployeeID select e).FirstOrDefault();

            for (int i = 0; i < DaysBetweenStartDateAndOrderStartDate; i++)
            {
                Journey journey = new Journey();
                journey.BusinessTripID = firstBt.BusinessTripID;
                journey.Date           = StartDateForJourneyForStartDifference.Value;
                if (journey.Date.DayOfWeek == DayOfWeek.Saturday || journey.Date.DayOfWeek == DayOfWeek.Sunday)
                {
                    journey.DayOff = true;
                }


                foreach (Holiday hol in context.Holidays)
                {
                    if (journey.Date == hol.HolidayDate.Date)
                    {
                        journey.DayOff = true;
                    }
                }

                if (Journeys.Where(j => ((j.BusinessTripID == firstBt.BusinessTripID) && (j.Date == journey.Date))).Count() == 0)
                {
                    SaveJourney(journey);

                    if ((firstBt.Status == (BTStatus.Confirmed | BTStatus.Reported)) && (firstBt.Status != BTStatus.Cancelled))
                    {
                        item.EmployeeID = firstBt.EmployeeID;
                        item.From       = journey.Date;
                        item.To         = journey.Date;
                        item.Type       = CalendarItemType.Journey;

                        empFirstBt.CalendarItems.Add(item);
                        SaveCalendarItem(item);
                        item = new CalendarItem();
                    }
                }
                StartDateForJourneyForStartDifference = new DateTime?(StartDateForJourneyForStartDifference.Value.AddDays(1));
            }

            for (int i = 0; i < DaysBetweenOrderEndDateAndEndDate; i++)
            {
                Journey journey = new Journey();
                journey.BusinessTripID = lastBt.BusinessTripID;
                journey.Date           = StartDateForJourneyForEndDifference.Value;

                if (journey.Date.DayOfWeek == DayOfWeek.Saturday || journey.Date.DayOfWeek == DayOfWeek.Sunday)
                {
                    journey.DayOff = true;
                }

                foreach (Holiday hol in context.Holidays)
                {
                    if (journey.Date == hol.HolidayDate.Date)
                    {
                        journey.DayOff = true;
                    }
                }

                if (Journeys.Where(j => ((j.BusinessTripID == lastBt.BusinessTripID) && (j.Date == journey.Date))).Count() == 0)
                {
                    SaveJourney(journey);



                    item.EmployeeID = lastBt.EmployeeID;
                    item.From       = journey.Date;
                    item.To         = journey.Date;
                    item.Type       = CalendarItemType.Journey;

                    empLastBt.CalendarItems.Add(item);
                    SaveCalendarItem(item);
                    item = new CalendarItem();
                }
                StartDateForJourneyForEndDifference = new DateTime?(StartDateForJourneyForEndDifference.Value.AddDays(1));
            }
        }
Ejemplo n.º 27
0
        public override async void Refresh()
        {
            base.Refresh();

            // Mark View as Refreshing
            Refreshing = true;

            // Clear Journey Groups
            Journeys.Clear();

            // Get collection of Journey objects from Journey Service
            var journeys = await Services.Host.JourneyService.GetJourneys();

            // Dump to array to prevent multiple enumerations
            var enumerable = journeys as Journey[] ?? journeys.ToArray();

            // Hold todays date
            var todaysDate = DateTime.UtcNow.Date;
            // Use Todays Date to filter journeys for Today and factory them into JourneyViewModel's
            var todaysJourneys = enumerable.Where(j => j.Date.Date == todaysDate).Select(j => new JourneyViewModel(j));
            // Dump to array to prevent multiple enumerations.
            var todaysJourneyViewModels = todaysJourneys as JourneyViewModel[] ?? todaysJourneys.ToArray();

            // Check if there were any journey's today.
            if (todaysJourneyViewModels.Any())
            {
                // Create the JourneyGroup for Today
                var todayGroup = new JourneyGroup("Today", todaysDate.Date.ToString());
                // Add Todays Journey's to the JourneyGroup
                todayGroup.AddRange(todaysJourneyViewModels);
                // Add Todays JourneyGroup to the Journey Grousp list
                Journeys.Add(todayGroup);
            }


            // Hold yesterdays date
            var yesterdaysDate = DateTimeOffset.UtcNow.AddDays(-1).Date;
            // Use Yesterdays Date to filter journeys for Yesterday and factory them into JourneyViewModel's
            var yesterdaysJourneys =
                enumerable.Where(j => j.Date.Date == yesterdaysDate)
                .Select(j => new JourneyViewModel(j));
            // Dump to array to prevent multiple enumerations.
            var yesterdaysJourneyViewModels = yesterdaysJourneys as JourneyViewModel[] ?? yesterdaysJourneys.ToArray();

            // Check if there were any journey's yesterday.
            if (yesterdaysJourneyViewModels.Any())
            {
                // Create the JourneyGroup for Yesterday
                var yesterdayGroup = new JourneyGroup("Yesterday", yesterdaysDate.Date.ToString());
                // Add Yesterdays Journey's to the JourneyGroup
                yesterdayGroup.AddRange(yesterdaysJourneyViewModels);
                // Add Yesterdays JourneyGroup to the Journey Grousp list
                Journeys.Add(yesterdayGroup);
            }

            // Hold Last Weeks date
            var lastWeeksDate = DateTimeOffset.UtcNow.Date.AddDays(-7).StartOfWeek(DayOfWeek.Sunday);

            // Use Yesterdays Date and Last Weeks Date to filter journeys for Last Week and factory them into JourneyViewModel's
            var lastWeeksJourneys = enumerable.Where(j => j.Date.Date > lastWeeksDate && j.Date.Date < yesterdaysDate)
                                    .Select(j => new JourneyViewModel(j));
            // Dump to array to prevent multiple enumerations.
            var lastWeeksJourneyViewModels = lastWeeksJourneys as JourneyViewModel[] ?? lastWeeksJourneys.ToArray();

            // Check if there were any journey's last week.
            if (lastWeeksJourneyViewModels.Any())
            {
                // Create the JourneyGroup for Last Week
                var lastWeekGroup = new JourneyGroup("Last Week", lastWeeksDate.Date.ToString());
                // Add Last Weeks Journey's to the JourneyGroup
                lastWeekGroup.AddRange(lastWeeksJourneyViewModels);
                // Add Last Weeks JourneyGroup to the Journey Grousp list
                Journeys.Add(lastWeekGroup);
            }

            // Filter remaining Journeys that havent been dealt with
            var remainingJourneys = enumerable.Where(j => j.Date < lastWeeksDate);
            // Group journeys by Year
            var journeysByYear = remainingJourneys.GroupBy(j => j.Date.Date.Year).Select(g => g.ToList()).ToList();

            // Go through years
            foreach (var yearsJourneys in journeysByYear)
            {
                // Group this years Journeys by Month
                var journeysByMonth =
                    yearsJourneys.GroupBy(j => j.Date.Date.Month).Select(g => g.ToList()).ToList();

                // Go through months
                foreach (var monthsJourneys in journeysByMonth)
                {
                    // Create the JourneyGroup for the Month
                    var monthsGroup = new JourneyGroup(monthsJourneys.FirstOrDefault().Date.ToString("MMMM", null), monthsJourneys.FirstOrDefault().Date.ToString("MMMM", null));
                    // Add Journeys to the JourneyGroup
                    monthsGroup.AddRange(monthsJourneys.Select(j => new JourneyViewModel(j)));
                    // Add
                    Journeys.Add(monthsGroup);
                }
            }

            // Set whether there are any journeys
            HasJourneys = Journeys.Any();

            // Mark View as not Refreshing
            Refreshing = false;
        }
Ejemplo n.º 28
0
 // adds journey to journeys
 public void AddJourney(Journey journey)
 {
     Journeys.Add(journey);
 }
Ejemplo n.º 29
0
        public async Task <AnnualJourneyGroupListRp> GetAnnualGroupReport(int productId, DateTime start)
        {
            var result = new AnnualJourneyGroupListRp();
            var period = DatePeriodValue.ToYearFromStart(start);

            var product = await this._dbContext.FullLoadProductWithSourceItems(productId, period.Start, period.End);

            var months         = period.ToYearPeriods();
            var journeysGroups = product.Journeys.GroupBy(c => c.Group).ToList();
            var pivot          = new Dictionary <string, List <(int count, decimal availability, decimal latency, decimal experience)> >();

            foreach (var monthperiod in months)
            {
                var groupsReport = new List <(string name, int count, decimal availability, decimal latency, decimal experience)>();
                foreach (var group in journeysGroups)
                {
                    var measures = group.Select(c => new { measure = c.Measure(monthperiod), slo = c.AvailabilitySlo }).ToList();
                    groupsReport.Add((group.Key, group.Count(),
                                      measures.Sum(c => c.measure.AvailabilityDebt),
                                      measures.Sum(c => c.measure.LatencyDebt),
                                      measures.Sum(c => c.measure.ExperienceDebt)
                                      ));
                }

                foreach (var group in groupsReport)
                {
                    if (!pivot.ContainsKey(group.name))
                    {
                        pivot.Add(group.name, new List <(int count, decimal availability, decimal latency, decimal experience)>());
                    }
                    pivot[group.name].Add((group.count, group.availability, group.latency, group.experience));
                }
                if (!pivot.ContainsKey("[Total]"))
                {
                    pivot.Add("[Total]", new List <(int count, decimal availability, decimal latency, decimal experience)>());
                }
                pivot["[Total]"].Add(
                    (
                        groupsReport.Sum(c => c.count),
                        groupsReport.Sum(c => c.availability),
                        groupsReport.Sum(c => c.latency),
                        groupsReport.Sum(c => c.experience)
                    ));
            }

            if (pivot.Count == 0)
            {
                return(result);
            }

            result.Availability = pivot.Select(c =>
            {
                var tmp = new MonthRp()
                {
                    Name = c.Key, Count = c.Value.ElementAt(0).count
                };
                for (int i = 0; i < c.Value.Count; i++)
                {
                    tmp.SetMonthValue(i, c.Value[i].availability);
                }
                return(tmp);
            }).ToList();

            result.Latency = pivot.Select(c =>
            {
                var tmp = new MonthRp()
                {
                    Name = c.Key, Count = c.Value.ElementAt(0).count
                };
                for (int i = 0; i < c.Value.Count; i++)
                {
                    tmp.SetMonthValue(i, c.Value[i].latency);
                }
                return(tmp);
            }).ToList();

            result.Experience = pivot.Select(c =>
            {
                var tmp = new MonthRp()
                {
                    Name = c.Key, Count = c.Value.ElementAt(0).count
                };
                for (int i = 0; i < c.Value.Count; i++)
                {
                    tmp.SetMonthValue(i, c.Value[i].experience);
                }
                return(tmp);
            }).ToList();


            var weeks = period.ToWeeksPeriods();
            var days  = period.ToDaysPeriods();

            var dayli_measures = days.Select(date => (date, product.Journeys.Select(d => d.Measure(date)))).ToList();

            foreach (var item in dayli_measures)
            {
                result.Series.Availability.Items.Add(new DatetimeSerieItemModel(item.date.Start, item.Item2.Sum(c => c.AvailabilityDebt)));
                result.Series.Latency.Items.Add(new DatetimeSerieItemModel(item.date.Start, item.Item2.Sum(c => c.LatencyDebt)));
                result.Series.Experience.Items.Add(new DatetimeSerieItemModel(item.date.Start, item.Item2.Sum(c => c.ExperienceDebt)));
            }

            foreach (var item in journeysGroups)
            {
                var measures_weeks = weeks.Select(week => (week, item.Select(c => c.Measure(week))));

                var temp = new DatetimeSerieListModel(item.Key);
                temp.Items.AddRange(measures_weeks.Select(c => new DatetimeSerieItemModel(c.week.Start, c.Item2.Sum(d => d.AvailabilityDebt))).ToList());
                result.Series.AvailabilityDetail.Add(temp);

                var tempLatency = new DatetimeSerieListModel(item.Key);
                tempLatency.Items.AddRange(measures_weeks.Select(c => new DatetimeSerieItemModel(c.week.Start, c.Item2.Sum(d => d.LatencyDebt))).ToList());
                result.Series.LatencyDetail.Add(tempLatency);

                var tempExperience = new DatetimeSerieListModel(item.Key);
                tempExperience.Items.AddRange(measures_weeks.Select(c => new DatetimeSerieItemModel(c.week.Start, c.Item2.Sum(d => d.ExperienceDebt))).ToList());
                result.Series.ExperienceDetail.Add(tempExperience);
            }
            return(result);
        }
 public bool IsAlreadyFlew()
 {
     return(Journeys != null && !Journeys.Any(x => x.DepartureDate > DateTime.UtcNow));
 }