;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Variable and Breed declarations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; globals [ current-question ;; index of the current question in the question list question-list ;; list of all the questions plot-showing? ;; are the votes being shown in the plot? plot-dirty? ;; does the plot need a redraw? voted?-color ;; color of turtles which have voted not-voted?-color ;; color of turtles which haven't voted ;; quick start instructions variables quick-start ;; current quickstart instruction displayed in the quickstart monitor qs-item ;; index of the current quickstart instruction qs-items ;; list of quickstart instructions ] turtles-own [ user-id ;; unique id, input by the client when they log in, to identify each student turtle slider-value ;; the value of the client's choice slider my-choices ;; list of my choices for each question ] ;;;;;;;;;;;;;;;;;;;;; ;; Setup Functions ;; ;;;;;;;;;;;;;;;;;;;;; to startup hubnet-set-client-interface "COMPUTER" [ "clients/Polling client.nlogo" ] hubnet-reset setup end ;; Initializes the display, and creates a list that contains the names of the shapes ;; used by turtles in this activity. The placement of the shape names in the last ;; corresponds to the numbers sent by calculators. Also initializes the data lists. to setup ca cc setup-vars setup-quick-start end ;; initialize global variables to setup-vars set not-voted?-color violet - 2 set voted?-color violet + 2 set plot-showing? show-data? set plot-dirty? true clear-all-data-and-questions end to clear-clients clear-plot cg cc end to clear-all-data-and-questions clear-plot hubnet-broadcast "Current Question" "" hubnet-broadcast "Current Choice" "" set current-question 0 set question-list [""] ask turtles [ clear-my-data ] end to clear-my-data ;; turtle procedure set color not-voted?-color set my-choices [] repeat length question-list [ set my-choices lput false my-choices ] end ;; give the user some information about what the setup button does so they can ;; know whether they want to proceed before actually doing the setup to setup-prompt if user-yes-or-no? ("The SETUP button should only be used when starting " + "over with a new group (such as a new set of students) since " + "all data is lost.\n" + "Are you sure you want to SETUP?") [ setup ] end to clear-current-data clear-plot ask turtles [ set color not-voted?-color set my-choices replace-item current-question my-choices false hubnet-send user-id "Current Choice" "" ] end ;;;;;;;;;;;;;;;;;;;;;;;; ;; Runtime Procedures ;; ;;;;;;;;;;;;;;;;;;;;;;;; to go listen-clients every 0.5 [ ask turtles [ wander ] ifelse show-data? [ if not plot-showing? [ set plot-showing? true set plot-dirty? true ] if plot-dirty? [ set plot-dirty? false do-plot ] ] [ if plot-showing? [ set plot-showing? false clear-plot ] ] ] end to wander ;; turtle procedure rt 90 * random 4 if not any? turtles-on patch-ahead 1 [ fd 1 ] end ;; Plotting Procedures to do-plot locals [current-data] clear-plot set current-data values-from turtles [item current-question my-choices] if not empty? remove false current-data [ set-current-plot-pen "data" histogram-list current-data set-current-plot-pen "mean" plot-vline mean current-data set-current-plot-pen "median" plot-vline median current-data set-current-plot-pen "mode" plot-modes current-data ] end to plot-vline [value] plotxy value 0 plotxy value plot-y-max end to plot-modes [lst] locals [values counts i n] set lst remove false lst set values remove-duplicates lst ifelse length values = length lst [ histogram-list lst ] ;; no duplicates so all items are modes [ set counts [] set i 0 repeat length values [ set counts lput ((length lst) - (length remove (item i values) lst)) counts set i i + 1 ] set n max counts ;; how many votes for the most frequent choice(s)? while [member? n counts] [ set values (replace-item (position n counts) values false) set counts (replace-item (position n counts) counts 0) ] set values remove false values set i 0 repeat length values [ set lst (remove (item i values) lst) set i i + 1 ] histogram-list lst ] end ;; Client Message Processing Procedures to listen-clients while [hubnet-message-waiting?] [ hubnet-fetch-message ifelse hubnet-enter-message? [ execute-create ] [ ifelse hubnet-exit-message? [ ask turtles with [user-id = hubnet-message-source] [ die ] set plot-dirty? true ] [ if hubnet-message-tag = "Choose" [ execute-choose ] if hubnet-message-tag = "Choice" [ change-choice ] ] ] ] end to execute-create locals [pos] cct 1 [ set pos random-one-of patches with [not any? turtles-here] ifelse pos != nobody [ setxy (pxcor-of pos) (pycor-of pos) ] [ message "Too many students. Make a bigger graphics window." ] set user-id hubnet-message-source set label user-id + " " set slider-value 0 clear-my-data hubnet-send user-id "Current Question" (item current-question question-list) ] end to execute-choose ask turtles with [user-id = hubnet-message-source] [ if (allow-change? or color = not-voted?-color) [ set color voted?-color set my-choices replace-item current-question my-choices slider-value hubnet-send hubnet-message-source "Current Choice" slider-value ] ] if plot-showing? [ set plot-dirty? true ] end to change-choice ask turtles with [user-id = hubnet-message-source] [ set slider-value hubnet-message ] end ;; Question Procedures to add-question if question-list = [""] [ set question-list [] ] set question-list lput user-input "Input new question?" question-list set-current-question (length question-list - 1) clear-current-data end to set-current-question [n] locals [i] if n >= 0 and n < length question-list [ set current-question n ask turtles [ while [length my-choices < current-question + 1] [ set my-choices lput false my-choices ] ifelse (item current-question my-choices) = false [ set color not-voted?-color hubnet-send user-id "Current Choice" "" ] [ set color voted?-color hubnet-send user-id "Current Choice" (item current-question my-choices) ] ] if plot-showing? [ set plot-dirty? true ] hubnet-broadcast "Current Question" (item current-question question-list) ] end to prev-question if current-question > 0 [ set-current-question current-question - 1] end to next-question if current-question + 1 < length question-list [ set-current-question current-question + 1] end ;; Quick Start Intruction Procedures ;; instructions to quickly setup the model, and clients to run this activity to setup-quick-start set qs-item 0 set qs-items [ "Teacher: Follow these directions to run the HubNet activity." "Optional: Zoom In (see Tools in the Menu Bar)" "Teacher: Open up the HubNet Control Center (see Tools in the Menu Bar)." "This will show you the IP Address of this computer." "Everyone: Open up a HubNet Client on your machine and input..." "the IP Address of this computer, type your user name in..." "the user name box and press ENTER." "Teacher: If you don't want to allow students to change their mind,..." "switch ALLOW-CHANGE? off." "If you don't want to show the current data in the plot as..." "it's being collected, switch SHOW-DATA? off." "You can turn it back on at any time to see the data." "Teacher: Press the NEW QUESTION button to input a question for everyone to answer." "Everyone: Once you see the question, move your CHOICE slider to the value..." "you want to choose and press the CHOOSE button." "Once you have chosen, your choice will appear in your CURRENT CHOICE monitor,..." "and your turtle in NetLogo will get brighter." "Teacher: To input another question, press NEW QUESTION again." "The data and CURRENT QUESTION will be saved and then the question will change..." "to your new question and everyone will be able to make their choices on the new question." "To return to a previous question, use the <<>> buttons to cycle through the questions." "Teacher: To rerun the activity with the same group, press..." "the CLEAR QUESTIONS button to erase all the questions and data." "Teacher: To start the simulation over with a new group but reuse the same questions..." "stop the model by pressing the NetLogo GO button, if it is on..." "and press the CLEAR CLIENTS button." "Teacher: To start the simulation over with a new group but with new questions..." "stop the GO button, if it is on, and press the SETUP button." "Follow these instructions from the beginning." ] set quick-start (item qs-item qs-items) end ;; view the next item in the quickstart monitor to view-next-quick-start set qs-item qs-item + 1 if qs-item >= length qs-items [ set qs-item length qs-items - 1 ] set quick-start (item qs-item qs-items) end ;; view the previous item in the quickstart monitor to view-prev-quick-start set qs-item qs-item - 1 if qs-item < 0 [ set qs-item 0 ] set quick-start (item qs-item qs-items) end ; *** NetLogo Model Copyright Notice *** ; ; This activity and associated models and materials was created as part of the projects: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and ; INTEGRATED SIMULATION AND MODELING ENVIRONMENT. ; These projects gratefully acknowledge the support of the ; National Science Foundation (REPP & ROLE programs) -- grant numbers ; REC #9814682 and REC-0126227. ; ; Copyright 2002 by Uri Wilensky & Walter Stroup. Updated 2002. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from the copyright holders. ; Contact the copyright holders for appropriate licenses for redistribution ; for profit. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. & Stroup, W. (2002). NetLogo HubNet Polling model. ; http://ccl.northwestern.edu/netlogo/models/HubNetPolling. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky and Walter Stroup. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/HubNetPolling ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice*** @#$#@#$#@ GRAPHICS-WINDOW 461 98 744 402 10 10 13.0 1 10 1 1 1 CC-WINDOW 461 404 735 483 Command Center BUTTON 1 41 72 76 Setup setup-prompt NIL 1 T OBSERVER T BUTTON 78 41 149 76 Go go T 1 T OBSERVER T PLOT 155 129 455 396 Data choice count 0.0 10.0 0.0 5.0 true true PENS "data" 1.0 1 -16777216 true "mean" 1.0 0 -11352576 true "median" 1.0 0 -16776961 true "mode" 1.0 1 -65536 true SWITCH 1 224 149 257 allow-change? allow-change? 0 1 -1000 BUTTON 1 129 149 164 Clear Current Data clear-current-data NIL 1 T OBSERVER T MONITOR 1 401 455 450 Current Question item current-question question-list 3 1 BUTTON 1 450 149 483 New Question add-question NIL 1 T OBSERVER T BUTTON 1 363 149 396 Clear Questions clear-all-data-and-questions NIL 1 T OBSERVER T BUTTON 155 450 304 483 <<>> next-question NIL 1 T OBSERVER T SWITCH 1 262 149 295 show-data? show-data? 0 1 -1000 MONITOR 1 170 72 219 mean mean values-from turtles [item current-question my-choices] 3 1 MONITOR 78 170 149 219 median median values-from turtles [item current-question my-choices] 3 1 BUTTON 157 59 300 92 Reset Instructions setup-quick-start NIL 1 T OBSERVER T BUTTON 584 59 736 92 Next Instruction>>> view-next-quick-start NIL 1 T OBSERVER T BUTTON 432 59 584 92 <<>> buttons to cycle through the questions. Teacher: To rerun the activity with the same group, press the CLEAR QUESTIONS button to erase all the questions and data. Teacher: To start the simulation over with a new group but reuse the same questions, stop the model by pressing the NetLogo GO button, if it is on, and press the CLEAR CLIENTS button. Teacher: To start the simulation over with a new group but with new questions, stop the GO button, if it is on, and press the SETUP button. Follow these instructions from the beginning. BUTTONS: -------- SETUP - clears everything including logged in clients. This should only be pressed when starting out with a new group of users since all data and questions are lost. GO - runs the simulation processing data from the clients. CLEAR CURRENT DATA - clears everyone's answers on the current question allowing them to re-choose. NEW QUESTION - allows you to write a new question to be asked. CLEAR CLIENTS - removes all the clients and clears the data, but leaves the questions intact. This should be used to start over with a new group but with the same set of questions. CLEAR QUESTIONS - erase all the questions and the data associated with them. This should be used if you want to start over with the same group or don't want clients to have to log back in. NEXT QUESTION>>> - changes the current question to the next question. <<>> - advances the quick start instructions. <<