Exemplo n.º 1
0
        internal ReportResult AllSamples(PurseSeineTrip trip)
        {
            var repo = TubsDataService.GetRepository<LengthSample>(MvcApplication.CurrentSession);
            var samples = repo.FilterBy(s => s.Header.Set.Activity.Day.Trip.Id == trip.Id);

            var items =
                from s in samples
                orderby s.Header.Set.SetNumber
                select new LengthSampleLineItem
                {
                    SetDate = s.Header.Set.Activity.LocalTime,
                    Latitude = s.Header.Set.Activity.Latitude, // TODO Numeric
                    Longitude = s.Header.Set.Activity.Longitude, // TODO Numeric
                    Eez = s.Header.Set.Activity.EezCode,
                    Association = s.Header.Set.Activity.SchoolAssociation.HasValue ? s.Header.Set.Activity.SchoolAssociation.Value.ToString() : "Unknown",
                    SetNumber = s.Header.Set.SetNumber.HasValue ? s.Header.Set.SetNumber.Value : -1,
                    SequenceNumber = s.SequenceNumber.HasValue ? s.SequenceNumber.Value : -1,
                    SpeciesCode = s.SpeciesCode,
                    Length = s.Length.HasValue ? s.Length.Value : -1
                };

            var report = new Report(items.ToReportSource());
            report.TextFields.Title = string.Format("Length frequency summary for trip {0}", trip.SpcTripNumber);
            return new ReportResult(report);
        }
Exemplo n.º 2
0
        internal ReportResult Summary(PurseSeineTrip trip)
        {
            // Empty spreadsheet
            if (null == trip || null == trip.SeaDays || 0 == trip.SeaDays.Count)
                return new ReportResult(new Report());

            var activities =
                from d in trip.SeaDays
                from a in d.Activities
                select new ActivityLogLineItem
                {
                    ShipsTime = a.LocalTime.Value,
                    Latitude = a.Latitude,
                    Longitude = a.Longitude,
                    Activity = a.ActivityType.HasValue ? a.ActivityType.Value.ToString() : String.Empty,
                    WindDirection = a.WindDirection,
                    WindSpeed = a.WindSpeed,
                    SeaCode = a.SeaCode.HasValue ? a.SeaCode.Value.ToString() : String.Empty,
                    Comments = a.Comments
                };

            var sets =
                from fset in trip.FishingSets
                select new SetLogLineItem
                {
                    SetNumber = fset.SetNumber,
                    VesselLogDate = fset.Activity.LocalTime.Value,
                    SkiffOff = fset.SkiffOff,
                    WinchOn = fset.WinchOn,
                    RingsUp = fset.RingsUp,
                    BrailStart = fset.BeginBrailing,
                    BrailEnd = fset.EndBrailing,
                    EndOfSet = fset.EndOfSet,
                    SumOfBrails = Sum(fset.SumOfBrail1, fset.SumOfBrail2), // Regular addition operator doesn't work as expected
                    TotalCatch = fset.TotalCatch
                };

            // From here (see jshannon99 response of 9 November)
            // http://doddlereport.codeplex.com/discussions/283107
            var writer = new DoddleReport.OpenXml.ExcelReportWriter();
            var activityReport = new Report(activities.ToReportSource(), writer);
            var setReport = new Report(sets.ToReportSource(), writer);

            // Set up some labels
            activityReport.TextFields.Title = trip.ToString();
            activityReport.RenderHints["SheetName"] = "Activity Log";
            setReport.RenderHints["SheetName"] = "Set Log";

            // TODO:  Consider adding confidentiality footers to the report
            activityReport.AppendReport(setReport);
            return new ReportResult(activityReport, writer);
        }
Exemplo n.º 3
0
        public static Trip ToTrip(this TripHeaderViewModel thvm)
        {
            if (null == thvm)
            {
                return null;
            }

            Trip trip = null;
            switch (thvm.GearCode)
            {
                case "S":
                    trip = new PurseSeineTrip();
                    break;
                case "L":
                    trip = new LongLineTrip();
                    break;
                case "P":
                    trip = new PoleAndLineTrip();
                    break;
                default:
                    // Don't know what kind of trip this is...
                    break;
            }

            // It's not correct to assume that DepartureDate and ReturnDate have values.
            // Yes, they are required, but the caller may pass us an invalid structure
            // here.  Bleah!
            if (null != trip)
            {
                trip.DepartureDate = thvm.DepartureDate;
                if (trip.DepartureDate.HasValue)
                {
                    trip.DepartureTimeOnly = trip.DepartureDate.Value.ToString("HHmm");
                    trip.DepartureDateOnly = thvm.DepartureDate.Value.Subtract(thvm.DepartureDate.Value.TimeOfDay);
                }
                trip.ReturnDate = thvm.ReturnDate;
                if (trip.ReturnDate.HasValue)
                {
                    trip.ReturnTimeOnly = trip.ReturnDate.Value.ToString("HHmm");
                    trip.ReturnDateOnly = thvm.ReturnDate.Value.Subtract(thvm.ReturnDate.Value.TimeOfDay);
                }
                trip.TripNumber = thvm.TripNumber;
                if (Enum.IsDefined(typeof(ObserverProgram), thvm.ProgramCode))
                {
                    trip.ProgramCode = (ObserverProgram)Enum.Parse(typeof(ObserverProgram), thvm.ProgramCode);
                }
                trip.CountryCode = thvm.CountryCode;

                if (Enum.IsDefined(typeof(WorkbookVersion), thvm.Version))
                {
                    trip.Version = (WorkbookVersion)Enum.Parse(typeof(WorkbookVersion), thvm.Version);
                }
            }
            return trip;
        }
