예제 #1
0
        /*
         * private static void squeezeHorseThenAdd(PageDetail curr, Horse entry, double entryHeight, double depthNotYetUsed)
         * {
         *
         * double shrinkFactor = Constants.PageHeight / ( Constants.PageHeight - depthNotYetUsed + entryHeight);
         * // 1a. srink existing entries. list of header+firsthorse
         * if (curr.seeHeaderAndFirstHorseList != null)
         * {
         *    curr.seeHeaderAndFirstHorseList.ForEach(hf => {
         *       hf.header.newHeight = shrinkFactor * hf.header.height;
         *       hf.firstHorse.newHeight = shrinkFactor * hf.firstHorse.height;
         *    });
         * }
         * //1b. other horses
         * curr.secondAndNextHorses.ForEach(h => h.newHeight = shrinkFactor * h.height);
         * //2. shrink current|last horse, add page statistic. Then add the horse to page
         * entry.newHeight = shrinkFactor * entry.height;
         * curr.runningDepth = Constants.PageHeight;
         * curr.depthNotYetUsed = 0;
         * entry.positionOnPage.leftspaceatEnd = curr.depthNotYetUsed;
         * curr.entryCount = curr.entryCount + 1;
         * entry.pgno = curr.pgNum;
         * curr.secondAndNextHorses.Add(entry);
         *
         * }
         */
        private static void squeezeHeaderFirsthorseThenAdd(PageDetail curr, HeaderAndFirstHorse hf, double entryHeight, double depthNotYetUsed)
        {
            double shrinkFactor = Constants.PageHeight / (Constants.PageHeight - depthNotYetUsed + entryHeight);


            //1. srink existing secondAndNextHorses list
            curr.secondAndNextHorses.ForEach(h => h.newHeight = shrinkFactor * h.height);
            //2. srink existing shrink header items
            if (curr.seeHeaderAndFirstHorseList != null)
            {
                curr.seeHeaderAndFirstHorseList.ForEach(entry => {
                    entry.firstHorse.newHeight = shrinkFactor * entry.firstHorse.height;
                    entry.header.newHeight     = shrinkFactor * entry.header.height;
                });
            }
            //3. shrink HeaderAndFirstHorse before putting
            hf.firstHorse.newHeight = shrinkFactor * hf.firstHorse.height;
            hf.header.newHeight     = shrinkFactor * hf.firstHorse.height;
            //addd the hf to page
            curr.addHeaderAndFirstHorse(hf);
            //set the page statistic
            curr.runningDepth    = Constants.PageHeight;
            curr.depthNotYetUsed = 0;
            hf.firstHorse.positionOnPage.leftspaceatEnd = curr.depthNotYetUsed;
            curr.isthereAheader = true;
            curr.entryCount     = curr.entryCount + 2;
            //calling method responsible to set as last entry on page
        }
예제 #2
0
        private List <Race <Horse> > prepInput(List <CardStruct.Race> praces) //***
        {
            List <Race <Horse> > raceList = new List <Race <Horse> >();

            foreach (CardStruct.Race race in praces)
            {
                Race <Horse> cRace = new Race <Horse>();

                //secure header & 1st horse
                CardStruct.HorseOrHeader header               = race.allHorsesWithRaceHeader[0];
                CardStruct.HorseOrHeader firstHorse           = race.allHorsesWithRaceHeader[1];
                HeaderAndFirstHorse      headerWithFirstHorse = new HeaderAndFirstHorse(new Header(header), new Horse(firstHorse));
                cRace.setRaceTop(headerWithFirstHorse);

                //next usual iteration below
                for (int i = 2; i < race.allHorsesWithRaceHeader.Count; i++)
                {
                    cRace.addHorse(new Horse(race.allHorsesWithRaceHeader[i]));
                }

                raceList.Add(cRace);
            }
            Horse lastHorseOfCard = raceList.Last().secondAndOtherHorseList.Last();

            lastHorseOfCard.IsLastHorseOfTheCard = true;
            return(raceList);
        }
