Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Models.py
blob: 44f10215c763ebe42ef83b584596c5906ea6f3f4 (plain)
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
import sqlite3
import hashlib
import os
import logging

class ScorePadDB():
    
    def __init__(self, nickname = ""):
        
        self.scorepaddb = "../ScorePad.activity/"+str(nickname)+"db.sqlite"
        self.connection = sqlite3.connect(self.scorepaddb)
        self.cursor = self.connection.cursor()
        
    def insert_rubric(self, rubric):
        temp = (rubric.title, rubric.author, rubric.description, rubric.is_predefined,
                rubric.xo_name, rubric.rubric_sha, rubric.enable_points)
        insert_str = "INSERT INTO rubric_table(title, author, description,is_predefined,\
                        xo_name, rubric_sha,enable_points)\
                        VALUES(?,?,?,?,?,?,?)"
        self.cursor.execute(insert_str,temp)
        self.connection.commit()
        
    def insert_category(self, category):
        temp = (category.name, category.rubric_id, category.category_sha, category.percentage)
        insert_str = "INSERT INTO category_table(name,rubric_id,category_sha,percentage) VALUES (?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
    def insert_level(self, level):
        temp = (level.name,level.description,level.category_id,level.rubric_id,level.level_sha,level.points)
        insert_str = "INSERT INTO level_table(name, description, category_id, rubric_id,level_sha,points) \
                        VALUES(?,?,?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
    def insert_criteria2(self, category, levels, rubric_id):
        temp = (category.name, rubric_id, category.category_sha,category.percentage)
        insert_str = "INSERT INTO category_table(name,rubric_id,category_sha,percentage) VALUES (?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
        query_str = "SELECT MAX(category_id) from category_table"
        self.cursor.execute(query_str)
        category_id = self.cursor.fetchone()[0]
        
        insert_str = "INSERT INTO level_table(name,description,category_id,rubric_id,level_sha,points)\
                            VALUES(?,?,?,?,?,?)"
        for level in levels:
            temp = (level.name, level.description,category_id,\
                    rubric_id, level.level_sha,level.points)
            self.cursor.execute(insert_str, temp)
            self.connection.commit()
        
    def query_maxrubric(self):
        query_str = "SELECT MAX(rubric_id) from rubric_table"
        self.cursor.execute(query_str)
        rubric_id = self.cursor.fetchone()[0]
        return rubric_id
    
    def query_level(self,category_id):
        
        query_str = "SELECT * from level_table where category_id ="+str(category_id)
        self.cursor.execute(query_str)
        
        level_list = []
        for row in self.cursor:
            level = Level(row[0], row[1], row[2], row[3], row[4], row[5],row[6])
            level_list.append(level)
        return level_list
    
    def rubric_exists(self, title, author):
        temp = (title, author)
        query_str = "SELECT * FROM rubric_table WHERE title = ? and author = ?"
        
        self.cursor.execute(query_str, temp)
        for row in self.cursor:
            rubric = Rubric(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7])
        
        try:
            if rubric.rubric_id == None:
                return None
            else:
                return rubric.rubric_id
        except:
            return None
    
    def close_db(self):
        self.cursor.close()

