/+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 plotDB.py

  • Committer: Gustav Hartvigsson
  • Date: 2011-01-10 18:31:12 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20110110183112-x8lk1f7va1c33wyh
added the beginings of the "plotter"

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3.1
 
2
"""
 
3
This file contains the plotting funcioton that plots the data into a bar graph.
 
4
"""
 
5
import sys
 
6
import sqlite3
 
7
import numpy
 
8
 
 
9
class plotDB(object):
 
10
        def __init__(self):
 
11
                ##This array is passed to getDB
 
12
                self.nameArray = ["gudar", "spoken", "religos", "sekulart" ,"vegan" ,"mars" ,"globaluppvarmning" ,"manen" ,"motion" ,"sund" ,"deprimerad_host" ,"sno" ,"oppet" ,"dodsstraff" ,"kvinnors_rattigheter" ,"abort", "kvinnors_kropp", "deprimerad_var" ,"gast_sverige" ,"fodd_sverige" ,"foraldrar_sverige" ,"komentarer"]
 
13
                
 
14
                GetData = getDB(self.nameArray)
 
15
        
 
16
        def doPlot(self):
 
17
                CountArray = GetData.doGet()
 
18
                
 
19
        
 
20
 
 
21
class getDB(object):
 
22
        """ returns an array of counts of  from the database"""
 
23
        def __init__(self, iarray):
 
24
                self.conn = sqlite3.connect("./awnsers.sqlite")
 
25
                self.db = self.conn.cursor()
 
26
                
 
27
                self.nameArray = iarray
 
28
                self.countArray = list()
 
29
                
 
30
                self.countStart = "select count(*) from awnsers where("
 
31
                self.countEnd = " == 1);"
 
32
                
 
33
        def doGet(self):
 
34
                for name in self.nameArray:
 
35
                        getItem = self.db.execute(self.countStart + str(name) + self.countEnd )
 
36
                        
 
37
                        for item in getItem:
 
38
                                self.countArray.append(item)
 
39
                
 
40
                return self.countArray
 
41