예제 #3
0
        private static void shrinkHorsesOnPagetoAddaHeader1stHorse(PageDetail curr, HeaderAndFirstHorse hf, double entryHeight, double depthNotYetUsed)
        {
            double shrinkFactor = Constants.PageHeight / (Constants.PageHeight - depthNotYetUsed + entryHeight);

            //1a. shrink existing entries. start with second list (only horses)
            curr.secondAndNextHorses.ForEach(h => h.newHeight = shrinkFactor * h.height);
            //1b. shrink existing entries. header+firsthorse list
            if (curr.seeHeaderAndFirstHorseList != null)
            {
                curr.seeHeaderAndFirstHorseList.ForEach(ahf =>
                {
                    ahf.header.newHeight     = shrinkFactor * ahf.header.height;
                    ahf.firstHorse.newHeight = shrinkFactor * ahf.firstHorse.height;
                });
            }
            //2. shrink new entry (hf). set page level and hf level statistics, set as last entry. Add to page (on header+firsthorse list)
            hf.header.newHeight     = shrinkFactor * hf.header.height;
            hf.firstHorse.newHeight = shrinkFactor * hf.firstHorse.height;
            curr.isthereAheader     = true;
            curr.runningDepth       = Constants.PageHeight;
            curr.depthNotYetUsed    = 0;
            hf.firstHorse.positionOnPage.leftspaceatEnd = curr.depthNotYetUsed;
            hf.firstHorse.positionOnPage.where          = EntryLocationOnPage.LastEntryOnPage;
            hf.firstHorse.pgno = curr.pgNum;
            curr.addHeaderAndFirstHorse(hf);
            curr.entryCount = curr.entryCount + 2;
        }
        public StitchedFinalPdf generatePdfCard(int numTracks)
        {
            //tracks total = 6 through 12.
            //28,29,30,32 leaves
            StitchedFinalPdf pdfData = new StitchedFinalPdf();

            Console.WriteLine("---pdf card for  " + numTracks + " tracks -----");

            for (int t = 1; t <= numTracks; t++)
            {
                Console.Write("================track-" + t + "==================");

                int raceCount = numberOfRacesPerTrack();
                for (int r = 1; r <= raceCount; r++)
                {
                    Console.Write("     race-" + r + ">>>>>> ");
                    int horseCount = numberOfHorsePerRace();
                    //process header and 1st horse
                    int[] conjugate = generateHeaderAnd1stdHorseDepth();
                    HeaderAndFirstHorse headerAndFirstHorse_v = new HeaderAndFirstHorse(new Header(conjugate[0], "", "", r, "", true), new Horse(GeneatingFunction.HorseSequence, conjugate[1], "", "", r, "", true, false, false));
                    //process 2nd horse onward
                    for (int h = 2; h <= horseCount; h++)
                    {
                        int depth = generateFrom2ndHorseDepth();
                        Console.Write("horse-" + h + " height=" + depth + " | ");
                    }
                    Console.WriteLine();
                    //spacer if needed. calculation
                }
            }
            return(pdfData);
        }
예제 #5
0
        private static void funcCreateRaceDelegatePrint()
        {
            HeaderAndFirstHorse header_1sthorse = new HeaderAndFirstHorse(new Header(110, "", "", 1, "", true), new Horse(GeneatingFunction.HorseSequence, 180, "", "", 1, "", true, false, false));
            Race <Horse>        r  = (new Race <Horse>()).setRaceTop(header_1sthorse).addHorse(new Horse(GeneatingFunction.HorseSequence, 102, "", "", 1, "", false, false, false)).addHorse(new Horse(GeneatingFunction.HorseSequence, 104, "", "", 1, "", false, false, false)).addHorse(new Horse(GeneatingFunction.HorseSequence, 106, "", "", 1, "", false, false, false)).addHorse(new Horse(GeneatingFunction.HorseSequence, 108, "", "", 1, "", false, true, true));
            string raceDescription = getStringOf_Race(r);

            Console.WriteLine("Race description: " + raceDescription);
            Console.WriteLine("This is end.");
        }
예제 #6
0
 internal void addHeaderAndFirstHorse(HeaderAndFirstHorse hf)
 {
     if (headerAndFirstHorseList == null)
     {
         headerAndFirstHorseList = new List <HeaderAndFirstHorse>();
         headerAndFirstHorseList.Add(hf);
     }
     else
     {
         //has already one header
         headerAndFirstHorseList.Add(hf);
     }
 }
