Improvement of the tool to extract members of Beyond Lunch

table of contents
- 1 Requirements
- 2 ① Allows you to specify the month
- 3 ② Make it possible to save (load) the lottery data
- 4 ③ After selecting the month for which the lottery has been drawn, the determined group will be displayed
- 5 ④ Avoid having the same members as the previous month (as much as possible)
- 6 summary
- 7 lastly
Thank you for your hard work.
This is Matsuyama from the System Development Department.
Last time, I created a simple tool for grouping Beyond Lunch. You can
the previous blog here.
Thanks to this, I received a lot of gratitude from the members of the Organizational Culture Committee. (Imagination)
However, President Haraoka pointed out to me, sternly but kindly, that simply grouping people randomly was not enough,
so I'll try to improve it a bit more. (Reality)
Requirements
① Since it will be held every month, you will be able to specify the month.
② You will be able to save (load) the lottery data.
③ Once you select the month for which the lottery has been held, the determined group will be displayed.
④ Make sure that the same members as the previous month do not overlap (as much as possible).
*Updated to Unity 2019.4.18f1 (LTS)
It's something like this.
In terms of Unity functionality, you'll probably need to use PlayerPrefs for steps ② and ③.
The rest is up to the program.
① Allows you to specify the month
Last time, we created a lottery button, so now we'll add a UI (Button and Text) to specify the month.
It will look something like this.

For the date, you can use System.DateTime, so get the current date and time at startup and
update it with AddMonth() using the left and right buttons (◀︎ / ▶︎).
Since only the year and month will be displayed, set the year and month to Text.
Next, let's review the screen size.
The default resolution for WebGL is 960x600, but we can change it in ProjectSettings, so we'll set it to 1960x1080. We'll

also change the canvas size and adjust the UI layout.
The whole thing looks like this.
It's a bit sparse on both sides, but that's part of the charm.

② Make it possible to save (load) the lottery data
Save the data (members) of the group you selected.
It's best to use PlayerPrefs to save it locally.
For an explanation of PlayerPrefs, click here
You can set a value for any key, so first decide on the key rules.
Use the year, month, and group number as a unique key.
string key = string.Format("group_{0}_{1}_{2}", GroupNo, date.Year, date.Month);
The value to be saved is the member name.
We will split it later with Split(), so we will separate it with spaces to make it a string.
string val = ""; for(int i=0; i<memberNames.Count; i++) { if (i > 0) val += " "; val += memberNames[i]; }
Now that we have the Key and Value, we can save them in PlayerPrefs
PlayerPrefs.SetString(key, val); PlayerPrefs.Save();
It's simple.
When I use it for work or other serious purposes, I encrypt it before saving it, but since this is an internal tool, I think it's fine to save it in plain text.
③ After selecting the month for which the lottery has been drawn, the determined group will be displayed
Load the data saved in ② from PlayerPrefs
string val = PlayerPrefs.GetString(key); string[] members = val.Split(' ');
All that's left to do is reflect the loaded data in the UI
④ Avoid having the same members as the previous month (as much as possible)
Finally, we will add a check to ensure that the same members as last month (last month) are not drawn at the time of the lottery.
This time, we will draw again in the following cases:
1. Not in the same group (leader) as last month
2. Not with the same members as last month
However, to prevent an infinite loop, if the lottery has to be redrawn five times in a row, it will be OK even if there are overlaps.
First, we load the members of each group from last month.
Then, we randomly select candidates and make the following judgments:
Do not join the same group (leader) as last month
Determine whether the selected candidate was in the same group last month.
Last month's members are stored in a List, so check with Contains().
If they are the same, reselect.
Do not overlap with the same members as the previous month
We check which group the selected candidate was in last month.
We compare last month's group members with the members already registered in the group the candidate is scheduled to join this month, and
if there are any identical members, we re-select the candidates.
Both member lists are Lists, so we cycle through them with foreach and check with Contains().
public bool IsSameMember(List<string> lastManthMembers) { // Check if this month's members are not members from last month bool isSame = false; foreach (string mem in memberNames) { if(lastManthMembers.Contains(mem)) { isSame = true; break; } } return isSame; }
Hmm, it's a little uncool, and I can't think of a better idea.
But I think it works properly.
summary
I think I managed to meet all the requirements.
・Ability to specify the month (System.DateTime)
・Save (load) the members selected by lottery (PlayerPrefs)
・Make sure they don't overlap with last month's members (self-implemented)
・Also adjust the resolution (WebGL)
This time, I've put together only the basic functions.
For now, the Beyond Lunch tool is complete (ver. 1.0.0).
If you have any requests, please feel free to contact us and we will improve the functionality.
That's all for today.
I will update Git.
I hope this will be helpful.
Unity Sample
lastly
I am a member of the system development service site "SEKARAKU Lab."
Beyond offers a one-stop service for everything from server design and construction to operation, so if you have any problems with server-side development, please feel free to contact us.
SEKARAKU Lab: [https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)
0