/+junk/Dataanalys

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/Dataanalys

« back to all changes in this revision

Viewing changes to awnser_sheet.py

  • Committer: Gustav Hartvigsson
  • Date: 2010-12-22 18:59:19 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20101222185919-xa4ot5ytlbiepf4w
Added a camand line interface, and finished up the awnser sheet thingy...

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python3.1
 
2
#-*- coding: utf-8 -*-
 
3
 
2
4
""" 
3
5
This file contains the cuestions that are to be awnserd.
4
6
the awnsers build up an sql query string that is then
7
9
 """
8
10
#=========== start class ================
9
11
 
10
 
class awnserSheet():
 
12
class awnserSheet:
11
13
        """" This returns the sql string that is built up during the prosses """
12
14
        sqlString = str(" ") # the strin that is going to be commited.
13
15
        sqlStringStart = """insert into awnsers(
29
31
"deprimerad_var",
30
32
"gast_sverige",
31
33
"fodd_sverige",
32
 
"foraldrar_sverige"
 
34
"foraldrar_sverige",
 
35
"komentarer"
33
36
)
34
37
values("""
35
38
        sqlStringEnd = ");"
36
39
        
 
40
        
37
41
        def qinput(): ## question input
38
42
                """ this function ruturns 1 or 0 or -1 when error """
39
43
                q = str(input("svara med 1 för sant och 0 för falskt:"))
40
44
                
41
 
                if(q != "0" or q != "1"):
 
45
                if(q != "0" and q != "1"):
42
46
                        print("!!! the input is invalid !!! \n !!! Try again !!!")
43
 
                        return(-1)
 
47
                        return("-1")
44
48
                
45
49
                return(q)
46
50
                
48
52
        ## start addToSqlString
49
53
        def addToSqlString(q):
50
54
                """ This function just adds to the sqlstring the value of q """
51
 
                global sqlString
52
 
                sqlString = sqlString + " " + q + ", " #FIXME: why, what the?
 
55
                awnserSheet.sqlString = awnserSheet.sqlString + " " + str(q) + ", "
53
56
        ## end addToSqlString
54
57
        ##start suestions section
55
58
        def question1():
60
63
                        awnserSheet.question1()
61
64
                else:
62
65
                        awnserSheet.addToSqlString(q)
 
66
                
63
67
        
64
68
        def question2():
65
69
                print("fråga 2:")
66
70
                print("tror du på spöken?")
67
71
                q = awnserSheet.qinput()
68
72
                if(q == "-1"):
69
 
                        awnserSheet.question3()
 
73
                        awnserSheet.question2()
70
74
                else:
71
75
                        awnserSheet.addToSqlString(q)
 
76
                
72
77
        
73
78
        def question3():
74
 
                print("Fråga 3")
 
79
                print("Fråga 3:")
75
80
                print("Är du religiös?")
76
81
                q = awnserSheet.qinput()
77
82
                if(q == "-1"):
78
83
                        awnserSheet.question3()
79
84
                else:
80
85
                        awnserSheet.addToSqlString(q)
 
86
                
81
87
        
82
88
        def question4():
83
 
                print("Fråga 4")
 
89
                print("Fråga 4:")
84
90
                print("är du för ett sekelärt samhälle?")
85
91
                q = awnserSheet.qinput()
86
92
                if(q == "-1"):
87
93
                        awnserSheet.question4()
88
94
                else:
89
95
                        awnserSheet.addToSqlString(q)
 
96
                
 
97
        
90
98
        def question5():
91
 
                print("Fråga 5")
 
99
                print("Fråga 5:")
92
100
                print("Är du vegetarian/vegan?")
93
101
                q = awnserSheet.qinput()
94
102
                if(q == "-1"):
95
103
                        awnserSheet.question5()
96
104
                else:
97
105
                        awnserSheet.addToSqlString(q)
 
106
                
98
107
        
99
108
        def question6():
100
109
                print("Fråga 6")
101
110
                print("Tycker du att mänskligheten skall besöka mars inom en snar framtid?")
102
111
                q = awnserSheet.qinput()
103
 
                if(q == "-1"):
 
112
                if(q == "-1:"):
104
113
                        awnserSheet.question6()
105
114
                else:
106
115
                        awnserSheet.addToSqlString(q)
 
116
                
107
117
        
108
118
        def question7():
109
 
                print("Fråga 6")
 
119
                print("Fråga 7:")
110
120
                print(" Tror du att mänskligheten är orsaken till den observerade globalauppvärmingen?")
111
121
                q = awnserSheet.qinput()
112
122
                if(q == "-1"):
113
123
                        awnserSheet.question7()
114
124
                else:
115
125
                        awnserSheet.addToSqlString(q)
116
 
        
117
 
        def questionAndReturn():
 
126
                
 
127
        
 
128
        def question8():
 
129
                print("Fråga 9:")
 
130
                print("tror du att vi varit på månen?")
 
131
                q = awnserSheet.qinput()
 
132
                if(q == "-1"):
 
133
                        awnserSheet.question8()
 
134
                else:
 
135
                        awnserSheet.addToSqlString(q)
 
136
                
 
137
        
 
138
        def question9():
 
139
                print("Fråga 10:")
 
140
                print("Motionerar du regelbundet?")
 
141
                q = awnserSheet.qinput()
 
142
                if(q == " -1"):
 
143
                        awnserSheet.question9()
 
144
                else:
 
145
                        awnserSheet.addToSqlString(q)
 
146
                
 
147
        
 
148
        def question10():
 
149
                print("Fråga 10:")
 
150
                print("Anser du att du har en sund livsstil?")
 
151
                q = awnserSheet.qinput()
 
152
                if(q == " -1"):
 