Exemplo n.º 4
0
        // This is still a work in progress
        private void AddTripNavbar(PurseSeineTrip tripId)
        {
            var routeValues = new { tripId = tripId.Id };
            IList<NavPill> pills = new List<NavPill>(12);

            pills.Add(new NavPill { Title = "PS-1", Href = Url.Action("Index", "Ps1", routeValues) });

            // Don't display pills for data we know we don't have
            if (!tripId.IsReadOnly || (tripId.IsReadOnly && tripId.VesselAttributes != null))
            {
                pills.Add(new NavPill { Title = "Vessel Characteristics (PS-1)", Href = Url.Action("Index", "Auxiliaries", routeValues) });
            }
            if (!tripId.IsReadOnly || (tripId.IsReadOnly && tripId.WellContent.Count > 0))
            {
                pills.Add(new NavPill { Title = "Well Contents (PS-1)", Href = Url.Action("Index", "WellContent", routeValues) });
            }
            if (!tripId.IsReadOnly || (tripId.IsReadOnly && tripId.VesselNotes != null))
            {
                pills.Add(new NavPill { Title = "Vessel Comments (PS-1)", Href = Url.Action("Index", "WellContent", routeValues) });
            }
            if (!tripId.IsReadOnly || (tripId.IsReadOnly && tripId.Crew.Count > 0))
            {
                pills.Add(new NavPill { Title = "Crew (PS-1)", Href = Url.Action("Index", "Crew", routeValues) });
            }
        }
Exemplo n.º 5
0
        /*
         * List of all PS-4 pages for a trip:
         * /Trip/{tripId}/PS-4/
         *
         * Direct link to a PS-4 page
         * /Trip/{tripId}/PS-4/{setNumber}/{pageNumber}/Index
         *
         * Edit link to a PS-4 page
         * /Trip/{tripId}/PS-4/{setNumber}/{pageNumber}/Edit
         *
         * Add a new PS-4 to a set
         * /Trip/{tripId}/PS-4/{setNumber}/Add
         */
        /// <summary>
        /// 
        /// </summary>
        /// <param name="trip">Current trip</param>
        /// <param name="setNumber">Set number within the trip</param>
        /// <param name="pageNumber">Page number within 'group' of PS-4 pages for this set</param>
        /// <returns></returns>
        internal ActionResult ViewActionImpl(PurseSeineTrip trip, int setNumber, int pageNumber)
        {
            int maxSets = trip.FishingSets.Count();
            if (setNumber > maxSets)
            {
                // This isn't like set, where someone can use
                // setNumber = 999 to get to the last set.
                // For now, redirect to List, but a better response is probably called for
                return RedirectToAction("List", new { tripId = trip.Id });
            }

            var repo = TubsDataService.GetRepository<PurseSeineSet>(MvcApplication.CurrentSession);

            var fset =
                repo.FilterBy(
                    s => s.Activity.Day.Trip.Id == trip.Id && s.SetNumber == setNumber
                ).FirstOrDefault();

            // Shouldn't happen, but then again...
            if (null == fset)
                return RedirectToAction("List", new { tripId = trip.Id });

            // We can (and should) be lenient on page number
            int maxPages = fset.SamplingHeaders.Count;

            if (pageNumber > maxPages)
                pageNumber = maxPages;

            var header = fset.SamplingHeaders.Skip(pageNumber - 1).Take(1).FirstOrDefault();
            if (null == header)
                return RedirectToAction("List", new { tripId = trip.Id });

            var vm = Mapper.Map<LengthSamplingHeader, LengthFrequencyViewModel>(header);
            vm.ActionName = CurrentAction;

            if (IsApiRequest)
                return GettableJsonNetData(vm);

            if (IsIndex)
                return View(vm);

            return View("_Editor", vm);
        }
Exemplo n.º 6
0
 public void GetMetricsForNewTrip()
 {
     var trip = new PurseSeineTrip();
     Assert.AreEqual(0, trip.Cpue);
     Assert.AreEqual(0, trip.VesselDays);
 }