# -*- coding: utf-8 -*-

import sys, os

class _Depute(object):
  def __init__(self, nom, prenom):
    self.nom         = nom
    self.prenom      = prenom
    self.groupe      = "xxx"
    self.orientation = "xxx"
    self.pacte       = 0
    self.votes       = {}
  def set_groupe(self, groupe):
    self.groupe = groupe
    if   groupe in [u"gdr", u"src"]: self.orientation = u"gauche"
    elif groupe in [u"ump", u"nc" ]: self.orientation = u"droite"
    else:                            self.orientation = u"xxx"
  def get_vote(self, date):
    vote = self.votes.get(date)
    if not vote: return 0
    return vote
  def __repr__(self): return "<Depute '%s' '%s' %s>" % (self.nom, self.prenom, self.orientation)
    
DEPUTES = {}
def Depute(nom, prenom):
  depute = DEPUTES.get((nom, prenom))
  if not depute: depute = DEPUTES[(nom, prenom)] = _Depute(nom, prenom)
  return depute

def enleve_accents(s):
  return s.replace(u"é", u"e").replace(u"è", u"e").replace(u"ê", u"e").replace(u"ë", u"e").replace(u"ï", u"i").replace(u"î", u"i").replace(u"à", u"a").replace(u"ä", u"a").replace(u"â", u"a").replace(u"ù", u"u").replace(u"û", u"u").replace(u"ü", u"u").replace(u"ö", u"o").replace(u"ô", u"o")

def ont_signe(s):
  s = enleve_accents(s)
  for ligne in s.split(u"\n"):
    champs = ligne.split(u"\t")
    prenom, nom = champs[1].replace(u" (site web)", u"").lower().split(None, 1)
    prenom = prenom.strip()
    nom    = nom   .strip()
    Depute(nom, prenom).pacte = 1
  
def ont_vote(date, groupe, vote, s):
  s = enleve_accents(s)
  s = s.replace(u"MM." , u"")
  s = s.replace(u"M."  , u"")
  s = s.replace(u"Mmes", u"")
  s = s.replace(u"Mme" , u"")
  s = s.replace(u" et ", u",")
  for nom_prenom in s.rsplit(u","):
    prenom, nom = nom_prenom.strip().lower().split(None, 1)
    depute = Depute(nom, prenom)
    depute.votes[date] = vote
    depute.set_groupe(groupe)


