Improvements to the tool for extracting members of Beyond Ranch
table of contents
thank you for your hard work.
This is Matsuyama from the System Development Office.
Last time, I created a simple tool to group Beyond Lunch.
here for the last blog.Thank
you very much to the members of the Organizational Culture Committee. (Delusion)
President Haraoka pointed out to me that simply random grouping is insufficient in functionality, (reality)
requirements
① Since it is held every month, make it possible to specify the month.
② Make it possible to save (load) the drawn data.
③ If you select a month that has already been drawn, the decided groups will be displayed.
④ If the same members as the previous month Avoid this (as much as possible)
*Updated to Unity 2019.4.18f1 (LTS)
Is it like this?
In terms of Unity functionality, I guess you can use PlayerPrefs in ② and ③.
The rest depends on the program.
① Make it possible to specify the month
Last time, we will add the UI (Button and Text) to specify the month around the time when we created the lottery button.
It's like this.
For the date, you can use System.DateTime, so get the current date and time at startup and
update it using AddMonth() using the left and right buttons (◀︎ / ▶︎).
Since only the year and month are displayed, set year and month to Text.
Also, consider the screen size.
The default resolution of WebGL is 960x600, but I was able to change it in ProjectSettings, so I set it to 1960x1080.
We will also change the size of the Canvas and adjust the UI layout.
The whole thing is like this.
The left and right sides are sparse, but it's charming.
② Make it possible to save (load) the drawn data
Save the data (members) of the selected group.
It is best to use PlayerPrefs to save locally.
Click here for explanation of PlayerPrefs
Since you can set a value for any key, first decide on the rules for the key.
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 name of the member.
We will separate them later using Split(), so separate them with spaces (half-width characters) to create 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 to PlayerPrefs.
PlayerPrefs.SetString(key, val); PlayerPrefs.Save();
It's easy.
When I use it seriously for work, I encrypt it before saving it, but since this is an in-house tool, I thought plain text would be fine.
③ After selecting a month that has already been drawn, display the groups that have been decided.
Load the data saved in ② from PlayerPrefs.
string val = PlayerPrefs.GetString(key); string[] members = val.Split(' ');
All you have to do now is reflect the loaded data on the UI.
④ Avoid having the same members as the previous month (as much as possible)
Finally, during the lottery, we will add a judgment so that the same members as last month (last month) do not win.
This time, we will re-draw the lottery in the following cases.
1. Not in the same group (leader) as the previous month
2. Not in the same group as the previous month
However, as a countermeasure against infinite loops, if you are redrawn 5 times in a row, it is OK to be in the same group (leader).
First, load last month's members of each group.
After that, candidates are randomly drawn and the following judgments are made.
Not joining the same group (leader) as the previous month
Determine whether the selected candidate was in the same group last month.
Last month's members are stored in a List, so check it with Contains().
If it is the same, there will be a re-draw.
Do not overlap with the same members as the previous month.
Find out which group the selected candidate was in last month.
Compare last month's group members with the members already registered in the group you plan to join this month, and
if there are the same members, the lottery will be drawn again.
Both member lists are Lists, so use foreach to pass through them and check them using Contains().
public bool IsSameMember(List<string> lastManthMembers) { // Check if this month's members have members from last month bool isSame = false; foreach (string mem in memberNames) { if(lastManthMembers.Contains(mem)) { isSame = true; break; } } return isSame ; }
Hmm, I don't think it's a good idea, but I don't have any good ideas.
However, I think it works correctly.
summary
I think I managed to meet the requirements.
・You can specify the month (System.DateTime)
・Save (load) the selected members (PlayerPrefs)
・Prevent them from overlapping with the members from last month (in-house implementation)
・Adjust the resolution (WebGL)
Basic functions this time as well I'm just assembling it.
For now, the Beyond Ranch tool is now complete (ver1.0.0).
If you have any requests, we will improve the functionality, so please feel free to contact us.
Well, that's all for now.
Keep Git updated.
I hope this will be of some help to you.
Unity sample
lastly
I have opened the system development service site "SEKARAKU Lab" to which I belong.
Beyond is a one-stop service for everything from server design and construction to operation, so if you have any trouble with server-side development, please feel free to contact us.
SEKARAKU Lab: [https://sekarakulab.beyondjapan.com/](https://sekarakulab.beyondjapan.com/)