Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# pickle

Options
  • 03-06-2015 10:19am
    #1
    Registered Users Posts: 1,830 ✭✭✭


    I'm querying a table which has a 0/1 (true/false) delivery indicator for each weekday. I need to store the delivery cycles.

    delivery cycle = (delivery day + 1) to next deliveryday

    E.g

    MO 1
    TU 1
    WE 1
    TH 0
    FR 0
    SA 0
    SO 0

    Cycle 1 = Tuesday only
    Cycle 2 = Wednesday only
    Cycle 3 = Thursday + Friday + Saturday + Sunday + Monday

    Can't get my head around a suitable routine to return this. Any ideas?


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Not entirely sure I understand the question, but from what I can gather, given a specific day you want to calculate when the delivery will occur? E.g. Given a Tuesday, you say the delivery will occur on Wednesday. Given a Friday, it returns Monday?


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    seamus wrote: »
    Not entirely sure I understand the question, but from what I can gather, given a specific day you want to calculate when the delivery will occur? E.g. Given a Tuesday, you say the delivery will occur on Wednesday. Given a Friday, it returns Monday?

    I need a routine to store all the possible delivery cycles. E.g using the example data I gave, the routine should return/store the 3 cycles at the bottom of the example.


  • Registered Users Posts: 11,977 ✭✭✭✭Giblet


    Domain language is confusing, what is the definition of a cycle.


  • Registered Users Posts: 10,493 ✭✭✭✭28064212


    Yeah, it's not clear at all what you're looking for. Why does Cycle 3 include Monday but not Tuesday or Wednesday? If, in your example, Tuesday was a 0, what would the cycles be?

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    Giblet wrote: »
    what is the definition of a cycle.

    delivery cycle = (delivery day + 1) to next deliveryday

    Using example data;

    delivery cycle 1 = (Monday + 1 day) to Tuesday
    delivery cycle 1 = Tuesday to Tuesday
    delivery cycle 1 = Tuesday


  • Advertisement
  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    28064212 wrote: »
    Why does Cycle 3 include Monday but not Tuesday or Wednesday?

    delivery cycle = (delivery day + 1) to next deliveryday

    Cycle 3 = (Wednesday + 1 day) to next delivery-day (Monday)
    Cycle 3 = Thursday-Monday


  • Registered Users Posts: 2,145 ✭✭✭dazberry


    MO 1
    TU 1
    WE 1
    TH 0
    FR 0
    SA 0
    SO 0

    Cycle 1 = Tuesday only
    Cycle 2 = Wednesday only
    Cycle 3 = Thursday + Friday + Saturday + Sunday + Monday

    What cycles would you get from:

    MO 1
    TU 1
    WE 0
    TH 1
    FR 0
    SA 0
    SO 0

    D.


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    dazberry wrote: »
    What cycles would you get from:

    MO 1
    TU 1
    WE 0
    TH 1
    FR 0
    SA 0
    SO 0

    D.

    delivery cycle = (delivery day + 1) to next deliveryday

    cycle 1 = (Monday + 1) to Tuesday
    cycle 1 = Tuesday

    cycle 2 = (Tuesday+ 1) to Thursday
    cycle 2 = Wednesday+Thursday

    cycle 3 = (Thursday + 1) to Monday
    cycle 3 = Friday+Saturday+Sunday+Monday


  • Registered Users Posts: 2,145 ✭✭✭dazberry


    Thanks, what cycles would you get from this also?

    MO 1
    TU 0
    WE 1
    TH 0
    FR 1
    SA 0
    SO 0

    D.


  • Registered Users Posts: 1,830 ✭✭✭CountingCrows


    Solved it. Key function I needed was to loop through the week starting on a specific day, in the this case the Delivery day + 1.
    DayOfWeek startDayPlusOne = startDay + 1;
    
    var daysOfWeek = Enum.GetValues(typeof(DayOfWeek))
                .OfType<DayOfWeek>()
                .OrderBy(day => day < startDayPlusOne);
    
    foreach (DayOfWeek day in daysOfWeek)
    {                
    [INDENT]foreach (DeliveryDay nextDelivery in deliveryDays)[/INDENT]
    [INDENT]{[/INDENT]
    

    Note to self - writing out a problem with other viewers in mind is a great way to take a step back as opposed to banging away with code!


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    This is one of those problems that there are multiple ways of doing this but most of them extremely ugly. I spent about 30 minutes doing various solution on this, all too ugly to post up here :p

    Note to self, sometimes code doesn't have to be pretty.


Advertisement