# Signature du pacte
ont_signe(u"""08/06/07 	 Michèle TABAROT (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Alpes-Maritimes - 9è circonscription
05/06/07 	Jean-Marc LEFRANC (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Calvados - 5è circonscription
26/05/07 	Marc LE FUR (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Côtes-d'Armor - 3è circonscription
06/06/07 	Patrick LABAUNE (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Drôme - 1ère circonscription
15/05/09 	Lionel TARDY 	UNION POUR UN MOUVEMENT POPULAIRE 	Haute-Savoie - 2è circonscription
05/06/07 	Martine AURILLAC 	UNION POUR UN MOUVEMENT POPULAIRE 	Paris - 3è circonscription
02/06/07 	Yves JEGO (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Seine-et-Marne - 3è circonscription
26/05/07 	Bernard CARAYON (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Tarn - 4è circonscription
01/06/07 	Georges MOTHRON (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Val-d'Oise - 5è circonscription
28/05/07 	François VANNSON (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Vosges - 3è circonscription
28/05/07 	Etienne PINTE (site web) 	UNION POUR UN MOUVEMENT POPULAIRE 	Yvelines - 1ère circonscription
31/05/07 	Jean LASSALLE (site web) 	UDF - Mouvement Démocrate 	Pyrénées-Atlantiques - 4è circonscription
27/05/07 	Jean-Pierre BRARD 	RASSEMBLEMENT DE LA GAUCHE POUR RESISTER 	Seine-Saint-Denis - 7è circonscription
04/06/07 	Jean MALLOT (site web) 	PARTI SOCIALISTE 	Allier - 3è circonscription
04/06/07 	Jean-Louis BIANCO (site web) 	PARTI SOCIALISTE 	Alpes-de-Haute-Provence - 1ère circonscription
01/06/07 	Philippe DURON (site web) 	PARTI SOCIALISTE 	Calvados - 1ère circonscription
01/06/07 	Laurence DUMONT (site web) 	PARTI SOCIALISTE 	Calvados - 2è circonscription
26/06/07 	Maxime BONO 	PARTI SOCIALISTE 	Charente-Maritime - 1ère circonscription
04/06/07 	François HOLLANDE (site web) 	PARTI SOCIALISTE 	Corrèze - 1ère circonscription
31/05/07 	Danielle BOUSQUET (site web) 	PARTI SOCIALISTE 	Côtes-d'Armor - 1ère circonscription
31/05/07 	Jean GAUBERT (site web) 	PARTI SOCIALISTE 	Côtes-d'Armor - 2è circonscription
31/05/07 	Marie-Renée OGET (site web) 	PARTI SOCIALISTE 	Côtes-d'Armor - 4è circonscription
31/05/07 	Corinne ERHEL (site web) 	PARTI SOCIALISTE 	Côtes-d'Armor - 5è circonscription
03/06/07 	Pierre MOSCOVICI (site web) 	PARTI SOCIALISTE 	Doubs - 4è circonscription
31/05/07 	William DUMAS (site web) 	PARTI SOCIALISTE 	Gard - 5è circonscription
04/06/07 	Michèle DELAUNAY (site web) 	PARTI SOCIALISTE 	Gironde - 2è circonscription
29/05/07 	Michel SAINTE-MARIE (site web) 	PARTI SOCIALISTE 	Gironde - 6è circonscription
02/06/07 	Alain ROUSSET 	PARTI SOCIALISTE 	Gironde - 7è circonscription
07/06/07 	François DELUGA (site web) 	PARTI SOCIALISTE 	Gironde - 8è circonscription
09/06/07 	Catherine LEMORTON (site web) 	PARTI SOCIALISTE 	Haute-Garonne - 1ère circonscription
03/06/07 	Pierre COHEN (site web) 	PARTI SOCIALISTE 	Haute-Garonne - 3è circonscription
02/06/07 	Martine MARTINEL (site web) 	PARTI SOCIALISTE 	Haute-Garonne - 4è circonscription
29/05/07 	Françoise IMBERT (site web) 	PARTI SOCIALISTE 	Haute-Garonne - 5è circonscription
03/06/07 	Monique IBORRA (site web) 	PARTI SOCIALISTE 	Haute-Garonne - 6è circonscription
05/06/07 	Monique BOULESTIN (site web) 	PARTI SOCIALISTE 	Haute-Vienne - 1ère circonscription
28/05/07 	Marie-Françoise PEROL-DUMONT 	PARTI SOCIALISTE 	Haute-Vienne - 3è circonscription
13/08/09 	Alain RODET 	PARTI SOCIALISTE 	Haute-Vienne - 4è circonscription
06/06/07 	Philippe TOURTELIER (site web) 	PARTI SOCIALISTE 	Ille-et-Vilaine - 2è circonscription
12/06/07 	Jean-Patrick GILLE 	PARTI SOCIALISTE 	Indre-et-Loire - 1ère circonscription
28/05/07 	François BROTTES (site web) 	PARTI SOCIALISTE 	Isère - 5è circonscription
07/06/07 	Alain VIDALIES 	PARTI SOCIALISTE 	Landes - 1ère circonscription
04/06/07 	Régis JUANICO (site web) 	PARTI SOCIALISTE 	Loire - 1ère circonscription
09/06/07 	Jean-Louis GAGNAIRE (site web) 	PARTI SOCIALISTE 	Loire - 2è circonscription
13/07/09 	Dominique RAIMBOURG (site web) 	PARTI SOCIALISTE 	Loire-Atlantique - 4è circonscription
06/06/07 	Hervé FERON (site web) 	PARTI SOCIALISTE 	Meurthe-et-Moselle - 2è circonscription
02/06/07 	Jean-Yves LE DEAUT 	PARTI SOCIALISTE 	Meurthe-et-Moselle - 6è circonscription
29/05/07 	Michel LIEBGOTT 	PARTI SOCIALISTE 	Moselle - 10è circonscription
26/05/07 	Christian PAUL (site web) 	PARTI SOCIALISTE 	Nièvre - 3è circonscription
05/06/07 	Bernard ROMAN (site web) 	PARTI SOCIALISTE 	Nord - 1ère circonscription
29/05/07 	Bernard DEROSIER (site web) 	PARTI SOCIALISTE 	Nord - 2è circonscription
08/06/07 	Yves DURAND (site web) 	PARTI SOCIALISTE 	Nord - 11è circonscription
26/05/07 	Danièle HOFFMAN-RISPAL (site web) 	PARTI SOCIALISTE 	Paris - 6è circonscription
26/05/07 	Patrick BLOCHE (site web) 	PARTI SOCIALISTE 	Paris - 7è circonscription
09/06/07 	Sandrine MAZETIER (site web) 	PARTI SOCIALISTE 	Paris - 8è circonscription
02/06/07 	Daniel VAILLANT (site web) 	PARTI SOCIALISTE 	Paris - 19è circonscription
30/05/07 	Jean-Pierre KUCHEIDA 	PARTI SOCIALISTE 	Pas-de-Calais - 12è circonscription
30/05/07 	Guy DELCOURT 	PARTI SOCIALISTE 	Pas-de-Calais - 13è circonscription
05/06/07 	Albert FACON 	PARTI SOCIALISTE 	Pas-de-Calais - 14è circonscription
27/05/07 	Alain NERI (site web) 	PARTI SOCIALISTE 	Puy-de-Dôme - 2è circonscription
29/05/07 	Jean-Paul BACQUET 	PARTI SOCIALISTE 	Puy-de-Dôme - 4è circonscription
04/06/07 	Martine LIGNIERES-CASSOU 	PARTI SOCIALISTE 	Pyrénées-Atlantiques - 1ère circonscription
04/06/07 	David HABIB 	PARTI SOCIALISTE 	Pyrénées-Atlantiques - 3è circonscription
03/06/07 	Jean-Louis TOURAINE (site web) 	PARTI SOCIALISTE 	Rhône - 3è circonscription
16/06/07 	Christophe BOUILLON (site web) 	PARTI SOCIALISTE 	Seine-Maritime - 5è circonscription
24/05/07 	Jean-Yves LE BOUILLONNEC (site web) 	PARTI SOCIALISTE 	Val-de-Marne - 11è circonscription
10/06/07 	Roland MUZEAU (site web) 	PARTI COMMUNISTE FRANCAIS 	Hauts-de-Seine - 1ère circonscription
31/05/07 	Jacqueline FRAYSSE (site web) 	PARTI COMMUNISTE FRANCAIS 	Hauts-de-Seine - 4è circonscription
09/06/07 	Marie-Hélène AMIABLE (site web) 	PARTI COMMUNISTE FRANCAIS 	Hauts-de-Seine - 11è circonscription
30/05/07 	Marie-George BUFFET (site web) 	PARTI COMMUNISTE FRANCAIS 	Seine-Saint-Denis - 4è circonscription
08/06/07 	Christian HUTIN (site web) 	MOUVEMENT REPUBLICAIN ET CITOYEN 	Nord - 12è circonscription
04/06/07 	Noël MAMERE (site web) 	LES VERTS 	Gironde - 3è circonscription
01/06/07 	Martine BILLARD (site web) 	LES VERTS 	Paris - 1ère circonscription
06/06/07 	Yves COCHET (site web) 	LES VERTS 	Paris - 11è circonscription
19/02/08 	Nicolas DUPONT-AIGNAN (site web) 	DEBOUT LA REPUBLIQUE 	Essonne - 8è circonscription
02/06/07 	Maxime GREMETZ (site web) 	COMMUNISTE 	Somme - 1ère circonscription
05/06/07 	Philippe FOLLIOT (site web) 	APPARENTE NOUVEAU CENTRE 	Tarn - 3è circonscription""")

