Jobanalysis program - suggestions
Hi, I have written a program for analysis of a concrete pour. I have included the data files and a couple of other files so that the program can be run live. Just select one of the records on the list and a set of parameters will be displayed. You can then calculate the analysis by pressing the calc button. I'm looking for any comments rebol savvy people might have about the coding.
posted by: John 10-Oct-2014/17:00:10-7:00
Here is the program itself: R E B O L [title: "Job Analysis"] do %play.r write/append %jobdata.txt "" database: load %jobdata.txt beep: load %err.wav clear-values: func [] [ foreach fc gui/pane [ if any [ fc/style = 'field fc/style = 'info ][ clear-face fc ] ] ] clear-info: func [] [ foreach fc gui/pane [ if any [ fc/style = 'info ][ clear-face fc ] ] ] validate: func [fields][ errfld: "" errmsg: "" foreach [fld tp] fields [ f: get fld if error? try [do rejoin [tp " " f/text]] [errfld: form fld errmsg: "Invalid entry"] ] reduce [errfld errmsg] ] validate-entries: does [ errs: validate fields either errs/2 <> "" [alert reform ["Errors " errs/1] focus do errs/1 return 0][ if any [ id/text = "" ] [ alert "Invalid ID" focus id return 0] if (nm/text = "") [ alert "Enter a Name Please" focus nm return 0] if any [ pd/text = "" ] [alert "Invalid Pour Date" focus pd return 0] if any [ ow/text = "" (to-decimal ow/text) <= 0 ] [ alert "Invalid Travel Time" focus ow return 0] if any [ ls/text = "" (to-decimal ls/text) <= 0 (to-decimal ls/text) > 12 ] [ alert "Invalid Load Size" focus ls return 0] if any [ yo/text = "" (to-decimal yo/text) = 0 (to-decimal yo/text) > 200 ] [ alert "Invalid Yards Ordered" focus yo return 0] if any [ yp/text = "" (to-decimal yp/text) = 0 (to-decimal yp/text) > 3000 ] [ alert "Invalid Yards in Pour" focus yp return 0] if any [ sd/text = "" (to-decimal sd/text) = 0 (to-decimal sd/text) > 20 ] [ alert "Invalid Slab Depth" focus sd return 0] if any [ pt/text = "" not (find pt/text ":") ] [ alert "Invalid Pour Time" focus pt return 0] if any [ ayt/text = "" (to-decimal ayt/text) > 60 ] [ alert "Invalid Added Yard Time" focus ayt return 0] if any [ rt/text = "" (to-decimal rt/text) > 60 ] [ alert "Invalid Added Return Time" focus rt return 0] if any [ pm/text = "" (to-decimal pm/text) > 60 ] [ alert "Enter Pump Move Time Please" focus pm return 0] ] ] fields: [ id to-integer pd to-date ow to-decimal ls to-decimal yo to-decimal yp to-decimal sd to-decimal pt to-time ayt to-decimal rt to-decimal pm to-decimal ] view center-face gui: layout [ text bold "Load an existing record:" name-list: text-list bold font-size 15 blue 250x100 data sort (extract database 12) [ if value = none [return] marker: index? find database value set-face id pick database marker set-face nm pick database (marker + 1) set-face pd pick database (marker + 2) set-face ow pick database (marker + 3) set-face ls pick database (marker + 4) set-face yo pick database (marker + 5) set-face yp pick database (marker + 6) set-face sd pick database (marker + 7) set-face pt pick database (marker + 8) set-face ayt pick database (marker + 9) set-face rt pick database (marker + 10) set-face pm pick database (marker + 11) clear-info show gui] guide text bold "Job ID:" id: field 100 bold font-size 15 yellow text bold "Name:" nm: field 100 bold font-size 15 yellow text bold "Pour Start Date:" pd: field 100 bold font-size 15 yellow text bold "One Way Travel:" ow: field 100 bold font-size 15 yellow text bold "Load Size:" ls: field 100 bold font-size 15 yellow text bold "YPH Ordered:" yo: field 100 bold font-size 15 yellow return text bold "Yards in Pour:" yp: field 100 bold font-size 15 yellow text bold "Slab Depth:" sd: field 100 bold font-size 15 yellow text bold "Pour Start Time:" pt: field 100 bold font-size 15 yellow text bold "Added Yard Time:" ayt: field 100 bold font-size 15 yellow text bold "Additional Return Time:" rt: field 100 bold font-size 15 yellow text bold "Pump Move Time:" pm: field 100 bold font-size 15 yellow return text bold "Maximum YPH:" my: info 75 bold font-size 15 green text bold "Unload Time:" ut: info 75 bold font-size 15 green text bold "Total Trip Time:" ttt: info 75 bold font-size 15 green text bold "Yds Per Truck Hour:" ypt: info 75 bold font-size 15 green text bold "Actual Trucks Required:" atr: info 75 bold font-size 15 green text bold "Optimum Trucks Required:" otr: info 75 bold font-size 15 green text bold "Maximum Trucks Required:" mtr: info 75 bold font-size 15 green text bold "Trucks Required using YPH Ordered:" rto: info 75 bold font-size 15 red return text bold "First Batch Start Time:" fbs: info 75 bold font-size 15 green text bold "YPH using Optimal Trucks:" ypo: info 75 bold font-size 15 green text bold "Added Gap:" ag: info 75 bold font-size 15 red text bold "Total Trucks Loaded at One Time:" ttl: info 75 bold font-size 15 green text bold "Pour Time Max Trucks:" ptm: info 75 bold font-size 15 green text bold "Pour Time Opt Trucks:" pto: info 75 bold font-size 15 green text bold "Total Number of Trips:" tt: info 75 bold font-size 15 green text bold "Mins Out of Concrete using Opt:" moc: info 75 bold font-size 15 red return text bold "Minimum Yds at Pump:" myp: info 75 bold font-size 15 green text bold "Total Mins Wasted using Max:" tmw: info 75 bold font-size 15 red text bold "Adjusted Truck Count if Limited Access:" atc: info 75 bold font-size 15 red text bold "Total Lost Hours to Pump Move:" tlp: info 75 bold font-size 15 red text bold "Wasted Assets Using YPH:" wa: info 75 bold font-size 15 red text bold "Substitute Slab Depth Limited Access:" sdl: info 75 bold font-size 15 red text bold "Substitute Slab Depth for Underorder:" sdu: info 75 bold font-size 15 red across btn "Save" [ if validate-entries = 0 [return] if find (extract database 12) id/text [ either true = request "Overwrite existing record?" [ remove/part (find database id/text) 12 ] [ return ] ] save %jobdata.txt repend database copy [id/text nm/text pd/text ow/text ls/text yo/text yp/text sd/text pt/text ayt/text rt/text pm/text] name-list/data: copy/deep sort (extract database 12) show name-list ] btn "Delete" [ if true = request rejoin ["Delete " id/text "?"] [ remove/part (find database id/text) 12 save %jobdata.txt database do-face clear-button name-list/data: copy/deep sort (extract database 12) show name-list ] ] clear-button: btn "New" [ clear-values ] calculate-button: btn "Calc" [ either validate-entries <> 0 [ set-face my (to-decimal sd/text) * (10.5) set-face ut round/to ( 60 / ((to-decimal my/text) / (to-decimal ls/text)) ) .1 set-face ttt round/to ((to-decimal ow/text) * (1.85) + 17 + (to-decimal ut/text) + (to-decimal ayt/text) + (to-decimal rt/text) ) .01 set-face ypt round/to (60 / (to-decimal ttt/text) * (to-decimal ls/text)) .01 set-face atr ((to-decimal my/text) / (to-decimal ypt/text)) set-face otr to-integer (to-decimal atr/text) set-face mtr to-integer (to-decimal atr/text) + 1 set-face ypo round/to ((to-decimal otr/text) * (to-decimal ypt/text)) .1 set-face rto round/to ((to-decimal yo/text) / (to-decimal my/text) * (to-decimal atr/text)) .1 set-face ptm round/to ((to-decimal yp/text) / (to-decimal my/text)) .01 set-face pto round/to ((to-decimal ptm/text) * ((to-decimal atr/text) / (to-decimal otr/text))) .01 bt: round ((to-decimal ayt/text) + (to-decimal ow/text) + 9) at: to-time rejoin [ "00:" (to-string bt) ":00"] set-face fbs (to-time pt/text) - (to-time at) set-face ag round/to (((to-decimal atr/text) - (to-decimal otr/text)) * (to-decimal ut/text)) .1 set-face tt round/to ((to-decimal yp/text) / (to-decimal ls/text)) .01 set-face tmw round (((to-decimal mtr/text) - (to-decimal atr/text)) * (to-decimal ptm/text) * 60) set-face moc round (((to-decimal pto/text) - (to-decimal ptm/text)) * 60) set-face myp round/to (((to-decimal my/text) / 60) * 3) .1 set-face ttl round/to (((to-decimal ow/text) + (to-decimal ayt/text) + 11 + (to-decimal ut/text)) / (to-decimal ut/text)) .1 set-face atc round/to (((to-decimal ut/text) / ((to-decimal ut/text) + 3)) * (to-decimal atr/text)) .1 set-face tlp round/to (((to-decimal pm/text) * (to-decimal atr/text)) / 60) .1 set-face wa if ((to-decimal rto/text) > (to-decimal atr/text)) [round (((to-decimal rto/text) - (to-decimal atr/text)) * 250000)] set-face sdl ((to-decimal sd/text) * (to-decimal ut/text)) / ((to-decimal ut/text) + 3) set-face sdu (to-decimal yo/text) / (to-decimal my/text) * (to-decimal sd/text) show gui ][ clear-info return ] ] ]
posted by: john 10-Oct-2014/17:01:36-7:00
here is the jobdata.txt file: "2" "2222" "10/10/14" "30" "10" "100" "400" "8" "8:00" "10" "10" "0" "1" "sssss" "10/10/14" "35" "10" "100" "400" "8" "8:00" "10" "10" "0" "5" "ffffff" "10/10/14" "30" "10" "100" "400" "8" "8:00" "0" "0" "0" "3" "3333" "10/10/14" "40" "5" "100" "400" "8" "7:00" "10" "10" "0" "7" "aaa" "10/10/14" "40" "10" "100" "400" "8" "8:00" "10" "10" "0" "4" "4444" "10/10/14" "50" "10" "100" "600" "8" "8:00" "10" "10" "0" "7777" "aaaa" "10/10/14" "50" "10" "100" "600" "8" "8:00" "0" "0" "0" "77.5" "xxxxx" "10/10/14" "50" "10" "100" "400" "8" "8:00" "0" "0" "0" "1.5" "sssss" "10/10/14" "35" "10" "100" "400" "8" "8:00" "10" "10" "0" "2.2" "aaaa" "10/10/14" "50" "10" "100" "600" "8" "8:00" "0" "0" "0"
posted by: John 10-Oct-2014/17:04:35-7:00
here is beep.r: R E B O L [] ; Load the sound file data into memory: audio: load %err.wav ; Open access to the sound device: sound-port: open sound:// ; Play the sound: insert sound-port audio ; Wait for the sound to finish: wait sound-port ; Close the sound device: close sound-port
posted by: john 10-Oct-2014/17:06:20-7:00
here is play.r: R E B O L [] play: func [ audio ] [ ; Open access to the sound device: sound-port: open sound:// ; Play the sound: insert sound-port audio ; Wait for the sound to finish: wait sound-port ; Close the sound device: close sound-port ]
posted by: john 10-Oct-2014/17:08:37-7:00
last is err.wav: you can just use any wave file that makes a sound.
posted by: John 10-Oct-2014/17:10:33-7:00
Scanning quickly, some verbosity could be reduced. For example, styles could be used to simplify the layout: text bold "Job ID:" id: field 100 bold font-size 15 yellow text bold "Name:" nm: field 100 bold font-size 15 yellow text bold "Pour Start Date:" pd: field 100 bold font-size 15 yellow text bold "One Way Travel:" ow: field 100 bold font-size 15 yellow text bold "Load Size:" ls: field 100 bold font-size 15 yellow text bold "YPH Ordered:" yo: field 100 bold font-size 15 yellow return text bold "Yards in Pour:" yp: field 100 bold font-size 15 yellow text bold "Slab Depth:" sd: field 100 bold font-size 15 yellow text bold "Pour Start Time:" pt: field 100 bold font-size 15 yellow text bold "Added Yard Time:" ayt: field 100 bold font-size 15 yellow text bold "Additional Return Time:" rt: field 100 bold font-size 15 yellow text bold "Pump Move Time:" pm: field 100 bold font-size 15 yellow could be: style tbld text bold style fby field 100 bold font-size 15 yellow tbld "Job ID:" id: fby tbld "Name:" nm: fby tbld "Pour Start Date:" pd: fby tbld "One Way Travel:" ow: fby tbld "Load Size:" ls: fby tbld "YPH Ordered:" yo: fby return tbld "Yards in Pour:" yp: fby tbld "Slab Depth:" sd: fby tbld "Pour Start Time:" pt: fby tbld "Added Yard Time:" ayt: fby tbld "Additional Return Time:" rt: fby tbld "Pump Move Time:" pm: fby My first instinct would also be to have used RebGUI to avoid all the to-decimal casting in the calculate-button function and because it has some built in (and extendable) validation features (and because it just generally tends to look and act better for these sorts of GUIs). You could also create a new style with a property which returns a decimal value from text contained in the field. If not, I'd at least be tempted to use some helper functions, again just to cut down some of the verbosity.
posted by: Nick 11-Oct-2014/1:20:52-7:00
Hi Yes, verbosity could be a lot better. I had tried rebgui and it blew up when I ran tour.r. It blew inside of rebDOC.r. Apparently, I have now initialized something because tour.r runs now. I ran tour.r demo from the rebol menu driven system. Now I can run tour.r standalone today. Anyhow I will install the toolbar in one of my programs and see how far I get.
posted by: john 11-Oct-2014/10:01:47-7:00
I found the coding to interesting in style and of some depth, good if you don't mind me saying so. Descriptive names are helpful. pd could be changed to pour-date for example, making reading and understanding faster and easier. But, the GUI, as an expression of the coding needs work. It seems to me to be hard o follow. Perhaps running the field labels and fields in columns might present better. The error feedback system seems to deal with one error at a time. I find this, from a user's viewpoint, to be excruciating. Instead, the fields with errors can be collected and their face color say, changed to show the user in one hit, just what needs more work. I appreciate the opportunity to view your code and make some comments. I found I learned a few things from it.
posted by: Doug 11-Oct-2014/23:45:40-7:00
Doug, thanks for the helpful remarks remarks. I agree with you.
posted by: john 29-Oct-2014/14:16:28-7:00
|