<commit_before>from django.db import connection, transaction
from itertools import groupby
from operator import itemgetter

def getAllAgendaPartyVotes():
    cursor = connection.cursor()
    cursor.execute(PARTY_QUERY)
    results = dict(map(lambda (key,group):(key,map(lambda g:(g[1],float(g[2]),float(g[3])),list(group))),
                       groupby(cursor.fetchall(),key=itemgetter(0))))
    return results

PARTY_QUERY = """
SELECT a.agendaid,
       a.partyid,
       round(coalesce(cast(coalesce(v.totalvotevalue,0.0)/a.totalscore*100.0 as numeric),0.0),2) score,
       round(coalesce(cast(coalesce(v.numvotes,0.0)/a.totalvolume*100.0 as numeric),0.0),2) volume
FROM   (SELECT agid                   agendaid,
               m.id                   partyid,
               sc * m.number_of_seats totalscore,
               numvotes * m.number_of_seats totalvolume
        FROM   (SELECT agenda_id               agid,
                       SUM(abs(score * importance)) sc,
                       COUNT(*) numvotes
                FROM   agendas_agendavote
                GROUP  BY agenda_id) agendavalues
               left outer join mks_party m
                 on 1=1) a
       left outer join (SELECT agenda_id, 
                          partyid, 
                          SUM(forvotes) - SUM(againstvotes) totalvotevalue ,
                          SUM(numvotes) numvotes
                   FROM   (SELECT a.agenda_id, 
                                  p.partyid, <commit_msg>Quick bug fix for divide by zero on empty agenda<commit_after>from django.db import connection, transaction
from itertools import groupby
from operator import itemgetter

def getAllAgendaPartyVotes():
    cursor = connection.cursor()
    cursor.execute(PARTY_QUERY)
    results = dict(map(lambda (key,group):(key,map(lambda g:(g[1],float(g[2]),float(g[3])),list(group))),
                       groupby(cursor.fetchall(),key=itemgetter(0))))
    return results

PARTY_QUERY = """
SELECT a.agendaid,
       a.partyid,
       round(coalesce(cast(coalesce(v.totalvotevalue,0.0)/(case when a.totalscore = 0 then 1 else a.totalscore end)*100.0 as numeric),0.0),2) score,
       round(coalesce(cast(coalesce(v.numvotes,0.0)/a.totalvolume*100.0 as numeric),0.0),2) volume
FROM   (SELECT agid                   agendaid,
               m.id                   partyid,
               sc * m.number_of_seats totalscore,
               numvotes * m.number_of_seats totalvolume
        FROM   (SELECT agenda_id               agid,
                       SUM(abs(score * importance)) sc,
                       COUNT(*) numvotes
                FROM   agendas_agendavote
                GROUP  BY agenda_id) agendavalues
               left outer join mks_party m
                 on 1=1) a
       left outer join (SELECT agenda_id, 
                          partyid, 
                          SUM(forvotes) - SUM(againstvotes) totalvotevalue ,
                          SUM(numvotes) numvotes
                   FROM   (SELECT a.agenda_id, 
                                  p.partyid, 
{'fraction_non_alphanumeric': 0.09309895833333333, 'fraction_numerical': 0.016276041666666668, 'mean_word_length': 1.7684684684684684, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1731010', 'n_tokens_mistral': 960, 'n_tokens_neox': 903, 'n_words': 191}