dates = ["12/5/2009", "15/9/2009"]

# Vote du 12/5/2009
ont_vote(dates[0], "gdr", -1, u"""Mme Marie-Hélène Amiable, M. François Asensi, Mmes Huguette Bello, Martine Billard, MM. Alain Bocquet, Patrick Braouezec, Jean-Pierre Brard, Mme Marie-George Buffet, MM. Jean-Jacques Candelier, André Chassaigne, Yves Cochet, Jacques Desallangre, Marc Dolez, Mme Jacqueline Fraysse, MM. André Gerin, Pierre Gosnat, Maxime Gremetz, Jean-Paul Lecoq, Noël Mamère, Roland Muzeau, Daniel Paul, François de Rugy, Jean-Claude Sandrier et Michel Vaxès""")

ont_vote(dates[0], "src",  1, u"""MM. Jack Lang""")
ont_vote(dates[0], "src", -1, u"""Mmes Patricia Adam, Sylvie Andrieux, MM. Jean-Marc Ayrault, Jean-Paul Bacquet, Dominique Baert, Jean-Pierre Balligand, Gérard Bapt, Claude Bartolone, Jacques Bascou, Christian Bataille, Mmes Delphine Batho, Chantal Berthelot, M. Jean-Louis Bianco, Mme Gisèle Biémouret, MM. Serge Blisko, Patrick Bloche, Daniel Boisserie, Maxime Bono, Jean-Michel Boucheron, Mme Marie-Odile Bouillé, M. Christophe Bouillon, Mme Monique Boulestin, M. Pierre Bourguignon, Mme Danielle Bousquet, MM. François Brottes, Alain Cacheux, Jérôme Cahuzac, Jean-Christophe Cambadélis, Thierry Carcenac, Christophe Caresche, Mme Martine Carrillon-Couvreur, MM. Laurent Cathala, Bernard Cazeneuve, Guy Chambefort, Jean-Paul Chanteguet, Alain Claeys, Jean-Michel Clément, Mme Marie-Françoise Clergeau, MM. Gilles Cocquempot, Pierre Cohen, Mmes Catherine Coutelle, Pascale Crozon, M. Frédéric Cuvillier, Mme Claude Darciaux, M. Pascal Deguilhem, Mme Michèle Delaunay, MM. Guy Delcourt, Michel Delebarre, François Deluga, Bernard Derosier, Michel Destot, René Dosière, Julien Dray, Tony Dreyfus, Jean-Pierre Dufau, Mme Laurence Dumont, MM. Jean-Louis Dumont, Jean-Paul Dupré, Yves Durand, Mme Odette Duriez, MM. Philippe Duron, Olivier Dussopt, Christian Eckert, Henri Emmanuelli, Mme Corinne Erhel, MM. Laurent Fabius, Albert Facon, Mme Martine Faure, M. Hervé Feron, Mmes Aurélie Filippetti, Geneviève Fioraso, M. Pierre Forgues, Mme Valérie Fourneyron, MM. Michel Françaix, Jean-Claude Fruteau, Jean-Louis Gagnaire, Mme Geneviève Gaillard, M. Jean Gaubert, Mmes Catherine Génisson, Annick Girardin, MM. Joël Giraud, Jean Glavany, Daniel Goldberg, Gaëtan Gorce, Marc Goua, Jean Grellier, Mme Elisabeth Guigou, M. David Habib, Mme Danièle Hoffman-Rispal, M. François Hollande, Mme Sandrine Hurel, M. Christian Hutin, Mme Monique Iborra, M. Jean-Louis Idiart, Mme Françoise Imbert, MM. Michel Issindou, Eric Jalton, Serge Janquin, Henri Jibrayel, Régis Juanico, Armand Jung, Mme Marietta Karamanli, M. Jean-Pierre Kucheida, Mme Conchita Lacuey, MM. Jérôme Lambert, François Lamy, Mme Colette Langlade, M. Jean-Yves Le Bouillonnec, Mme Marylise Lebranchu, MM. Patrick Lebreton, Gilbert Le Bris, Jean-Yves Le Déaut, Michel Lefait, Jean-Marie Le Guen, Mme Annick Le Loch, M. Patrick Lemasle, Mmes Catherine Lemorton, Annick Lepetit, MM. Bruno Le Roux, Jean-Claude Leroy, Bernard Lesterlin, Serge Letchimy, Michel Liebgott, Mme Martine Lignières-Cassou, MM. Albert Likuvalu, François Loncle, Victorin Lurel, Jean Mallot, Louis-Joseph Manscour, Mmes Jacqueline Maquet, Jeanny Marc, Marie-Lou Marcel, MM. Jean-René Marsac, Philippe Martin, Mmes Martine Martinel, Frédérique Massat, MM. Gilbert Mathon, Didier Mathus, Mme Sandrine Mazetier, MM. Michel Ménard, Kléber Mesquida, Didier Migaud, Pierre Moscovici, Pierre-Alain Muet, Philippe Nauche, Henri Nayrou, Alain Néri, Mmes Marie-Renée Oget, Françoise Olivier-Coupeau, MM. Michel Pajon, Christian Paul, Mme George Pau-Langevin, MM. Germinal Peiro, Jean-Luc Perat, Jean-Claude Perez, Mmes Marie-Françoise Pérol-Dumont, Martine Pinville, MM. Philippe Plisson, François Pupponi, Mme Catherine Quéré, MM. Jean-Jack Queyranne, Dominique Raimbourg, Mmes Marie-Line Reynaud, Chantal Robin-Rodrigo, MM. Alain Rodet, Bernard Roman, René Rouquet, Alain Rousset, Patrick Roy, Michel Sainte-Marie, Michel Sapin, Mme Odile Saugues, M. Christophe Sirugue, Mme Christiane Taubira, M. Pascal Terrasse, Mme Marisol Touraine, MM. Jean-Louis Touraine, Philippe Tourtelier, Jean Jacques Urvoas, Daniel Vaillant, Jacques Valax, André Vallini, Manuel Valls, Michel Vauzelle, Michel Vergnier, André Vézinhet, Alain Vidalies, Jean-Michel Villaumé, Jean-Claude Viollet et Philippe Vuilque""")
ont_vote(dates[0], "src",  0, u"""MM. Gérard Charasse, Paul Giacobbi, Jean Michel, Arnaud Montebourg, Mmes Dominique Orliac et Sylvia Pinel""")