153
                        awnserSheet.question10()
 
154
                else:
 
155
                        awnserSheet.addToSqlString(q)
 
156
                
 
157
        
 
158
        def question11():
 
159
                print("Fråga 11:")
 
160
                print("Blir du deprimerad/nedstämd på hösten/vintern?")
 
161
                q = awnserSheet.qinput()
 
162
                if(q == " -1"):
 
163
                        awnserSheet.question11()
 
164
                else:
 
165
                        awnserSheet.addToSqlString(q)
 
166
                
 
167
        
 
168
        def question12():
 
169
                print("Fråga 12:")
 
170
                print("Gillar du snö?")
 
171
                q = awnserSheet.qinput()
 
172
                if(q == " -1"):
 
173
                        awnserSheet.question12()
 
174
                else:
 
175
                        awnserSheet.addToSqlString(q)
 
176
                
 
177
        
 
178
        def question13():
 
179
                print("Fråga 13:")
 
180
                print("Är du för ett öppet samhälle?")
 
181
                q = awnserSheet.qinput()
 
182
                if(q == " -1"):
 
183
                        awnserSheet.question13()
 
184
                else:
 
185
                        awnserSheet.addToSqlString(q)
 
186
                
 
187
        
 
188
        def question14():
 
189
                print("Fråga 14:")
 
190
                print("Är du för dödsstraff?")
 
191
                q = awnserSheet.qinput()
 
192
                if(q == " -1"):
 
193
                        awnserSheet.question14()
 
194
                else:
 
195
                        awnserSheet.addToSqlString(q)
 
196
                
 
197
        
 
198
        def question15():
 
199
                print("Fråga 15:")
 
200
                print("Är du för kvinnors rättigheter?")
 
201
                q = awnserSheet.qinput()
 
202
                if(q == " -1"):
 
203
                        awnserSheet.question15()
 
204
                else:
 
205
                        awnserSheet.addToSqlString(q)
 
206
                
 
207
        
 
208
        def question16():
 
209
                print("Fråga 16:")
 
210
                print("Är du för abort?")
 
211
                q = awnserSheet.qinput()
 
212
                if(q == " -1"):
 
213
                        awnserSheet.question16()
 
214
                else:
 
215
                        awnserSheet.addToSqlString(q)
 
216
                
 
217
        
 
218
        def question17():
 
219
                print("Fråga 17:")
 
220
                print("Är du för kvinnors rätt att bestämma över sin egen kropp?")
 
221
                q = awnserSheet.qinput()
 
222
                if(q == " -1"):
 
223
                        awnserSheet.question17()
 
224
                else:
 
225
                        awnserSheet.addToSqlString(q)
 
226
                
 
227
        def question18():
 
228
                print("Fråga 18:")
 
229
                print("Blir du deprimerad/nedstämd på våren?")
 
230
                q = awnserSheet.qinput()
 
231
                if(q == " -1"):
 
232
                        awnserSheet.question18()
 
233
                else:
 
234
                        awnserSheet.addToSqlString(q)
 
235
                
 
236
        
 
237
        def questionI()
 
238
                print("Fråga I:")
 
239
                print("Är du gäststuderande här i Sverige?")
 
240
                q = awnserSheet.qinput()
 
241
                if(q == " -1"):
 
242
                        awnserSheet.questionI()
 
243
                else:
 
244
                        awnserSheet.addToSqlString(q)
 
245
                
 
246
        def questionII():
 
247
                print("Fråga II")
 
248
                print("Är du född i Sverige?")
 
249
                q = awnserSheet.qinput()
 
250
                if(q == " -1"):
 
251
                        awnserSheet.questionI()
 
252
                else:
 
253
                        awnserSheet.addToSqlString(q)
 
254
                
 
255
        def questionIII():
 
256
                print("Fråga III")
 
257
                print("Är en eller båda av dina föreldrar inte födda i Sverige?")
 
258
                q = awnserSheet.qinput()
 
259
                if(q == " -1"):
 
260
                        awnserSheet.questionI()
 
261
                else:
 
262
                        awnserSheet.addToSqlString(q)
 
263
                
 
264
        def questionCommentry():
 
265
                print("Komentarer:")
 
266
                print("Skriv en komentar på denna undörsökning:")
 
267
                q = str(input(">>>>>>"))
 
268
                wnserSheet.addToSqlString(q)
 
269
        #
 
270
###
 
271
###
 
272
        def questionAndReturn(self):
118
273
                awnserSheet.question1()
119
274
                awnserSheet.question2()
120
 
        
121
 
                return( sqlStringStart + sqlString + sqlStringEnd )
122
 
        
 
275
                awnserSheet.question3()
 
276
                awnserSheet.question4()
 
277
                awnserSheet.question5()
 
278
                awnserSheet.question6()
 
279
                awnserSheet.question7()
 
280
                awnserSheet.question8()
 
281
                awnserSheet.question9()
 
282
                awnserSheet.question10()
 
283
                awnserSheet.question11()
 
284
                awnserSheet.question12()
 
285
                awnserSheet.question13()
 
286
                awnserSheet.question14()
 
287
                awnserSheet.question15()
 
288
                awnserSheet.question16()
 
289
                awnserSheet.question18()
 
290
                awnserSheet.questionI()
 
291
                awnserSheet.questionII()
 
292
                awnserSheet.questionIII()
 
293
                awnserSheet.questionCommentry()
 
294
                
 
295
                
 
296
                print("\n\n======================== tack och adjöken ^_^ ===================\n\n")
 
297
        
 
298
                return( awnserSheet.sqlStringStart + awnserSheet.sqlString + awnserSheet.sqlStringEnd )
 
299
        
 
300