Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

C# pickle

  • 03-06-2015 09:19AM
    #1
    Registered Users, Registered Users 2 Posts: 1,842 ✭✭✭


    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, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 1,842 ✭✭✭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, Registered Users 2 Posts: 12,027 ✭✭✭✭Giblet


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


  • Registered Users, Registered Users 2 Posts: 11,094 ✭✭✭✭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, Registered Users 2 Posts: 1,842 ✭✭✭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, Registered Users 2 Posts: 1,842 ✭✭✭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, Registered Users 2 Posts: 2,157 ✭✭✭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, Registered Users 2 Posts: 1,842 ✭✭✭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, Registered Users 2 Posts: 2,157 ✭✭✭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, Registered Users 2 Posts: 1,842 ✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭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