ont_vote(dates[0], "nc" ,  1, u"""MM. Raymond Durand, Michel Hunault, Olivier Jardé, Yvan Lachaud, Maurice Leroy, Nicolas Perruchot, Rudy Salles, François Sauvadet, Marc Vampa, Francis Vercamer et Philippe Vigier""")
ont_vote(dates[0], "nc" , -1, u"""MM. Jean-Pierre Abelin, Jean Dionis du Séjour, Philippe Folliot, Jean-Christophe Lagarde, Jean-Luc Préel et François Rochebloine""")
ont_vote(dates[0], "nc" ,  0, u"""MM. Thierry Benoit, Charles de Courson, Francis Hillmeyer, Mme Colette Le Moal et M. Claude Leteurtre""")

ont_vote(dates[0], "ump",  1, u"""MM. Élie Aboud, Manuel Aeschlimann, Yves Albarello, Alfred Almont, Mme Nicole Ameline, MM. Benoist Apparu, Jean Auclair, Mme Martine Aurillac, MM. Pierre-Christophe Baguet, Patrick Balkany, Jean Bardet, Mme Brigitte Barèges, M. François Baroin, Mme Sylvia Bassot, MM. Patrick Beaudouin, Jean-Claude Beaulieu, Jacques Alain Bénisti, Jean-Louis Bernard, Marc Bernier, Xavier Bertrand, Jean-Yves Besselat, Gabriel Biancheri, Jérôme Bignon, Jean-Marie Binetruy, Claude Birraux, Etienne Blanc, Emile Blessig, Roland Blum, Claude Bodin, Philippe Boennec, Marcel Bonnot, Jean-Yves Bony, Jean-Claude Bouchet, Gilles Bourdouleix, Mme Chantal Bourragué, MM. Loïc Bouvard, Michel Bouvard, Mmes Valérie Boyer, Françoise Branget, M. Xavier Breton, Mme Françoise Briand, MM. Philippe Briand, Bernard Brochand, Mme Chantal Brunel, MM. Michel Buillard, Patrice Calméjane, François Calvet, Bernard Carayon, Pierre Cardo, Gilles Carrez, Mme Joëlle Ceccaldi-Raynaud, MM. Yves Censi, Hervé de Charette, Jean-Paul Charié, Jérôme Chartier, Gérard Cherpion, Jean-François Chossy, Jean-Louis Christ, Dino Cinieri, Eric Ciotti, Pascal Clément, Philippe Cochet, Georges Colombier, Mme Geneviève Colot, MM. Jean-François Copé, François Cornut-Gentille, Louis Cosyns, Edouard Courtial, Alain Cousin, Jean-Yves Cousin, Jean-Michel Couve, Mme Marie-Christine Dalloz, MM. Olivier Dassault, Marc-Philippe Daubresse, Patrice Debray, Bernard Debré, Jean-Pierre Decool, Bernard Deflesselles, Rémi Delatte, Richard Dell'Agnola, Mme Sophie Delong, MM. Yves Deniaud, Bernard Depierre, Vincent Descoeur, Nicolas Dhuicq, Eric Diard, Michel Diefenbacher, Jacques Domergue, Jean-Pierre Door, Dominique Dord, Mme Cécile Dumoulin, MM. Jean-Pierre Dupont, Christian Estrosi, Gilles d' Ettore, Daniel Fasquelle, Jean-Michel Ferrand, Alain Ferry, Daniel Fidelin, Jean-Claude Flory, Nicolas Forissier, Mme Marie-Louise Fort, MM. Jean-Michel Fourgous, Marc Francina, Mme Arlette Franco, MM. Pierre Frogier, Yves Fromion, Mme Cécile Gallez, MM. Sauveur Gandolfi-Scheit, Jean-Paul Garraud, Claude Gatignol, Gérard Gaudron, Hervé Gaymard, Guy Geoffroy, Bernard Gérard, Alain Gest, Franck Gilard, Georges Ginesta, Jean-Pierre Giran, Louis Giscard d'Estaing, Claude Goasguen, Didier Gonzales, Jean-Pierre Gorges, Philippe Gosselin, Philippe Goujon, Michel Grall, Mme Claude Greff, M. Jean Grenet, Mme Anne Grommerch, MM. François Grosdidier, Jacques Grosperrin, Mme Arlette Grosskost, MM. Serge Grouard, Louis Guédon, Mme Françoise Guégot, MM. Jean-Claude Guibal, Jean-Jacques Guillet, Gérard Hamel, Michel Havard, Laurent Hénart, Michel Herbillon, Antoine Herth, Mme Françoise Hostalier, MM. Philippe Houillon, Guénhaël Huet, Sébastien Huyghe, Mme Jacqueline Irles, MM. Christian Jacob, Paul Jeanneteau, Mme Maryse Joissains-Masini, MM. Marc Joulaud, Didier Julia, Christian Kert, Jacques Kossowski, Patrick Labaune, Mme Fabienne Labrette-Ménager, MM. Marc Laffineur, Jacques Lamblin, Mme Marguerite Lamour, MM. Jean-François Lamour, Pierre Lasbordes, Charles de La Verpillière, Thierry Lazaro, Robert Lecou, Frédéric Lefebvre, Jean-Marc Lefranc, Guy Lefrand, Michel Lejeune, Pierre Lellouche, Dominique Le Mèner, Jacques Le Nay, Jean-Claude Lenoir, Jean-Louis Léonard, Jean Leonetti, Pierre Lequiller, Céleste Lett, Mme Geneviève Levy, MM. François Loos, Gérard Lorgeoux, Mme Gabrielle Louis-Carabin, MM. Daniel Mach, Guy Malherbe, Richard Mallié, Jean-François Mancel, Alain Marc, Jean-Pierre Marcon, Thierry Mariani, Mme Christine Marin, M. Hervé Mariton, Mme Muriel Marland-Militello, M. Philippe-Armand Martin, Mme Henriette Martinez, MM. Alain Marty, Jacques Masdeu-Arus, Jean-Claude Mathis, Jean-Philippe Maurer, Pierre Méhaignerie, Christian Ménard, Damien Meslot, Philippe Meunier, Jean-Claude Mignon, Gérard Millet, Mme Marie-Anne Montchamp, MM. Pierre Morange, Pierre Morel-A-L'Huissier, Philippe Morenvillier, Jean-Marie Morisset, Georges Mothron, Etienne Mourrut, Alain Moyne-Bressand, Renaud Muselier, Jacques Myard, Jean-Marc Nesme, Yves Nicolin, Patrick Ollier, Mme Françoise de Panafieu, MM. Bertrand Pancher, Yanick Paternotte, Christian Patria, Mme Béatrice Pavy, MM. Jacques Pélissard, Dominique Perben, Bernard Perrut, Etienne Pinte, Michel Piron, Henri Plagnol, Serge Poignant, Mme Bérengère Poletti, M. Axel Poniatowski, Mme Josette Pons, MM. Daniel Poulou, Christophe Priou, Jean Proriol, Didier Quentin, Michel Raison, Eric Raoult, Frédéric Reiss, Jean-Luc Reitzer, Jacques Remiller, Bernard Reynès, Franck Reynier, Franck Riester, Jean Roatta, Didier Robert, Arnaud Robinet, Camille de Rocca Serra, Mme Marie-Josée Roig, M. Jean-Marie Rolland, Mme Valérie Rosso-Debord, MM. Jean-Marc Roubaud, Max Roustan, Martial Saddier, Francis Saint-Léger, Bruno Sandras, François Scellier, André Schneider, Jean-Pierre Schosteck, Jean-Marie Sermier, Georges Siffredi, Jean-Pierre Soisson, Michel Sordi, Daniel Spagnou, Eric Straumann, Mme Michèle Tabarot, MM. Jean-Charles Taugourdeau, Guy Teissier, Michel Terrot, Jean-Claude Thomas, Dominique Tian, Jean Tiberi, Alfred Trassy-Paillogues, Jean Ueberschlag, Yves Vandewalle, François Vannson, Mmes Isabelle Vasseur, Catherine Vautrin, MM. Patrice Verchère, Jean-Sébastien Vialatte, René-Paul Victoria, Philippe Vitel, Gérard Voisin, Michel Voisin, Jean-Luc Warsmann, André Wojciechowski et Gaël Yanno""")
ont_vote(dates[0], "ump", -1, u"""MM. François Goulard, Denis Jacquat, Franck Marlin, Lionel Tardy, Christian Vanneste et Michel Zumkeller""")
ont_vote(dates[0], "ump",  0, u"""MM. Jean-Paul Anciaux, Yves Bur, Olivier Carré, René Couanau, Henri Cuq, Lucien Degauchy, Yannick Favennec, François-Michel Gonnot, Jean-Pierre Grand, Christophe Guilloteau, Pierre Lang, Jacques Le Guen, Lionnel Luca, Patrice Martin-Lalande, Jean-Frédéric Poisson, Georges Tron et Mme Marie-Jo Zimmermann""")