class YardStickDB():
    
    def connect_db(self, nickname = ""):
        is_newlycreated = False
        self.yardstickdb = str(nickname)+"db.sqlite"
        if not os.path.isfile(self.yardstickdb):
            logging.debug("the database already exist")
        
        self.connection = sqlite3.connect(self.yardstickdb)
        logging.debug("ScorepadDB-->connect")
        self.cursor = self.connection.cursor()
        try:
            self.create_tables()
            is_newlycreated = True
            logging.debug("ScorepadDB -->create_tables")
        except:
            logging.debug("Exception here")
        
        return is_newlycreated
        
    def create_tables(self):
        rubric_table = "CREATE TABLE rubric_table (rubric_id INTEGER PRIMARY KEY,\
                                                title VARCHAR(40) NOT NULL,\
                                                author VARCHAR(40) NOT NULL,\
                                                description TEXT,\
                                                is_predefined INTEGER,\
                                                xo_name VARCHAR(50),\
                                                rubric_sha TEXT,\
                                                enable_points INTERGER)"
        category_table = "CREATE TABLE category_table (category_id INTEGER PRIMARY KEY,\
                                                    name VARCHAR(40) NOT NULL,\
                                                    rubric_id INTEGER NOT NULL REFERENCES rubric_table(rubric_id),\
                                                    category_sha TEXT,\
                                                    percentage FLOAT)"
        
        level_table = "CREATE TABLE level_table (level_id INTEGER PRIMARY KEY,\
                                            name VARCHAR(40) NOT NULL,\
                                            description TEXT NOT NULL,\
                                            category_id INTEGER NOT NULL REFERENCES category_table(category_id),\
                                            rubric_id INTEGER NOT NULL REFERENCES rubric_table(rubric_id),\
                                            level_sha TEXT,\
                                            points INTEGER)"
                                                    
        project_table = "CREATE TABLE project_table (project_id INTEGER PRIMARY KEY,\
                                                title VARCHAR(40) NOT NULL,\
                                                author VARCHAR(40) NOT NULL,\
                                                description TEXT,\
                                                subject VARCHAR(40),\
                                                publish_date TEXT,\
                                                is_owned INTEGER,\
                                                is_shared INTEGER,\
                                                rubric_id INTEGER NOT NULL REFERENCES rubric_table(rubric_id),\
                                                xo_name VARCHAR(50),\
                                                project_sha TEXT,\
                                                total_score FLOAT)"
        
        score_table = "CREATE TABLE score_table (score_id INTEGER PRIMARY KEY,\
                                                project_id INTEGER NOT NULL REFERENCES project_table(project_id),\
                                                rubric_id INTEGER NOT NULL REFERENCES rubric_table(rubric_id),\
                                                category_id INTEGER NOT NULL REFERENCES category_table(category_id),\
                                                level_id INTEGER NOT NULL REFERENCES level_table(level_id),\
                                                project_sha TEXT REFERENCES project_table(project_sha),\
                                                rubric_sha TEXT REFERENCES rubric_table(rubric_sha),\
                                                category_sha TEXT REFERENCES category_table(category_sha),\
                                                level_sha TEXT REFERENCES level_table(level_sha),\
                                                count INTEGER NOT NULL)"
        
        self.cursor.execute(rubric_table)
        print "rubric table created"       
        self.cursor.execute(category_table)
        print "category table created"
        self.cursor.execute(level_table)
        print "level table created"
        self.cursor.execute(project_table)
        print "project table created"
        self.cursor.execute(score_table)
        print "score table created"
        
    def insert_rubric(self, rubric):
        temp = (rubric.title, rubric.author, rubric.description, rubric.is_predefined,
                rubric.xo_name, rubric.rubric_sha, rubric.enable_points)
        insert_str = "INSERT INTO rubric_table(title, author, description,is_predefined,\
                        xo_name,rubric_sha,enable_points)\
                        VALUES(?,?,?,?,?,?,?)"
        self.cursor.execute(insert_str,temp)
        self.connection.commit()
        
    def query_maxrubric(self):
        query_str = "SELECT MAX(rubric_id) from rubric_table"
        self.cursor.execute(query_str)
        rubric_id = self.cursor.fetchone()[0]
        return rubric_id
    
    def insert_criteria(self, category, levels):
        temp = (category.name, category.rubric_id,category.category_sha,category.percentage)
        insert_str = "INSERT INTO category_table(name,rubric_id,category_sha,percentage) VALUES (?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
        query_str = "SELECT MAX(category_id) from category_table"
        self.cursor.execute(query_str)
        category_id = self.cursor.fetchone()[0]
        
        insert_str = "INSERT INTO level_table(name,description,category_id,rubric_id,level_sha,points)\
                            VALUES(?,?,?,?,?,?)"
        for i in range(len(levels)):
            temp = (levels[i].name, levels[i].description,category_id ,\
                    levels[i].rubric_id, levels[i].level_sha, levels[i].points)
            self.cursor.execute(insert_str, temp)
            self.connection.commit()
    
    def insert_project(self, project):
        temp = (project.title, project.author, project.description, project.subject,\
                project.publish_date, project.is_owned,\
                project.is_shared, project.rubric_id,project.xo_name,\
                project.project_sha,project.total_score)
        
        insert_str = "INSERT INTO project_table(title, author, description, subject,\
                        publish_date, is_owned, is_shared, rubric_id,xo_name,\
                        project_sha,total_score) VALUES (?,?,?,?,?,?,?,?,?,?,?)"
                        
        self.cursor.execute(insert_str,temp)
        self.connection.commit()
        
    def query_maxproject(self):
        query_str = "SELECT MAX(project_id) from project_table"
        self.cursor.execute(query_str)
        project_id = self.cursor.fetchone()[0]
        return project_id

    def insert_score(self, score):
        temp = (score.project_id, score.rubric_id, score.category_id, score.level_id,
                score.project_sha, score.rubric_sha, score.category_sha, score.level_sha, score.count)
        insert_str = "INSERT INTO score_table(project_id,rubric_id,category_id,level_id,\
                        project_sha, rubric_sha, category_sha, level_sha, count)\
                        VALUES (?,?,?,?,?,?,?,?,?)"
        self.cursor.execute(insert_str,temp)
        self.connection.commit()
        
    def insert_category(self, category):
        temp = (category.name,category.rubric_id,category.category_sha,category.percentage)
        insert_str = "INSERT INTO category_table(name,rubric_id,category_sha,percentage) VALUES (?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
    def insert_level(self, level):
        temp = (level.name, level.description, level.category_id, level.rubric_id, level.level_sha, level.points)
        insert_str = "INSERT INTO level_table(name, description, category_id, rubric_id, level_sha, points) \
                        VALUES(?,?,?,?,?,?)"
        self.cursor.execute(insert_str, temp)
        self.connection.commit()
        
    
    def query_maxscore(self):
        query_str = "SELECT MAX(score_id) from score_table"
        self.cursor.execute(query_str)
        score_id = self.cursor.fetchone()[0]
        return score_id
    
    def query_maxcategory(self):
        query_str = "SELECT MAX(category_id) from category_table"
        self.cursor.execute(query_str)
        category_id = self.cursor.fetchone()[0]
        return category_id
            
    def queryall_rubric(self, is_predefined):
        query_str = "SELECT * from rubric_table where is_predefined = "+str(is_predefined)
        self.cursor.execute(query_str)
        
        rubric_list = []
        for row in self.cursor:
            rubric = Rubric(row[0], row[1], row[2], row[3], row[4], row[5], row[6],row[7])
            rubric_list.append(rubric)
        return rubric_list
    
    def queryall_project(self, is_owned):
        query_str = "SELECT * from project_table where is_owned = "+str(is_owned)
        self.cursor.execute(query_str)
        
        project_list = []
        for row in self.cursor:
            project = Project(row[0],row[1],row[2],row[3],row[4],
                              row[5],row[6],row[7],row[8], row[9],row[10],row[11])
            project_list.append(project)
        return project_list
    
    def query_rubric(self, rubric_id):
        query_str = "SELECT * from rubric_table where rubric_id = "+str(rubric_id)
        self.cursor.execute(query_str)
        
        for row in self.cursor:
            rubric = Rubric(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7])
        
        return rubric
    
    def queryall_category(self, rubric_id):
        query_str = "SELECT * from category_table where rubric_id = "+str(rubric_id)
        self.cursor.execute(query_str)
        
        category_list = []
        for row in self.cursor:
            category = Category(row[0], row[1], row[2], row[3],row[4])
            category_list.append(category)
        return category_list
    
    def query_level(self,category_id):
        
        query_str = "SELECT * from level_table where category_id ="+str(category_id)
        self.cursor.execute(query_str)
        
        level_list = []
        for row in self.cursor:
            level = Level(row[0], row[1], row[2], row[3], row[4], row[5],row[6])
            level_list.append(level)
        return level_list
    
    def querylevel_id(self, category_id, level_name):
        temp = (category_id, level_name)
        query_str = "SELECT level_id from level_table WHERE category_id = ? and name = ?"
        self.cursor.execute(query_str,temp)
        level_id = self.cursor.fetchone()[0]
        return level_id

    def query_score(self, project_id, rubric_id, category_id, level_id):
        temp = (project_id, rubric_id, category_id, level_id)
        query_str = "SELECT count from score_table WHERE project_id = ? \
                    and rubric_id = ? and category_id = ? and \
                    level_id = ?"
        self.cursor.execute(query_str, temp)
        count = self.cursor.fetchone()[0]
        return count

    def query_score2(self, project_id, rubric_id, category_id, level_id):
        temp = (project_id, rubric_id, category_id, level_id)
        query_str = "SELECT * from score_table WHERE project_id = ? \
                    and rubric_id = ? and category_id = ? and \
                    level_id = ?"

        self.cursor.execute(query_str, temp)
        for row in self.cursor:
            score = Score(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9])
        return score

    def query_project_sha(self, project_id):
        query_str = "SELECT project_sha from project_table WHERE project_id = "+ str(project_id)
        self.cursor.execute(query_str)
        
        project_sha = self.cursor.fetchone()[0]
        return str(project_sha)
        
    def query_project(self, project_id):
        query_str = "SELECT * from project_table WHERE project_id ="+ str(project_id)
        self.cursor.execute(query_str)        

        for row in self.cursor:
            project = Project(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9],row[10],row[11])

        return project

    def query_rubric_sha(self, rubric_id):
        query_str = "SELECT rubric_sha from rubric_table WHERE rubric_id = "+ str(rubric_id)
        self.cursor.execute(query_str)
        
        rubric_sha = self.cursor.fetchone()[0]
        return str(rubric_sha)       

    def query_category_sha(self, category_id):
        query_str = "SELECT category_sha from category_table WHERE category_id = "+ str(category_id)
        self.cursor.execute(query_str)
        
        category_sha = self.cursor.fetchone()[0]
        return str(category_sha)
    
    def query_level_sha(self, level_id):
        query_str = "SELECT level_sha from level_table WHERE level_id = "+ str(level_id)
        self.cursor.execute(query_str)
        
        level_sha = self.cursor.fetchone()[0]
        return str(level_sha)
    
    def query_score_id(self, project_sha, rubric_sha, category_sha, level_sha):
        temp = (project_sha, rubric_sha, category_sha, level_sha)
        query_str = "SELECT score_id from score_table WHERE project_sha = ? \
                    and rubric_sha = ? and category_sha = ? and level_sha = ?"
        self.cursor.execute(query_str, temp)
        score_id = self.cursor.fetchone()[0]
        return score_id
    
    def is_points_enabled(self, rubric_id):
        query_str = "SELECT enable_points from rubric_table WHERE rubric_id = " + str(rubric_id)
        self.cursor.execute(query_str)
        enable_points = self.cursor.fetchone()[0]
        if enable_points == 0:
            return False
        else :
            return True
    
    def queryall_level(self, rubric_id):
        query_str = "SELECT * from level_table where rubric_id = "+str(rubric_id)
        self.cursor.execute(query_str)
        
        level_list = []
        for row in self.cursor:
            level = Level(row[0],row[1],row[2],row[3],row[4],row[5],row[6])
            level_list.append(level)
        return level_list
    
    def query_category_id(self, rubric_id, name):
        temp = (rubric_id, name)
        query_str = "SELECT * from category_table where rubric_id = ? and name = ?"
        self.cursor.execute(query_str, temp)
        category_id = self.cursor.fetchone()[0]
        
        return category_id
    
    def query_level_id(self, rubric_id, category_id, name):
        temp = (rubric_id, category_id, name)
        query_str = "SELECT * from level_table where rubric_id = ? and category_id = ? and name = ?"
        self.cursor.execute(query_str, temp)
        level_id = self.cursor.fetchone()[0]
        
        return level_id

    def update_project(self, modified_project):
        temp = (modified_project.title,modified_project.author,modified_project.description,\
                        modified_project.subject,\
                        modified_project.publish_date,\
                        modified_project.rubric_id,modified_project.project_sha,\
                        modified_project.total_score,\
                        modified_project.project_id)
        update_str = "UPDATE project_table SET title = ?,"+\
                        "author = ?, "+\
                        "description = ?,"+\
                        "subject = ?,"+\
                        "publish_date = ?,"+\
                        "rubric_id = ?,"+\
                        "project_sha = ?"+\
                        "total_score = ?"+\
                        "WHERE project_id = ?"
        self.cursor.execute(update_str,temp)
        self.connection.commit()
        
    def update_levels(self, modified_levels):
        
        for i in modified_levels:
            temp = (i.name,i.description,i.level_id,)
            update_str = "UPDATE level_table SET name = ?,"+\
                            "description = ?"+\
                            "WHERE level_id = ?"
            self.cursor.execute(update_str,temp)
            self.connection.commit()
            
    def update_level(self, modified_level):
        temp = (modified_level.name,modified_level.description,modified_level.level_id,)
        update_str = "UPDATE level_table SET name = ?,"+\
                            "description = ?"+\
                            "WHERE level_id = ?"
        self.cursor.execute(update_str,temp)
        self.connection.commit()
            
    def update_categories(self, modified_categories):
        for i in modified_categories:
            temp = (i.name,i.rubric_id,i.category_id)
            update_str = "UPDATE category_table SET name = ?"+\
                            "WHERE rubric_id = ? and category_id = ?"
            self.cursor.execute(update_str,temp)
            self.connection.commit()
            
    def update_category(self, modified_category):
        temp = (modified_category.name,modified_category.rubric_id,modified_category.category_id)
        update_str = "UPDATE category_table SET name = ?"+\
                            "WHERE rubric_id = ? and category_id = ?"
        self.cursor.execute(update_str,temp)
        self.connection.commit()
            
    def update_rubric(self, modified_rubric):
        temp = (modified_rubric.title,modified_rubric.author,modified_rubric.description,modified_rubric.enable_points,
                modified_rubric.rubric_id)
        update_str = "UPDATE rubric_table SET title = ?,"+\
                        "author = ?, "+\
                        "description = ?,"+\
                        "enable_points = ?"+\
                        "WHERE rubric_id = ?"
        self.cursor.execute(update_str,temp)
        self.connection.commit()
        
    def update_percentage(self, category_id, percentage):
        temp = (percentage, category_id)
        update_str = "UPDATE category_table SET percentage = ?"+\
                        "WHERE category_id = ?"
        self.cursor.execute(update_str, temp)
        self.connection.commit()
        
    def update_points(self, category_id, level_name, points):
        temp = (points, category_id, level_name)
        update_str = "UPDATE level_table SET points = ?"+\
                        "WHERE category_id = ? and name = ?"
        self.cursor.execute(update_str, temp)
        self.connection.commit()
        
    def update_enablepoints(self, rubric_id, is_enable):
        temp = (is_enable, rubric_id)
        update_str = "UPDATE rubric_table SET enable_points = ?"+\
                        "WHERE rubric_id = ?"
        self.cursor.execute(update_str, temp)
        self.connection.commit()
        
        
    
    def delete_project(self, project_id):
        delete_str = "DELETE FROM project_table WHERE project_id ="+ str(project_id)
        self.cursor.execute(delete_str)
        
        self.connection.commit()
        
    def delete_rubric(self, rubric_id):
        delete_str = "DELETE FROM rubric_table WHERE rubric_id ="+ str(rubric_id)
        self.cursor.execute(delete_str)
        
        delete_str = "DELETE FROM category_table WHERE rubric_id ="+ str(rubric_id)
        self.cursor.execute(delete_str)
        
        delete_str = "DELETE FROM level_table WHERE rubric_id ="+ str(rubric_id)
        self.cursor.execute(delete_str)
        
        self.connection.commit()
        
    def score_exists(self, project_id, rubric_id, category_id, level_id):
        temp = (project_id, rubric_id, category_id, level_id)
        query_str = "SELECT * FROM score_table WHERE project_id = ? and rubric_id = ? and \
                        category_id = ? and level_id = ?"
        
        self.cursor.execute(query_str, temp)
        for row in self.cursor:
            score = Score(row[0],row[1],row[2],row[3],row[4],row[5],row[6],\
                          row[7],row[8],row[9])
        
        try:
            if score.score_id == None:
                return False
            else:
                return True
        except:
            return False
        
    def project_exists(self, project_sha, author):
        temp = (project_sha, author)
        query_str = "SELECT * FROM project_table WHERE project_sha = ? and author = ?"
        
        self.cursor.execute(query_str, temp)
        for row in self.cursor:
            project = Project(row[0],row[1],row[2],row[3],row[4],row[5],row[6],\
                          row[7],row[8],row[9],row[10],row[11])
        
        try:
            if project.project_id == None:
                return False
            else:
                return True
        except:
            return False
    
    def rubric_exists(self, rubric_sha, description):
        temp = (rubric_sha, description)
        query_str = "SELECT * FROM rubric_table WHERE rubric_sha = ? and description = ?"
        
        self.cursor.execute(query_str, temp)
        for row in self.cursor:
            rubric = Rubric(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7])
        
        try:
            if rubric.rubric_id == None:
                return None
            else:
                return rubric.rubric_id
        except:
            return None
        
    def rubric_title_exists(self, rubric_title):
        query_str = "SELECT * FROM rubric_table WHERE title = \'" + str(rubric_title) +"\'"
        self.cursor.execute(query_str)
        count = 0
        for row in self.cursor:
            rubric = Rubric(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7])
            count = count+1
            
        try:
            if rubric.rubric_id == None:
                return None
            else:
                return count
        except:
            return None
        
    def query_score_attr(self, score_id):
        query_str = "SELECT * from score_table WHERE score_id = " + str(score_id)
        self.cursor.execute(query_str)
        
        for row in self.cursor:
            score = Score(row[0],row[1],row[2],row[3],row[4],row[5],row[6],\
                          row[7],row[8],row[9])
        
        attr = [score.project_id, score.rubric_id, score.category_id, score.level_id]
        return attr
        
        
    def increment_scorecount(self, project_id, rubric_id, category_id, level_id):
        temp = (project_id, rubric_id, category_id, level_id)
        query_str = "SELECT * FROM score_table WHERE project_id = ? and rubric_id = ? and \
                        category_id = ? and level_id = ?"
        self.cursor.execute(query_str, temp)
        
        for row in self.cursor:
            score = Score(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9])
        
        score_id = score.score_id
        count = score.count
        count = count +1
        temp = (count, score_id)
        update_str = "UPDATE score_table SET count = ?"+\
                        "WHERE score_id = ?"
        self.cursor.execute(update_str, temp)
        self.connection.commit()
        return score_id
    
    def close_db(self):
        self.cursor.close()
    
