コード例 #1
0
def pca(request):
    """
    PCA view
    :param request:
    :return:
    """
    context = RequestContext(request)
    content['activesite'] = scatter['pca']
    reusable_query = Topic.objects.all().order_by('id')
    content['parties'] = Party.objects.all().order_by('id')
    content['topics'] = reusable_query
    content['selected_topics'] = []
    parties = []
    topics = []
    if request.method == 'POST':
        query = request.POST
        if query.getlist('party'):
            parties = query.getlist('party')
        if query.getlist('topic'):
            topics = query.getlist('topic')
        votes = get_votes_for_scatter(parties,topics)
        scores = run_pca(votes)
        content['scatter_data'] = mark_safe(get_data_scatter(scores))
        return render_to_response('pca.html', content, context)

    else:
    # FOR THE CONCURRENCY
    # You want to find the 'freshest' which you have not responded to
    # either by timestamp and keeping a record of what you responded to
    # or by having an extra field where you record the answer to requests
        votes = get_votes_for_scatter(parties,topics)
        scores = run_pca(votes)
        content['scatter_data'] = mark_safe(get_data_scatter(scores))
        return render_to_response('pca.html', content, context)
コード例 #2
0
    def testType(self):

        django_settings = __import__(os.environ['DJANGO_SETTINGS_MODULE'],
                                     fromlist='DATABASES')
        databases = django_settings.DATABASES
        for name, db in databases.iteritems():
            host = db['HOST']
            user = db['USER']
            password = db['PASSWORD']
            port = db['PORT']
            db_name = db['NAME']
            db_type = db['ENGINE']

            cn = pq.connect('dbname=' + db_name + ' user='******' password='******' host=' + host)

        vote = 'SELECT DISTINCT vote.msp_id, vote.division_id, vote.vote FROM msp_vote AS vote, msp_msp AS msp WHERE msp.id = 330'

        cr = cn.cursor()
        cr.execute(vote)
        returned_votes = cr.fetchall()
        output = run_pca(returned_votes)
        L = []

        print(str(type(output)) + '==' + str(type(L)))
        print('testType Passes')
コード例 #3
0
    def testType(self):

         django_settings = __import__(os.environ['DJANGO_SETTINGS_MODULE'], fromlist='DATABASES')
         databases = django_settings.DATABASES
         for name, db in databases.iteritems():
             host = db['HOST']
             user = db['USER']
             password = db['PASSWORD']
             port = db['PORT']
             db_name = db['NAME']
             db_type = db['ENGINE']


             cn = pq.connect('dbname=' + db_name + ' user='******' password='******' host=' + host)

         vote = 'SELECT DISTINCT vote.msp_id, vote.division_id, vote.vote FROM msp_vote AS vote, msp_msp AS msp WHERE msp.id = 330'

         cr = cn.cursor()
         cr.execute(vote)
         returned_votes = cr.fetchall()
         output = run_pca(returned_votes)
         L = []

         print str(type(output)) + '==' +  str(type(L))
         print 'testType Passes'