ont_vote(dates[0], "xxx", -1, u"""MM. Abdoulatifou Aly, François Bayrou, Mme Véronique Besse, MM. Nicolas Dupont-Aignan, Jean Lassalle, Dominique Souchet et François-Xavier Villain""")

# Vote du 15/9/2009
ont_vote(dates[1], "gdr", -1, u"""Mme Marie-Hélène Amiable, M. François Asensi, Mmes Huguette Bello, Martine Billard, MM. Alain Bocquet, Patrick Braouezec, Jean-Pierre Brard, Mme Marie-George Buffet, MM. Jean-Jacques Candelier, André Chassaigne, Yves Cochet, Jacques Desallangre, Marc Dolez, Mme Jacqueline Fraysse, MM. André Gerin, Pierre Gosnat, Maxime Gremetz, Jean-Paul Lecoq, Noël Mamère, Roland Muzeau, Daniel Paul, François de Rugy, Jean-Claude Sandrier et Michel Vaxès""")

ont_vote(dates[1], "src",  1, u"""MM. Jack Lang, Jean Michel et Jean-Claude Perez""")
ont_vote(dates[1], "src", -1, u"""Mmes Patricia Adam, Sylvie Andrieux, MM. Jean-Marc Ayrault, Jean-Paul Bacquet, Dominique Baert, Jean-Pierre Balligand, Gérard Bapt, Claude Bartolone, Jacques Bascou, Christian Bataille, Mmes Delphine Batho, Chantal Berthelot, M. Jean-Louis Bianco, Mme Gisèle Biémouret, MM. Serge Blisko, Patrick Bloche, Daniel Boisserie, Maxime Bono, Jean-Michel Boucheron, Mme Marie-Odile Bouillé, M. Christophe Bouillon, Mme Monique Boulestin, M. Pierre Bourguignon, Mme Danielle Bousquet, MM. François Brottes, Alain Cacheux, Jérôme Cahuzac, Jean-Christophe Cambadélis, Thierry Carcenac, Christophe Caresche, Mme Martine Carrillon-Couvreur, MM. Laurent Cathala, Bernard Cazeneuve, Guy Chambefort, Jean-Paul Chanteguet, Gérard Charasse, Alain Claeys, Jean-Michel Clément, Mme Marie-Françoise Clergeau, M. Pierre Cohen, Mmes Catherine Coutelle, Pascale Crozon, M. Frédéric Cuvillier, Mme Claude Darciaux, MM. Pascal Deguilhem, Guy Delcourt, Michel Delebarre, François Deluga, Bernard Derosier, Michel Destot, René Dosière, Tony Dreyfus, Jean-Pierre Dufau, William Dumas, Mme Laurence Dumont, MM. Jean-Louis Dumont, Jean-Paul Dupré, Yves Durand, Mme Odette Duriez, MM. Philippe Duron, Olivier Dussopt, Christian Eckert, Henri Emmanuelli, Mme Corinne Erhel, MM. Laurent Fabius, Albert Facon, Mme Martine Faure, M. Hervé Feron, Mmes Aurélie Filippetti, Geneviève Fioraso, M. Pierre Forgues, Mme Valérie Fourneyron, MM. Michel Françaix, Jean-Claude Fruteau, Jean-Louis Gagnaire, Mme Geneviève Gaillard, MM. Guillaume Garot, Jean Gaubert, Mme Catherine Génisson, M. Jean-Patrick Gille, Mme Annick Girardin, MM. Joël Giraud, Jean Glavany, Daniel Goldberg, Gaëtan Gorce, Mme Pascale Got, MM. Marc Goua, Jean Grellier, Mme Elisabeth Guigou, MM. David Habib, François Hollande, Mme Sandrine Hurel, MM. Christian Hutin, Jean-Louis Idiart, Mme Françoise Imbert, MM. Michel Issindou, Eric Jalton, Serge Janquin, Henri Jibrayel, Régis Juanico, Armand Jung, Jean-Pierre Kucheida, Mme Conchita Lacuey, MM. Jérôme Lambert, François Lamy, Mme Colette Langlade, MM. Jean Launay, Jean-Yves Le Bouillonnec, Mme Marylise Lebranchu, MM. Patrick Lebreton, Gilbert Le Bris, Jean-Yves Le Déaut, Michel Lefait, Jean-Marie Le Guen, Mme Annick Le Loch, M. Patrick Lemasle, Mme Catherine Lemorton, MM. Bruno Le Roux, Jean-Claude Leroy, Bernard Lesterlin, Serge Letchimy, Mme Martine Lignières-Cassou, MM. Apeleto Albert Likuvalu, François Loncle, Victorin Lurel, Jean Mallot, Louis-Joseph Manscour, Mmes Jacqueline Maquet, Marie-Lou Marcel, MM. Jean-René Marsac, Philippe Martin, Mmes Martine Martinel, Frédérique Massat, MM. Gilbert Mathon, Didier Mathus, Mme Sandrine Mazetier, MM. Michel Ménard, Kléber Mesquida, Didier Migaud, Pierre Moscovici, Pierre-Alain Muet, Philippe Nauche, Henri Nayrou, Alain Néri, Mmes Marie-Renée Oget, Françoise Olivier-Coupeau, MM. Michel Pajon, Christian Paul, Mme George Pau-Langevin, M. Jean-Luc Perat, Mmes Marie-Françoise Pérol-Dumont, Martine Pinville, MM. Philippe Plisson, François Pupponi, Mme Catherine Quéré, MM. Jean-Jack Queyranne, Dominique Raimbourg, Simon Renucci, Mmes Marie-Line Reynaud, Chantal Robin-Rodrigo, MM. Alain Rodet, Marcel Rogemont, Bernard Roman, Alain Rousset, Patrick Roy, Michel Sainte-Marie, Mme Odile Saugues, M. Christophe Sirugue, Mme Christiane Taubira, M. Pascal Terrasse, Mme Marisol Touraine, MM. Jean-Louis Touraine, Philippe Tourtelier, Jean Jacques Urvoas, Daniel Vaillant, Jacques Valax, André Vallini, Manuel Valls, Michel Vauzelle, Michel Vergnier, André Vézinhet, Alain Vidalies, Jean-Michel Villaumé, Jean-Claude Viollet et Philippe Vuilque""")
ont_vote(dates[1], "src",  0, u"""M. Paul Giacobbi, Mmes Dominique Orliac et Sylvia Pinel""")