class Project():
    
    def __init__(self, project_id = 0, title = "", author = "",
                 description = "", subject = "", publish_date = "",
                 is_owned = 1, is_shared = 1, rubric_id = None, xo_name = "",
                 project_sha = "", total_score = 0):
        self.project_id = project_id
        self.title = title
        self.author = author
        self.description = description
        self.subject = subject
        self.publish_date = publish_date
        self.is_owned = is_owned
        self.is_shared = is_shared
        self.rubric_id = rubric_id
        self.xo_name = xo_name
        self.project_sha = self.get_sha(xo_name, title, publish_date)
        self.total_score = total_score
        
    
    def get_sha(self, xo_name, title, publish_date):
        text = xo_name + title + str(publish_date)
        h = hashlib.sha1()
        h.update(text)
        project_sha = str(h.hexdigest())
        
        return project_sha
        

        
class Rubric():
    
    def __init__(self, rubric_id = 0, title = "", author = "", description = "",\
                 is_predefined =None, xo_name = "", rubric_sha = "", enable_points = 0):
        self.rubric_id = rubric_id
        self.title = title
        self.author = author
        self.description = description
        self.is_predefined = is_predefined
        self.xo_name = xo_name
        self.rubric_sha = self.get_sha(xo_name, title, author)
        self.enable_points = enable_points
        
    def get_sha(self, xo_name, title, author):
        text = xo_name + title + author
        h = hashlib.sha1()
        h.update(text)
        rubric_sha = str(h.hexdigest())
        
        return rubric_sha
        

