-
Notifications
You must be signed in to change notification settings - Fork 0
/
narracat_launcher.py
586 lines (500 loc) · 23.1 KB
/
narracat_launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# -----------------------------------------------------------------------------------------------------------------
# NarraCat: Tools for Narrative Catalysis
# -----------------------------------------------------------------------------------------------------------------
# License: Affero GPL 1.0 http://www.affero.org/oagpl.html
# Google Code Project: http://code.google.com/p/narracat/
# Copyright 2011 Cynthia Kurtz
# -----------------------------------------------------------------------------------------------------------------
# This file:
#
# Launcher window - main interface window, calls and includes browser frame
# -----------------------------------------------------------------------------------------------------------------
from narracat_constants import *
from narracat_utils import *
from narracat_stats import *
from narracat_compile import *
from narracat_slice import *
from narracat_data import *
from narracat_browser import *
from narracat_network import *
from narracat_merge import *
from narracat_ternary import *
from narracat_cluster import *
from narracat_testing import *
import numpy as np
class NarracatLauncher(Frame):
def __init__(self, master=None, questions=None, participants=None, stories=None):
Frame.__init__(self, master)
self.questions = questions
self.participants = participants
self.stories = stories
# custom
#mergeDataFiles_2()
#graphNetworkNodeDiagram(DATA_PATH + "archetypes.csv", "test", "test", OUTPUT_PATH)
#sampleSize = 100
#xValues = np.random.normal(50, 25, sampleSize)
#yValues = np.random.normal(50, 25, sampleSize)
#zValues = np.random.normal(50, 25, sampleSize)
#graphPNG3DScatter(xValues, yValues, zValues, "x", "y", "z", "test 3d scatter graph", 'test 3d scatter graph', '')
self.BUTTON_FUNCTION_MAP = [
["Data integrity", "LABEL"],
["Print data as read", self.dataIntegrityCheck_Printouts],
["Answer summaries", self.dataIntegrityCheck_Values],
["Participant summaries", self.dataIntegrityCheck_Participants],
["Output stories and metadata", self.dataOutput],
["Choices", "LABEL"],
["Choice graphs", self.choiceGraphs],
["Choices x choices", "LABEL"],
["Chi squared tests", self.chiSquaredContingencies],
["Answer contingencies", self.answerContingencies],
["Scales", "LABEL"],
["Scale histograms", self.scaleHistograms],
["Scales + choices", "LABEL"],
["T tests", self.tTests],
["Skew differences", self.skewDifferences],
["Scale histograms by choice", self.scaleHistogramsByChoice],
["Scale histograms by choice combined 3D", self.stackedScaleHistogramsByChoice],
["Scales x scales", "LABEL"],
["Correlation matrix", self.correlationMatrix],
["Scatter graphs", self.scatterGraphs],
["Scales x scales + choices", "LABEL"],
["Correlation CSV summaries by choices", self.correlationCSVSummariesByChoice],
["Correlation matrices by choice", self.correlationMatricesByChoice],
["Scatter graphs by choice", self.scatterGraphsByChoice],
]
if STABILITY_QUESTION_NAME:
stabilityOptions = [
["Stability landscapes", "LABEL"],
["Stability landscapes", self.stabilityLandscapes],
["Stability landscapes by choice", self.stabilityLandscapesByChoice],
]
for option in stabilityOptions:
self.BUTTON_FUNCTION_MAP.append(option)
if SHOW_CLUSTER_ANALYSIS_OPTIONS:
clusterOptions = [
["Cluster analysis", "LABEL"],
["K-means (3 clusters)", self.clusterAnalysis_KMeans_3Clusters],
["K-means (4 clusters)", self.clusterAnalysis_KMeans_4Clusters],
["K-means (5 clusters)", self.clusterAnalysis_KMeans_5Clusters],
["Agglomerative (best number of clusters)", self.clusterAnalysis_Agglomerative],
]
for option in clusterOptions:
self.BUTTON_FUNCTION_MAP.append(option)
if DATA_HAS_SLICES:
slicesOptions = [
["Slices", "LABEL"],
["Slice graphs", self.sliceGraphs],
]
for option in slicesOptions:
self.BUTTON_FUNCTION_MAP.append(option)
if DATA_HAS_TERNARY_SETS:
ternaryOptions = [
["Ternary sets", "LABEL"],
["Ternary set data integrity check", self.dataIntegrityCheckForTernarySets],
["Ternary set graphs", self.ternarySetGraphs],
["Ternary set graphs by choice", self.ternarySetGraphsByChoice],
["Ternary set by ternary set graphs", self.ternarySetByTernarySetGraphs],
["Ternary set by ternary set graphs by choice", self.ternarySetByTernarySetGraphsByChoice],
["Ternary set with scale graphs", self.ternarySetByScaleGraphs],
["Ternary set with scale graphs by choice", self.ternarySetByScalesGraphsByChoice],
]
for option in ternaryOptions:
self.BUTTON_FUNCTION_MAP.append(option)
if SHOW_TESTING_BUTTONS:
self.BUTTON_FUNCTION_MAP.append(["Testing", "LABEL"])
self.BUTTON_FUNCTION_MAP.append(["Regression testing", self.testingGraphs])
#self.BUTTON_FUNCTION_MAP.append([" ", "LABEL"])
self.BUTTON_FUNCTION_MAP_WITHOUT_LABELS = []
for name, function in self.BUTTON_FUNCTION_MAP:
if function != "LABEL":
self.BUTTON_FUNCTION_MAP_WITHOUT_LABELS.append([name, function])
self.pack(fill=BOTH, expand=YES)
self.buildWindow()
def buildWindow(self):
# on left, things to do
operationsFrame = Frame(self, relief=SUNKEN, borderwidth=2)
operationsFrame.pack(side=LEFT, fill=BOTH)
littleFont = tkFont.Font(family="Helvetica", size=12)
# file loaded
label = Label(operationsFrame, foreground='blue', text="Data file", font=littleFont)
label.pack(side=TOP, anchor=W)
self.currentFileName = Text(operationsFrame, width=30, height=2, relief=SUNKEN, borderwidth=2, font=littleFont)
self.currentFileName.pack(side=TOP, fill=BOTH)
self.readCSVCheckBoxState = IntVar()
readCSVCheckBox = Checkbutton(operationsFrame, variable=self.readCSVCheckBoxState, text=" Read from CSV", font=littleFont)
readCSVCheckBox.pack(side=TOP, anchor=W)
self.loadFileButton = Button(operationsFrame)
self.loadFileButton["text"] = " Load Data "
self.loadFileButton["command"] = self.loadFile
self.loadFileButton.pack(side=TOP)
# frame to hold checkboxes and scroll bar
outerCheckboxesFrame = Frame(operationsFrame)#, relief=SUNKEN, borderwidth=2)
outerCheckboxesFrame.pack(side=TOP, fill=BOTH)
label = Label(outerCheckboxesFrame, foreground='blue', text="Operations", font=littleFont)
label.pack(side=TOP, anchor=W)
# canvas to allow scrolling within outerCheckboxesFrame
self.canvas=Canvas(outerCheckboxesFrame)
# frame to put checkboxes on
checkBoxesFrame = Frame(self.canvas, relief=SUNKEN, borderwidth=2)
scrollbar = Scrollbar(outerCheckboxesFrame, orient=VERTICAL, command=self.canvas.yview)
scrollbar.pack(side=RIGHT, fill=Y, expand=FALSE)
self.canvas.configure(yscrollcommand=scrollbar.set)
self.canvas.xview_moveto(0)
self.canvas.yview_moveto(0)
self.canvas.create_window((0,0), window=checkBoxesFrame, anchor='nw')
self.canvas.pack(side=TOP)
checkBoxesFrame.bind("<Configure>", self.checkBoxesFrameScrollFunction)
self.checkBoxStates = []
for name, function in self.BUTTON_FUNCTION_MAP:
if function == "LABEL":
label = Label(checkBoxesFrame, text=name, font=littleFont)
label.pack(side=TOP, anchor=W)
else:
checkBoxState = IntVar()
checkBox = Checkbutton(checkBoxesFrame, variable=checkBoxState, text=" " + name, font=littleFont)
checkBox.pack(side=TOP, anchor=W)
self.checkBoxStates.append(checkBoxState)
self.doOperationsButton = Button(operationsFrame)
self.doOperationsButton["text"] = " Perform Selected Operations "
self.doOperationsButton["command"] = self.doOperations
self.doOperationsButton.pack(side=TOP)
self.doOperationsButton = Button(operationsFrame)
self.doOperationsButton["text"] = " Uncheck All "
self.doOperationsButton["command"] = self.uncheckAll
self.doOperationsButton.pack(side=TOP)
Label(operationsFrame, text=" ").pack(side=TOP, anchor=W) # spacer so quit button stands out
self.quitButton = Button(operationsFrame)
self.quitButton["text"] = " Quit "
self.quitButton["command"] = self.quit
self.quitButton.pack(side=TOP)
browserFrame = Frame(self, relief=SUNKEN, borderwidth=2)
browserFrame.pack(side=RIGHT, fill=BOTH)
self.browser = NarracatBrowser(master=browserFrame, questions=self.questions, participants=self.participants, stories=self.stories)
def quit(self):
sys.exit(0)
def checkBoxesFrameScrollFunction(self, event):
# change this height if you change the main window height
self.canvas.configure(scrollregion=self.canvas.bbox("all"),width=200,height=350)
def doOperations(self):
commandsToDo = []
i = 0
for state in self.checkBoxStates:
if state.get():
commandsToDo.append(self.BUTTON_FUNCTION_MAP_WITHOUT_LABELS[i])
i += 1
for name, function in commandsToDo:
print '\nPERFORMING OPERATION:\n %s\n' % name
function()
def uncheckAll(self):
for state in self.checkBoxStates:
state.set(False)
def loadFile(self):
forceReread = self.readCSVCheckBoxState.get()
if HAS_MULTIPLE_DATA_FILES:
fileNamesWithPath = []
for fileName in MULTIPLE_DATA_FILE_NAMES:
fileNamesWithPath.append(DATA_PATH + fileName)
else:
fileNamesWithPath = None
self.questions, self.participants, self.stories = readData(DATA_PATH + PICKLE_FILE_NAME,
DATA_FILE_PATH, LABELS_FILE_PATH, HAS_MULTIPLE_DATA_FILES, fileNamesWithPath, forceReread=forceReread)
self.browser.questions = self.questions
self.browser.participants = self.participants
self.browser.stories = self.stories
createPathIfNonexistent(OUTPUT_PATH)
self.currentFileName.delete('0.0', END)
self.currentFileName.insert(END, " " + DATA_PATH + PICKLE_FILE_NAME)
self.browser.initializeQABox()
# OVERALL
def dataIntegrityCheck_Printouts(self):
if not (self.questions and self.participants and self.stories):
return
printQuestionsToCheckTheyWereReadRight(self.questions)
printStoriesToCheckTheyWereReadRight(self.questions, self.stories)
printParticipantsToCheckTheyWereReadRight(self.questions, self.participants)
printNumberOfResponsesToEachQuestion(self.questions, self.stories)
printNumberOfResponsesForEachStory(self.questions, self.stories)
print '\n data integrity check (printouts) DONE'
def dataIntegrityCheck_Values(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphOneGiantHistogramOfAllScaleValues(self.questions, self.stories, slice=slice)
graphBarChartOfExtremeAndNAProportionsPerScale(self.questions, self.stories, slice=slice)
graphBarChartOfNAProportionsPerChoiceQuestion(self.questions, self.stories, slice=slice)
# custom
#printResultForSpecificQuestionID(self.questions, self.stories, "Come from")
#printNamesOfStoriesWithNoArchetypeData(self.stories, self.questions)
print '\n data integrity check (values) DONE'
def dataIntegrityCheck_Participants(self):
if not (self.questions and self.participants and self.stories):
return
graphMeanAndSDAmongScaleValuesPerParticipant(self.questions, self.participants)
graphAllScaleValuesPerParticipant(self.questions, self.participants)
graphHowManyScaleValuesWereEnteredPerParticipant(self.questions, self.participants)
print '\n data integrity check (participants) DONE'
def dataOutput(self):
if not (self.questions and self.participants and self.stories):
return
writeSimplifiedDataToCSV(self.questions, self.stories)
writeStoriesToTextFile(self.questions, self.stories, includeMetadata=False)
writeStoriesToTextFile(self.questions, self.stories, includeMetadata=True)
writeOtherResponsesToQuestions(self.questions, self.stories)
if WRITE_EMPTY_THEMES_FILE_TO_FILL_IN_BY_HAND:
writeEmptyThemesFile(self.stories)
if WRITE_THEMES_FILE_FROM_THEMES_QUESTION:
writeThemesFileWithDataFromThemesQuestion(self.stories, THEMES_QUESTION_ID)
writeInfoAboutPeopleAndNumberOfStoriesTold(self.questions, self.stories, self.participants)
print '\n data output DONE'
# CHOICES
def choiceGraphs(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphBarChartsOfAnswerCountsPerQuestion(self.questions, self.stories, slice=slice)
print '\n choice graphs DONE'
def answerContingencies(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphBarChartOfAnswerCombinationCounts(self.questions, self.stories)
graphAnswerContingencies(self.questions, self.stories, slice=slice)
print '\n answer contingencies DONE'
def chiSquaredContingencies(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphAnswerContingencies(self.questions, self.stories, slice=slice, chiSquared=True)
print '\n chi squared tests DONE'
# SCALES
def scaleHistograms(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleHistograms(self.questions, self.stories, inOwnDirectory=False, slice=slice)
print '\n scale histograms DONE'
# SCALES WITH CHOICES
def tTests(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
doTTestsToCompareScaleValuesWithQuestionAnswers(self.questions, self.stories, slice=slice, byQuestion=False)
print '\n t-tests DONE'
def skewDifferences(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
compareSkewInScaleValuesWithQuestionAnswers(self.questions, self.stories, slice=slice, byQuestion=False)
print '\n skew differences DONE'
def scaleHistogramsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleHistogramsPerQuestionAnswer(self.questions, self.stories, slice=slice)
print '\n scale histograms by choice DONE'
def stackedScaleHistogramsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphStackedScaleHistogramsPerQuestionAnswer(self.questions, self.stories, slice=slice)
print '\n stacked scale histograms by choice DONE'
# SCALES WITH SCALES
def correlationMatrix(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleCorrelationMatrix(self.questions, self.stories, slice=slice)
print '\n correlation matrix DONE'
def scatterGraphs(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleScattergrams(self.questions, self.stories, slice=slice, separateDirectories=False)
print '\n scatter graphs DONE'
# SCALES WITH SCALES AND CHOICES
def correlationCSVSummariesByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
writeCorrelationsToCSVForQuestionAnswers(self.questions, self.stories, slice=slice)
writeDifferencesInCorrelationsToCSVForQuestionAnswers(self.questions, self.stories, slice=slice)
print '\n correlation matrices by choice DONE'
def correlationMatricesByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleCorrelationMatrixForQuestionAnswers(self.questions, self.stories, slice=slice)
print '\n correlation matrices by choice DONE'
def scatterGraphsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleScattergramsForQuestionAnswers(self.questions, self.stories, slice=slice)
print '\n scatter graphs by choice DONE'
# STABILITY
def stabilityLandscapes(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleContourGraphsAgainstStability(self.questions, self.stories, STABILITY_QUESTION_NAME, separateDirectories=False, slice=slice)
print '\n stability landscapes DONE'
def stabilityLandscapesByChoice(self):
if not (self.questions and self.participants and self.stories):
return
for slice in SLICES:
graphScaleContourGraphsAgainstStabilityForQuestionAnswers(self.questions, self.stories, STABILITY_QUESTION_NAME, slice=slice)
print '\n stability landscapes by choice DONE'
# SLICES
def sliceGraphs(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_SLICES:
print "\n no slices set up in data"
return
columns = {}
columns[SLICE_QUESTION_ID] = []
for slice in SLICES_TO_CREATE:
columns[SLICE_QUESTION_ID].append(slice)
columns[ALL_DATA_SLICE] = [ALL_DATA_SLICE]
# questions alone
graphAnswerCountsForSlices(self.questions, self.stories, columns)
graphAnswerContingenciesForSlices(self.questions, self.stories, columns)
# scales alone
graphOneScaleStatsForSlices(self.questions, self.stories, columns)
graphScaleMeansAndStdDevsForSlices(self.questions, self.stories, columns)
graphScaleNAsForSlices(self.questions, self.stories, columns)
graphOneCorrelationGridForSlices(self.questions, self.stories, columns)
graphCorrelationValuesForSlices(self.questions, self.stories, columns)
# scales with questions
graphTTestValuesForSlices(self.questions, self.stories, columns)
print '\n slice graphs DONE'
# TERNARY SETS
def dataIntegrityCheckForTernarySets(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
for slice in SLICES:
graphOneGiantTernaryPlotOfAllTernarySetValues(self.questions, self.stories, slice=slice)
calculateThirdValueStrengthForTernaryAnswers(self.questions, self.stories)
graphTernaryPlotValuesPerParticipant(self.questions, self.stories, self.participants)
print '\n data integrity check for ternary sets DONE'
def ternarySetGraphs(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphTernaryPlots(self.questions, self.stories, separateDirectories=False)
print '\n ternary set graphs DONE'
def ternarySetGraphsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphTernaryPlotsForQuestionAnswers(self.questions, self.stories)
compareTernaryMeansForScaleValuesWithQuestionAnswers(self.questions, self.stories, byQuestion=False)
print '\n ternary set graphs by choice DONE'
def ternarySetByTernarySetGraphs(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphDifferencesBetweenTernaryPlots(self.questions, self.stories, separateDirectories=False)
print '\n ternary set by ternary set graphs DONE'
def ternarySetByTernarySetGraphsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphTernaryPlotDifferencesForQuestionAnswers(self.questions, self.stories)
print '\n ternary set by ternary set graphs by choice DONE'
def ternarySetByScaleGraphs(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphTernaryPlotsAgainstScales(self.questions, self.stories, separateDirectories=False)
print '\n ternary set by scale graphs DONE'
def ternarySetByScalesGraphsByChoice(self):
if not (self.questions and self.participants and self.stories):
return
if not DATA_HAS_TERNARY_SETS:
print "\n no ternary sets set up in data"
return
graphTernaryPlotsAgainstScalesForQuestionAnswers(self.questions, self.stories)
print '\n ternary set by scales graphs by choice DONE'
# CLUSTERS
def clusterAnalysis_KMeans_3Clusters(self):
if not (self.questions and self.participants and self.stories):
return
if not self.checkIfWeCanDoClusterAnalysis(slice):
return
self.clusterAnalysis(method="k-means", k=3)
def clusterAnalysis_KMeans_4Clusters(self):
if not (self.questions and self.participants and self.stories):
return
if not self.checkIfWeCanDoClusterAnalysis(slice):
return
self.clusterAnalysis(method="k-means", k=4)
def clusterAnalysis_KMeans_5Clusters(self):
if not (self.questions and self.participants and self.stories):
return
if not self.checkIfWeCanDoClusterAnalysis(slice):
return
self.clusterAnalysis(method="k-means", k=5)
def clusterAnalysis_Agglomerative(self):
if not (self.questions and self.participants and self.stories):
return
if not self.checkIfWeCanDoClusterAnalysis(slice):
return
self.clusterAnalysis(method="agglomerative")
def clusterAnalysis(self, method, k=3):
# k-means
if method == "k-means":
for slice in SLICES:
# to include only SOME questions, change the second self.questions here
calculateClusterMembershipsAndWriteToFile(self.questions, self.questions, self.participants, method=method, slice=slice, k=k)
printCountsOfClusterParticipants(self.questions, self.participants, method=method, slice=slice, k=k)
graphClusterMeansAndHistograms(self.questions, self.participants, method=method, slice=slice, k=k)
graphClusterAnswerCounts(self.questions, self.participants, method=method, slice=slice, k=k)
graphClusterScatterGraphs(self.questions, self.participants, method=method, slice=slice, k=k)
graphClusterContours(self.questions, self.participants, method=method, slice=slice, k=k)
elif method == "agglomerative":
for slice in SLICES:
# to include only SOME questions, change the second self.questions here
calculateClusterMembershipsAndWriteToFile(self.questions, self.questions, self.participants, method=method, slice=slice)
graphClusterMeansAndHistograms(self.questions, self.participants, method=method, slice=slice)
graphClusterAnswerCounts(self.questions, self.participants, method=method, slice=slice)
graphClusterScatterGraphs(self.questions, self.participants, method=method, slice=slice)
print '\n cluster analysis DONE'
def checkIfWeCanDoClusterAnalysis(self, slice):
# the cluster analysis methods cannot deal with situations where there are not the same number of values per participant
# so if there are, we will just use the first X number of values, where X is the largest number EVERY participant has
scaleValuesByParticipant = gatherScaleValuesByParticipant(self.questions, self.participants, slice=slice)
minNumValuesPerParticipant = 100000
maxNumValuesPerParticipant = 0
for participantValueSet in scaleValuesByParticipant:
if len(participantValueSet) < minNumValuesPerParticipant:
minNumValuesPerParticipant = len(participantValueSet)
if len(participantValueSet) > maxNumValuesPerParticipant:
maxNumValuesPerParticipant = len(participantValueSet)
if minNumValuesPerParticipant != maxNumValuesPerParticipant:
print '\n cluster analysis requires all participants to have the same number of scale values.'
return False
else:
return True
# TESTING
def testingGraphs(self):
# normal, uniform distributions
generateAndSaveNormalData()
graphHistogramsOfNormalAndUniformTestData()
# t tests
generateAndSaveTTestData()
graphHistogramsAndTTestResultsOfTTestData()
print 'testing graphs DONE'