ont_vote(dates[1], "nc" ,  1, u"""MM. Jean-Pierre Abelin, Charles de Courson, Michel Hunault, Olivier Jardé, Yvan Lachaud, Mme Colette Le Moal, MM. Maurice Leroy, Claude Leteurtre, Nicolas Perruchot, Rudy Salles, André Santini, François Sauvadet, Marc Vampa, Francis Vercamer et Philippe Vigier""")
ont_vote(dates[1], "nc" , -1, u"""MM. Jean Dionis du Séjour, Philippe Folliot, Jean-Christophe Lagarde et François Rochebloine""")
ont_vote(dates[1], "nc" ,  0, u"""MM. Stéphane Demilly, Raymond Durand et Jean-Luc Préel""")

ont_vote(dates[1], "ump",  1, u"""MM. Élie Aboud, Manuel Aeschlimann, Yves Albarello, Alfred Almont, Mme Nicole Ameline, M. Jean Auclair, Mme Martine Aurillac, MM. Pierre-Christophe Baguet, Patrick Balkany, Jean Bardet, Mme Brigitte Barèges, M. François Baroin, Mme Sylvia Bassot, MM. Patrick Beaudouin, Jean-Claude Beaulieu, Jacques Alain Bénisti, Jean-Louis Bernard, Marc Bernier, Xavier Bertrand, Jean-Yves Besselat, Gabriel Biancheri, Jérôme Bignon, Jean-Marie Binetruy, Claude Birraux, Etienne Blanc, Emile Blessig, Roland Blum, Philippe Boennec, Marcel Bonnot, Jean-Yves Bony, Jean-Claude Bouchet, Gilles Bourdouleix, Bruno Bourg-Broc, Mme Chantal Bourragué, M. Loïc Bouvard, Mme Françoise Branget, M. Xavier Breton, Mme Françoise Briand, MM. Philippe Briand, Bernard Brochand, Mme Chantal Brunel, MM. Michel Buillard, Dominique Caillaud, Patrice Calméjane, François Calvet, Bernard Carayon, Pierre Cardo, Gilles Carrez, Mme Joëlle Ceccaldi-Raynaud, MM. Yves Censi, Hervé de Charette, Jean-Paul Charié, Jérôme Chartier, Gérard Cherpion, Jean-François Chossy, Jean-Louis Christ, Dino Cinieri, Eric Ciotti, Pascal Clément, Philippe Cochet, Georges Colombier, Mme Geneviève Colot, MM. Jean-François Copé, François Cornut-Gentille, Louis Cosyns, René Couanau, Edouard Courtial, Alain Cousin, Jean-Yves Cousin, Jean-Michel Couve, Mme Marie-Christine Dalloz, MM. Olivier Dassault, Marc-Philippe Daubresse, Bernard Deflesselles, Rémi Delatte, Richard Dell'Agnola, Mme Sophie Delong, MM. Yves Deniaud, Bernard Depierre, Vincent Descoeur, Nicolas Dhuicq, Eric Diard, Michel Diefenbacher, Jacques Domergue, Jean-Pierre Door, Dominique Dord, Mme Cécile Dumoulin, MM. Jean-Pierre Dupont, Gilles d' Ettore, Daniel Fasquelle, Jean-Michel Ferrand, Alain Ferry, Daniel Fidelin, Jean-Claude Flory, Nicolas Forissier, Mme Marie-Louise Fort, MM. Jean-Michel Fourgous, Marc Francina, Mme Arlette Franco, MM. Pierre Frogier, Yves Fromion, Mme Cécile Gallez, MM. Sauveur Gandolfi-Scheit, Jean-Paul Garraud, Claude Gatignol, Gérard Gaudron, Hervé Gaymard, Guy Geoffroy, Bernard Gérard, Alain Gest, Franck Gilard, Georges Ginesta, Charles-Ange Ginesy, Jean-Pierre Giran, Louis Giscard d'Estaing, Didier Gonzales, Philippe Gosselin, Michel Grall, Mme Claude Greff, M. Jean Grenet, Mme Anne Grommerch, MM. François Grosdidier, Jacques Grosperrin, Mme Arlette Grosskost, MM. Serge Grouard, Louis Guédon, Mme Françoise Guégot, MM. Jean-Claude Guibal, Gérard Hamel, Michel Havard, Laurent Hénart, Michel Herbillon, Antoine Herth, Mme Françoise Hostalier, MM. Philippe Houillon, Guénhaël Huet, Sébastien Huyghe, Mme Jacqueline Irles, MM. Christian Jacob, Paul Jeanneteau, Yves Jego, Mme Maryse Joissains-Masini, MM. Marc Joulaud, Didier Julia, Christian Kert, Jacques Kossowski, Patrick Labaune, Mme Fabienne Labrette-Ménager, MM. Marc Laffineur, Jacques Lamblin, Mme Marguerite Lamour, MM. Jean-François Lamour, Pierre Lasbordes, Charles de La Verpillière, Thierry Lazaro, Robert Lecou, Jean-Marc Lefranc, Guy Lefrand, Michel Lejeune, Jacques Le Nay, Jean-Claude Lenoir, Jean-Louis Léonard, Jean Leonetti, Pierre Lequiller, Céleste Lett, Mme Geneviève Levy, MM. François Loos, Gérard Lorgeoux, Mme Gabrielle Louis-Carabin, MM. Daniel Mach, Guy Malherbe, Richard Mallié, Jean-François Mancel, Alain Marc, Jean-Pierre Marcon, Thierry Mariani, Mme Christine Marin, M. Hervé Mariton, Mme Muriel Marland-Militello, M. Philippe-Armand Martin, Mme Henriette Martinez, MM. Alain Marty, Jean-Claude Mathis, Jean-Philippe Maurer, Pierre Méhaignerie, Christian Ménard, Damien Meslot, Philippe Meunier, Jean-Claude Mignon, Pierre Morange, Pierre Morel-A-L'Huissier, Philippe Morenvillier, Jean-Marie Morisset, Georges Mothron, Etienne Mourrut, Alain Moyne-Bressand, Renaud Muselier, Jacques Myard, Jean-Marc Nesme, Yves Nicolin, Patrick Ollier, Mme Françoise de Panafieu, MM. Bertrand Pancher, Yanick Paternotte, Christian Patria, Mme Béatrice Pavy, MM. Jacques Pélissard, Dominique Perben, Bernard Perrut, Etienne Pinte, Michel Piron, Henri Plagnol, Serge Poignant, Axel Poniatowski, Mme Josette Pons, MM. Daniel Poulou, Christophe Priou, Jean Proriol, Didier Quentin, Michel Raison, Eric Raoult, Frédéric Reiss, Jean-Luc Reitzer, Bernard Reynès, Franck Reynier, Franck Riester, Jean Roatta, Didier Robert, Arnaud Robinet, Mme Marie-Josée Roig, M. Jean-Marie Rolland, Mme Valérie Rosso-Debord, MM. Jean-Marc Roubaud, Max Roustan, Martial Saddier, Francis Saint-Léger, Bruno Sandras, François Scellier, André Schneider, Jean-Pierre Schosteck, Jean-Marie Sermier, Georges Siffredi, Jean-Pierre Soisson, Michel Sordi, Daniel Spagnou, Eric Straumann, Mme Michèle Tabarot, MM. Jean-Charles Taugourdeau, Guy Teissier, Michel Terrot, Jean-Claude Thomas, Dominique Tian, Jean Tiberi, Alfred Trassy-Paillogues, Jean Ueberschlag, Yves Vandewalle, François Vannson, Mmes Isabelle Vasseur, Catherine Vautrin, MM. Patrice Verchère, Jean-Sébastien Vialatte, René-Paul Victoria, Philippe Vitel, Jean-Luc Warsmann, André Wojciechowski, Gaël Yanno et Mme Marie-Jo Zimmermann""")
ont_vote(dates[1], "ump", -1, u"""MM. André Flajolet, François Goulard, Dominique Le Mèner, Franck Marlin, Lionel Tardy et Christian Vanneste""")
ont_vote(dates[1], "ump",  0, u"""MM. Jean-Paul Anciaux, Claude Bodin, Jean-Pierre Grand, Christophe Guilloteau, Jacques Le Guen, Alain Suguenot, Georges Tron, Gérard Voisin et Michel Voisin""")