예제 #7
0
 private static void fitHeaderWithFirstHorse(PageDetail curr, HeaderAndFirstHorse hf)
 {
     if (curr.depthNotYetUsed == Config.Constants.PageHeight)
     {
         hf.firstHorse.positionOnPage.where = EntryLocationOnPage.FirstEntryOnPage;
     }
     curr.isthereAheader = true;
     curr.addHeaderAndFirstHorse(hf);
     curr.runningDepth    = curr.runningDepth + hf.header.height + hf.firstHorse.height;
     curr.depthNotYetUsed = curr.bottom - curr.runningDepth;
     hf.firstHorse.positionOnPage.leftspaceatEnd = curr.depthNotYetUsed;
     curr.entryCount    = curr.entryCount + 2;
     hf.firstHorse.pgno = curr.pgNum;
 }
        public StitchedFinalPdf generateAPdfStructure(int numTracks)
        {
            //tracks total = 5 through 12.
            //28,29,30,32 leaves
            // track count = 1
            StitchedFinalPdf pdfData = new StitchedFinalPdf();

            Console.WriteLine("---pdf card for  " + numTracks + " tracks -----");

            for (int t = 1; t <= numTracks; t++)
            {
                Track track = new Track();
                Console.Write("================track-" + t + "==================");

                int raceCount = numberOfRacesPerTrack();
                for (int r = 1; r <= raceCount; r++)
                {
                    Console.Write("     race-" + r + ">>>>>> ");
                    Race <Horse> race       = new Race <Horse>();
                    int          horseCount = numberOfHorsePerRace();
                    //process header and 1st horse
                    int[] conjugate        = generateHeaderAnd1stdHorseDepth();
                    HeaderAndFirstHorse hf = new HeaderAndFirstHorse(new Header(conjugate[0], "", "", r, "", true), new Horse(GeneatingFunction.HorseSequence, conjugate[1], "", "", r, "", true, false, false));
                    race = race.setRaceTop(hf);

                    //process 2nd horse onward
                    for (int h = 2; h <= horseCount; h++)
                    {
                        int depth = generateFrom2ndHorseDepth();
                        //Horse horse2on = new Horse(height);
                        //horse2.spCount = 0; auto initialize to 0
                        race = race.addHorse(new Horse(GeneatingFunction.HorseSequence, depth, "", "", r, "", false, false, false)); //adding horses on race **********1
                        Console.Write("horse-" + h + " height=" + depth + " | ");
                    }//horse-for
                    Console.WriteLine();
                    track = track.addRace(race);   //adding races to track *************************2
                }//race-for
                pdfData = pdfData.addTrack(track); //adding track to pdf ************************3
            }//track-for

            Horse lastHorse = pdfData.trackList.Last().raceList.Last <Race <Horse> >().secondAndOtherHorseList.Last <Horse>();

            lastHorse.IsLastHorseOfTheCard = true;
            return(pdfData);
        }
예제 #9
0
        private void shrinkFitAHeader1stHorseAtTheBottom(PageDetail curr, HeaderAndFirstHorse hf) // if needed only <= 10 dots
        {
            if (curr.depthNotYetUsed == Constants.PageHeight)
            {
                hf.firstHorse.positionOnPage.where = EntryLocationOnPage.FirstEntryOnPage;
            }
            double spaceToShrinkPerEntry = (hf.header.height + hf.firstHorse.height - curr.depthNotYetUsed) / 2;

            hf.header.newHeight     = hf.header.newHeight - spaceToShrinkPerEntry;
            hf.firstHorse.newHeight = hf.firstHorse.newHeight - spaceToShrinkPerEntry;
            curr.addHeaderAndFirstHorse(hf);
            curr.runningDepth    = Constants.PageHeight;
            curr.depthNotYetUsed = curr.bottom - curr.runningDepth;
            hf.firstHorse.positionOnPage.leftspaceatEnd = curr.depthNotYetUsed;
            curr.entryCount    = curr.entryCount + 2;
            hf.firstHorse.pgno = curr.pgNum;
            hf.firstHorse.positionOnPage.where = EntryLocationOnPage.LastEntryOnPage;
        }