class Category():
    
    def __init__(self, category_id = None, name = "", rubric_id = None, 
                 category_sha = "", percentage = 0.0):
        self.category_id = category_id
        self.name = name
        self.rubric_id = rubric_id
        self.category_sha = self.get_sha(name)
        self.percentage = percentage
        
    def get_sha(self, name):
        text = name
        h = hashlib.sha1()
        h.update(text)
        category_sha = str(h.hexdigest())
        
        return category_sha
    

class Level():
    
    def __init__(self, level_id = None, name = "", description = "",
                category_id = None, rubric_id = None,
                level_sha = "", points = 0):
        self.level_id = level_id
        self.name = name
        self.description = description
        self.category_id = category_id
        self.rubric_id = rubric_id
        self.level_sha = self.get_sha(name,description)
        self.points = points
        
    def get_sha(self, name, description):
        text = name + description
        h = hashlib.sha1()
        h.update(text)
        level_sha = str(h.hexdigest())
        
        return level_sha

class Score():
    
    def __init__(self, score_id = 0, project_id = None, rubric_id = None, category_id = None,level_id = None,
                 project_sha = "", rubric_sha = "", category_sha = "", level_sha = "",count = 0):
        self.score_id = score_id
        self.project_id = project_id
        self.rubric_id = rubric_id
        self.category_id = category_id
        self.level_id = level_id
        self.project_sha = project_sha
        self.rubric_sha = rubric_sha
        self.category_sha = category_sha
        self.level_sha = level_sha
        self.count = count