ont_vote(dates[1], "xxx", -1, u"""MM. Abdoulatifou Aly, François Bayrou, Nicolas Dupont-Aignan, Daniel Garrigue, Jean Lassalle et François-Xavier Villain""")
ont_vote(dates[1], "xxx",  0, u"""Mme Véronique Besse et M. Dominique Souchet""")


# Vérification
print len(DEPUTES), "députés"

for depute in DEPUTES.values():
  if not depute.votes:
    print u"WARNING a signé mais n'a jamais voté : '%s' '%s'" % (depute.nom, depute.prenom)
print

# Correction
Depute("le fur", "marc").set_groupe("ump")

# Écriture de tableaux récapitulatifs
def calc_case(date, orientation, pacte):
  nbs = { -1 : 0, 0 : 0, 1 : 0 }
  for depute in DEPUTES.values():
    if depute.orientation == u"xxx": continue
    if (not orientation is None) and (depute.orientation != orientation): continue
    if (not pacte       is None) and (depute.pacte       != pacte      ): continue
    nbs[depute.get_vote(date)] += 1
  return u"%s (%s/%s/%s)" % (nbs[1] + nbs[-1] + nbs[0], nbs[1], nbs[-1], nbs[0])
def cherche(date, orientation, pacte, vote):
  deputes = []
  for depute in DEPUTES.values():
    if depute.orientation == u"xxx": continue
    if (not orientation is None) and (depute.orientation    != orientation): continue
    if (not pacte       is None) and (depute.pacte          != pacte      ): continue
    if (not vote        is None) and (depute.get_vote(date) != vote       ): continue
    deputes.append(depute)
  return deputes