예제 #10
0
        //00000000000000000000--- MOST REFINED begin---000000000000000000000000000
        public List <PageDetail> useOptimalSpace(List <Race <Horse> > listOfRace) //mimicked after tryPageCalculation() and enhanced
        {
            string raceStr = "";

            listOfRace.ForEach(r => raceStr += r);
            log.Info("PRE:" + raceStr);
            log.Info("@@@@@@@@@@@@@@@@@@@@@@Begin . . . useOptimalSpace ...PageDetail . . . . .1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            List <PageDetail> pages   = new List <PageDetail>();
            PageDetail        firstPg = new PageDetail(++pgNumAtLastline);

            pages.Add(firstPg);

            for (int r = 0; r < listOfRace.Count; r++)
            {
                Race <Horse> arace = listOfRace[r];
                //---------- fit header & 1st horse ----------------
                HeaderAndFirstHorse hf   = arace.headerFirstHorse;
                PageDetail          curr = pages.Last <PageDetail>();

                if ((hf.header.height + hf.firstHorse.height) > Constants.PageHeight)
                {
                    Debug.Print("LARGE_ENTRY::header and firsthorse is bigger than pageHeight" + hf);
                    fitA_header_with_Large_1sthorse(curr, hf, pages);
                }
                else if (curr.depthNotYetUsed >= (hf.header.height + hf.firstHorse.height))
                {
                    fitHeaderWithFirstHorse(curr, hf);
                }
                else if ((curr.depthNotYetUsed + Constants.SHRINK_THRESHOLD_ONE_HORSE + 1) > (hf.header.height + hf.firstHorse.height))
                {
                    //shrink and fit a head and firsthorse
                    //shrinkFitAHeader1stHorseAtTheBottom(curr, hf);
                    shrinkHorsesOnPagetoAddaHeader1stHorse(curr, hf, (hf.firstHorse.height + hf.header.height), curr.depthNotYetUsed);
                }
                else //hf does not fit at the bottom. So do 3 tasks: (1) mark last horse on page. (2) add a page. (3) fit hf for new race
                {
                    markLastHorseOnPage(curr); //(1) //override here
                    pages.Add(new PageDetail(++pgNumAtLastline)); //(2)
                    curr = pages.Last <PageDetail>();
                    fitHeaderWithFirstHorse(curr, hf);            //(3)
                }
                //-------- fit 2nd and other horses ----------
                for (int h = 0; h < arace.secondAndOtherHorseList.Count; h++)
                {
                    Horse ahorse = arace.secondAndOtherHorseList[h];
                    curr = pages.Last <PageDetail>();

                    if (ahorse.height > Constants.PageHeight)
                    {
                        Debug.Print("LARGE_ENTRY::horse [not 1st one] is bigger than pageHeight" + ahorse);
                        fitA_Large_horse(curr, ahorse, pages);
                    }
                    else if (curr.depthNotYetUsed >= ahorse.height)
                    {
                        fitAHorse(curr, ahorse);
                    }

                    else if ((curr.depthNotYetUsed + Constants.SHRINK_THRESHOLD_ONE_HORSE + 1) > ahorse.height)
                    {
                        //shrink and fit a horse
                        //shrinkFitAHorseAtTheBottom(curr, ahorse);
                        shrinkHorsesOnPagetoAddaHorse(curr, ahorse, ahorse.height, curr.depthNotYetUsed);
                    }

                    else //horse height is larger than leftover space
                    {
                        //1. mark last horse on page. 2. Next, add a new page. 3. Fit h at new pg
                        markLastHorseOnPage(curr);                    //1
                        pages.Add(new PageDetail(++pgNumAtLastline)); //2
                        curr = pages.Last <PageDetail>();
                        fitAHorse(curr, ahorse);                      //3
                    }
                }
            }

            log.Info("see how it lays:");
            pages.ForEach(p => log.Info("debug<< " + p));
            log.Info("end debug:");

            if ((pages.Last().entryCount == 1) && pages.Last().secondAndNextHorses.Last().height < Constants.PageHeight / 3)
            {
                saveAPagebyshrinkLastHorseOfCard(pages);
            }
            //sparse must be after shrinkage
            sparseEntrieseOnSomePage(pages);

            //pages.ForEach(p => log.Info("debug<< " + p));
            return(pages);
        }
예제 #11
0
        private void fitA_header_with_Large_1sthorse(PageDetail curr, HeaderAndFirstHorse hf, List <PageDetail> pages)
        {
            if (curr.depthNotYetUsed == Constants.PageHeight)
            {
                hf.firstHorse.positionOnPage.where = EntryLocationOnPage.FirstEntryOnPage;
            }
            //decision 1: if space left does not fillup header + (1 x header height of horse content) give page break and start laying hf on next page
            if (curr.depthNotYetUsed < 2 * hf.header.height)
            {
                //don't layout. give page break. start on a brand new page
                markLastHorseOnPage(curr);
                //create new page below and start laying out
                int partiallyUsedBeginpage = 0;                                                                                       // partly filled initial page is none
                //brand new pages
                int middlePageCount  = Convert.ToInt16(Math.Floor((hf.firstHorse.height + hf.header.height) / Constants.PageHeight)); // 1 or more
                int endPageCount     = (((hf.header.height + hf.firstHorse.height) % Config.Constants.PageHeight) > 0) ? 1 : 0;       // 0 or 1
                int totalPageSpanned = partiallyUsedBeginpage + middlePageCount + endPageCount;
                Debug.Print("Header-first-horse begins on new page totalPageSpanned: " + totalPageSpanned);
                double contentGoesOnBeginPage = 0; // because started on a brand new page [notion: middle page filling up full-height]
                for (int i = 1; i <= middlePageCount; i++)
                {
                    PageDetail midPg = new PageDetail(++pgNumAtLastline);
                    pages.Add(midPg);
                    midPg.runningDepth    = Constants.PageHeight;
                    midPg.depthNotYetUsed = 0;
                    if (i == 1)
                    {
                        midPg.doesVeryLargeHorseBegin = true;
                    }
                    else
                    {
                        midPg.doesVeryLargeHorseMiddle = true;
                    }
                    if ((endPageCount == 0) && (i == middlePageCount))
                    { //horse fit at the endline of this page: use case 1
                        midPg.addHeaderAndFirstHorse(hf);
                        hf.firstHorse.positionOnPage.leftspaceatEnd = 0;
                        midPg.doesVeryLargeHorseEnd = true;
                        midPg.entryCount            = midPg.entryCount + 2;
                        hf.firstHorse.pgno          = midPg.pgNum;
                    }
                }//for
                // if block when horse fills up part of a ending page
                if (endPageCount == 1) // has an ending page. usecase: horse fit on a last page but has space at the end
                {
                    PageDetail lastPg = new PageDetail(++pgNumAtLastline);
                    pages.Add(lastPg);
                    lastPg.addHeaderAndFirstHorse(hf);
                    lastPg.runningDepth          = lastPg.runningDepth + (hf.header.height + hf.firstHorse.height - contentGoesOnBeginPage - (middlePageCount * Constants.PageHeight));
                    lastPg.depthNotYetUsed       = lastPg.bottom - lastPg.runningDepth;
                    lastPg.doesVeryLargeHorseEnd = true;
                    hf.firstHorse.positionOnPage.leftspaceatEnd = lastPg.depthNotYetUsed;
                    hf.firstHorse.pgno = lastPg.pgNum;
                    lastPg.entryCount  = lastPg.entryCount + 2;
                }
            }
            else
            {
                //start laying on begin page because has enough space for header and good size of first horse content
                // TO-DO
                int endPageCount           = (((hf.header.height + hf.firstHorse.height - curr.depthNotYetUsed) % Config.Constants.PageHeight) > 0) ? 1 : 0;       // 0 or 1
                int middlePageCount        = Convert.ToInt16(Math.Floor((hf.firstHorse.height + hf.header.height - curr.depthNotYetUsed) / Constants.PageHeight)); // 1 or more
                int partiallyUsedBeginpage = 1;
                int totalPageSpanned       = partiallyUsedBeginpage + middlePageCount + endPageCount;
                Debug.Print("Header-first-horse begins on existing page totalPageSpanned: " + totalPageSpanned);
                double contentGoesOnBeginPage = curr.depthNotYetUsed;
                //on beginning page no header or horse statistics. Wait to give on to the last page
                curr.runningDepth            = Constants.PageHeight;
                curr.depthNotYetUsed         = 0;
                curr.doesVeryLargeHorseBegin = true;

                //full middle pages
                for (int i = 1; i <= middlePageCount; i++)
                {
                    PageDetail midPg = new PageDetail(++pgNumAtLastline);
                    pages.Add(midPg);
                    midPg.runningDepth             = Constants.PageHeight;
                    midPg.depthNotYetUsed          = 0;
                    midPg.doesVeryLargeHorseMiddle = true;
                    if ((endPageCount == 0) && (i == middlePageCount))
                    { //horse fit at the endline of this page: use case 1
                        midPg.addHeaderAndFirstHorse(hf);
                        hf.firstHorse.positionOnPage.leftspaceatEnd = 0;
                        midPg.doesVeryLargeHorseEnd = true;
                        midPg.entryCount            = midPg.entryCount + 2;
                        hf.firstHorse.pgno          = midPg.pgNum;
                    }
                }
                // if block when horse occupies part of a ending page
                if (endPageCount == 1) // has an ending page. usecase: horse fit on a last page but has space at the end
                {
                    PageDetail lastPg = new PageDetail(++pgNumAtLastline);
                    pages.Add(lastPg);
                    lastPg.addHeaderAndFirstHorse(hf);
                    lastPg.runningDepth          = lastPg.runningDepth + (hf.header.height + hf.firstHorse.height - contentGoesOnBeginPage - (middlePageCount * Constants.PageHeight));
                    lastPg.depthNotYetUsed       = lastPg.bottom - lastPg.runningDepth;
                    lastPg.doesVeryLargeHorseEnd = true;
                    hf.firstHorse.positionOnPage.leftspaceatEnd = lastPg.depthNotYetUsed;
                    hf.firstHorse.pgno = lastPg.pgNum;
                    lastPg.entryCount  = lastPg.entryCount + 2;
                }
            }
        }