Jim Gill Posted October 24, 2012 Posted October 24, 2012 I have a script that schedules children, based on their choices, into six class periods per day. We call these class periods "Focuses" (just so you understand the verbiage in the script). My staff had been giving me feedback that the the morning focuses attendance was jammed full and the afternoon was slack. This made sense because the script would schedule kids systematically starting at focus 1 filling the classes to focus 6. So I wrote a sub-script (Attached) that would randomize the order in which each focus was scheduled, so the kids were distributed into each class equally throughout the day. This works well but the this sub-script REALLY bogs the overall progress of the main script. There has to be an easier way (have a look at the attached). Here is what I need: A calculation/script that randomize numbers 1 to 6 (example: 4, 1 3, 2 6, 5) - no repeats. I don't care if the results appear in a single field or across six different fields. Any help is much appreciated! Just an FYI: I'm not a developer - go easy on me! I'm just a camp director that loves this stuff! Thanks, Jim Random Distridution Across Class.pdf
Raybaudi Posted October 24, 2012 Posted October 24, 2012 Hi give a look at the custom function: http://www.briandunning.com/cf/454 1
jbante Posted October 24, 2012 Posted October 24, 2012 Raybaudi has the right idea. Rather than calculating the trial-and-error random number generation until you get unique values within your range, you should start with the list of enumerated possible values (1, 2, 3, 4, 5, 6), and randomize the order of them. The function Raybaudi referenced could work with the right parameters: NoRepDigit ( 6 ; 6 ) But my first instinct is more like this: ValueShuffle ( List ( 1 ; 2 ; 3 ; 4 ; 5 ; 6 ) ) ... with the ValueShuffle custom function here. This function will work better if you have numbers larger than 10 as possibilities or if you have text values you need to randomize the order of. With NoRepDigit, you can extract the returned values in order with the Middle function. With ValueShuffle, you can use GetValue. As a side note, I saw that your script made extensive use of the Insert Calculated Result script step. Set Field is nearly always the better choice, since the target field does not have to be on the current layout for it to work. 1
LaRetta Posted October 24, 2012 Posted October 24, 2012 (edited) I guess I do not understand the need. If there are only 6 focus groups (and probably more than 6 students) then a single focus number (between 1 and 6) must be repeated through the student list, right? Whether a group number repeats should not matter since you want random and random CAN repeat. If you for sure do not want a repeat then why not just number them 1 through 6 over and over down the list? Also, what is the max number of Students a focus group can hold? If you use Random() isn't there a possibility that a single group will be overbooked? Anyway, I've created a script which assigns to the students in case Daniele and Jeremy's suggestions don't fit the bill. You can also just make it a calculation and display your list of Students and you have your random 1-6 answer. If a calculation, any screen refresh will change the random number so you should print the list or write to field if you need to preserve it. UPDATE: I added second script which assigns full list to each student and keeps them unique and removed extra variable. Version 11 and 12 are included in case someone has 11 instead. RandomMOD.zip Edited October 24, 2012 by LaRetta 1
Jim Gill Posted October 24, 2012 Author Posted October 24, 2012 Thanks you all! "Side Note" noted Jeremy - thanks! LaRetta - You nailed it for me - thank you so much!! To your questions: The main script schedules campers by their activity choices. There are parameters which must be met for the camper to be scheduled into each class including capacity limits. We have over 200 campers and up to 40 classes per focus period. Lets say 80 campers chose Gymnastics as there # 1 choice. The capacity max for gymnastics is 20 kids per focus. So what was happening, prior to the introduction of the sub-script you just helped me with, was gymnastics focus periods 1 - 4 were maxed to capacity and then I had 3 staff members with the nothing to do the last 2 focus periods (5 &6) of the day. So with the introduction of the above sub-script, filemaker will try to schedule each camper into random systematic focus periods to distribute the class load throughout the day. Hopefully this makes sense - thank you again!
LaRetta Posted October 25, 2012 Posted October 25, 2012 "The capacity max for gymnastics is 20 kids per focus." I started with relational approach but switched to list in Student record, LOL. Relational is better because a Classes table can hold numeric Capacity. An Assignments table would join them and hold the date, TeacherID, StudentID, ClassID. Script would create 6 records instead of lines per Student and random fill (but never exceed) a Class' capacity. Students ---< Assignments >--- Classes. In fact you probably have much of this in place already. BTW, those custom functions will achieve the same result as an inner loop (and faster if record sets are quite large) but script seemed simplest approach here. :wink3:
David Nelson Posted November 1, 2012 Posted November 1, 2012 Hi LaRetta, So a loop is same as iteration and since you can pass the results to variable in the Let() to be used in the next iteration, what you show in your file in that inner loop is actually recursion. Is this right? I have read most of the google answers and I have been studying but I still do not have the entire picture.
LaRetta Posted November 2, 2012 Posted November 2, 2012 Hi David, I would say yes and that you phrased it quite well. You can also recurse with repetitions - see here by Comment: http://fmforums.com/forum/topic/29250-poor-mans-recursive-function/. Custom Function would probably be fastest (if written well) because setting of variable or global would be eliminated (which scripts require). Actually none of us has the entire picture although there are some here who get pretty darned close to understanding it all. Unfortunately I'm not one of them. yet
David Nelson Posted November 2, 2012 Posted November 2, 2012 I struggle in learning recursives because they hang bad and destroy my test files. At least with script you can escape but no escaping a runaway calc. Or is there?
LaRetta Posted November 2, 2012 Posted November 2, 2012 There is only one thing I know to do, David ... I always create a null layout with no fields and I set in file options to load that layout at startup. Then if it crashes and I reopen file, I can drop into layout mode and go change the CF before returning to browse. I suppose you could also write a protection into your CF such as wrapping with If ( not gHalt ; your CF ...) where you can pre-fill with 1 at startup but I am unsure which would take place first ... Setting the global at startup or the CF evaluating on the layout last opened which is where the crash last left it. It is easier to set the opening layout to one without the fields. :-) ADDED: Never run tests and re-use a GOOD file which has crashed. I re-use crashed test files only and never good files.
Recommended Posts
This topic is 4402 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now