def print_tableau(tableau):
  taille_cols = [0] * len(tableau[0])
  for ligne in tableau:
    col = 0
    for case in ligne:
      if len(case) > taille_cols[col]: taille_cols[col] = len(case)
      col += 1
  for ligne in tableau:
    col = 0
    for case in ligne:
      print case + u" " * (taille_cols[col] - len(case) + 2),
      col += 1
    print
  
print "----- RÉCAPITULATIF -----"
for date in dates:
  print date, u": total (pour/contre/abstention)"
  tableau = [[u""] * 4] * 4
  tableau = [[u""              , u"Gauche"                      , u"Droite"                      , u"Totaux"],
             [u"Signataire"    , calc_case(date, "gauche", 1   ), calc_case(date, "droite", 1   ), calc_case(date, None, 1   )],
             [u"Non-signataire", calc_case(date, "gauche", 0   ), calc_case(date, "droite", 0   ), calc_case(date, None, 0   )],
             [u"Totaux"        , calc_case(date, "gauche", None), calc_case(date, "droite", None), calc_case(date, None, None)],
             ]
  print_tableau(tableau)
  print


# Écriture du fichier de données
f = open("/tmp/analyse_candidatsfr.csv", "w")
print >> f, "nom,prenom,groupe,orientation,pacte,vote1,vote2"
for depute in DEPUTES.values():
  if depute.orientation == u"xxx": continue
  l = [depute.nom, depute.prenom, depute.groupe, depute.orientation, unicode(depute.pacte)]
  for date in dates:
    l.append(unicode(depute.get_vote(date)))
  print >> f, u",".join(l).encode("utf8")
  
f.close()

print
print "Les traîtres : ils ont signé le pacte puis voté pour Hadopi :"
for depute in DEPUTES.values():
  if depute.pacte:
    for date in dates:
      if depute.get_vote(date) == 1:
        print "  ", depute.nom, depute.prenom, depute.groupe
        break
      
print

#from rpy import *

#tableau = r.read_table("/tmp/analyse_candidatsfr.csv", sep=",", header=True)

#anova = r.aov(r("vote1 ~ orientation * pacte"), data = tableau)


#print str(r.summary(anova))
#x=r(""" aov(vote1 ~ orientation * pacte,data=tableau)""")

import popen2
f1, f2 = popen2.popen4("R --no-readline --no-save")
f2.write("""
t = read.table("/tmp/analyse_candidatsfr.csv", sep=",", header=TRUE)

c = aov(pacte ~ orientation,data=t)
summary(c)

bartlett.test(vote1 ~ orientation * pacte,data=t)
bartlett.test(vote2 ~ orientation * pacte,data=t)

c = aov(vote1 ~ orientation * pacte,data=t)
summary(c)

c = aov(vote2 ~ orientation * pacte,data=t)
summary(c)

t.test(t$vote1, t$vote2, paired = TRUE)
""")
f2.flush()
f2.close()
print f1.read() 





#Rcode= """

#t = read.table("/tmp/analyse_candidatsfr.csv", sep=",", header=TRUE)
#c = aov(vote1 ~ orientation * pacte,data=t)
#str(summary(c))"""

#x = r(Rcode)
#print x

resultat = """

                        Df Sum Sq Mean Sq   F value Pr(>F)    
orientation              1 441.08  441.08 3318.6206 <2e-16 ***
signataire               1   0.37    0.37    2.7771 0.0962 .  
orientation:signataire   1   0.21    0.21    1.5725 0.2104    
Residuals              547  72.70    0.13                     
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 

"""


