How to create a cleaning roster with Bash?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
bpuppy
Posts: 14
Joined: Tue 25 Apr 2017, 13:03
Location: Quebec

How to create a cleaning roster with Bash?

#1 Post by bpuppy »

I have to create a cleaning roster for an appartment building and would like to automate it with GNU bash if possible.

Requirements:
The tenants have to clean the corridor on their floor every week.
The cycle starts on Feb. 11, 2019 and lasts for 30 weeks (10x3).
There are 4 floors to my building.
There are 10 tenants capable of doing the task per floor.
The names of the tenants are in the 3rd column of the file tenants.csv, (sep=|).
The 1st column contains the appartment number which if it starts with a 2, such as in 214 means they are located on Floor number 2.

I'd like to generate the dates automatically (maybe from the Date command week number %V which is starting on mondays) and merge in the names of the tenants from the csv file. Use of the date command and %V is way more complicated than I am used to. I don't know how to tackle this. :?:

Desired Output (sample taken from the 2018 roster):
Attachments
snap-019.jpg
(8.69 KiB) Downloaded 281 times

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#2 Post by fabrice_035 »

Hey,

My idea, use https://www.google.com/sheets/about/ https://www.google.com/sheets/about/

And search a forum to talk about if you a newbie :wink:

Regard
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#3 Post by some1 »

You explained the problem very well.

I noticed that:
1) You operate with 10 workers.
2) Apartment-number can be 214.

Q: Can you have more tenants per floor -
than those enrolled to work?
If so - we need a creteria/filter to extract
the doers from the tenants.csv-file.
---
Its a busy evening around here - so I have to leave -
but will be back with the date-solution(s).
Could you sketch how you intend to code the solution -
my hunch is that you are acquainted with arrays/is a coder.

Anyway - Merry Christmas.

User avatar
bpuppy
Posts: 14
Joined: Tue 25 Apr 2017, 13:03
Location: Quebec

#4 Post by bpuppy »

Hi some1 and fabrice,
Q: Can you have more tenants per floor -
than those enrolled to work?
If so - we need a creteria/filter to extract
the doers from the tenants.csv-file.
Yes, we do have more tenants but they are not capable of doing the job due to old age or handicaps. But i have a csv list of names of only those capable as they change very little from 1 cycle to the other.

So the merging of names to the dates and floors will be a matter of using awk properly.

What really bugs me, is how do i translate the date command %V (because the week starts on Mondays) as such:

`date +%V` gives the week number but i need it to give me the reverse to determine the 3 dates for Mrs.X, as they must be week 06, week 16 and week 26, so that week 16 = Apr 15 and that week 26 = Jun 24. Thus, my first line would be:

Feb 11, Apr 15, Jun 24 Mrs.X Mr.Y Ms.XX Mr.YY

I could start coding using vars such as [date_01..date_30] and replace them later by their real values if we figure out how to get those dates. Maybe, it's impossible with the 'date' command... i wonder.

Anyhow, like you say, these are busy days for all and i have at least 6-8 weeks before the roster is needed (though i will do it manually if no solution comes to mind.)
It's just a challenge i wanted to do for the fun of it. I love using bash and yad, i always want to know more!

Thanks for your reply and Merry Christmas to both of you :D

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

bpuppy wrote: they must be week 06, week 16 and week 26, so that week 16 = Apr 15 and that week 26 = Jun 24. Thus, my first line would be:

Feb 11, Apr 15, Jun 24 Mrs.X Mr.Y Ms.XX Mr.YY
Shouldn't your cycle start on Feb 4 2019?
I think you mixed up the years:

Code: Select all

# date -d "2/11/2018" +%V
06
# date -d "2/11/2019" +%V
07
# date -d "2/4/2019" +%V 
06
I also wonder why you insist on using the %V option. You know the start day of the cycle and you know that a week has 7 days. What would you need the ISO week number for?

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#6 Post by 6502coder »

Here's a quick-and-dirty attempt at a solution.
Just bash, the date command, and some awk.

Edit: I see I forgot to rename "doit.sh" to the intended name "hallduty.sh"; too much eggnog! ("doit.sh" is my generic name for nonce scripts). Fixed now.
Attachments
hallduty.zip
Unzip anywhere convenient. Read the Readme.txt
(2.16 KiB) Downloaded 99 times

User avatar
bpuppy
Posts: 14
Joined: Tue 25 Apr 2017, 13:03
Location: Quebec

#7 Post by bpuppy »

@MochiMoppel

Thanks for pointing that out.

After checking back on the 2019 calendar year, i can see why i said week 6. %V is said to start weeks on Mondays. If you check on January 2019, we find that the 1st falls on a Tuesday, thus making Feb. 11, 2019 equal to week 6 while in reality it is week 7.

I will make the adjustment.
Cordially

User avatar
bpuppy
Posts: 14
Joined: Tue 25 Apr 2017, 13:03
Location: Quebec

hallduty script

#8 Post by bpuppy »

@6502coder,

Super Awsome. Exactly what i was looking for. BTW, you are an excellent problem solver. I'll take the week in my spare time to analyze it thouroughly :D

Once i get it all, i'll make some kind of template to merge the info to some final presentation format. With the dates all figured out, i should not have much trouble with that.

Cheers!

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#9 Post by 6502coder »

Thanks, glad to help. I enjoy taking on a problem as I almost always learn something in the process, even if I'm unsuccessful.

BTW the caveat implying that the script doesn't work across a year-end boundary can be ignored. It's a left-over from an early version of the script. The present version should handle such cases; e.g. changing the "week" parameter in the function "makeDates" from 7 to 41 gives a schedule that starts Oct 7, 2019 and extends well into 2020.

User avatar
mikeslr
Posts: 3890
Joined: Mon 16 Jun 2008, 21:20
Location: 500 seconds from Sol

#10 Post by mikeslr »

Misread your post's title. (':oops:')
Thought this problem had been solved long ago. (':shock:')

Suggest the assignment sheets advise that those assigned can trade dates for doing the cleaning with others, but that the person assigned will be responsible for the cleaning on the date assigned. The ability of the tenants to exchange their actual cleaning date makes an assignment less arbitrary. Spelling out the significance of a trade saves you from having to do the juggling when something occurs (illness, vacation...) or mediating disputes as to who was responsible for the work not being done when there was a trade.
Attachments
hen-on-egg.jpg
Step 3 in creating rooster
(66.48 KiB) Downloaded 106 times

Post Reply